cancel
Showing results for 
Search instead for 
Did you mean: 

How to port __no_init IAR directive with specific address (@) to GCC compiler?

SegmentFault
Associate II

I am trying to port an IAR project to STM32CubeIDE and I having several problems. One of them is located in the following line of code

__no_init const char reserved_area[2048] @0x08040000 ;
#pragma required=reserved_area

In particular, I don't know how to port that line to GCC. I think that it could be something similar to the following:

__attribute__((section("no_init")))
__attribute__((used))
const char reserved_area[2048] = (*(const char*)0x08040000);

The problem is that I get the following error:

initializer element is not constant

In addition, I don't know the validity of this approach. Because, as far as I know, __attribute__((section("no_init"))) place the variable into the no_init section that may not match with the exact address that I want (0x08040000).

So, to sum up, how can I port the IAR code that I show here to GCC compiler?

3 REPLIES 3
TDK
Guru

I think the closest you can get without modifying the linker or using C++ is:

const char * reserved_area = (const char *) 0x08040000;

Which isn't exactly the same, but is functionally close.

If you modify your linker script to include a new section (e.g. "no_init"), you can place this array it in and it'll be at the start of that section, provided you don't add any other variables.

__attribute__((section("no_init")))
const char reserved_area[2048];

However, I do question the use of an const array which is not initialized.

If you feel a post has answered your question, please click "Accept as Solution".

Could you explain the functionally differences between

    const char * reserved_area = (const char *) 0x08040000;

and

__no_init const char reserved_area[2048] @0x08040000 ;

?

Thank you

Mainly, sizeof(reserved_area) will return different values.

If you feel a post has answered your question, please click "Accept as Solution".