Help with a HardFault on Cortex-M3

Started by pozz September 1, 2022
I'm stuck with a stupid issue on a Cortex-M3 (LPC1788 by NXP).

It's a classical issue that happens randomly and in different ways when 
the code is slightly changed, so it's very difficult to debug.

MCUXpresso (IDE from NXP) and Ozone (a software from Segger) says that 
IBUSERR and FORCED are set when HardFault exception occurs. I understand 
it is related to a program counter with a wrong address, maybe a 
corrupted function pointer. Indeed, when the HardFault triggers, 
MCUExpresso shows the stacked PC register as 0x824490, that is 
definitely wrong.

Stacked LR should say something about the calling function 
(GUI__DoAlphaBlending of emWin). Following disassembly the faulty 
instruction should be:

   bx r3

Stacked R3 (at the fault moment) is 0x24491 (_GetDevProp of emWin), that 
should be correct, but stacked PC is 0x824490. It seems the 20-th bit 
was flipped for some reason.

I can't explain why this happens, except for a hardware issue with the MCU.