Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stm32f4_chibios_vectors.c
Go to the documentation of this file.
1 /*
2  ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
3  2011,2012,2013 Giovanni Di Sirio.
4 
5  This file is part of ChibiOS/RT.
6 
7  ChibiOS/RT is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  ChibiOS/RT is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
29 #include "mcuconf.h"
30 
31 #include <ch.h>
32 
36 typedef void (*irq_vector_t)(void);
39 void prvGetRegistersFromStack( uint32_t *pulFaultStackAddress ) __attribute__((unused));
40 
44 typedef struct {
61  irq_vector_t vectors[82];
62 } vectors_t;
63 
64 #if !defined(__DOXYGEN__)
65 
66 
67 
68 
70 extern void ResetHandler(void);
71 extern void NMIVector(void);
72 extern void HardFaultVector(void);
73 extern void MemManageVector(void);
74 extern void BusFaultVector(void);
75 extern void UsageFaultVector(void);
76 extern void Vector1C(void);
77 extern void Vector20(void);
78 extern void Vector24(void);
79 extern void Vector28(void);
80 extern void SVCallVector(void);
81 extern void DebugMonitorVector(void);
82 extern void Vector34(void);
83 extern void PendSVVector(void);
84 extern void SysTickVector(void);
85 extern void Vector40(void);
86 extern void Vector44(void);
87 extern void Vector48(void);
88 extern void Vector4C(void);
89 extern void Vector50(void);
90 extern void Vector54(void);
91 extern void Vector58(void);
92 extern void Vector5C(void);
93 extern void Vector60(void);
94 extern void Vector64(void);
95 extern void Vector68(void);
96 extern void Vector6C(void);
97 extern void Vector70(void);
98 extern void Vector74(void);
99 extern void Vector78(void);
100 extern void Vector7C(void);
101 extern void Vector80(void);
102 extern void Vector84(void);
103 extern void Vector88(void);
104 extern void Vector8C(void);
105 extern void Vector90(void);
106 extern void Vector94(void);
107 extern void Vector98(void);
108 extern void Vector9C(void);
109 extern void VectorA0(void);
110 extern void VectorA4(void);
111 extern void VectorA8(void);
112 extern void VectorAC(void);
113 extern void VectorB0(void);
114 extern void VectorB4(void);
115 extern void VectorB8(void);
116 extern void VectorBC(void);
117 extern void VectorC0(void);
118 extern void VectorC4(void);
119 extern void VectorC8(void);
120 extern void VectorCC(void);
121 extern void VectorD0(void);
122 extern void VectorD4(void);
123 extern void VectorD8(void);
124 extern void VectorDC(void);
125 extern void VectorE0(void);
126 extern void VectorE4(void);
127 extern void VectorE8(void);
128 extern void VectorEC(void);
129 extern void VectorF0(void);
130 extern void VectorF4(void);
131 extern void VectorF8(void);
132 extern void VectorFC(void);
133 extern void Vector100(void);
134 extern void Vector104(void);
135 extern void Vector108(void);
136 extern void Vector10C(void);
137 extern void Vector110(void);
138 extern void Vector114(void);
139 extern void Vector118(void);
140 extern void Vector11C(void);
141 extern void Vector120(void);
142 extern void Vector124(void);
143 extern void Vector128(void);
144 extern void Vector12C(void);
145 extern void Vector130(void);
146 extern void Vector134(void);
147 extern void Vector138(void);
148 extern void Vector13C(void);
149 extern void Vector140(void);
150 extern void Vector144(void);
151 extern void Vector148(void);
152 extern void Vector14C(void);
153 extern void Vector150(void);
154 extern void Vector154(void);
155 extern void Vector158(void);
156 extern void Vector15C(void);
157 extern void Vector160(void);
158 extern void Vector164(void);
159 extern void Vector168(void);
160 extern void Vector16C(void);
161 extern void Vector170(void);
162 extern void Vector174(void);
163 extern void Vector178(void);
164 extern void Vector17C(void);
165 extern void Vector180(void);
166 extern void Vector184(void);
167 #endif
168 
172 #if !defined(__DOXYGEN__)
173 __attribute__ ((used, section("vectors")))
174 #endif
180  {
181  DECLARE_IRQS
182  }
183 };
184 
195 static void _unhandled_exception ( void ) __attribute__( ( naked ) );
196 
197 
198 void _unhandled_exception (void) {
199  __asm volatile
200  (
201  " tst lr, #4 \n"
202  " ite eq \n"
203  " mrseq r0, msp \n"
204  " mrsne r0, psp \n"
205  " ldr r1, [r0, #24] \n"
206  " ldr r2, handler2_address_const \n"
207  " bx r2 \n"
208  " handler2_address_const: .word prvGetRegistersFromStack \n"
209  );
210 }
211 
212 
214  while (TRUE);
215 }
216 
220 }
224 }
228 }
229 
230 void NMIVector(void) __attribute__((weak, alias("_unhandled_exception_NMIVector")));
231 void HardFaultVector(void) __attribute__((weak, alias("_unhandled_exception")));
232 void MemManageVector(void) __attribute__((weak, alias("_unhandled_exception_MemManageVector")));
233 void BusFaultVector(void) __attribute__((weak, alias("_unhandled_exception_BusFaultVector")));
234 void UsageFaultVector(void) __attribute__((weak, alias("_unhandled_exception_UsageFaultVector")));
235 void Vector1C(void) __attribute__((weak, alias("_unhandled_exception")));
236 void Vector20(void) __attribute__((weak, alias("_unhandled_exception")));
237 void Vector24(void) __attribute__((weak, alias("_unhandled_exception")));
238 void Vector28(void) __attribute__((weak, alias("_unhandled_exception")));
239 void SVCallVector(void) __attribute__((weak, alias("_unhandled_exception")));
240 void DebugMonitorVector(void) __attribute__((weak, alias("_unhandled_exception")));
241 void Vector34(void) __attribute__((weak, alias("_unhandled_exception")));
242 void PendSVVector(void) __attribute__((weak, alias("_unhandled_exception")));
243 void SysTickVector(void) __attribute__((weak, alias("_unhandled_exception")));
244 void Vector40(void) __attribute__((weak, alias("_unhandled_exception")));
245 void Vector44(void) __attribute__((weak, alias("_unhandled_exception")));
246 void Vector48(void) __attribute__((weak, alias("_unhandled_exception")));
247 void Vector4C(void) __attribute__((weak, alias("_unhandled_exception")));
248 void Vector50(void) __attribute__((weak, alias("_unhandled_exception")));
249 void Vector54(void) __attribute__((weak, alias("_unhandled_exception")));
250 void Vector58(void) __attribute__((weak, alias("_unhandled_exception")));
251 void Vector5C(void) __attribute__((weak, alias("_unhandled_exception")));
252 void Vector60(void) __attribute__((weak, alias("_unhandled_exception")));
253 void Vector64(void) __attribute__((weak, alias("_unhandled_exception")));
254 void Vector68(void) __attribute__((weak, alias("_unhandled_exception")));
255 void Vector6C(void) __attribute__((weak, alias("_unhandled_exception")));
256 void Vector70(void) __attribute__((weak, alias("_unhandled_exception")));
257 void Vector74(void) __attribute__((weak, alias("_unhandled_exception")));
258 void Vector78(void) __attribute__((weak, alias("_unhandled_exception")));
259 void Vector7C(void) __attribute__((weak, alias("_unhandled_exception")));
260 void Vector80(void) __attribute__((weak, alias("_unhandled_exception")));
261 void Vector84(void) __attribute__((weak, alias("_unhandled_exception")));
262 void Vector88(void) __attribute__((weak, alias("_unhandled_exception")));
263 void Vector8C(void) __attribute__((weak, alias("_unhandled_exception")));
264 void Vector90(void) __attribute__((weak, alias("_unhandled_exception")));
265 void Vector94(void) __attribute__((weak, alias("_unhandled_exception")));
266 void Vector98(void) __attribute__((weak, alias("_unhandled_exception")));
267 void Vector9C(void) __attribute__((weak, alias("_unhandled_exception")));
268 void VectorA0(void) __attribute__((weak, alias("_unhandled_exception")));
269 void VectorA4(void) __attribute__((weak, alias("_unhandled_exception")));
270 void VectorA8(void) __attribute__((weak, alias("_unhandled_exception")));
271 void VectorAC(void) __attribute__((weak, alias("_unhandled_exception")));
272 void VectorB0(void) __attribute__((weak, alias("_unhandled_exception")));
273 void VectorB4(void) __attribute__((weak, alias("_unhandled_exception")));
274 void VectorB8(void) __attribute__((weak, alias("_unhandled_exception")));
275 void VectorBC(void) __attribute__((weak, alias("_unhandled_exception")));
276 void VectorC0(void) __attribute__((weak, alias("_unhandled_exception")));
277 void VectorC4(void) __attribute__((weak, alias("_unhandled_exception")));
278 void VectorC8(void) __attribute__((weak, alias("_unhandled_exception")));
279 void VectorCC(void) __attribute__((weak, alias("_unhandled_exception")));
280 void VectorD0(void) __attribute__((weak, alias("_unhandled_exception")));
281 void VectorD4(void) __attribute__((weak, alias("_unhandled_exception")));
282 void VectorD8(void) __attribute__((weak, alias("_unhandled_exception")));
283 void VectorDC(void) __attribute__((weak, alias("_unhandled_exception")));
284 void VectorE0(void) __attribute__((weak, alias("_unhandled_exception")));
285 void VectorE4(void) __attribute__((weak, alias("_unhandled_exception")));
286 void VectorE8(void) __attribute__((weak, alias("_unhandled_exception")));
287 void VectorEC(void) __attribute__((weak, alias("_unhandled_exception")));
288 void VectorF0(void) __attribute__((weak, alias("_unhandled_exception")));
289 void VectorF4(void) __attribute__((weak, alias("_unhandled_exception")));
290 void VectorF8(void) __attribute__((weak, alias("_unhandled_exception")));
291 void VectorFC(void) __attribute__((weak, alias("_unhandled_exception")));
292 void Vector100(void) __attribute__((weak, alias("_unhandled_exception")));
293 void Vector104(void) __attribute__((weak, alias("_unhandled_exception")));
294 void Vector108(void) __attribute__((weak, alias("_unhandled_exception")));
295 void Vector10C(void) __attribute__((weak, alias("_unhandled_exception")));
296 void Vector110(void) __attribute__((weak, alias("_unhandled_exception")));
297 void Vector114(void) __attribute__((weak, alias("_unhandled_exception")));
298 void Vector118(void) __attribute__((weak, alias("_unhandled_exception")));
299 void Vector11C(void) __attribute__((weak, alias("_unhandled_exception")));
300 void Vector120(void) __attribute__((weak, alias("_unhandled_exception")));
301 void Vector124(void) __attribute__((weak, alias("_unhandled_exception")));
302 void Vector128(void) __attribute__((weak, alias("_unhandled_exception")));
303 void Vector12C(void) __attribute__((weak, alias("_unhandled_exception")));
304 void Vector130(void) __attribute__((weak, alias("_unhandled_exception")));
305 void Vector134(void) __attribute__((weak, alias("_unhandled_exception")));
306 void Vector138(void) __attribute__((weak, alias("_unhandled_exception")));
307 void Vector13C(void) __attribute__((weak, alias("_unhandled_exception")));
308 void Vector140(void) __attribute__((weak, alias("_unhandled_exception")));
309 void Vector144(void) __attribute__((weak, alias("_unhandled_exception")));
310 void Vector148(void) __attribute__((weak, alias("_unhandled_exception")));
311 void Vector14C(void) __attribute__((weak, alias("_unhandled_exception")));
312 void Vector150(void) __attribute__((weak, alias("_unhandled_exception")));
313 void Vector154(void) __attribute__((weak, alias("_unhandled_exception")));
314 void Vector158(void) __attribute__((weak, alias("_unhandled_exception")));
315 void Vector15C(void) __attribute__((weak, alias("_unhandled_exception")));
316 void Vector160(void) __attribute__((weak, alias("_unhandled_exception")));
317 void Vector164(void) __attribute__((weak, alias("_unhandled_exception")));
318 void Vector168(void) __attribute__((weak, alias("_unhandled_exception")));
319 void Vector16C(void) __attribute__((weak, alias("_unhandled_exception")));
320 void Vector170(void) __attribute__((weak, alias("_unhandled_exception")));
321 void Vector174(void) __attribute__((weak, alias("_unhandled_exception")));
322 void Vector178(void) __attribute__((weak, alias("_unhandled_exception")));
323 void Vector17C(void) __attribute__((weak, alias("_unhandled_exception")));
324 void Vector180(void) __attribute__((weak, alias("_unhandled_exception")));
325 void Vector184(void) __attribute__((weak, alias("_unhandled_exception")));
326 
327 
328 void prvGetRegistersFromStack( uint32_t *pulFaultStackAddress )
329 {
330  /* These are volatile to try and prevent the compiler/linker optimising them
331  away as the variables never actually get used. If the debugger won't show the
332  values of the variables, make them global my moving their declaration outside
333  of this function. */
334 
335  /*
336  When entering hard fault, the stm32 push the value of register on the stack, and loop forever.
337  You can easily retrieve address of faulty instruction in variable pc,
338  status in variable psr.
339 
340  in gdb, after when hard-fault is triggered, you just have to type some commands :
341 
342  ° print /x pc => retrieve instruction
343  ° info line *pc : see the source code of the line which has triggered exception
344  ° disassemble pc : see the assembly of the address which has triggered exception
345  */
346 
347  volatile uint32_t r0 __attribute__((unused));
348  volatile uint32_t r1 __attribute__((unused));
349  volatile uint32_t r2 __attribute__((unused));
350  volatile uint32_t r3 __attribute__((unused));
351  volatile uint32_t r12 __attribute__((unused));
352  volatile uint32_t lr __attribute__((unused)); /* Link register. */
353  volatile uint32_t pc __attribute__((unused)); /* Program counter. */
354  volatile uint32_t psr __attribute__((unused));/* Program status register. */
355 
356  r0 = pulFaultStackAddress[ 0 ];
357  r1 = pulFaultStackAddress[ 1 ];
358  r2 = pulFaultStackAddress[ 2 ];
359  r3 = pulFaultStackAddress[ 3 ];
360 
361  r12 = pulFaultStackAddress[ 4 ];
362  lr = pulFaultStackAddress[ 5 ];
363  pc = pulFaultStackAddress[ 6 ];
364  psr = pulFaultStackAddress[ 7 ];
365 
366  /* When the following line is hit, the variables contain the register values. */
367  while (1);
368 }
369 
void Vector6C(void)
void(* irq_vector_t)(void)
Type of an IRQ vector.
uint32_t __main_stack_end__
void VectorB8(void)
void VectorC0(void)
void Vector158(void)
void Vector24(void)
void VectorEC(void)
void ResetHandler(void)
irq_vector_t busfault_vector
void Vector1C(void)
void Vector34(void)
void Vector11C(void)
irq_vector_t vector34
irq_vector_t pendsv_vector
void Vector12C(void)
void VectorDC(void)
void VectorAC(void)
void Vector130(void)
void Vector20(void)
void Vector168(void)
void Vector98(void)
void MemManageVector(void)
irq_vector_t systick_vector
void _unhandled_exception_NMIVector(void)
void Vector178(void)
void Vector134(void)
void DebugMonitorVector(void)
void _unhandled_exception_UsageFaultVector(void)
void Vector124(void)
vectors_t _vectors
STM32 vectors table.
void VectorBC(void)
irq_vector_t memmanage_vector
void Vector120(void)
void Vector60(void)
irq_vector_t reset_vector
void VectorA4(void)
void PendSVVector(void)
void Vector40(void)
void Vector14C(void)
void Vector80(void)
Type of a structure representing the whole vectors table.
void VectorD8(void)
void VectorC4(void)
void _unhandled_exception_BusFaultVector(void)
void Vector15C(void)
void Vector164(void)
void Vector4C(void)
irq_vector_t usagefault_vector
void Vector118(void)
void Vector128(void)
void Vector84(void)
void Vector9C(void)
void VectorFC(void)
irq_vector_t hardfault_vector
void Vector78(void)
void Vector138(void)
void VectorF4(void)
void Vector140(void)
void Vector70(void)
void Vector54(void)
void SysTickVector(void)
unsigned long uint32_t
Definition: types.h:18
void Vector94(void)
void VectorF8(void)
void VectorE4(void)
static enum HardwareFaultType hardwareFaultType
void Vector180(void)
void VectorB0(void)
void Vector108(void)
void Vector44(void)
uint32_t * init_stack
void prvGetRegistersFromStack(uint32_t *pulFaultStackAddress)
void Vector88(void)
void Vector90(void)
void UsageFaultVector(void)
#define TRUE
Definition: imu_chimu.h:144
void HardFaultVector(void)
void Vector174(void)
void VectorC8(void)
void VectorCC(void)
void Vector148(void)
void Vector144(void)
void VectorE8(void)
irq_vector_t vector1c
void VectorA8(void)
void Vector104(void)
void Vector184(void)
void BusFaultVector(void)
void Vector170(void)
irq_vector_t vector20
void Vector7C(void)
void Vector100(void)
void VectorD4(void)
void VectorD0(void)
void Vector58(void)
static void _unhandled_exception(void)
Unhandled exceptions handler.
void Vector68(void)
irq_vector_t nmi_vector
void Vector160(void)
void Vector150(void)
void Vector28(void)
irq_vector_t svcall_vector
void VectorF0(void)
void Vector64(void)
void Vector74(void)
void Vector16C(void)
void Vector13C(void)
void _unhandled_exception_MemManageVector(void)
void Vector48(void)
irq_vector_t debugmonitor_vector
void Vector50(void)
void Vector10C(void)
void VectorB4(void)
void NMIVector(void)
irq_vector_t vector28
void VectorA0(void)
void SVCallVector(void)
void Vector17C(void)
void Vector114(void)
void Vector8C(void)
irq_vector_t vector24
void VectorE0(void)
void Vector5C(void)
void Vector154(void)
void Vector110(void)