This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I’m learning about bit-banding and am making good progress. However, I’m a bit confused why the bit banding alias words are spaced 4 apart for each bit of a word in the bit band region,
eg. Taking the first word in the SRAM bit band region 0x2000.0000 and it’s accompanying bit band alias words for each of its’ bits:
Bit-Band Region Aliased Equivalent
0x20000000 bit[0] 0x22000000 bit[0]
0x20000000 bit[1] 0x22000004 bit[0] (4 words ahead)
0x20000000 bit[2] 0x22000008 bit[0] (another 4 words ahead, etc, etc)
… …
0x20000000 bit[31] 0x2200007C bit[0]
Why does each word in the bit-band alias region need to be 4 apart. I’m mainly just curious.
Why couldn’t it be like this:
Bit-Band Region Aliased Equivalent
0x20000000 bit[0] 0x22000000 bit[0]
0x20000000 bit[1] 0x22000001 bit[0]
0x20000000 bit[2] 0x22000002 bit[0] (and so forth)
Is it just something in the design of the hardware and we really don’t need to care, or is there some logical reason that I can’t see.
The About bit-banding section of the ARM® Cortex®‑M4 Processor Technical Reference Manual says:Keith Scott said:Is it just something in the design of the hardware and we really don’t need to care, or is there some logical reason that I can’t see
i.e. it was the design intention for the bit-band aliases to be spaced 4 apart to use word-aligned addresses.Bit-banding enables every individual bit in the bit-banding region to be directly accessible from a word-aligned address using a single LDR instruction.
The Address alignment section of the Cortex-M4 Devices Generic User Guide explains the benefit of using aligned addresses:
Unaligned accesses are usually slower than aligned accesses. In addition, some memory regions might not support unaligned accesses. Therefore, ARM recommends that programmers ensure that accesses are aligned.
The ARMv7-M address space is byte addressable. Therefore the addresses 0x22000000 and 0x22000004 are four bytes apart, or one 32-bit word apart.Keith Scott said:So in my opening example, where there is bit-band alias address 0x22000000 (representing bit[0]) and 0x22000004 (representing bit[1]), I took it they were 4 WORDS apart.
Could anyone confirm or correct that assumption.
See the A3.1 Address space section in the ARMv7-M Architecture Reference Manual
I downloaded that manual and checked out the section you mentioned. For others reference and understanding, here's part of the explanation from the manual:
The ARMv7-M architecture uses a single, flat address space of 2(to power 32) 8-bit bytes.
Byte addresses are treated as unsigned numbers, running from 0 to 2(to power 32) - 1.
This address space is regarded as consisting of 2(to power 30) 32-bit words, each of whose addresses is word-aligned, meaning that the address is divisible by 4.
The word whose word-aligned address is A consists of the four bytes with addresses A, A+1, A+2, and A+3.
The address space can also be considered as consisting of 2(to power 31) 16-bit halfwords, each of whose addresses is halfword-aligned, meaning that the address is divisible by 2.
The halfword whose halfword-aligned address is A consists of the two bytes with addresses A and A+1.
It all makes sense now. I would never have guessed a 32 bit micro used a byte divisible address space. So effectively each 32 bit WORD address space is 4 apart; 0, 4, 8, 12, etc (bytes that are word aligned).
Keith.
Hi Keith,
Keith Scott said:So effectively each 32 bit WORD address space is 4 apart; 0, 4, 8, 12, etc (bytes that are word aligned).
Just a small correction on "(bytes that are word aligned)", the individual bytes are still byte (8-bit) aligned. For example, you can write to a byte address (i.e. 0x1001 or 0x1002) using a STRB instruction. The byte addresses are not word aligned. But you meant to say that 4 bytes making up a word is word aligned then you are correct.
Don't want to complicate things further, the Cortex-M architecture also supports unaligned access which means you can possibly do a STR (a 32-bit write) to an address that is not word aligned. The CPU simply breaks up an unaligned access into multiple aligned accesses. However, unaligned access in the bit-band region will produce unpredictable behavior. Disregard the last paragraph if you wish as it is not directly related to your original question. :-)
Charles Tsai said:The ARM architecture is only byte addressable, not bit addressable. If the ARM architecture is bit addressable then you would not need the bit-banging using the alias address at all.
Bit banging is something totally different, and is done without hardware support or acceleration, at least usually.