2017. 10. 26. 23:09 devel/code
arm hardfault handler
출처 : https://stackoverflow.com/questions/21293580/atmel-studio-dummy-handler
인터럽트 소스 얻어오는 방법
uint32_t phantomISR = 9999;
void Dummy_Handler(void)
{
while(1) {
phantomISR = __get_IPSR();
}
}
ISR_NUMBER This is the number of the current exception: 0 = Thread mode 1 = Reserved 2 = NMI 3 = Hard fault 4 = Memory management fault 5 = Bus fault 6 = Usage fault 7-10 = Reserved 11 = SVCall 12 = Reserved for Debug 13 = Reserved 14 = PendSV 15 = SysTick 16 = IRQ0 45 = IRQ29
SVC handler - gcc inline assembly
__attribute__((naked)) void SVC_Handler(void) {
__asm__ __volatile__ (
" tst lr, #0x4 \n\t"
" ite eq \n\t"
" mrseq r0, msp \n\t"
" mrsne r0, psp \n\t"
" b SVC_Handler_C \n\t");
}
__attribute__((naked)) void SVC_Handler(void) { register unsigned int *svc_args __asm__("r0"); __asm__ __volatile__ ( "tst lr, #0x4 ite eq mrseq %0, msp mrsne %0, psp" : "=r"(svc_args)); return SVC_Handler_C(svc_args); }
출처 : https://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | // From Joseph Yiu, minor edits by FVH // hard fault handler in C, // with stack frame location as input parameter // called from HardFault_Handler in file xxx.s 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; stacked_r0 = ((unsigned long) hardfault_args[0]); stacked_r1 = ((unsigned long) hardfault_args[1]); stacked_r2 = ((unsigned long) hardfault_args[2]); stacked_r3 = ((unsigned long) hardfault_args[3]); stacked_r12 = ((unsigned long) hardfault_args[4]); stacked_lr = ((unsigned long) hardfault_args[5]); stacked_pc = ((unsigned long) hardfault_args[6]); stacked_psr = ((unsigned long) hardfault_args[7]); printf ("\n\n[Hard fault handler - all numbers in hex]\n"); printf ("R0 = %x\n", stacked_r0); printf ("R1 = %x\n", stacked_r1); printf ("R2 = %x\n", stacked_r2); printf ("R3 = %x\n", stacked_r3); printf ("R12 = %x\n", stacked_r12); printf ("LR [R14] = %x subroutine call return address\n", stacked_lr); printf ("PC [R15] = %x program counter\n", stacked_pc); printf ("PSR = %x\n", stacked_psr); printf ("BFAR = %x\n", (*((volatile unsigned long *)(0xE000ED38)))); printf ("CFSR = %x\n", (*((volatile unsigned long *)(0xE000ED28)))); printf ("HFSR = %x\n", (*((volatile unsigned long *)(0xE000ED2C)))); printf ("DFSR = %x\n", (*((volatile unsigned long *)(0xE000ED30)))); printf ("AFSR = %x\n", (*((volatile unsigned long *)(0xE000ED3C)))); printf ("SCB_SHCSR = %x\n", SCB->SHCSR); while (1); } |
'devel > code' 카테고리의 다른 글
argument parsing (0) | 2017.02.17 |
---|---|
Unnamed Structure and Union Fields - 이름없는 구조체 (0) | 2016.12.20 |
디버그 on/off에 따라 자료형을 다르게 하는 방법 (0) | 2016.12.02 |
bus_for_each_dev - while 조건문 (0) | 2016.10.10 |
구조체 선언 없이 값 리턴 (0) | 2016.04.29 |