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 > STM32L0 chip FLASH programming simple demonstration

STM32L0 chip FLASH programming simple demonstration

Date: 26-04-2021 ClickCount: 69

Here is a simple demonstration of the STM32L053 chip FLASH programming and some reminders for those who need it.

Generally speaking, FLASH programming mainly includes erase, code programming, OpTIon word modification operation, about OpTIon programming is not introduced below. STM32L0 chip erase in addition to support the whole chip erase, then is to support page erase, the size of each page is 128Bytes, that is, 32 words. Programming can be programmed by word or by half page [64Bytes]. Single-page erase, single-word programming and half-page programming time is the same, about 3.2ms, this point is also clear in the chip data sheet out.

Here are 2 reminders. The first point, when doing erase or programming, pay attention to the issue of address alignment, page erase address to 128-byte alignment, word programming attention to 4-byte alignment, half-page programming attention to 64-byte alignment. Another point is that when doing half-page programming, the execution code of half-page programming should be put into RAM, which is also emphasized in the manual.

The following demonstrates the operation of word programming, page programming, and page erase. Here I first write 5 words in word programming mode, and then program 5 half-page pages in FLASH in half-page programming mode, and record the time spent on both to see if the word programming time is the same as the half-page programming. In addition, after completing the 5 half-page programming, a page erase operation is performed to erase 1 of the 5 half-pages that have just been programmed, i.e., only 3 half-pages of content should be left at the end [Note: For STM32L0 series chips, the internal FLASH is erased with all 0 content].

The following code screenshot is organized based on the STM32Cube library, which mainly involves three operations: word programming, half-page programming, and page erase, corresponding to the three library functions underlined in green.

STM32L0

Among them, the execution code for half-page programming needs to be configured to run in RAM. In addition, Period1 and Period2 stm32l0 discovery are used to store the programming time for writing 5 words and 5 half-pages, respectively, and placed in the specified FLASH location. After compiling and running we can see the following results.

STM32L0

The above screenshot shows the contents of the FLASH space inside the chip after running. 5 red boxes are the results of 5 word programming, and the data inside the blue boxes are the results of 5 half-page programming, but finally only 3 half-page programming contents are visible, that is because the contents of the last two half-pages disappeared after the page erase operation.

The timer used to count the programming time has a counting frequency of 1MHz, so obviously Period1 and Period2 are basically equal, and the programming time is 3.3ms after dividing them by 5. Obviously, it is more efficient to use half-page programming for batch code programming.

As mentioned earlier, the code to be executed when doing half-page programming needs to be put into RAM, and this code is in the STM32cube library file stm32l0xx_hal_flash_ramfunc.c. The implementation of this operation is handled slightly differently by different IDEs. Here is a simple configuration based on the ARM MDK to divide some RAM out for it.

STM32L0

STM32L0

This is all about the STM32L0 series FLASH programming demo, hope it can help those who need it to save some time and effort.

  • How to choose between IIC and SPI in embedded systems?
  • STM32 variables are stored in the specified location in the on-chip FLASH

Hot Products

  • PIC18F26K42-E/SP

    Manufacturer: Microchip

    IC MCU 8BIT 64KB FLASH 28SDIP

    Product Categories: 8bit MCU

    Lifecycle:

    RoHS:

  • ADSP-BF514BBCZ-4F4

    Manufacturer: Analog Devices

    IC DSP 16/32B 400MHZ 168CSBGA

    Product Categories: DSP

    Lifecycle:

    RoHS:

  • PIC24F08KA101-I/MQ

    Manufacturer: Microchip

    IC MCU 16BIT 8KB FLASH 20QFN

    Product Categories: 16bit MCU

    Lifecycle:

    RoHS:

  • ADSP-BF516BSWZ-4F4

    Manufacturer: Analog Devices

    IC DSP 16/32B 400MHZ LP 176LQFP

    Product Categories: DSP

    Lifecycle:

    RoHS:

Customer Comments

  • Looking forward to your comment

  • Comment

    Verification Code * 

Compare products

Compare Empty