Here the STM32L4R5 is used as an example (the official DEMO board) to store the variable at the specified on-chip FLASH address (0x081F8000).
uint8_t version[12] __attribute__((section(".ARM.__AT_0x081F8000")))= {0x11,0x12,0x13,0x14,0x15,0x16};
uint8_t version1[12] __attribute__((at(0x081F8010)))= {0x11,0x12,0x13,0x14,0x15,0x16};
As shown above, using the above method, version and version1 can be stored at 0x081F8000 and 0x081F8010 addresses of the on-chip FLASH of STM32 microcontroller respectively.
For embedded systems or microcontrollers, a series of configuration files are usually stored in a specified section. In other words, a certain type of variable is stored in a specified area. Here, it is time to modify the link file of STM32.
The following figure shows the default link file configuration of STM32.
Modify the Scatter File file. Add the code in the red box in the figure below. The meaning of this code is to define a region RW_IROM2 (segment attribute UNINIT_FIXED_LOC), which starts at 0x081F8000 and has a size of 0x00008000. .ANY(UNINIT_FIXED_LOC) means to store any segment attribute UNINIT_ FIXED_LOC.
Uncheck the box at 1 and select your own modified Scatter File at 2.
In this way, when programming, only the corresponding data types need to be defined in this way.
uint8_t version2[12] __attribute__((section("UNINIT_FIXED_LOC"), zero_init));
After compilation, look at the .map file and you can see that 0x081f8000 stores data of size 0x0000000c with the segment attribute UNINIT_FIXED_LOC
Add the following code to the link file (.icf)
define symbol __ICFEDIT_region_FIXED_LOC_start__ = 0x081F8000;
define region uninit_fixed_loc = mem:[from __ICFEDIT_region_FIXED_LOC_start__ size 32K];
place in uninit_fixed_loc { readonly section UNINIT_FIXED_LOC };
This article stores the variables in the STM32 on-chip FLASH, so when operating on the variables, you need to follow the on-chip FLASH operation, i.e., first unlock, then modify, then add lock.
Manufacturer: Analog Devices
IC DSP 16/32B 400MHZ 168CSBGA
Product Categories: DSP
Lifecycle:
RoHS:
Manufacturer: Analog Devices
IC DSP 16/32B 400MHZ 168CSBGA
Product Categories: DSP
Lifecycle:
RoHS:
Manufacturer: Microchip
IC MCU 8BIT 8KB FLASH 20SOIC
Product Categories: 8bit MCU
Lifecycle:
RoHS:
Manufacturer: Analog Devices
IC DSP 16/32B 400MHZ 168CSBGA
Product Categories: DSP
Lifecycle:
RoHS:
Looking forward to your comment
Comment