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
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 #define UART1_GPIO_AF GPIO_AF7
139 #define UART1_GPIO_PORT_RX GPIOA
140 #define UART1_GPIO_RX GPIO10
141 #define UART1_GPIO_PORT_TX GPIOA
142 #define UART1_GPIO_TX GPIO9
143 
144 #define UART2_GPIO_AF GPIO_AF7
145 #define UART2_GPIO_PORT_RX GPIOA
146 #define UART2_GPIO_RX GPIO3
147 #define UART2_GPIO_PORT_TX GPIOA
148 #define UART2_GPIO_TX GPIO2
149 
150 #define UART3_GPIO_AF GPIO_AF7
151 #define UART3_GPIO_PORT_RX GPIOC
152 #define UART3_GPIO_RX GPIO11
153 #define UART3_GPIO_PORT_TX GPIOC
154 #define UART3_GPIO_TX GPIO10
155 
156 #define UART5_GPIO_AF GPIO_AF8
157 #define UART5_GPIO_PORT_RX GPIOD
158 #define UART5_GPIO_RX GPIO2
159 #define UART5_GPIO_PORT_TX GPIOC
160 #define UART5_GPIO_TX GPIO12
161 
162 /*
163  * Spektrum
164  */
165 /* The line that is pulled low at power up to initiate the bind process */
166 /* These are not common between versions of lisa/mx and thus defined in the
167  * version specific header files. */
168 /* #define SPEKTRUM_BIND_PIN GPIO0 */
169 /* #define SPEKTRUM_BIND_PIN_PORT GPIOB */
170 
171 #define SPEKTRUM_UART1_RCC RCC_USART1
172 #define SPEKTRUM_UART1_BANK GPIOA
173 #define SPEKTRUM_UART1_PIN GPIO10
174 #define SPEKTRUM_UART1_AF GPIO_AF7
175 #define SPEKTRUM_UART1_IRQ NVIC_USART1_IRQ
176 #define SPEKTRUM_UART1_ISR usart1_isr
177 #define SPEKTRUM_UART1_DEV USART1
178 
179 #define SPEKTRUM_UART5_RCC RCC_UART5
180 #define SPEKTRUM_UART5_BANK GPIOD
181 #define SPEKTRUM_UART5_PIN GPIO2
182 #define SPEKTRUM_UART5_AF GPIO_AF7
183 #define SPEKTRUM_UART5_IRQ NVIC_UART5_IRQ
184 #define SPEKTRUM_UART5_ISR uart5_isr
185 #define SPEKTRUM_UART5_DEV UART5
186 
187 /* PPM
188  *
189  * Default is PPM config 2, input on GPIOA1 (Servo pin 6)
190  */
191 
192 #ifndef PPM_CONFIG
193 #define PPM_CONFIG 2
194 #endif
195 
196 #if PPM_CONFIG == 1
197 /* input on PA10 (UART1_RX) */
198 #define USE_PPM_TIM1 1
199 #define PPM_CHANNEL TIM_IC3
200 #define PPM_TIMER_INPUT TIM_IC_IN_TI3
201 #define PPM_IRQ NVIC_TIM1_CC_IRQ
202 #define PPM_IRQ2 NVIC_TIM1_UP_TIM10_IRQ
203 // Capture/Compare InteruptEnable and InterruptFlag
204 #define PPM_CC_IE TIM_DIER_CC3IE
205 #define PPM_CC_IF TIM_SR_CC3IF
206 #define PPM_GPIO_PORT GPIOA
207 #define PPM_GPIO_PIN GPIO10
208 #define PPM_GPIO_AF GPIO_AF1
209 
210 #elif PPM_CONFIG == 2
211 /* input on PA01 (Servo 6 pin) */
212 #define USE_PPM_TIM2 1
213 #define PPM_CHANNEL TIM_IC2
214 #define PPM_TIMER_INPUT TIM_IC_IN_TI2
215 #define PPM_IRQ NVIC_TIM2_IRQ
216 // Capture/Compare InteruptEnable and InterruptFlag
217 #define PPM_CC_IE TIM_DIER_CC2IE
218 #define PPM_CC_IF TIM_SR_CC2IF
219 #define PPM_GPIO_PORT GPIOA
220 #define PPM_GPIO_PIN GPIO1
221 #define PPM_GPIO_AF GPIO_AF1
222 
223 // Move default ADC timer
224 #if USE_AD_TIM2
225 #undef USE_AD_TIM2
226 #endif
227 #define USE_AD_TIM1 1
228 
229 #else
230 #error "Unknown PPM config"
231 
232 #endif // PPM_CONFIG
233 
234 /* SPI */
235 #define SPI1_GPIO_AF GPIO_AF5
236 #define SPI1_GPIO_PORT_MISO GPIOA
237 #define SPI1_GPIO_MISO GPIO6
238 #define SPI1_GPIO_PORT_MOSI GPIOA
239 #define SPI1_GPIO_MOSI GPIO7
240 #define SPI1_GPIO_PORT_SCK GPIOA
241 #define SPI1_GPIO_SCK GPIO5
242 
243 #define SPI2_GPIO_AF GPIO_AF5
244 #define SPI2_GPIO_PORT_MISO GPIOB
245 #define SPI2_GPIO_MISO GPIO14
246 #define SPI2_GPIO_PORT_MOSI GPIOB
247 #define SPI2_GPIO_MOSI GPIO15
248 #define SPI2_GPIO_PORT_SCK GPIOB
249 #define SPI2_GPIO_SCK GPIO13
250 
251 #define SPI_SELECT_SLAVE0_PORT GPIOA
252 #define SPI_SELECT_SLAVE0_PIN GPIO15
253 
254 #define SPI_SELECT_SLAVE1_PORT GPIOA
255 #define SPI_SELECT_SLAVE1_PIN GPIO4
256 
257 #define SPI_SELECT_SLAVE2_PORT GPIOB
258 #define SPI_SELECT_SLAVE2_PIN GPIO12
259 
260 #define SPI_SELECT_SLAVE3_PORT GPIOC
261 #define SPI_SELECT_SLAVE3_PIN GPIO13
262 
263 #define SPI_SELECT_SLAVE4_PORT GPIOC
264 #define SPI_SELECT_SLAVE4_PIN GPIO12
265 
266 #define SPI_SELECT_SLAVE5_PORT GPIOC
267 #define SPI_SELECT_SLAVE5_PIN GPIO4
268 
269 
270 /* I2C mapping */
271 #define I2C1_GPIO_PORT GPIOB
272 #define I2C1_GPIO_SCL GPIO6
273 #define I2C1_GPIO_SDA GPIO7
274 
275 #define I2C2_GPIO_PORT GPIOB
276 #define I2C2_GPIO_SCL GPIO10
277 #define I2C2_GPIO_SDA GPIO11
278 
279 
280 /*
281  * ADC
282  */
283 
284 /* Onboard ADCs */
285 /*
286  ADC1 PC3/ADC13
287  ADC2 PC0/ADC10
288  ADC3 PC1/ADC11
289  ADC4 PC5/ADC15
290  ADC6 PC2/ADC12
291  BATT PC4/ADC14
292 */
293 
294 /* provide defines that can be used to access the ADC_x in the code or airframe file
295  * these directly map to the index number of the 4 adc channels defined above
296  * 4th (index 3) is used for bat monitoring by default
297  */
298 #if USE_ADC_1
299 #define AD1_1_CHANNEL 13
300 #define ADC_1 AD1_1
301 #define ADC_1_GPIO_PORT GPIOC
302 #define ADC_1_GPIO_PIN GPIO3
303 #endif
304 
305 #if USE_ADC_2
306 #define AD1_2_CHANNEL 10
307 #define ADC_2 AD1_2
308 #define ADC_2_GPIO_PORT GPIOC
309 #define ADC_2_GPIO_PIN GPIO0
310 #endif
311 
312 #if USE_ADC_3
313 #define AD1_3_CHANNEL 11
314 #define ADC_3 AD1_3
315 #define ADC_3_GPIO_PORT GPIOC
316 #define ADC_3_GPIO_PIN GPIO1
317 #endif
318 
319 #if USE_ADC_4
320 #define AD2_1_CHANNEL 15
321 #define ADC_4 AD2_1
322 #define ADC_4_GPIO_PORT GPIOC
323 #define ADC_4_GPIO_PIN GPIO5
324 #endif
325 
326 // Internal ADC for battery enabled by default
327 #ifndef USE_ADC_5
328 #define USE_ADC_5 1
329 #endif
330 #if USE_ADC_5
331 #define AD1_4_CHANNEL 14
332 #define ADC_5 AD1_4
333 #define ADC_5_GPIO_PORT GPIOC
334 #define ADC_5_GPIO_PIN GPIO4
335 #endif
336 
337 #if USE_ADC_6
338 #define AD2_2_CHANNEL 12
339 #define ADC_6 AD2_2
340 #define ADC_6_GPIO_PORT GPIOC
341 #define ADC_6_GPIO_PIN GPIO2
342 #endif
343 
344 /* allow to define ADC_CHANNEL_VSUPPLY in the airframe file*/
345 #ifndef ADC_CHANNEL_VSUPPLY
346 #define ADC_CHANNEL_VSUPPLY ADC_5
347 #endif
348 
349 #define DefaultVoltageOfAdc(adc) (0.0045*adc)
350 
351 
352 /*
353  * PWM
354  *
355  */
356 #define PWM_USE_TIM3 1
357 #define PWM_USE_TIM5 1
358 
359 #define USE_PWM1 1
360 #define USE_PWM2 1
361 #define USE_PWM3 1
362 #define USE_PWM4 1
363 #define USE_PWM5 1
364 #define USE_PWM6 1
365 
366 #if USE_SERVOS_7AND8
367  #if USE_I2C1
368  #error "You cannot USE_SERVOS_7AND8 and USE_I2C1 at the same time"
369  #else
370  #define ACTUATORS_PWM_NB 8
371  #define USE_PWM7 1
372  #define USE_PWM8 1
373  #define PWM_USE_TIM4 1
374  #endif
375 #else
376  #define ACTUATORS_PWM_NB 6
377 #endif
378 
379 // Servo numbering on LisaM silkscreen/docs starts with 1
380 
381 // PWM_SERVO_x is the index of the servo in the actuators_pwm_values array
382 #if USE_PWM1
383 #define PWM_SERVO_1 0
384 #define PWM_SERVO_1_TIMER TIM3
385 #define PWM_SERVO_1_GPIO GPIOC
386 #define PWM_SERVO_1_PIN GPIO6
387 #define PWM_SERVO_1_AF GPIO_AF2
388 #define PWM_SERVO_1_OC TIM_OC1
389 #define PWM_SERVO_1_OC_BIT (1<<0)
390 #else
391 #define PWM_SERVO_1_OC_BIT 0
392 #endif
393 
394 #if USE_PWM2
395 #define PWM_SERVO_2 1
396 #define PWM_SERVO_2_TIMER TIM3
397 #define PWM_SERVO_2_GPIO GPIOC
398 #define PWM_SERVO_2_PIN GPIO7
399 #define PWM_SERVO_2_AF GPIO_AF2
400 #define PWM_SERVO_2_OC TIM_OC2
401 #define PWM_SERVO_2_OC_BIT (1<<1)
402 #else
403 #define PWM_SERVO_2_OC_BIT 0
404 #endif
405 
406 #if USE_PWM3
407 #define PWM_SERVO_3 2
408 #define PWM_SERVO_3_TIMER TIM3
409 #define PWM_SERVO_3_GPIO GPIOC
410 #define PWM_SERVO_3_PIN GPIO8
411 #define PWM_SERVO_3_AF GPIO_AF2
412 #define PWM_SERVO_3_OC TIM_OC3
413 #define PWM_SERVO_3_OC_BIT (1<<2)
414 #else
415 #define PWM_SERVO_3_OC_BIT 0
416 #endif
417 
418 #if USE_PWM4
419 #define PWM_SERVO_4 3
420 #define PWM_SERVO_4_TIMER TIM3
421 #define PWM_SERVO_4_GPIO GPIOC
422 #define PWM_SERVO_4_PIN GPIO9
423 #define PWM_SERVO_4_AF GPIO_AF2
424 #define PWM_SERVO_4_OC TIM_OC4
425 #define PWM_SERVO_4_OC_BIT (1<<3)
426 #else
427 #define PWM_SERVO_4_OC_BIT 0
428 #endif
429 
430 #if USE_PWM5
431 #define PWM_SERVO_5 4
432 #define PWM_SERVO_5_TIMER TIM5
433 #define PWM_SERVO_5_GPIO GPIOA
434 #define PWM_SERVO_5_PIN GPIO0
435 #define PWM_SERVO_5_AF GPIO_AF2
436 #define PWM_SERVO_5_OC TIM_OC1
437 #define PWM_SERVO_5_OC_BIT (1<<0)
438 #else
439 #define PWM_SERVO_5_OC_BIT 0
440 #endif
441 
442 #if USE_PWM6
443 #define PWM_SERVO_6 5
444 #define PWM_SERVO_6_TIMER TIM5
445 #define PWM_SERVO_6_GPIO GPIOA
446 #define PWM_SERVO_6_PIN GPIO1
447 #define PWM_SERVO_6_AF GPIO_AF2
448 #define PWM_SERVO_6_OC TIM_OC2
449 #define PWM_SERVO_6_OC_BIT (1<<1)
450 #else
451 #define PWM_SERVO_6_OC_BIT 0
452 #endif
453 
454 #if USE_PWM7
455 #define PWM_SERVO_7 6
456 #define PWM_SERVO_7_TIMER TIM4
457 #define PWM_SERVO_7_GPIO GPIOB
458 #define PWM_SERVO_7_PIN GPIO6
459 #define PWM_SERVO_7_AF GPIO_AF2
460 #define PWM_SERVO_7_OC TIM_OC1
461 #define PWM_SERVO_7_OC_BIT (1<<0)
462 #else
463 #define PWM_SERVO_7_OC_BIT 0
464 #endif
465 
466 #if USE_PWM8
467 #define PWM_SERVO_8 7
468 #define PWM_SERVO_8_TIMER TIM4
469 #define PWM_SERVO_8_GPIO GPIOB
470 #define PWM_SERVO_8_PIN GPIO7
471 #define PWM_SERVO_8_AF GPIO_AF2
472 #define PWM_SERVO_8_OC TIM_OC2
473 #define PWM_SERVO_8_OC_BIT (1<<1)
474 #else
475 #define PWM_SERVO_8_OC_BIT 0
476 #endif
477 
478 /* servos 1-4 on TIM3 */
479 #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)
480 /* servos 5-6 on TIM5 */
481 #define PWM_TIM5_CHAN_MASK (PWM_SERVO_5_OC_BIT|PWM_SERVO_6_OC_BIT)
482 /* servos 7-8 on TIM4 if USE_SERVOS_7AND8 */
483 #define PWM_TIM4_CHAN_MASK (PWM_SERVO_7_OC_BIT|PWM_SERVO_8_OC_BIT)
484 
485 
486 /* by default activate onboard baro */
487 #ifndef USE_BARO_BOARD
488 #define USE_BARO_BOARD 1
489 #endif
490 
491 #endif /* CONFIG_LISA_MX_COMMON_H */