cancel
Showing results for 
Search instead for 
Did you mean: 

Structure in bit band region

Zanon.Luciano
Senior

Hi, I have this very simple code that sets generic flags to the desired value:

struct GenFlgStr

{

uint8_t F1 : 1;

uint8_t F2 : 1;

uint8_t f3 : 1;

};

struct GenFlgStr GenFlg;

main{

GenFlg.F1=1;

GenFlg.F2=0;

}

------------------------------------------------------------

Now I want to reply this simple structure in bit band region:

struct GenFlgStr

{

uint32_t F1;

uint32_t F2;

uint32_t F3;

};

uint8_t FLG[1];

struct GenFlgStr GenFlg __attribute__((at(((uint32_t)FLG - RAM_BASE) * 32 + RAM_BB_BASE))); // Bit Band Alias region

main{

GenFlg.F1=1;

GenFlg.F2=0;

}

When I compile this code (STM32cubeide) the "__attribute __ ((at" .... is ignored and a structure of 3 integers is generated in the main memory and not in the bit band region ....

Can someone help me?

the goal is to only change the structure definition and keep the same main when the code is compiled for M3 which supports the bit band region .

4 REPLIES 4

Try using pointers instead of this non-portable AT nonsense.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

The "at" attribute is Keil-specific, there's no such in gcc.

Use named sections instead ("section" attribute), and add the bit-banded section into the linker script.

JW

Zanon.Luciano
Senior

Thank you for your quick answer

but the problem is not solved by using the "section" attribute nor by using pointers as I need to establish a link between the normal region and the bit banded region.

In other words, I need to access the same bit flags (F1, F2 etc.) both as a byte and as a bit, and when possible (M3) I want to have the advantages of the atomic bit-band operation ...

All this is feasible with the keil compiler using the "at" attribute, and it seems strange to me that the gcc compiler does not allow this way of operation ...

> All this is feasible with the keil compiler using the "at" attribute, and it seems strange to me that the gcc compiler does not allow this way of operation ...

gcc (and binutils) are open source, so you are free to add this feature if you wish so.

As I've told above, you have to add the bit-band section in the linker script. You can assign address to that section there, also using expressions based on the non-bit-banded section to which you'd place the non-bit-banded version of the same variable.

I'd also recommend liberal use of "volatile" qualifier with such aliased variables.

JW