cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt causes flash operations to fail

wtywtykk
Associate

Hello,

I was using the flash to save the configuration data of my mcu. But I've got two problems:

The HAL_FLASHEx_Erase function fails with a sequence error.

The first 4 bytes get zeroed with HAL_FLASH_Program. The mcu never boots up after that since the first 4 bytes are the stack pointer.

I checked all the parameters and they are all correct. After disabling the interrupts, the function works. While with a high frequency interrupt, the function always fails.

However, I never found anything about this in the reference manual as well as the errata. The reference manual says the processor will be paused and the read requests will be processed correctly after the operation is done.

Chip is STM32F401RC.

Below is my flash layout:

|Sect 0-1| 2 | 3 | 4 - |

|Bootldr | Cfg1 | Cfg2 | Program code|

The erased and programed data is in sector 2. And the code that starts the flash operation is in the last block.

1 ACCEPTED SOLUTION

Accepted Solutions
wtywtykk
Associate

We found out the problem finally. It's caused by an uninitialized pointer and a race condition.

We have an led toggling in the systick callback to monitor whether the code in it completes on time. And we used a custom gpio library that accesses gpio with bitband address. However, i forgot to check whether the bitband pointer is initialized. An uninitialized pointer points to 0 address, so the first 4 bytes in the flash gets erased.

​The picture below describes the whole problem.0690X00000AtN67QAF.png

View solution in original post

4 REPLIES 4

Review what's actually being erased.

If you erase memory used by the vector table things will break.

Your description suggests you're erasing different memory than you think you are.

More likely to be a coding issue than an errata.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

What do those interrupts do? If you disable them selectively, is there any pattern with regard to FLASH programming?

Do you use some watchdog?

JW

PS. Please change your username to a normal nick.

wtywtykk
Associate

We found out the problem finally. It's caused by an uninitialized pointer and a race condition.

We have an led toggling in the systick callback to monitor whether the code in it completes on time. And we used a custom gpio library that accesses gpio with bitband address. However, i forgot to check whether the bitband pointer is initialized. An uninitialized pointer points to 0 address, so the first 4 bytes in the flash gets erased.

​The picture below describes the whole problem.0690X00000AtN67QAF.png

Thanks for coming back with the solution and explanation.

Please select your post as Best, so that this thread is marked as solved.

JW