In the realm of embedded systems, manipulating individual bits within memory or peripheral registers is an everyday task. But with traditional methods, this seemingly simple task often leads to complexities, inefficiencies, and potential pitfalls. Bit-banding is a feature in ARM Cortex-M architectures that elegantly tackles these challenges.
𝐖𝐡𝐲 𝐮𝐬𝐞 𝐁𝐢t 𝐁𝐚𝐧𝐝𝐢𝐧𝐠?
Imagine you’re in a library, and you want to borrow a specific book. Typically, you’d need to:
– Visit the shelf (read the current list of borrowed books).
– Remove the book you want (modify the list).
– Update the library’s records with the new list (write the modified list back).
In the world of embedded systems, when you need to modify a single bit within a memory word, you often follow a similar process:
– Read the entire word from memory.
– Modify the desired bit.
– Write the entire word back to memory.
This “read-modify-write” sequence isn’t just complex; it’s risky. What if, between your reading and writing, another process modifies the word? You’d unintentionally overwrite that change, leading to data corruption and unpredictable behaviour.
In the ARM Cortex-M3 and M4 architectures, the memory map is well-defined, with specific regions allocated for various tasks. Two of these regions, important to our discussion on bit-banding, are the bit-band region and the alias region.

𝐁𝐢𝐭-𝐁𝐚𝐧𝐝 𝐑𝐞𝐠𝐢𝐨𝐧:
– This is the actual memory space where the data resides.
– It spans a 1MB block of memory, starting from 0x20000000 and ending at 0x200FFFFF.
– Think of this region as a large storage room where each bit of data is like an item stored in a box.
𝐀𝐥𝐢𝐚𝐬 𝐑𝐞𝐠𝐢𝐨𝐧:
– This is a much larger memory space dedicated to providing direct access to individual bits in the bit-band region.
– It’s 32 times larger than the bit-band region, ranging from 0x22000000 to 0x23FFFFFF.
– Imagine this region as a massive directory or index, where each bit from the bit-band region gets its own dedicated section.
For every single bit in the bit-band region, there’s a corresponding 32-bit word in the alias region. This means, if you want to manipulate a specific bit, you don’t need to fetch the entire word, alter the bit, and then write it back. Instead, you directly access the corresponding 32-bit word in the alias region and make your changes there, ensuring atomicity and efficiency.
Consider the ARM Cortex-M3 and M4 architectures:
Numerical Example:
Bit-Band Region: A 1MB block from 0x20000000 to 0x200FFFFF.
Alias Region: A region 32 times larger, from 0x22000000 to 0x23FFFFFF.
Now, let’s say you want to modify the 5th bit of the word at address 0x20000020. Using bit-banding, you’d access its alias address:
Alias address = Alias base + (32 * (Bit-band address – Bit-band base)) + (4 * bit number)
Plug in our values:
Alias address = 0x22000000 + (32 * (0x20000020 – 0x20000000)) + (4 * 5) = 0x220000A8
By simply writing a value to 0x220000A8, you’d be directly modifying the 5th bit of the word at 0x20000020.
Img Src: Cortex M3 Technical reference manual.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An Article by: Yashwanth Naidu Tikkisetty
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
