I have searched information on Bit-Banding in Cortex-M3 and M4 with the GNU GCC ARM EABI NONE, I have seen basic examples on the internet but none works with GNU GCC also seems that no intention to have such feature implemented.
Can someone tell me if the LD via memory remapping really work? the best approach?
What is the best way?
BitBanding works with GCC.
There are two ways BitBanding can be used.
ARM Keil offers an extra attribute for bitbanding:
Compiler User Guide: __attribute__((bitband)) type attribute
To me, it looks like the __attribute__((bitband)) have not yet made it into GCC (please correct me if I'm wrong).
There are two manual approaches too. One is to calculate the address yourself (normally by using macros), the other is to make the compiler/linker do the hard work and make the source code pretty (by using a linker-script that supports the bitband regions).
I believe the approach you want to take, by using the linker-scripts should work.
-But I also believe it's important to mark all the variables, which you intend to use with bitbanding as 'volatile'.
If you don't, your compiler will cache the old variable values and you will not see the effect of the bit-changes.
Example: You have an 8-bit variable in main memory. You set its value to 10.
In the next line, you use the bitband region to clear bit 1.
In the next line, you use printf to send the result of the variable to your favourite debug-console.
You get the result '10' if you did not mark any of the variables 'volatile'. You get the result '8' if you marked both variables 'volatile'. If you marked only one of the variables volatile, you may get either 8 or 10, but not always the value you would expect.
In short: Mark both the 8-bit and the 1-bit 'variables' as volatile, and it should work the way you would expect.
Jens (jensbauer), I am using the ARM GNU GCC GNU ARM Embedded Toolchain in Launchpad , Keil also uses the same compiler? I think no!
Nope.
GCC is one compiler.
ARM's own compiler is a different compiler
and clang is a third compiler.
Previous versions of Keil uses ARM's own compiler.
Newer versions of Keil uses clang.
-So GCC, which is used for almost every system, which is not Windows, does not have the __attribute__((bitband)) available.
However, I'd like to encourage you to try the linker script and remember to prefix every variable you use with bitbanding by 'volatile'.
If that fails, you can still use bitbanding the old way (by using predefined macros).
If you're using STM, I know ST-Microelectronics have macros defined in STM32Cube.