2017-10-12 07:52 AM
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 isdisabled.2017-10-12 08:09 AM
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.
2017-10-13 03:12 AM
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)