cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault interupt when erasing FLASH (intermittent)

pbayton9
Associate II
Posted on October 12, 2017 at 16:52

I frequently get a Hardfault interrupt generating when erasing (and in some cases programming) the flash using HAL_FLASHEx_Erase and HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, ..)

Part is STM32L433CC

It may have something to do with the debugger, as it does not generally occur when the program is first loaded and run, but does occur when the program is reset (executed a second time)

Code is executed in flash, but in a different page from that being erased

CPU is running at 8MHz Range1 0WS, caches enabled (not sure this makes any difference anyway)

Any suggestions for locating the source of the fault ?

SCB - HFSR (hard fault status register) indicates:

FORCED: Forced hard fault. Indicates a forced hard fault, generated by escalation of a fault

with configurable priority that cannot be handles, either because of priority or because it is

disabled.
2 REPLIES 2
Posted on October 12, 2017 at 17:09

Caching stale data can certainly be a problem, mostly execution/prefetch, but don't know enough about the ART implementation to say authoritatively beyond that.

I would make sure to catch any status/error thrown by the functions, and also make sure the word is in fact 0xFFFFFFFF before attempting to write.

Make sure any hanging status in the Flash Controller is cleared prior to sending commands for erase/write.

Have a Hard Fault handler that present usable data, and review the instructions around where it faults. These are gross failures and tend to have reasonably apparent causes.

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pbayton9
Associate II
Posted on October 13, 2017 at 12:12

SOLVED

It was just a corrupt stack in the end (insufficient stack space allowed)

Didn't realise there were two stack frames on this processor - main stack (MSP) and process stack (PSP)

The real interrupt was a usage fault INVPC (invalid EXC_RETURN)