2026-01-11 5:31 PM
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
Solved! Go to Solution.
2026-01-29 4:18 PM
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
2026-01-12 2:44 AM
Hello @Huiqi
Since it worked on STM32L431 and fails on STM32L471, the causes are almost always one (or more) of:
2026-01-12 9:56 PM
Hello @Saket_Om
As to the two possible reasons, the reply is:
The programming address is within the flash range, from 0x08021800. It is correct.
How to handle with the write-protected sector?
Best Regards,
2026-01-13 1:01 AM
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
2026-01-13 10:41 PM
Hello @Saket_Om
Here is the protection area definition read from STM32CubeProgrammer, and it seems address 0x08021800 is not in the protection area.
Best Regards,
2026-01-13 11:09 PM
By the way, I also try HAL_FLASH_OB_Unlock() in firmware, and the result is same.
2026-01-16 12:15 AM
@Saket_Om Anymore thoughts about this issue?
2026-01-16 5:56 AM
Hello @Huiqi
Are you preforming an erase operation before programming the flash?
2026-01-20 11:23 PM
2026-01-29 4:18 PM
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