在启动文件中修改
IMPORT rt_hw_hard_fault_exception
EXPORT HardFault_Handler
HardFault_Handler PROC
; get current context
TST lr, #0x04 ; if(!EXC_RETURN[2])
ITE EQ
MRSEQ r0, msp ; [2]=0 ==> Z=1, get fault context from handler.
MRSNE r0, psp ; [2]=1 ==> Z=0, get fault context from thread.
STMFD r0!, {r4 - r11} ; push r4 - r11 register
STMFD r0!, {lr} ; push exec_return register
TST lr, #0x04 ; if(!EXC_RETURN[2])
ITE EQ
MSREQ msp, r0 ; [2]=0 ==> Z=1, update stack pointer to MSP.
MSRNE psp, r0 ; [2]=1 ==> Z=0, update stack pointer to PSP.
PUSH {lr}
BL rt_hw_hard_fault_exception
POP {lr}
ORR lr, lr, #0x04
BX lr
ENDP
调用的硬件中断函数
#define rt_uint32_t unsigned int
struct exception_info
{
rt_uint32_t exc_return;
rt_uint32_t r4;
rt_uint32_t r5;
rt_uint32_t r6;
rt_uint32_t r7;
rt_uint32_t r8;
rt_uint32_t r9;
rt_uint32_t r10;
rt_uint32_t r11;
rt_uint32_t r0;
rt_uint32_t r1;
rt_uint32_t r2;
rt_uint32_t r3;
rt_uint32_t r12;
rt_uint32_t lr;
rt_uint32_t pc;
rt_uint32_t psr;
};
/*
* fault exception handler
*/
void rt_hw_hard_fault_exception(struct exception_info * exception_info)
{
unsigned int *app_sp;
int i;
app_sp = (unsigned int *)(exception_info + 1); /* context + 16*4 */
printf("psr: 0x%08x\r\n", exception_info->psr);
printf("r00: 0x%08x\r\n", exception_info->r0);
printf("r01: 0x%08x\r\n", exception_info->r1);
printf("r02: 0x%08x\r\n", exception_info->r2);
printf("r03: 0x%08x\r\n", exception_info->r3);
printf("r04: 0x%08x\r\n", exception_info->r4);
printf("r05: 0x%08x\r\n", exception_info->r5);
printf("r06: 0x%08x\r\n", exception_info->r6);
printf("r07: 0x%08x\r\n", exception_info->r7);
printf("r08: 0x%08x\r\n", exception_info->r8);
printf("r09: 0x%08x\r\n", exception_info->r9);
printf("r10: 0x%08x\r\n", exception_info->r10);
printf("r11: 0x%08x\r\n", exception_info->r11);
printf("r12: 0x%08x\r\n", exception_info->r12);
printf(" lr: 0x%08x\r\n", exception_info->lr);
printf(" pc: 0x%08x\r\n", exception_info->pc);
printf("stacks: \r\n");
i = 0;
for (i = 0; i < 1024; )
{
printf("%08x ", *app_sp);
app_sp++;
i++;
if (i % 16 == 0)
printf("\r\n");
}
printf("\r\n");
while (1);
}
fromelf --text -a -c --output=xxx.dis Objects\xxx.axf