Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 
199 {
200  __asm volatile
201  (
202  " tst lr, #4 \n"
203  " ite eq \n"
204  " mrseq r0, msp \n"
205  " mrsne r0, psp \n"
206  " ldr r1, [r0, #24] \n"
207  " ldr r2, handler2_address_const \n"
208  " bx r2 \n"
209  " handler2_address_const: .word prvGetRegistersFromStack \n"
210  );
211 }
212 
213 
215 {
216  while (TRUE);
217 }
218 
220 {
223 }
225 {
228 }
230 {
233 }
234 
235 void NMIVector(void) __attribute__((weak, alias("_unhandled_exception_NMIVector")));
236 void HardFaultVector(void) __attribute__((weak, alias("_unhandled_exception")));
237 void MemManageVector(void) __attribute__((weak, alias("_unhandled_exception_MemManageVector")));
238 void BusFaultVector(void) __attribute__((weak, alias("_unhandled_exception_BusFaultVector")));
239 void UsageFaultVector(void) __attribute__((weak, alias("_unhandled_exception_UsageFaultVector")));
240 void Vector1C(void) __attribute__((weak, alias("_unhandled_exception")));
241 void Vector20(void) __attribute__((weak, alias("_unhandled_exception")));
242 void Vector24(void) __attribute__((weak, alias("_unhandled_exception")));
243 void Vector28(void) __attribute__((weak, alias("_unhandled_exception")));
244 void SVCallVector(void) __attribute__((weak, alias("_unhandled_exception")));
245 void DebugMonitorVector(void) __attribute__((weak, alias("_unhandled_exception")));
246 void Vector34(void) __attribute__((weak, alias("_unhandled_exception")));
247 void PendSVVector(void) __attribute__((weak, alias("_unhandled_exception")));
248 void SysTickVector(void) __attribute__((weak, alias("_unhandled_exception")));
249 void Vector40(void) __attribute__((weak, alias("_unhandled_exception")));
250 void Vector44(void) __attribute__((weak, alias("_unhandled_exception")));
251 void Vector48(void) __attribute__((weak, alias("_unhandled_exception")));
252 void Vector4C(void) __attribute__((weak, alias("_unhandled_exception")));
253 void Vector50(void) __attribute__((weak, alias("_unhandled_exception")));
254 void Vector54(void) __attribute__((weak, alias("_unhandled_exception")));
255 void Vector58(void) __attribute__((weak, alias("_unhandled_exception")));
256 void Vector5C(void) __attribute__((weak, alias("_unhandled_exception")));
257 void Vector60(void) __attribute__((weak, alias("_unhandled_exception")));
258 void Vector64(void) __attribute__((weak, alias("_unhandled_exception")));
259 void Vector68(void) __attribute__((weak, alias("_unhandled_exception")));
260 void Vector6C(void) __attribute__((weak, alias("_unhandled_exception")));
261 void Vector70(void) __attribute__((weak, alias("_unhandled_exception")));
262 void Vector74(void) __attribute__((weak, alias("_unhandled_exception")));
263 void Vector78(void) __attribute__((weak, alias("_unhandled_exception")));
264 void Vector7C(void) __attribute__((weak, alias("_unhandled_exception")));
265 void Vector80(void) __attribute__((weak, alias("_unhandled_exception")));
266 void Vector84(void) __attribute__((weak, alias("_unhandled_exception")));
267 void Vector88(void) __attribute__((weak, alias("_unhandled_exception")));
268 void Vector8C(void) __attribute__((weak, alias("_unhandled_exception")));
269 void Vector90(void) __attribute__((weak, alias("_unhandled_exception")));
270 void Vector94(void) __attribute__((weak, alias("_unhandled_exception")));
271 void Vector98(void) __attribute__((weak, alias("_unhandled_exception")));
272 void Vector9C(void) __attribute__((weak, alias("_unhandled_exception")));
273 void VectorA0(void) __attribute__((weak, alias("_unhandled_exception")));
274 void VectorA4(void) __attribute__((weak, alias("_unhandled_exception")));
275 void VectorA8(void) __attribute__((weak, alias("_unhandled_exception")));
276 void VectorAC(void) __attribute__((weak, alias("_unhandled_exception")));
277 void VectorB0(void) __attribute__((weak, alias("_unhandled_exception")));
278 void VectorB4(void) __attribute__((weak, alias("_unhandled_exception")));
279 void VectorB8(void) __attribute__((weak, alias("_unhandled_exception")));
280 void VectorBC(void) __attribute__((weak, alias("_unhandled_exception")));
281 void VectorC0(void) __attribute__((weak, alias("_unhandled_exception")));
282 void VectorC4(void) __attribute__((weak, alias("_unhandled_exception")));
283 void VectorC8(void) __attribute__((weak, alias("_unhandled_exception")));
284 void VectorCC(void) __attribute__((weak, alias("_unhandled_exception")));
285 void VectorD0(void) __attribute__((weak, alias("_unhandled_exception")));
286 void VectorD4(void) __attribute__((weak, alias("_unhandled_exception")));
287 void VectorD8(void) __attribute__((weak, alias("_unhandled_exception")));
288 void VectorDC(void) __attribute__((weak, alias("_unhandled_exception")));
289 void VectorE0(void) __attribute__((weak, alias("_unhandled_exception")));
290 void VectorE4(void) __attribute__((weak, alias("_unhandled_exception")));
291 void VectorE8(void) __attribute__((weak, alias("_unhandled_exception")));
292 void VectorEC(void) __attribute__((weak, alias("_unhandled_exception")));
293 void VectorF0(void) __attribute__((weak, alias("_unhandled_exception")));
294 void VectorF4(void) __attribute__((weak, alias("_unhandled_exception")));
295 void VectorF8(void) __attribute__((weak, alias("_unhandled_exception")));
296 void VectorFC(void) __attribute__((weak, alias("_unhandled_exception")));
297 void Vector100(void) __attribute__((weak, alias("_unhandled_exception")));
298 void Vector104(void) __attribute__((weak, alias("_unhandled_exception")));
299 void Vector108(void) __attribute__((weak, alias("_unhandled_exception")));
300 void Vector10C(void) __attribute__((weak, alias("_unhandled_exception")));
301 void Vector110(void) __attribute__((weak, alias("_unhandled_exception")));
302 void Vector114(void) __attribute__((weak, alias("_unhandled_exception")));
303 void Vector118(void) __attribute__((weak, alias("_unhandled_exception")));
304 void Vector11C(void) __attribute__((weak, alias("_unhandled_exception")));
305 void Vector120(void) __attribute__((weak, alias("_unhandled_exception")));
306 void Vector124(void) __attribute__((weak, alias("_unhandled_exception")));
307 void Vector128(void) __attribute__((weak, alias("_unhandled_exception")));
308 void Vector12C(void) __attribute__((weak, alias("_unhandled_exception")));
309 void Vector130(void) __attribute__((weak, alias("_unhandled_exception")));
310 void Vector134(void) __attribute__((weak, alias("_unhandled_exception")));
311 void Vector138(void) __attribute__((weak, alias("_unhandled_exception")));
312 void Vector13C(void) __attribute__((weak, alias("_unhandled_exception")));
313 void Vector140(void) __attribute__((weak, alias("_unhandled_exception")));
314 void Vector144(void) __attribute__((weak, alias("_unhandled_exception")));
315 void Vector148(void) __attribute__((weak, alias("_unhandled_exception")));
316 void Vector14C(void) __attribute__((weak, alias("_unhandled_exception")));
317 void Vector150(void) __attribute__((weak, alias("_unhandled_exception")));
318 void Vector154(void) __attribute__((weak, alias("_unhandled_exception")));
319 void Vector158(void) __attribute__((weak, alias("_unhandled_exception")));
320 void Vector15C(void) __attribute__((weak, alias("_unhandled_exception")));
321 void Vector160(void) __attribute__((weak, alias("_unhandled_exception")));
322 void Vector164(void) __attribute__((weak, alias("_unhandled_exception")));
323 void Vector168(void) __attribute__((weak, alias("_unhandled_exception")));
324 void Vector16C(void) __attribute__((weak, alias("_unhandled_exception")));
325 void Vector170(void) __attribute__((weak, alias("_unhandled_exception")));
326 void Vector174(void) __attribute__((weak, alias("_unhandled_exception")));
327 void Vector178(void) __attribute__((weak, alias("_unhandled_exception")));
328 void Vector17C(void) __attribute__((weak, alias("_unhandled_exception")));
329 void Vector180(void) __attribute__((weak, alias("_unhandled_exception")));
330 void Vector184(void) __attribute__((weak, alias("_unhandled_exception")));
331 
332 
333 void prvGetRegistersFromStack(uint32_t *pulFaultStackAddress)
334 {
335  /* These are volatile to try and prevent the compiler/linker optimising them
336  away as the variables never actually get used. If the debugger won't show the
337  values of the variables, make them global my moving their declaration outside
338  of this function. */
339 
340  /*
341  When entering hard fault, the stm32 push the value of register on the stack, and loop forever.
342  You can easily retrieve address of faulty instruction in variable pc,
343  status in variable psr.
344 
345  in gdb, after when hard-fault is triggered, you just have to type some commands :
346 
347  ° print /x pc => retrieve instruction
348  ° info line *pc : see the source code of the line which has triggered exception
349  ° disassemble pc : see the assembly of the address which has triggered exception
350  */
351 
352  volatile uint32_t r0 __attribute__((unused));
353  volatile uint32_t r1 __attribute__((unused));
354  volatile uint32_t r2 __attribute__((unused));
355  volatile uint32_t r3 __attribute__((unused));
356  volatile uint32_t r12 __attribute__((unused));
357  volatile uint32_t lr __attribute__((unused)); /* Link register. */
358  volatile uint32_t pc __attribute__((unused)); /* Program counter. */
359  volatile uint32_t psr __attribute__((unused));/* Program status register. */
360 
361  r0 = pulFaultStackAddress[ 0 ];
362  r1 = pulFaultStackAddress[ 1 ];
363  r2 = pulFaultStackAddress[ 2 ];
364  r3 = pulFaultStackAddress[ 3 ];
365 
366  r12 = pulFaultStackAddress[ 4 ];
367  lr = pulFaultStackAddress[ 5 ];
368  pc = pulFaultStackAddress[ 6 ];
369  psr = pulFaultStackAddress[ 7 ];
370 
371  /* When the following line is hit, the variables contain the register values. */
372  while (1);
373 }
374 
irq_vector_t vector1c
void Vector6C(void)
void(* irq_vector_t)(void)
Type of an IRQ vector.
irq_vector_t vector20
irq_vector_t vector28
uint32_t __main_stack_end__
void VectorB8(void)
void VectorC0(void)
void Vector158(void)
void Vector24(void)
void VectorEC(void)
void ResetHandler(void)
void Vector1C(void)
void Vector34(void)
void Vector11C(void)
irq_vector_t systick_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)
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)
void Vector120(void)
void Vector60(void)
void VectorA4(void)
void PendSVVector(void)
void Vector40(void)
irq_vector_t reset_vector
void Vector14C(void)
void Vector80(void)
void VectorD8(void)
Type of a structure representing the whole vectors table.
void VectorC4(void)
void _unhandled_exception_BusFaultVector(void)
void Vector15C(void)
void Vector164(void)
void Vector4C(void)
#define TRUE
Definition: std.h:4
irq_vector_t vector34
void Vector118(void)
void Vector128(void)
void Vector84(void)
void Vector9C(void)
void VectorFC(void)
void Vector78(void)
void Vector138(void)
void VectorF4(void)
void Vector140(void)
void Vector70(void)
void Vector54(void)
irq_vector_t hardfault_vector
void SysTickVector(void)
irq_vector_t nmi_vector
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)
void prvGetRegistersFromStack(uint32_t *pulFaultStackAddress)
void Vector88(void)
void Vector90(void)
void UsageFaultVector(void)
void HardFaultVector(void)
irq_vector_t pendsv_vector
void Vector174(void)
void VectorC8(void)
void VectorCC(void)
void Vector148(void)
void Vector144(void)
void VectorE8(void)
void VectorA8(void)
void Vector104(void)
void Vector184(void)
void BusFaultVector(void)
void Vector170(void)
irq_vector_t usagefault_vector
void Vector7C(void)
void Vector100(void)
void VectorD4(void)
void VectorD0(void)
void Vector58(void)
irq_vector_t busfault_vector
static void _unhandled_exception(void)
Unhandled exceptions handler.
void Vector68(void)
uint32_t * init_stack
void Vector160(void)
void Vector150(void)
void Vector28(void)
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 vector24
void Vector50(void)
void Vector10C(void)
void VectorB4(void)
void NMIVector(void)
void VectorA0(void)
void SVCallVector(void)
irq_vector_t memmanage_vector
void Vector17C(void)
void Vector114(void)
void Vector8C(void)
irq_vector_t debugmonitor_vector
void VectorE0(void)
irq_vector_t svcall_vector
void Vector5C(void)
void Vector154(void)
void Vector110(void)