my Cortex M3 happen Hardfault after running some time. it is long sometimes and short sometimes. no rule. and it use FreeRTOS7.5.2, after Hardfault, I dump CPU context as following
[Hard fault handler]
R0 = 2e
R1 = 0
R2 = ffffffff
R3 = 20005f48
R12 = 4f588000
LR = fffffffd
PC = 28024f14
PSR = 21000035
BFAR = e000ed38
CFSR = 100
HFSR = 40000000
DFSR = 0
AFSR = 0
it is strange that PC value is not a valid address, anyone meet same problem ?
If the dump was done while you were in the hardfault handler then I would expect the PC to point to code inside the hardfault handler.
I would suggest starting here: http://www.freertos.org/FAQHelp.html for a list of possible problems if the hardfault is occurring in FreeRTOS itself (rather than in your application).
I always enable conf_assert and make sure that there is no assert when hardfault happen. I start to guess HW issue and collect more record about PC value, it may be 0x0Cxxxxxx, 0x28xxxxxx, 0xc8xxxxxx, it is random case
use following code to save cpu context when hardfault happen
IMPORT hard_fault_handler_c
TST LR, #4
ITE EQ
MRSEQ R0, MSP
MRSNE R0, PSP
B hard_fault_handler_c
then, go to hardfault_handle to dump those context
void hard_fault_handler_c(unsigned int * hardfault_args)
{
unsigned int stacked_r0;
unsigned int stacked_r1;
unsigned int stacked_r2;
unsigned int stacked_r3;
unsigned int stacked_r12;
unsigned int stacked_lr;
unsigned int stacked_pc;
unsigned int stacked_psr;
Could the problem be in the printf() from an exception handler? If you look at the value of stacked_pc in the debugger does it match the value printed out?