This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LD Scripts is the best approach for BitBanding with GCC?

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?

Parents
  • BitBanding works with GCC.

    There are two ways BitBanding can be used.

    • Automatically
    • Manually

    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.

Reply
  • BitBanding works with GCC.

    There are two ways BitBanding can be used.

    • Automatically
    • Manually

    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.

Children