Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
lisa_mx_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Piotr Esden-Tempski <piotr@esden.net>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 #ifndef CONFIG_LISA_MX_COMMON_H
24 #define CONFIG_LISA_MX_COMMON_H
25 
26 #define BOARD_LISA_MX
27 
28 /* Lisa/M has a 12MHz external clock and 168MHz internal. */
29 #define EXT_CLK 12000000
30 #define AHB_CLK 168000000
31 
32 /*
33  * Onboard LEDs
34  */
35 
36 /* red, on PA8 */
37 #ifndef USE_LED_1
38 #define USE_LED_1 1
39 #endif
40 #define LED_1_GPIO GPIOA
41 #define LED_1_GPIO_PIN GPIO8
42 #define LED_1_GPIO_ON gpio_clear
43 #define LED_1_GPIO_OFF gpio_set
44 #define LED_1_AFIO_REMAP ((void)0)
45 
46 /* green, shared with JTAG_TRST */
47 #ifndef USE_LED_2
48 #define USE_LED_2 1
49 #endif
50 #define LED_2_GPIO GPIOB
51 #define LED_2_GPIO_PIN GPIO4
52 #define LED_2_GPIO_ON gpio_clear
53 #define LED_2_GPIO_OFF gpio_set
54 #define LED_2_AFIO_REMAP ((void)0)
55 
56 /* green, shared with ADC12 (ADC_6 on connector ANALOG2) */
57 #ifndef USE_LED_3
58 #define USE_LED_3 1
59 #endif
60 #define LED_3_GPIO GPIOC
61 #define LED_3_GPIO_PIN GPIO2
62 #define LED_3_GPIO_ON gpio_clear
63 #define LED_3_GPIO_OFF gpio_set
64 #define LED_3_AFIO_REMAP ((void)0)
65 
66 /* red, shared with ADC15 (ADC_4 on connector ANALOG2) */
67 #ifndef USE_LED_4
68 #define USE_LED_4 1
69 #endif
70 #define LED_4_GPIO GPIOC
71 #define LED_4_GPIO_PIN GPIO5
72 #define LED_4_GPIO_ON gpio_clear
73 #define LED_4_GPIO_OFF gpio_set
74 #define LED_4_AFIO_REMAP ((void)0)
75 
76 /* green, on PC15 */
77 #ifndef USE_LED_5
78 #define USE_LED_5 1
79 #endif
80 #define LED_5_GPIO GPIOC
81 #define LED_5_GPIO_PIN GPIO15
82 #define LED_5_GPIO_ON gpio_clear
83 #define LED_5_GPIO_OFF gpio_set
84 #define LED_5_AFIO_REMAP ((void)0)
85 
86 /*
87  * LEDs not populated by default
88  */
89 /* PC3, ADC13 on ADC_1 */
90 #define LED_6_GPIO GPIOC
91 #define LED_6_GPIO_PIN GPIO3
92 #define LED_6_GPIO_ON gpio_clear
93 #define LED_6_GPIO_OFF gpio_set
94 #define LED_6_AFIO_REMAP ((void)0)
95 
96 /* PC0, ADC10 on ADC_2 */
97 #define LED_7_GPIO GPIOC
98 #define LED_7_GPIO_PIN GPIO0
99 #define LED_7_GPIO_ON gpio_clear
100 #define LED_7_GPIO_OFF gpio_set
101 #define LED_7_AFIO_REMAP ((void)0)
102 
103 /* PC1, ADC11 on ADC_3 */
104 #define LED_8_GPIO GPIOC
105 #define LED_8_GPIO_PIN GPIO1
106 #define LED_8_GPIO_ON gpio_clear
107 #define LED_8_GPIO_OFF gpio_set
108 #define LED_8_AFIO_REMAP ((void)0)
109 
110 
111 /*
112  * not actual LEDS, used as GPIOs
113  */
114 
115 /* PB1, DRDY on EXT SPI connector*/
116 #define LED_BODY_GPIO GPIOB
117 #define LED_BODY_GPIO_PIN GPIO1
118 #define LED_BODY_GPIO_ON gpio_set
119 #define LED_BODY_GPIO_OFF gpio_clear
120 #define LED_BODY_AFIO_REMAP ((void)0)
121 
122 /* PC12, on GPIO connector*/
123 #define LED_12_GPIO GPIOC
124 #define LED_12_GPIO_PIN GPIO12
125 #define LED_12_GPIO_ON gpio_clear
126 #define LED_12_GPIO_OFF gpio_set
127 #define LED_12_AFIO_REMAP ((void)0)
128 
129 
130 /* Default actuators driver */
131 #define DEFAULT_ACTUATORS "subsystems/actuators/actuators_pwm.h"
132 #define ActuatorDefaultSet(_x,_y) ActuatorPwmSet(_x,_y)
133 #define ActuatorsDefaultInit() ActuatorsPwmInit()
134 #define ActuatorsDefaultCommit() ActuatorsPwmCommit()
135 
136 
137 /* UART */
138 #if REMAP_UART1
139 #define UART1_GPIO_AF GPIO_AF7
140 #define UART1_GPIO_PORT_RX GPIOB
141 #define UART1_GPIO_RX GPIO7
142 #define UART1_GPIO_PORT_TX GPIOB
143 #define UART1_GPIO_TX GPIO6
144 #else
145 #define UART1_GPIO_AF GPIO_AF7
146 #define UART1_GPIO_PORT_RX GPIOA
147 #define UART1_GPIO_RX GPIO10
148 #define UART1_GPIO_PORT_TX GPIOA
149 #define UART1_GPIO_TX GPIO9
150 #endif /* REMAP_UART1 */
151 
152 #define UART2_GPIO_AF GPIO_AF7
153 #define UART2_GPIO_PORT_RX GPIOA
154 #define UART2_GPIO_RX GPIO3
155 #define UART2_GPIO_PORT_TX GPIOA
156 #define UART2_GPIO_TX GPIO2
157 
158 #if REMAP_UART3 // For UART4 we need to remap UART 3
159 #define UART3_GPIO_AF GPIO_AF7
160 #define UART3_GPIO_PORT_RX GPIOB
161 #define UART3_GPIO_RX GPIO11
162 #define UART3_GPIO_PORT_TX GPIOB
163 #define UART3_GPIO_TX GPIO10
164 
165 #define UART4_GPIO_AF GPIO_AF8
166 #define UART4_GPIO_PORT_RX GPIOC
167 #define UART4_GPIO_RX GPIO11
168 #define UART4_GPIO_PORT_TX GPIOC
169 #define UART4_GPIO_TX GPIO10
170 
171 #else
172 #define UART3_GPIO_AF GPIO_AF7
173 #define UART3_GPIO_PORT_RX GPIOC
174 #define UART3_GPIO_RX GPIO11
175 #define UART3_GPIO_PORT_TX GPIOC
176 #define UART3_GPIO_TX GPIO10
177 #endif
178 
179 
180 #define UART5_GPIO_AF GPIO_AF8
181 #define UART5_GPIO_PORT_RX GPIOD
182 #define UART5_GPIO_RX GPIO2
183 #define UART5_GPIO_PORT_TX GPIOC
184 #define UART5_GPIO_TX GPIO12
185 
186 #define UART6_GPIO_AF GPIO_AF8
187 #define UART6_GPIO_PORT_RX GPIOC
188 #define UART6_GPIO_RX GPIO7
189 #define UART6_GPIO_PORT_TX GPIOC
190 #define UART6_GPIO_TX GPIO6
191 
192 /*
193  * Spektrum
194  */
195 /* The line that is pulled low at power up to initiate the bind process */
196 /* These are not common between versions of lisa/mx and thus defined in the
197  * version specific header files. */
198 /* #define SPEKTRUM_BIND_PIN GPIO0 */
199 /* #define SPEKTRUM_BIND_PIN_PORT GPIOB */
200 
201 #define SPEKTRUM_UART1_RCC RCC_USART1
202 #define SPEKTRUM_UART1_BANK GPIOA
203 #define SPEKTRUM_UART1_PIN GPIO10
204 #define SPEKTRUM_UART1_AF GPIO_AF7
205 #define SPEKTRUM_UART1_IRQ NVIC_USART1_IRQ
206 #define SPEKTRUM_UART1_ISR usart1_isr
207 #define SPEKTRUM_UART1_DEV USART1
208 
209 #define SPEKTRUM_UART5_RCC RCC_UART5
210 #define SPEKTRUM_UART5_BANK GPIOD
211 #define SPEKTRUM_UART5_PIN GPIO2
212 #define SPEKTRUM_UART5_AF GPIO_AF8
213 #define SPEKTRUM_UART5_IRQ NVIC_UART5_IRQ
214 #define SPEKTRUM_UART5_ISR uart5_isr
215 #define SPEKTRUM_UART5_DEV UART5
216 
217 /* PPM
218  *
219  * Default is PPM config 2, input on GPIOA1 (Servo pin 6)
220  */
221 
222 #ifndef PPM_CONFIG
223 #define PPM_CONFIG 2
224 #endif
225 
226 #if PPM_CONFIG == 1
227 /* input on PA10 (UART1_RX) */
228 #define USE_PPM_TIM1 1
229 #define PPM_CHANNEL TIM_IC3
230 #define PPM_TIMER_INPUT TIM_IC_IN_TI3
231 #define PPM_IRQ NVIC_TIM1_CC_IRQ
232 #define PPM_IRQ2 NVIC_TIM1_UP_TIM10_IRQ
233 // Capture/Compare InteruptEnable and InterruptFlag
234 #define PPM_CC_IE TIM_DIER_CC3IE
235 #define PPM_CC_IF TIM_SR_CC3IF
236 #define PPM_GPIO_PORT GPIOA
237 #define PPM_GPIO_PIN GPIO10
238 #define PPM_GPIO_AF GPIO_AF1
239 
240 #elif PPM_CONFIG == 2
241 /* input on PA01 (Servo 6 pin) */
242 #define USE_PPM_TIM2 1
243 #define PPM_CHANNEL TIM_IC2
244 #define PPM_TIMER_INPUT TIM_IC_IN_TI2
245 #define PPM_IRQ NVIC_TIM2_IRQ
246 // Capture/Compare InteruptEnable and InterruptFlag
247 #define PPM_CC_IE TIM_DIER_CC2IE
248 #define PPM_CC_IF TIM_SR_CC2IF
249 #define PPM_GPIO_PORT GPIOA
250 #define PPM_GPIO_PIN GPIO1
251 #define PPM_GPIO_AF GPIO_AF1
252 
253 // Move default ADC timer
254 #if USE_AD_TIM2
255 #undef USE_AD_TIM2
256 #endif
257 #define USE_AD_TIM1 1
258 
259 #else
260 #error "Unknown PPM config"
261 
262 #endif // PPM_CONFIG
263 
264 /* SPI */
265 #define SPI1_GPIO_AF GPIO_AF5
266 #define SPI1_GPIO_PORT_MISO GPIOA
267 #define SPI1_GPIO_MISO GPIO6
268 #define SPI1_GPIO_PORT_MOSI GPIOA
269 #define SPI1_GPIO_MOSI GPIO7
270 #define SPI1_GPIO_PORT_SCK GPIOA
271 #define SPI1_GPIO_SCK GPIO5
272 
273 #define SPI2_GPIO_AF GPIO_AF5
274 #define SPI2_GPIO_PORT_MISO GPIOB
275 #define SPI2_GPIO_MISO GPIO14
276 #define SPI2_GPIO_PORT_MOSI GPIOB
277 #define SPI2_GPIO_MOSI GPIO15
278 #define SPI2_GPIO_PORT_SCK GPIOB
279 #define SPI2_GPIO_SCK GPIO13
280 
281 #define SPI_SELECT_SLAVE0_PORT GPIOA
282 #define SPI_SELECT_SLAVE0_PIN GPIO15
283 
284 #define SPI_SELECT_SLAVE1_PORT GPIOA
285 #define SPI_SELECT_SLAVE1_PIN GPIO4
286 
287 #define SPI_SELECT_SLAVE2_PORT GPIOB
288 #define SPI_SELECT_SLAVE2_PIN GPIO12
289 
290 #define SPI_SELECT_SLAVE3_PORT GPIOC
291 #define SPI_SELECT_SLAVE3_PIN GPIO13
292 
293 #define SPI_SELECT_SLAVE4_PORT GPIOC
294 #define SPI_SELECT_SLAVE4_PIN GPIO12
295 
296 #define SPI_SELECT_SLAVE5_PORT GPIOC
297 #define SPI_SELECT_SLAVE5_PIN GPIO4
298 
299 
300 #define SPI1_GPIO_PORT_NSS GPIOA
301 #define SPI1_GPIO_NSS GPIO4
302 
303 #define SPI2_GPIO_PORT_NSS GPIOB
304 #define SPI2_GPIO_NSS GPIO12
305 
306 #define SPI3_GPIO_PORT_NSS GPIOA
307 #define SPI3_GPIO_NSS GPIO15
308 
309 /* I2C mapping */
310 #define I2C1_GPIO_PORT GPIOB
311 #define I2C1_GPIO_SCL GPIO6
312 #define I2C1_GPIO_SDA GPIO7
313 
314 #define I2C2_GPIO_PORT GPIOB
315 #define I2C2_GPIO_SCL GPIO10
316 #define I2C2_GPIO_SDA GPIO11
317 
318 
319 /*
320  * ADC
321  */
322 
323 /* Onboard ADCs */
324 /*
325  ADC1 PC3/ADC13
326  ADC2 PC0/ADC10
327  ADC3 PC1/ADC11
328  ADC4 PC5/ADC15
329  ADC6 PC2/ADC12
330  BATT PC4/ADC14
331 */
332 
333 /* provide defines that can be used to access the ADC_x in the code or airframe file
334  * these directly map to the index number of the 4 adc channels defined above
335  * 4th (index 3) is used for bat monitoring by default
336  */
337 #if USE_ADC_1
338 #define AD1_1_CHANNEL 13
339 #define ADC_1 AD1_1
340 #define ADC_1_GPIO_PORT GPIOC
341 #define ADC_1_GPIO_PIN GPIO3
342 #endif
343 
344 #if USE_ADC_2
345 #define AD1_2_CHANNEL 10
346 #define ADC_2 AD1_2
347 #define ADC_2_GPIO_PORT GPIOC
348 #define ADC_2_GPIO_PIN GPIO0
349 #endif
350 
351 #if USE_ADC_3
352 #define AD1_3_CHANNEL 11
353 #define ADC_3 AD1_3
354 #define ADC_3_GPIO_PORT GPIOC
355 #define ADC_3_GPIO_PIN GPIO1
356 #endif
357 
358 #if USE_ADC_4
359 #define AD2_1_CHANNEL 15
360 #define ADC_4 AD2_1
361 #define ADC_4_GPIO_PORT GPIOC
362 #define ADC_4_GPIO_PIN GPIO5
363 #endif
364 
365 // Internal ADC for battery enabled by default
366 #ifndef USE_ADC_5
367 #define USE_ADC_5 1
368 #endif
369 #if USE_ADC_5
370 #define AD1_4_CHANNEL 14
371 #define ADC_5 AD1_4
372 #define ADC_5_GPIO_PORT GPIOC
373 #define ADC_5_GPIO_PIN GPIO4
374 #endif
375 
376 #if USE_ADC_6
377 #define AD2_2_CHANNEL 12
378 #define ADC_6 AD2_2
379 #define ADC_6_GPIO_PORT GPIOC
380 #define ADC_6_GPIO_PIN GPIO2
381 #endif
382 
383 /* allow to define ADC_CHANNEL_VSUPPLY in the airframe file*/
384 #ifndef ADC_CHANNEL_VSUPPLY
385 #define ADC_CHANNEL_VSUPPLY ADC_5
386 #endif
387 
388 #define DefaultVoltageOfAdc(adc) (0.0045*adc)
389 
390 
391 /*
392  * PWM
393  *
394  */
395 #define PWM_USE_TIM3 1
396 #define PWM_USE_TIM5 1
397 
398 #define USE_PWM1 1
399 #define USE_PWM2 1
400 #define USE_PWM3 1
401 #define USE_PWM4 1
402 #define USE_PWM5 1
403 #define USE_PWM6 1
404 
405 #if USE_SERVOS_7AND8
406 #if USE_I2C1
407 #error "You cannot USE_SERVOS_7AND8 and USE_I2C1 at the same time"
408 #else
409 #define ACTUATORS_PWM_NB 8
410 #define USE_PWM7 1
411 #define USE_PWM8 1
412 #define PWM_USE_TIM4 1
413 #endif
414 #else
415 #define ACTUATORS_PWM_NB 6
416 #endif
417 
418 // Servo numbering on LisaM silkscreen/docs starts with 1
419 
420 // PWM_SERVO_x is the index of the servo in the actuators_pwm_values array
421 #if USE_PWM1
422 #define PWM_SERVO_1 0
423 #define PWM_SERVO_1_TIMER TIM3
424 #define PWM_SERVO_1_GPIO GPIOC
425 #define PWM_SERVO_1_PIN GPIO6
426 #define PWM_SERVO_1_AF GPIO_AF2
427 #define PWM_SERVO_1_OC TIM_OC1
428 #define PWM_SERVO_1_OC_BIT (1<<0)
429 #else
430 #define PWM_SERVO_1_OC_BIT 0
431 #endif
432 
433 #if USE_PWM2
434 #define PWM_SERVO_2 1
435 #define PWM_SERVO_2_TIMER TIM3
436 #define PWM_SERVO_2_GPIO GPIOC
437 #define PWM_SERVO_2_PIN GPIO7
438 #define PWM_SERVO_2_AF GPIO_AF2
439 #define PWM_SERVO_2_OC TIM_OC2
440 #define PWM_SERVO_2_OC_BIT (1<<1)
441 #else
442 #define PWM_SERVO_2_OC_BIT 0
443 #endif
444 
445 #if USE_PWM3
446 #define PWM_SERVO_3 2
447 #define PWM_SERVO_3_TIMER TIM3
448 #define PWM_SERVO_3_GPIO GPIOC
449 #define PWM_SERVO_3_PIN GPIO8
450 #define PWM_SERVO_3_AF GPIO_AF2
451 #define PWM_SERVO_3_OC TIM_OC3
452 #define PWM_SERVO_3_OC_BIT (1<<2)
453 #else
454 #define PWM_SERVO_3_OC_BIT 0
455 #endif
456 
457 #if USE_PWM4
458 #define PWM_SERVO_4 3
459 #define PWM_SERVO_4_TIMER TIM3
460 #define PWM_SERVO_4_GPIO GPIOC
461 #define PWM_SERVO_4_PIN GPIO9
462 #define PWM_SERVO_4_AF GPIO_AF2
463 #define PWM_SERVO_4_OC TIM_OC4
464 #define PWM_SERVO_4_OC_BIT (1<<3)
465 #else
466 #define PWM_SERVO_4_OC_BIT 0
467 #endif
468 
469 #if USE_PWM5
470 #define PWM_SERVO_5 4
471 #define PWM_SERVO_5_TIMER TIM5
472 #define PWM_SERVO_5_GPIO GPIOA
473 #define PWM_SERVO_5_PIN GPIO0
474 #define PWM_SERVO_5_AF GPIO_AF2
475 #define PWM_SERVO_5_OC TIM_OC1
476 #define PWM_SERVO_5_OC_BIT (1<<0)
477 #else
478 #define PWM_SERVO_5_OC_BIT 0
479 #endif
480 
481 #if USE_PWM6
482 #define PWM_SERVO_6 5
483 #define PWM_SERVO_6_TIMER TIM5
484 #define PWM_SERVO_6_GPIO GPIOA
485 #define PWM_SERVO_6_PIN GPIO1
486 #define PWM_SERVO_6_AF GPIO_AF2
487 #define PWM_SERVO_6_OC TIM_OC2
488 #define PWM_SERVO_6_OC_BIT (1<<1)
489 #else
490 #define PWM_SERVO_6_OC_BIT 0
491 #endif
492 
493 #if USE_PWM7
494 #define PWM_SERVO_7 6
495 #define PWM_SERVO_7_TIMER TIM4
496 #define PWM_SERVO_7_GPIO GPIOB
497 #define PWM_SERVO_7_PIN GPIO6
498 #define PWM_SERVO_7_AF GPIO_AF2
499 #define PWM_SERVO_7_OC TIM_OC1
500 #define PWM_SERVO_7_OC_BIT (1<<0)
501 #else
502 #define PWM_SERVO_7_OC_BIT 0
503 #endif
504 
505 #if USE_PWM8
506 #define PWM_SERVO_8 7
507 #define PWM_SERVO_8_TIMER TIM4
508 #define PWM_SERVO_8_GPIO GPIOB
509 #define PWM_SERVO_8_PIN GPIO7
510 #define PWM_SERVO_8_AF GPIO_AF2
511 #define PWM_SERVO_8_OC TIM_OC2
512 #define PWM_SERVO_8_OC_BIT (1<<1)
513 #else
514 #define PWM_SERVO_8_OC_BIT 0
515 #endif
516 
517 /* servos 1-4 on TIM3 */
518 #define PWM_TIM3_CHAN_MASK (PWM_SERVO_1_OC_BIT|PWM_SERVO_2_OC_BIT|PWM_SERVO_3_OC_BIT|PWM_SERVO_4_OC_BIT)
519 /* servos 5-6 on TIM5 */
520 #define PWM_TIM5_CHAN_MASK (PWM_SERVO_5_OC_BIT|PWM_SERVO_6_OC_BIT)
521 /* servos 7-8 on TIM4 if USE_SERVOS_7AND8 */
522 #define PWM_TIM4_CHAN_MASK (PWM_SERVO_7_OC_BIT|PWM_SERVO_8_OC_BIT)
523 
524 
525 /* by default activate onboard baro */
526 #ifndef USE_BARO_BOARD
527 #define USE_BARO_BOARD 1
528 #endif
529 
530 #endif /* CONFIG_LISA_MX_COMMON_H */