Our project uses SEGGER Embedded Studio for ARM Release 7.12a Build 2023031402.52776 and works with the STM32F411VET. There are end-user settings we want to store in flash so they can be modified and preserved between power cycles of the device. Looking around we found two major sources of information on how to pull this off, but neither worked completely correctly.
The first comes from this Segger forum post (note that this is dated 2017, so may now be inaccurate) :
[SOLVED] Placing data at a specific memory address with Segger Embedded Studio
This tells you to edit the XML memory map file and then use the "attribute" property to flag where the variable should be stored. Following the example from the above thread and having the XML file modified like so:
And then declaring the variable to be placed in flash like so (tPagedata being a structure type) :
This ends up not working since the location in memory for value flashData ends up being 0x080066D8, not 0x08000000 as expected. Side note, after trying :
As a variation, the value was still placed at 0x080066D8. The second description comes from a Segger wiki (which is at least dated from 2023) :
wiki.segger.com/Add_new_Memory_Sections_and_Segments
Following these directions the XML memory map gets altered as such :
With the flash.icf file getting this added to the end :
However, if I do this, then the code fails to execute and I get a UsageFault_StateError. We could use some guidance on how to get either of these techniques working correctly.
The first comes from this Segger forum post (note that this is dated 2017, so may now be inaccurate) :
[SOLVED] Placing data at a specific memory address with Segger Embedded Studio
This tells you to edit the XML memory map file and then use the "attribute" property to flag where the variable should be stored. Following the example from the above thread and having the XML file modified like so:
XML Source Code
- <!DOCTYPE Board_Memory_Definition_File>
- <root name="STM32F411VETx">
- <MemorySegment name="FLASH1" start="0x08000000" size="0x00080000" access="ReadOnly" />
- <MemorySegment name="RAM1" start="0x20000000" size="0x00020000" access="Read/Write" />
- <MemorySegment name="$(FLASH_NAME:FLASH)">
- <ProgramSection alignment="4" load="Yes" name=".MyVar" start="0x00080000" />
- </MemorySegment>
- </root>
And then declaring the variable to be placed in flash like so (tPagedata being a structure type) :
XML Source Code
- <!DOCTYPE Board_Memory_Definition_File>
- <root name="STM32F411VETx">
- <MemorySegment name="FLASH1" start="0x08000000" size="0x00080000" access="ReadOnly">
- <ProgramSection alignment="4" load="Yes" name=".MyVar" start="0x00080000" />
- </MemorySegment>
- <MemorySegment name="RAM1" start="0x20000000" size="0x00020000" access="Read/Write" />
- </root>
wiki.segger.com/Add_new_Memory_Sections_and_Segments
Following these directions the XML memory map gets altered as such :
XML Source Code
- <!DOCTYPE Board_Memory_Definition_File>
- <root name="STM32F411VETx">
- <MemorySegment name="CONFIG" start="0x08000000" size="0x00004000" access="ReadOnly" />
- <MemorySegment name="FLASH1" start="0x08004000" size="0x0007C000" access="ReadOnly" />
- <MemorySegment name="RAM1" start="0x20000000" size="0x00020000" access="Read/Write" />
- </root>
However, if I do this, then the code fails to execute and I get a UsageFault_StateError. We could use some guidance on how to get either of these techniques working correctly.