Paparazzi UAS  v5.15_devel-81-gd13dafb
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  ADC7 PA3/ADC03
331  ADC8 PA0/ADC00
332  BATT PC4/ADC14
333 */
334 
335 /* provide defines that can be used to access the ADC_x in the code or airframe file
336  * these directly map to the index number of the 4 adc channels defined above
337  * 4th (index 3) is used for bat monitoring by default
338  */
339 #if USE_ADC_1
340 #define AD1_1_CHANNEL 13
341 #define ADC_1 AD1_1
342 #define ADC_1_GPIO_PORT GPIOC
343 #define ADC_1_GPIO_PIN GPIO3
344 #endif
345 
346 #if USE_ADC_2
347 #define AD1_2_CHANNEL 10
348 #define ADC_2 AD1_2
349 #define ADC_2_GPIO_PORT GPIOC
350 #define ADC_2_GPIO_PIN GPIO0
351 #endif
352 
353 #if USE_ADC_3
354 #define AD1_3_CHANNEL 11
355 #define ADC_3 AD1_3
356 #define ADC_3_GPIO_PORT GPIOC
357 #define ADC_3_GPIO_PIN GPIO1
358 #endif
359 
360 #if USE_ADC_4
361 #define AD2_1_CHANNEL 15
362 #define ADC_4 AD2_1
363 #define ADC_4_GPIO_PORT GPIOC
364 #define ADC_4_GPIO_PIN GPIO5
365 #endif
366 
367 // Internal ADC for battery enabled by default
368 #ifndef USE_ADC_5
369 #define USE_ADC_5 1
370 #endif
371 #if USE_ADC_5
372 #define AD1_4_CHANNEL 14
373 #define ADC_5 AD1_4
374 #define ADC_5_GPIO_PORT GPIOC
375 #define ADC_5_GPIO_PIN GPIO4
376 #endif
377 
378 #if USE_ADC_6
379 #define AD2_2_CHANNEL 12
380 #define ADC_6 AD2_2
381 #define ADC_6_GPIO_PORT GPIOC
382 #define ADC_6_GPIO_PIN GPIO2
383 #endif
384 
385 #if USE_ADC_7
386 #define AD2_3_CHANNEL 3
387 #define ADC_4 AD2_3
388 #define ADC_4_GPIO_PORT GPIOA
389 #define ADC_4_GPIO_PIN GPIO3
390 #endif
391 
392 #if USE_ADC_8
393 #define AD2_4_CHANNEL 0
394 #define ADC_8 AD2_4
395 #define ADC_8_GPIO_PORT GPIOA
396 #define ADC_8_GPIO_PIN GPIO0
397 #endif
398 
399 /* allow to define ADC_CHANNEL_VSUPPLY in the airframe file*/
400 #ifndef ADC_CHANNEL_VSUPPLY
401 #define ADC_CHANNEL_VSUPPLY ADC_5
402 #endif
403 
404 #define DefaultVoltageOfAdc(adc) (0.0045*adc)
405 
406 
407 /*
408  * PWM
409  *
410  */
411 #define PWM_USE_TIM3 1
412 #define PWM_USE_TIM5 1
413 
414 #define USE_PWM1 1
415 #define USE_PWM2 1
416 #define USE_PWM3 1
417 #define USE_PWM4 1
418 
419 #ifndef USE_PWM5 // this allows to disable servo 5 on Lisa MXS
420 #define USE_PWM5 1
421 #endif
422 
423 #define USE_PWM6 1
424 
425 #if USE_SERVOS_7AND8
426 #if USE_I2C1
427 #error "You cannot USE_SERVOS_7AND8 and USE_I2C1 at the same time"
428 #else
429 #define ACTUATORS_PWM_NB 8
430 #define USE_PWM7 1
431 #define USE_PWM8 1
432 #define PWM_USE_TIM4 1
433 #endif
434 #else
435 #define ACTUATORS_PWM_NB 6
436 #endif
437 
438 // Servo numbering on LisaM silkscreen/docs starts with 1
439 
440 // PWM_SERVO_x is the index of the servo in the actuators_pwm_values array
441 #if USE_PWM1
442 #define PWM_SERVO_1 0
443 #define PWM_SERVO_1_TIMER TIM3
444 #define PWM_SERVO_1_GPIO GPIOC
445 #define PWM_SERVO_1_PIN GPIO6
446 #define PWM_SERVO_1_AF GPIO_AF2
447 #define PWM_SERVO_1_OC TIM_OC1
448 #define PWM_SERVO_1_OC_BIT (1<<0)
449 #else
450 #define PWM_SERVO_1_OC_BIT 0
451 #endif
452 
453 #if USE_PWM2
454 #define PWM_SERVO_2 1
455 #define PWM_SERVO_2_TIMER TIM3
456 #define PWM_SERVO_2_GPIO GPIOC
457 #define PWM_SERVO_2_PIN GPIO7
458 #define PWM_SERVO_2_AF GPIO_AF2
459 #define PWM_SERVO_2_OC TIM_OC2
460 #define PWM_SERVO_2_OC_BIT (1<<1)
461 #else
462 #define PWM_SERVO_2_OC_BIT 0
463 #endif
464 
465 #if USE_PWM3
466 #define PWM_SERVO_3 2
467 #define PWM_SERVO_3_TIMER TIM3
468 #define PWM_SERVO_3_GPIO GPIOC
469 #define PWM_SERVO_3_PIN GPIO8
470 #define PWM_SERVO_3_AF GPIO_AF2
471 #define PWM_SERVO_3_OC TIM_OC3
472 #define PWM_SERVO_3_OC_BIT (1<<2)
473 #else
474 #define PWM_SERVO_3_OC_BIT 0
475 #endif
476 
477 #if USE_PWM4
478 #define PWM_SERVO_4 3
479 #define PWM_SERVO_4_TIMER TIM3
480 #define PWM_SERVO_4_GPIO GPIOC
481 #define PWM_SERVO_4_PIN GPIO9
482 #define PWM_SERVO_4_AF GPIO_AF2
483 #define PWM_SERVO_4_OC TIM_OC4
484 #define PWM_SERVO_4_OC_BIT (1<<3)
485 #else
486 #define PWM_SERVO_4_OC_BIT 0
487 #endif
488 
489 #if USE_PWM5
490 #define PWM_SERVO_5 4
491 #define PWM_SERVO_5_TIMER TIM5
492 #define PWM_SERVO_5_GPIO GPIOA
493 #define PWM_SERVO_5_PIN GPIO0
494 #define PWM_SERVO_5_AF GPIO_AF2
495 #define PWM_SERVO_5_OC TIM_OC1
496 #define PWM_SERVO_5_OC_BIT (1<<0)
497 #else
498 #define PWM_SERVO_5_OC_BIT 0
499 #endif
500 
501 #if USE_PWM6
502 #define PWM_SERVO_6 5
503 #define PWM_SERVO_6_TIMER TIM5
504 #define PWM_SERVO_6_GPIO GPIOA
505 #define PWM_SERVO_6_PIN GPIO1
506 #define PWM_SERVO_6_AF GPIO_AF2
507 #define PWM_SERVO_6_OC TIM_OC2
508 #define PWM_SERVO_6_OC_BIT (1<<1)
509 #else
510 #define PWM_SERVO_6_OC_BIT 0
511 #endif
512 
513 #if USE_PWM7
514 #define PWM_SERVO_7 6
515 #define PWM_SERVO_7_TIMER TIM4
516 #define PWM_SERVO_7_GPIO GPIOB
517 #define PWM_SERVO_7_PIN GPIO6
518 #define PWM_SERVO_7_AF GPIO_AF2
519 #define PWM_SERVO_7_OC TIM_OC1
520 #define PWM_SERVO_7_OC_BIT (1<<0)
521 #else
522 #define PWM_SERVO_7_OC_BIT 0
523 #endif
524 
525 #if USE_PWM8
526 #define PWM_SERVO_8 7
527 #define PWM_SERVO_8_TIMER TIM4
528 #define PWM_SERVO_8_GPIO GPIOB
529 #define PWM_SERVO_8_PIN GPIO7
530 #define PWM_SERVO_8_AF GPIO_AF2
531 #define PWM_SERVO_8_OC TIM_OC2
532 #define PWM_SERVO_8_OC_BIT (1<<1)
533 #else
534 #define PWM_SERVO_8_OC_BIT 0
535 #endif
536 
537 /* servos 1-4 on TIM3 */
538 #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)
539 /* servos 5-6 on TIM5 */
540 #define PWM_TIM5_CHAN_MASK (PWM_SERVO_5_OC_BIT|PWM_SERVO_6_OC_BIT)
541 /* servos 7-8 on TIM4 if USE_SERVOS_7AND8 */
542 #define PWM_TIM4_CHAN_MASK (PWM_SERVO_7_OC_BIT|PWM_SERVO_8_OC_BIT)
543 
544 
545 /* by default activate onboard baro */
546 #ifndef USE_BARO_BOARD
547 #define USE_BARO_BOARD 1
548 #endif
549 
550 #endif /* CONFIG_LISA_MX_COMMON_H */