cancel
Showing results for 
Search instead for 
Did you mean: 

Storing data in internal Flash during Fault interupt.

MatPet
Associate

Team,

i'm trying to store data - by use of HAL lib - during Hardware,Memory.. and so on Fault Interrupt routine. Idea is to write some data at the very end of flash - allowable area.

 So, the code is tested druing normal operation. However, placed in Hard Fault ISR its stooped/ failed during erase inside function HAL_FLASHEx_Erase(addr,bank) precisley at line __HAL_LOCK(&pFlash);

I was trying to figure it our on my own, however seems i'm not able to clear the Flash SR register bits - or IDE is not refresing correctly - doubtful. 

FLASH->SR ^= 0x3FF; //or SR=0x0 // clears error bits in SR reg
FLASH->CR ^= 0x8404; // clears mer1 mer 2 and bker bit

Initializing erase procedure sets WPRERR bit anyway and after erase, errors are set back. 

Result is, flash bank is not erased nor data stored. Im woring on STM32G474

Can anyone support me ?

3 REPLIES 3
TDK
Guru

Show your code and show what's in the pFlash variable at the time it tries to lock it. Likely the pointer is broken.

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

 However, placed in Hard Fault ISR its stooped/ failed during erase inside function HAL_FLASHEx_Erase

You don't want to erase in a fault handler. Have the write area erased and ready to write, and the status bits already cleared. Preventing possibility of a problem is more robust than solving it.

 

Could you stash data in NVRAM /BKPRAM or end-of SRAM?

Must you use HAL, couldn't you just do some minimal assembler or LL, where you just walk through the FLASH programming without pointers, HAL instances, locks, or need for timing interrupts?

As Pavel suggests, pre-erase, or journal this data across the sector. Here we spill data immediately to a USART

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