cancel
Showing results for 
Search instead for 
Did you mean: 

Flash erase function need to be called multiple times now

LWill.4
Associate II

We have a project that works just fine using STM32L071RBT (compiler 5.0.6 build 960). As part of the project we erase a portion of the flash and then reprogram it for the fota, which again works great.

I then branched the project to make another variation, removed some code to make room, and added some code. And this works great right up until we run the same erase routine... When we try to run HAL_FLASHEx_Erase(), it fails the first time on FLASH_WaitForLastOperation() with the only flag being FLASH_FLAG_EOP, but works if the function is called a second time

I'm assuming that I deleted something that we need, but have scoured my code and for the life of me cannot find what it could be. The build configurations are identical, and the old code still builds and works fine. The new code functions, but I'm finding it concerning that previously functioning code that has stopped working, and would like to get to the bottom of it.

Yes, I've already googled anything and everything I can think of, haven't found anything helpful

No, I can't upload my project, propriety and whatnot

If anyone has any thoughts as to what the problem might be, it would be greatly appreciated!

2 REPLIES 2
Piranha
Chief II

Before those erase function calls some code, which tries to program/erase flash memory, fails and leaves FLASH_SR register error bits set. The first erase call fails but also clears those error bits, which makes the second call successful. HAL code is written by incompetent fools and cannot deal with such situation properly. Of course, the real problem is the code which sets the error bits.

Amel NASRI
ST Employee

Hi @LWill.4​ ,

Your case is reported internally to investigate the possible improvements for Flash HAL driver.

Internal ticket number: 140628 (This is an internal tracking number and is not accessible or usable by customers).

-Amel

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.