Contiki 3.x
fault-handlers.c
Go to the documentation of this file.
1 /**
2  * \file
3  * Implementation of debugging fault handlers for ARM Cortex M3/M4 CPUs.
4  *
5  * \author
6  * Joakim Gebart <joakim.gebart@eistec.se>
7  */
8 #include <stdint.h>
9 #include <stdio.h>
10 #include "K60.h"
11 
12 /**
13  * Hard fault handler (C part)
14  *
15  * This is basically a copy and paste of the hardfault handler originally
16  * written by Joseph Yiu and published on various forums around the web.
17  *
18  * Author: Joseph Yiu
19  *
20  * \see Cortex-M4 Devices Generic User Guide, ARM, 2010
21  * \see The Definitive Guide to ARM® Cortex®-M3 and Cortex®-M4 Processors, Third Edition, ISBN-978-0124080829
22  *
23  * \param hardfault_args A pointer to the stack area where the hardfault parameters are located.
24  *
25  * \note This function should never return.
26  */
27 void
28 hard_fault_handler_c(uint32_t *hardfault_args)
29 {
30  uint32_t stacked_r0;
31  uint32_t stacked_r1;
32  uint32_t stacked_r2;
33  uint32_t stacked_r3;
34  uint32_t stacked_r12;
35  uint32_t stacked_lr;
36  uint32_t stacked_pc;
37  uint32_t stacked_psr;
38  uint32_t rBFAR;
39  uint32_t rCFSR;
40  uint32_t rHFSR;
41  uint32_t rDFSR;
42  uint32_t rAFSR;
43  uint32_t rMMAR;
44 
45  stacked_r0 = hardfault_args[0];
46  stacked_r1 = hardfault_args[1];
47  stacked_r2 = hardfault_args[2];
48  stacked_r3 = hardfault_args[3];
49 
50  stacked_r12 = hardfault_args[4];
51  stacked_lr = hardfault_args[5];
52  stacked_pc = hardfault_args[6];
53  stacked_psr = hardfault_args[7];
54 
55  rBFAR = (*((volatile uint32_t *)(0xE000ED38)));
56  rCFSR = (*((volatile uint32_t *)(0xE000ED28)));
57  rHFSR = (*((volatile uint32_t *)(0xE000ED2C)));
58  rDFSR = (*((volatile uint32_t *)(0xE000ED30)));
59  rAFSR = (*((volatile uint32_t *)(0xE000ED3C)));
60  rMMAR = (*((volatile uint32_t *)(0xE000ED34)));
61 
62  printf("[Hard fault handler]\n");
63  printf("R0 = %x\n", (unsigned int)stacked_r0);
64  printf("R1 = %x\n", (unsigned int)stacked_r1);
65  printf("R2 = %x\n", (unsigned int)stacked_r2);
66  printf("R3 = %x\n", (unsigned int)stacked_r3);
67  printf("R12 = %x\n", (unsigned int)stacked_r12);
68  printf("LR = %x\n", (unsigned int)stacked_lr);
69  printf("PC = %x\n", (unsigned int)stacked_pc);
70  printf("PSR = %x\n", (unsigned int)stacked_psr);
71  printf("BFAR = %x\n", (unsigned int)rBFAR);
72  printf("CFSR = %x\n", (unsigned int)rCFSR);
73  printf("HFSR = %x\n", (unsigned int)rHFSR);
74  printf("DFSR = %x\n", (unsigned int)rDFSR);
75  printf("AFSR = %x\n", (unsigned int)rAFSR);
76  printf("MMAR = %x\n", (unsigned int)rMMAR);
77 
78  /* Trigger a debugger to break here */
79  DEBUGGER_BREAK(BREAK_FAULT_HANDLER);
80  while(1);
81 }
void hard_fault_handler_c(uint32_t *hardfault_args)
Hard fault handler (C part)
K60 hardware register header wrapper.
#define DEBUGGER_BREAK(sig)
Make the CPU signal to the debugger and break execution by issuing a bkpt instruction.
Definition: K60.h:164