I wonder to know is there anyone who define a variable in bit-band area in c programming language for cortex-M3.
I have followed the compiler attribute based on the below link www.keil.com/.../armcc_chr1359124215827.htm but when I check the address range, it has been defined out of the scope of bit-banding and it seems the attribute doesn't effect the code even if I use this code __attribute__((at())) ?
As far as I know bit-banded area map each bit into 8 bit if we write 0b00000001 into the 8 bit the corresponding bit become one and vice versa but what I want to know is, it has been said that bit-banded area help us to toggle bit in a atomic way (what I'm looking for) ,how could be accomplished !?
Have you looked at the processor-specific header files?
They show how the individual bits of different peripheral registers are configured.
By having an int represent a bit directly in the memory controller, the processor does not need to perform a read + modify + write to set or clear a bit. It just writes a value and the memory controller performs the action of setting or clearing the individual bit that is represented by the specified address. So a rather trivial way to adjust the hardware to let a standard programming language magically get "bit" variables.
Thanks Per for your reply.
Yes I did but I couldn't find anythings useful that let me use the bit-banded area. The Processor that I'm using is LPC17xx from NXP company.
By having an int represent a bit directly in the memory controller, the processor does not need to perform a read + modify + write to set or clear a bit
Exactly. This is the concept of bit-banded but what I'm looking for is, how is it possible to toggle a bit without performing a read + modify + write sequence in this region as in the ARM information centre says: This allows every individual bit in the bit-banding region to be directly accessible from a word-aligned address using a single LDR instruction. It also allows individual bits to be toggled from C without performing a read-modify-write sequence of instructions.
For set a bit what we should write in the int that represent a bit (any value except zero or just 1)?
You create a struct of 32 int. Map this struct at the very specific address the datasheet describes will map over the bit-band area for one 32-bit bit-addressable register. Then you access the individual integers in this struct and the memory controller remaps the accesses into a bit access in the 32-bit register associated with that address range.
Have you done that before? because when I do and check the debugger I see that variable is not located in the bi-banded region and also when I set the more specific region address for the variable with this __attribute__((at())) command, it doesn't work.
Are you sure you have done everything correctly?
Note that there are two regions associated with every bit-band range.
One region where the actual registers are stored. And another aliased region where you are expected to place the struct of integers.
And have you verified in the map file that you did place your struct at the very specific address that actually will translate accesses towards the very specific register in the bit-band region?
So to access peripheral registers that exists in the address range 0x40000000-0x400fffff you need to place structures in the address range 0x42000000-0x43ffffff.
So there is one 1-megabyte region of 32-bit registers - in total 8 million bits. And one 32-megabyte region where you place the structures - in total 8 million int.
1 MB fits 262144 32-bit registers.
And the 32 MB region will fit 262144 structures that each is 128 bytes large. You can fit 32 32-bit integers in a 128 byte large struct. So each and every integer will map to one unique bit in the 1MB of peripheral register area.
In total 8 million bits that can be either directly accessed or accessed using the 8 million aliased 32-bit integers.
And the processor have a second set of 1MB RAM + 32MB alias region to allow bit-band access to normal variables too.
But this is documented in the processor user manual.
No
I knew and considered that in my project
Have you got any simple sample that worked for you and you have checked it before?
Thanks
"I knew and considered that in my project"
You considered it? It's not optional if you want to use the bit-banding feature. The memory controller will only give you this additional "magic" if you do place your "int" variables in the 32 MB memory range - then accesses to the int will alias to a specific bit in the 1MB address range.
"Have you got any simple sample that worked for you and you have checked it before?"
Why does it sound like you don't believe it will work? The compiler or language need not know anything about this magic since it's part of the hardware. The only important thing is that there is aliasing between the bits and the integers - so it's important to use "volatile" to make sure the compiler doesn't cache values. The only potential tool issues is that the debugger might not know about this alias functionality.
For testing, it's enough for you to compute the alias address of a specific bit and then just use a int pointer that points to this aliased address. Suddenly you can toggle a specific I/O pin with an assign to the pointer. Trivial to test. The user manual very clearly describes the formula for computing the alias address. But the formula is so trivial you don't need it - you can figure it out yourself if you just know the base address of the bit range and the int range.
It's by reading the documentation you learn. Not by having someone else post "magic" code that you just reuse.
So in the end - if it hasn't worked for you, then you have placed the data at the wrong address. And the map file is excellent for verify the location of variables. Or you might have forgotten "volatile".
"with an assign to the pointer" should of course be "with an assign through the pointer"
This forum should do well to use a standard implementation with real accounts and edit functionality.
Thanks per you are right but I wanted to make sure about the IDE attribute that it works or not. Thanks for your time
What IDE attribute?