cancel
Showing results for 
Search instead for 
Did you mean: 

Program STM32L471 with HAL_FLASH_Program failed

Huiqi
Associate II

I am migrating from STM32L431 to STM32L471. After migration, the function relating to internal flash writing does not work any more. The problem is when I programmed internal flash with HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data), following errors occurred, including FLASH_SR_PROGERR, FLASH_FLAG_PGAERR, and FLASH_FLAG_PGSERR.

I searched on the web, and found problem may relate to timer initialization and watchdog usage. I added HAL_TIM_Base_DeInit before HAL_TIM_Base_Init, and watchdog is disabled completely in the system including wathdog initialization and update.. But the problem is still there.

By the way, the development environment is MDK5.36, ARM::CMSIS IS 5.8.0 (5.6.0 is also tested), ARM::CMSIS-Driver is 2.6.1, Keil::STM32L4xx_DFP is 2.6.1.

So, what the problem it might be, and how can I solve this problem?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

@Saket_Om 

The problem is solved finally.

The erasing operation existed. But it turned out that the flash bank doesn't exist in STM32L431, and the bank definition in STM32L471 is 1 and 2. The value used in STM32L431 based problem did not work at all. So the problem is reported in writing operation instead of erasing operation.

In my opinion, the condition of writing data other than 0 to non-blank region in flash is kind of misleading. It is different from the common concept. I found the problem when I read the flash register detailed description.

Anyway, thanks for your help.

Huiqi Li

 

View solution in original post

9 REPLIES 9
Saket_Om
ST Employee

Hello @Huiqi 

Since it worked on STM32L431 and fails on STM32L471, the causes are almost always one (or more) of:

  1. Different flash size / address map ⇒ invalid address
  2. Different option bytes ⇒ write‑protected sector
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

Hello @Saket_Om 

As to the two possible reasons, the reply is:

  • Different flash size / address map ⇒ invalid address

         The programming address is within the flash range, from 0x08021800. It is correct.

  • Different option bytes ⇒ write‑protected sector

        How to handle with the write-protected sector?

Best Regards,

 

Hello @Huiqi 

To check and remove flash write protection on the STM32L471, first connect your board to the PC using an ST‑LINK and open STM32CubeProgrammer. Click Connect to establish the connection with the target, then open the “OB” (Option Bytes) tab. In this tab, locate the Write Protection sections and examine the configured page ranges. Determine whether the page that contains the address 0x08021800 falls within any of these protected ranges. If it does, adjust the configuration in the Write Protection section by unchecking the corresponding ranges or setting them to “Not protected” for the pages you need to write. For testing purposes, you can temporarily disable write protection for all pages to confirm that it resolves the programming errors

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
Huiqi
Associate II

Hello @Saket_Om 

Here is the protection area definition read from STM32CubeProgrammer, and it seems address 0x08021800 is not in the protection area.

Huiqi_0-1768372693625.png

Best Regards,

 

By the way, I also try HAL_FLASH_OB_Unlock() in firmware, and the result is same.

 

@Saket_Om Anymore thoughts about this issue?

Hello @Huiqi 

Are you preforming an erase operation before programming the flash? 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
@Saket_Om I made erasing operation before writing. Based on the debugging, the erasing operation completed successfully, no error was found.

@Saket_Om 

The problem is solved finally.

The erasing operation existed. But it turned out that the flash bank doesn't exist in STM32L431, and the bank definition in STM32L471 is 1 and 2. The value used in STM32L431 based problem did not work at all. So the problem is reported in writing operation instead of erasing operation.

In my opinion, the condition of writing data other than 0 to non-blank region in flash is kind of misleading. It is different from the common concept. I found the problem when I read the flash register detailed description.

Anyway, thanks for your help.

Huiqi Li