We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Problem
Once in a blue moon (every ~500 hours of run time, non-deterministic) I am getting a Usage Fault/ Illegal unaligned load or store. Please, help me to trace the fault to actual offending instruction and extract additional info.
What have I done so far:
Per ARM AN209 (http://www.keil.com/appnotes/files/apnt209.pdf) I have installed a hard fault handler.
extern C void HardFault_Handler(void) { __asm volatile ( tst lr, #4 \n ite eq \n mrseq r0, msp \n mrsne r0, psp \n ldr r1, [r0, #24] \n ldr r2, handler2_address_const \n bx r2 \n handler2_address_const: .word prvGetRegistersFromStack \n ); }
Values of the registers extracted from the exception stack frame are:
HFSR is 0x40000000 indicating Forced (I do not have a separate handler for UsageFaults)
CFSR is 0x01000000 indicating UsageFault, UNALIGNED access
xSPR is 0100 0003
MMFAR is 0
BFAR is 0
pc (0x0803A758) points to
a dead loop of osRtxIdleThread.
This could not be the offending instruction, could it? What am I missing?
I have checked the RM0385 Reference manual, I see that the exception stack has been parsed properly:
My system is:
Cortex M7 (STM32F746NG..)
Keil RTOS
Once the unit is stalled, I have connected to it using SEGGER J-Link/J-Trace for Cortex M (using Ozone), stopped the program, and examined the memory contents.
Unaligned access fault trap (UNALIGN_TRP) is disabled ( per reference it means that only ... can generate this fault)
I read:
https://community.arm.com/developer/tools-software/tools/f/armds-forum/402/debugging-a-usage-fault-for-an-unaligned-memory-access
http://www.keil.com/support/docs/3777.htm (but no external SDRAM is used)
RM0385 Reference manual
also read:
https://medium.com/@iLevex/the-curious-case-of-unaligned-access-on-arm-5dd0ebe24965
https://stackoverflow.com/questions/18269181/unaligned-access-causes-error-on-arm-cortex-m4
https://stackoverflow.com/questions/20926386/what-is-non-aligned-access-arm-keil
https://stackoverflow.com/questions/5119496/arm-unaligned-memory-access-workaround
Duplicated post:
https://community.arm.com/developer/ip-products/processors/f/cortex-m-forum/43707/unable-to-determine-offending-instruction-usage-fault-illegal-unaligned-load-or-store-cortex-m7-keil-mdk-pro
It was my first post in the forum, and it was delayed, probably due to manual moderation. Sorry about polluting. As I do not have a button to delete my post, moderators please feel free to delete it.
Do not delete it yet. I made a tiny formatting change to my original post, and it is now inaccessible tot he public due to pending moderation.
No problem. I just put the note so people know they are the same - yes, sometime our moderation system can takes time.
Regarding stack overflow - I don't have any solid evidence that it s a stack overflow. But since you said the problem happen only once in a while then stack overflow could be one possibility.