Where do I see which Port I use while bit-banding?
Ah. I didn't notice that you had bits on separate PORTs. That will make bit-banding less attractive ![]()
if you wanted to access "xxxx_bits[bitnumber]", you'd need a separate definition for each port.
This sample looks like it creates the correct object code; it's not actually tested, and I'll caution again that I haven't actually tried to use bit-banding before...
#include <sam.h>
// create an address in the bitband region for a single register in IO space.
// This can then be accessed as an array indexed by bit number (for example)
#define BITBAND_REG(addr) ((volatile int*)(((unsigned int)addr - 0x40000000)*32 + 0x42000000))
// define bit-accessible aliases for the PIO Output data register.
// (don't forget that you need to fiddle with "PIO Output Write Enable Register")
#define PORTA_BB_BITS BITBAND_REG(&PIOA->PIO_ODSR)
#define PORTB_BB_BITS BITBAND_REG(&PIOB->PIO_ODSR)
#define PORTC_BB_BITS BITBAND_REG(&PIOC->PIO_ODSR)
int main() {
PORTA_BB_BITS[17] = 1;
if (PORTB_BB_BITS[5]) {
PORTC_BB_BITS[3] = 1;
}
}
PORTA_BB_BITS[17] = 1;
0: 4a05 ldr r2, [pc, #20] ; (18 <main+0x18>)
2: 2301 movs r3, #1
4: 6013 str r3, [r2, #0]
if (PORTB_BB_BITS[5]) {
6: f502 527f add.w r2, r2, #16320 ; 0x3fc0
a: 3210 adds r2, #16
c: 6812 ldr r2, [r2, #0]
e: b10a cbz r2, 14 <main+0x14>
PORTC_BB_BITS[3] = 1;
10: 4a02 ldr r2, [pc, #8] ; (1c <main+0x1c>)
12: 6013 str r3, [r2, #0]
}
}
14: 2000 movs r0, #0
16: 4770 bx lr
18: 43c1c744 .word 0x43c1c744
1c: 43c2470c .word 0x43c2470c
People on the ARM community forums note that bit-banding doesn't seem to have been very successful. Assorted compiler extensions haven't gotten implemented and the feature is not present on M0 or M7 chips ![]()
https://community.arm.com/tools/f/discussions/7142/ld-scripts-is-the-best-approach-for-bitbanding-with-gcc
https://community.arm.com/tools/f/discussions/8856/arm-compiler-6-clang-and-bit-banding