2020-07-30 03:55 AM
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?
2020-07-30 05:43 AM
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.
2020-07-31 12:44 AM
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
2020-07-31 03:07 AM
Mainly, sizeof(reserved_area) will return different values.