LP-500 HoTT Telemetry added device definitions
[librepilot.git] / flight / targets / boards / revolution / firmware / cm3_fault_handlers.c
blobe74ffa76add716a045e2fda439a5ce848324ddcb
1 /*
2 * cm3_fault_handlers.c
4 * Created on: Apr 24, 2011
5 * Author: msmith
6 */
8 #include <stdint.h>
9 #include "inc/dcc_stdio.h"
10 #ifdef STM32F4XX
11 # include <stm32f4xx.h>
12 #endif
13 #ifdef STM32F2XX
14 # include <stm32f2xx.h>
15 #endif
17 #define FAULT_TRAMPOLINE(_vec) \
18 __attribute__((naked, no_instrument_function)) \
19 void \
20 _vec##_Handler(void) \
21 { \
22 __asm(".syntax unified\n" \
23 "MOVS R0, #4 \n" \
24 "MOV R1, LR \n" \
25 "TST R0, R1 \n" \
26 "BEQ 1f \n" \
27 "MRS R0, PSP \n" \
28 "B " #_vec "_Handler2 \n" \
29 "1: \n" \
30 "MRS R0, MSP \n" \
31 "B " #_vec "_Handler2 \n" \
32 ".syntax divided\n"); \
33 } \
34 struct hack
36 struct cm3_frame {
37 uint32_t r0;
38 uint32_t r1;
39 uint32_t r2;
40 uint32_t r3;
41 uint32_t r12;
42 uint32_t lr;
43 uint32_t pc;
44 uint32_t psr;
47 FAULT_TRAMPOLINE(HardFault);
48 FAULT_TRAMPOLINE(BusFault);
49 FAULT_TRAMPOLINE(UsageFault);
51 /* this is a hackaround to avoid an issue where dereferencing SCB seems to result in bad codegen and a link error */
52 #define SCB_REG(_reg) (*(uint32_t *)&(SCB->_reg))
54 void HardFault_Handler2(struct cm3_frame *frame)
56 dbg_write_str("\nHARD FAULT");
57 dbg_write_hex32(frame->pc);
58 dbg_write_char('\n');
59 dbg_write_hex32(SCB_REG(HFSR));
60 dbg_write_char('\n');
61 for (;;) {
66 void BusFault_Handler2(struct cm3_frame *frame)
68 dbg_write_str("\nBUS FAULT");
69 dbg_write_hex32(frame->pc);
70 dbg_write_char('\n');
71 dbg_write_hex32(SCB_REG(CFSR));
72 dbg_write_char('\n');
73 dbg_write_hex32(SCB_REG(BFAR));
74 dbg_write_char('\n');
75 for (;;) {
80 void UsageFault_Handler2(struct cm3_frame *frame)
82 dbg_write_str("\nUSAGE FAULT");
83 dbg_write_hex32(frame->pc);
84 dbg_write_char('\n');
85 dbg_write_hex32(SCB_REG(CFSR));
86 dbg_write_char('\n');
87 for (;;) {