Hello! Welcome to Embedic!
This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > Embedded Events > STM32 variables are stored in the specified location in the on-chip FLASH

STM32 variables are stored in the specified location in the on-chip FLASH

Date: 05-05-2021 ClickCount: 139

Here the STM32L4R5 is used as an example (the official DEMO board) to store the variable at the specified on-chip FLASH address (0x081F8000).

MDK Keil software operation

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.

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.

STM32

Uncheck the box at 1 and select your own modified Scatter File at 2.

STM32

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

STM32

IAR Operation

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 };  

Note

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.

  • STM32L0 chip FLASH programming simple demonstration
  • The rules of the microcontroller development process

Hot Products

  • ADSP-BF512BBCZ-4F4

    Manufacturer: Analog Devices

    IC DSP 16/32B 400MHZ 168CSBGA

    Product Categories: DSP

    Lifecycle:

    RoHS:

  • ADSP-BF514KBCZ-4F4

    Manufacturer: Analog Devices

    IC DSP 16/32B 400MHZ 168CSBGA

    Product Categories: DSP

    Lifecycle:

    RoHS:

  • PIC18F13K50-I/SO

    Manufacturer: Microchip

    IC MCU 8BIT 8KB FLASH 20SOIC

    Product Categories: 8bit MCU

    Lifecycle:

    RoHS:

  • ADSP-BF518BBCZ-4F4

    Manufacturer: Analog Devices

    IC DSP 16/32B 400MHZ 168CSBGA

    Product Categories: DSP

    Lifecycle:

    RoHS:

Customer Comments

  • Looking forward to your comment

  • Comment

    Verification Code * 

Compare products

Compare Empty