ATSAM3N Cortex-M3 RAM Bit Banding

armatmelcortex-m3

If i do not use Bit Banding feature on ATSAM3N, this region, it will used by the compiler for the program? Or it will stay unused?

What if my program, randomly (by itself) should need to assign and access this region?

Best Answer

The linker controlled by a link script (not the compiler), places variables and code at specific memory locations. Normally, the linker script does not attempt to place variables or code, within the Bit-band regions.

So, unless you write a liner script to explicitly place something into the bit-band regions' address ranges, the linker will not normally place anything there.

However, those regions are just 'overlays'; bit-banding only provides an alternative address range to access the RAM or peripherals which are already accessible with their own 'real' addresses. The Bit-band regions do not provide any extra storage, just a different access mechanism, so IMHO it is a bit misleading to ask "Or it will stay unused?".

Put another way, the compiler+linker can use all available RAM, irrespective of using Bit-band addresses to access it. Bit-band addressing is only extra addressing hardware.

Bit-band addressing is used to access peripheral registers or RAM as individual bits. This can be very useful to implement atomic bit-access, or faster access to individual bits, for example to control pins connected to ports.

Each Bit-band address contains a 1-bit value. So they are useful for boolean values, but little else.

The easy way to take advantage of bit-band functionality to test or update bits within RAM or peripherals is via C/C++. ARM documentation, and the books by J.Yiu, explain how to exploit bit band addressing; set the value of unsigned int (32 bit) pointer to an address within the bit-band range, e.g.
volatile uint32_t GPIOA_BASE = (uint32_t*) 0x40010800; (not correct bit-band address)

Then any access to memory or peripheral registers via a correctly initialised pointer variable will actually read or write a single bit within the real RAM or peripheral register:
*GPIOA_BASE = 1; // set bit to true