2024-08-29 05:44 PM
I'm using an STM32F103C8 and I have an array of unit8_t that I want to save to a particular position in flash memory, where such position is specified at compile/link time.
Eg. suppose the application resides in flash memory from position 0x08000000 to position 0x08004000, and then I want this array to not live with the rest of the application, but to start after the application ends in memory, at flash location 0x08004000.
And then at runtime I want to be able to modify the array by using flash write operations to that particular flash memory location and read/access the array by using flash read operations to the same flash memory location.
How can that be done?
2024-08-29 06:07 PM
> Eg. suppose the application resides in flash memory from position 0x08000000 to position 0x08004000, and then I want this array to not live with the rest of the application, but to start after the application ends in memory, at flash location 0x08004000.
There's not an easy way to do this with STM32CubeIDE/GCC, but you do have some options:
> And then at runtime I want to be able to modify the array by using flash write operations to that particular flash memory location and read/access the array by using flash read operations to the same flash memory location.
FLASH is not RAM and cannot be easily modified as such. If you want to modify it, you will have to erase the entire page it resides in first, then write the new value. There are no special requirements for reading the array, just writing to it.
2024-08-29 06:13 PM
Thank you.
The part I don't know too much about is:
"Create a section in the linker file specifically for this array and use __attribute__ to assign it as such, with necessary modifications so that it gets assigned at compile time."
Can you elaborate on how to do that and what the __attribute__ looks like?
2024-09-03 12:23 AM
You can define it like:
uint8_t your_array[SIZE] __attribute__ ((section ("YOUR_SECTION"))) = { 0 };
And you'll need to define that section in your linker script.
But be careful, as @TDK said before you'll be able to write those values once but to rewrite them, you'll have to erase the whole sector. So you'd better define a specific sector for it (generally at the end of the flash).