You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation / example for "safely" accessible flash #1144
I want to use the STM32G474's flash to save some data, that I calculate in my application, similar to the G474 flash example.
The example starts using the Flash from page 32 on, which is safe since the example is only a few bytes large.
Is there a good way to find a safe starting page automatically?
One way would probably be, to reduce the LENGTH of the FLASH section in the linker script and then use pages beyond that at runtime on the G4, right?
In this case, I would have to adjust the FLASH length manually every time application changes size, which is not very nice imho.
Is there a good way to find a safe starting page automatically?
In many applications you wouldn't want that. If you like to upgrade the device with a larger binary without overwriting the present data in flash, the data section will have to be placed at a fixed location that can't overlap with the code.
If you know how much space is needed for data you could reserve some pages at the end of flash. In the custom linker script you can reduce the LENGTH of the FLASH section by that amount.
In case you don't need data to be persistent across updates the end of your binary is accessible via the symbol __rom_end defined in the linker script. Just declare extern "C" const uint32_t __rom_end[];. You'd need to align the pointer to the next flash page and put your data after.
Yes, __rom_end exists for this purpose. You can do Flash::getPage(&__rom_end) + 1 to get the next page, but better check that the index is not beyond the last page, since modm(-devices) currently doesn't know how many pages actually exist.
Activity
chris-durand commentedon Mar 11, 2024
In many applications you wouldn't want that. If you like to upgrade the device with a larger binary without overwriting the present data in flash, the data section will have to be placed at a fixed location that can't overlap with the code.
If you know how much space is needed for data you could reserve some pages at the end of flash. In the custom linker script you can reduce the
LENGTHof theFLASHsection by that amount.In case you don't need data to be persistent across updates the end of your binary is accessible via the symbol
__rom_enddefined in the linker script. Just declareextern "C" const uint32_t __rom_end[];. You'd need to align the pointer to the next flash page and put your data after.salkinium commentedon Mar 11, 2024
Yes,
__rom_endexists for this purpose. You can doFlash::getPage(&__rom_end) + 1to get the next page, but better check that the index is not beyond the last page, since modm(-devices) currently doesn't know how many pages actually exist.