Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
matek_f405_wing_v1.h
Go to the documentation of this file.
1 /*
2  * Chris Efstathiou hendrixgr@gmail.com
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_MATEK_F405_WING_1_0_H
24 #define CONFIG_MATEK_F405_WING_1_0_H
25 
26 #define BOARD_MATEK_F405_WING
27 
28 /* The Matek F405 Wing autopilot has a 8MHz external clock and 168MHz internal. */
29 #define EXT_CLK 8000000
30 #define AHB_CLK 168000000
31 
32 // Onboard LEDs
33 /* STAT blue, on PB5 */
34 #ifndef USE_LED_1
35 #define USE_LED_1 1
36 #endif
37 #define LED_1_GPIO GPIOA
38 #define LED_1_GPIO_PIN GPIO14
39 #define LED_1_GPIO_ON gpio_clear
40 #define LED_1_GPIO_OFF gpio_set
41 #define LED_1_AFIO_REMAP ((void)0)
42 
43 /* WARN red, on PB4 */
44 #ifndef USE_LED_2
45 #define USE_LED_2 1
46 #endif
47 #define LED_2_GPIO GPIOA
48 #define LED_2_GPIO_PIN GPIO13
49 #define LED_2_GPIO_ON gpio_clear
50 #define LED_2_GPIO_OFF gpio_set
51 #define LED_2_AFIO_REMAP ((void)0)
52 
53 // LED STRIP 2812
54 #ifndef USE_LED_3
55 #define USE_LED_3 1
56 #endif
57 #define LED_3_GPIO GPIOA
58 #define LED_3_GPIO_PIN GPIO15
59 #define LED_3_GPIO_ON gpio_clear
60 #define LED_3_GPIO_OFF gpio_set
61 #define LED_3_AFIO_REMAP ((void)0)
62 
63 // BEEPER
64 #ifndef USE_LED_4
65 #define USE_LED_4 1
66 #endif
67 #define LED_4_GPIO GPIOC
68 #define LED_4_GPIO_PIN GPIO15
69 #define LED_4_GPIO_ON gpio_clear
70 #define LED_4_GPIO_OFF gpio_set
71 #define LED_4_AFIO_REMAP ((void)0)
72 
73 
74 /* Default actuators driver */
75 #define DEFAULT_ACTUATORS "modules/actuators/actuators_pwm.h"
76 #define ActuatorDefaultSet(_x,_y) ActuatorPwmSet(_x,_y)
77 #define ActuatorsDefaultInit() ActuatorsPwmInit()
78 #define ActuatorsDefaultCommit() ActuatorsPwmCommit()
79 
80 
81 #define VBUS_GPIO GPIOC
82 #define VBUS_GPIO_PIN GPIO13
83 
84 /* UART */
85 //CAN BE USED AS GPS SERIAL PORT
86 #define UART1_GPIO_AF GPIO_AF7
87 #define UART1_GPIO_PORT_TX GPIOA
88 #define UART1_GPIO_TX GPIO9
89 #define UART1_GPIO_PORT_RX GPIOA
90 #define UART1_GPIO_RX GPIO10
91 
92 // UART 2 RX INPUT IS USED AS THE PPM INPUT THUS I WILL USE THE TX OUTPUT AS ADC INPUT
93 #define UART2_GPIO_AF GPIO_AF7
94 #define UART2_GPIO_PORT_TX GPIOA
95 #define UART2_GPIO_TX GPIO2
96 #define UART2_GPIO_PORT_RX GPIOA
97 #define UART2_GPIO_RX GPIO3
98 
99 #define UART3_GPIO_AF GPIO_AF7
100 #define UART3_GPIO_PORT_TX GPIOC
101 #define UART3_GPIO_TX GPIO10
102 #define UART3_GPIO_PORT_RX GPIOC
103 #define UART3_GPIO_RX GPIO11
104 
105 #define UART4_GPIO_AF GPIO_AF8
106 #define UART4_GPIO_PORT_TX GPIOA
107 #define UART4_GPIO_TX GPIO0
108 #define UART4_GPIO_PORT_RX GPIOA
109 #define UART4_GPIO_RX GPIO1
110 
111 #define UART5_GPIO_AF GPIO_AF8
112 #define UART5_GPIO_PORT_TX GPIOC
113 #define UART5_GPIO_TX GPIO12
114 #define UART5_GPIO_PORT_RX GPIOD
115 #define UART5_GPIO_RX GPIO2
116 
117 // CAN BE USED AS A MODEM SERIAL PORT
118 #define UART6_GPIO_AF GPIO_AF8
119 #define UART6_GPIO_PORT_TX GPIOC
120 #define UART6_GPIO_TX GPIO6
121 #define UART6_GPIO_PORT_RX GPIOC
122 #define UART6_GPIO_RX GPIO7
123 
124 // SPI1, MPU6000 ON SPI1
125 #define SPI1_GPIO_AF GPIO_AF5
126 
127 #define SPI1_GPIO_PORT_SCK GPIOA
128 #define SPI1_GPIO_SCK GPIO5
129 #define SPI1_GPIO_PORT_MISO GPIOA
130 #define SPI1_GPIO_MISO GPIO6
131 #define SPI1_GPIO_PORT_MOSI GPIOA
132 #define SPI1_GPIO_MOSI GPIO7
133 #define SPI1_GPIO_PORT_NSS GPIOA
134 #define SPI1_GPIO_NSS GPIO4
135 
136 #define SPI_SELECT_SLAVE0_PORT GPIOA
137 #define SPI_SELECT_SLAVE0_PIN GPIO4
138 
139 // SPI2 IS USED FOR THE MAX7456 OSD
140 #define SPI2_GPIO_AF GPIO_AF5
141 
142 #define SPI2_GPIO_PORT_SCK GPIOB
143 #define SPI2_GPIO_SCK GPIO13
144 #define SPI2_GPIO_PORT_MISO GPIOC
145 #define SPI2_GPIO_MISO GPIO2
146 #define SPI2_GPIO_PORT_MOSI GPIOC
147 #define SPI2_GPIO_MOSI GPIO3
148 #define SPI2_GPIO_PORT_NSS GPIOB
149 #define SPI2_GPIO_NSS GPIO12
150 
151 #define SPI_SELECT_SLAVE1_PORT GPIOB
152 #define SPI_SELECT_SLAVE1_PIN GPIO12
153 
154 // SDCARD ON SPI3
155 #define SPI3_GPIO_AF GPIO_AF5
156 
157 #define SPI3_GPIO_PORT_SCK GPIOB
158 #define SPI3_GPIO_SCK GPIO3
159 #define SPI3_GPIO_PORT_MISO GPIOB
160 #define SPI3_GPIO_MISO GPIO4
161 #define SPI3_GPIO_PORT_MOSI GPIOB
162 #define SPI3_GPIO_MOSI GPIO5
163 #define SPI3_GPIO_PORT_NSS GPIOC
164 #define SPI3_GPIO_NSS GPIO14
165 
166 #define SPI_SELECT_SLAVE2_PORT GPIOC
167 #define SPI_SELECT_SLAVE2_PIN GPIO14
168 
169 
170 /* I2C mapping */
171 /* HMC5883L mag on I2C1 with DRDY on PB7 */
172 /* MS5611 baro on I2C1 */
173 #define I2C1_GPIO_PORT GPIOB
174 #define I2C1_GPIO_SCL GPIO8
175 #define I2C1_GPIO_SDA GPIO9
176 
177 #define I2C2_GPIO_PORT GPIOB
178 #define I2C2_GPIO_SCL GPIO10
179 #define I2C2_GPIO_SDA GPIO11
180 
181 // ADC
182 
183 /* Onboard ADCs */
184 /*
185  ADC1 PC2/ADC1,2,3 channel 12 (Voltage input 3.3v max)
186  ADC2 PC1/ADC1,2,3 channel 11 (Current input 3.3v max)
187  ADC3 PA3/ADC1,2,3 channel 3
188  ADC4 PA2/ADC1,2,3 channel 2
189 */
190 
191 /* provide defines that can be used to access the ADC_x in the code or airframe file
192  * these directly map to the index number of the 4 adc channels defined above
193  * 4th (index 3) is used for bat monitoring by default
194  */
195 
196 #define USE_AD_TIM2 1
197 
198 #ifndef USE_ADC_1
199 #define USE_ADC_1 1
200 #endif
201 
202 #ifndef USE_ADC_2
203 #define USE_ADC_2 1
204 #endif
205 
206 #ifndef USE_ADC_3
207 #define USE_ADC_3 1
208 #endif
209 
210 #ifndef USE_ADC_4
211 #define USE_ADC_4 1
212 #endif
213 
214 // POWER SUPPLY VOLTAGE MEASUREMENT INPUT
215 #if USE_ADC_1
216 #define AD1_1_CHANNEL 10
217 #define ADC_1 AD1_1
218 #define ADC_1_GPIO_PORT GPIOC
219 #define ADC_1_GPIO_PIN GPIO0
220 #endif
221 
222 // CURRENT MEASUREMENT INPUT
223 #if USE_ADC_2
224 #define AD1_2_CHANNEL 11
225 #define ADC_2 AD1_2
226 #define ADC_2_GPIO_PORT GPIOC
227 #define ADC_2_GPIO_PIN GPIO1
228 #ifndef CURRENT_ADC_IN
229 #define CURRENT_ADC_IN ADC_2
230 #endif
231 #endif
232 
233 // RSSI MEASUREMENT INPUT
234 #if USE_ADC_3
235 #define AD1_3_CHANNEL 15
236 #define ADC_3 AD1_3
237 #define ADC_3_GPIO_PORT GPIOC
238 #define ADC_3_GPIO_PIN GPIO5
239 #endif
240 
241 // FREE, LABELED AS UART2 TX PIN
242 #if USE_ADC_4
243 #define AD1_4_CHANNEL 2
244 #define ADC_4 AD1_4
245 #define ADC_4_GPIO_PORT GPIOA
246 #define ADC_4_GPIO_PIN GPIO2
247 #endif
248 
249 /* allow to define ADC_CHANNEL_VSUPPLY in the airframe file*/
250 #ifndef ADC_CHANNEL_VSUPPLY
251 #define ADC_CHANNEL_VSUPPLY ADC_1
252 #endif
253 
254 #ifndef ADC_CHANNEL_CURRENT
255 #define ADC_CHANNEL_CURRENT ADC_2
256 #endif
257 
258 /* no voltage divider on board, adjust VoltageOfAdc in airframe file */
259 #define DefaultVoltageOfAdc(adc) (0.008830925*adc)
260 #define DefaultMilliAmpereOfAdc(adc) (25*adc)
261 
262 #define UART2_RX 1
263 #define SERVO9_PWM_OUT 2
264 
265 #if defined(RADIO_CONTROL_PPM_PIN) && RADIO_CONTROL_PPM_PIN == UART2_RX
266 
267 // THE PPM INPUT IS ALSO THE UART2 RX
268 #define USE_PPM_TIM9 1
269 #define PPM_CHANNEL TIM_IC2
270 #define PPM_TIMER_INPUT TIM_IC_IN_TI2
271 #define PPM_IRQ NVIC_TIM1_BRK_TIM9_IRQ
272 // Capture/Compare InteruptEnable and InterruptFlag
273 #define PPM_CC_IE TIM_DIER_CC2IE
274 #define PPM_CC_IF TIM_SR_CC2IF
275 #define PPM_GPIO_PORT GPIOA
276 #define PPM_GPIO_PIN GPIO3
277 #define PPM_GPIO_AF GPIO_AF3
278 
279 #else
280 
281 #define USE_PPM_TIM1 1
282 #define PPM_CHANNEL TIM_IC1
283 #define PPM_TIMER_INPUT TIM_IC_IN_TI1
284 #define PPM_IRQ NVIC_TIM1_CC_IRQ
285 // Capture/Compare InteruptEnable and InterruptFlag
286 #define PPM_CC_IE TIM_DIER_CC1IE
287 #define PPM_CC_IF TIM_SR_CC1IF
288 #define PPM_GPIO_PORT GPIOA
289 #define PPM_GPIO_PIN GPIO8
290 #define PPM_GPIO_AF GPIO_AF1
291 
292 #endif
293 
294 // SERVO DEFINITIONS
295 #define PWM_USE_TIM1 0
296 #define PWM_USE_TIM3 1
297 #define PWM_USE_TIM4 1
298 #define PWM_USE_TIM8 1
299 #define PWM_USE_TIM12 1
300 
301 #define USE_PWM1 1
302 #define USE_PWM2 1
303 #define USE_PWM3 1
304 #define USE_PWM4 1
305 #define USE_PWM5 1
306 #define USE_PWM6 1
307 #define USE_PWM7 1
308 #define USE_PWM8 1
309 #define USE_PWM9 0
310 
311 // PWM_SERVO_x is the index of the servo in the actuators_pwm_values array
312 #if USE_PWM1
313 #define PWM_SERVO_1 0
314 #define PWM_SERVO_1_TIMER TIM4
315 #define PWM_SERVO_1_GPIO GPIOB
316 #define PWM_SERVO_1_PIN GPIO7
317 #define PWM_SERVO_1_AF GPIO_AF2
318 #define PWM_SERVO_1_OC TIM_OC2
319 #define PWM_SERVO_1_OC_BIT (1<<1)
320 #else
321 #define PWM_SERVO_1_OC_BIT 0
322 #endif
323 
324 #if USE_PWM2
325 #define PWM_SERVO_2 1
326 #define PWM_SERVO_2_TIMER TIM4
327 #define PWM_SERVO_2_GPIO GPIOB
328 #define PWM_SERVO_2_PIN GPIO6
329 #define PWM_SERVO_2_AF GPIO_AF2
330 #define PWM_SERVO_2_OC TIM_OC1
331 #define PWM_SERVO_2_OC_BIT (1<<0)
332 #else
333 #define PWM_SERVO_2_OC_BIT 0
334 #endif
335 
336 #if USE_PWM3
337 #define PWM_SERVO_3 2
338 #define PWM_SERVO_3_TIMER TIM3
339 #define PWM_SERVO_3_GPIO GPIOB
340 #define PWM_SERVO_3_PIN GPIO0
341 #define PWM_SERVO_3_AF GPIO_AF2
342 #define PWM_SERVO_3_OC TIM_OC3
343 #define PWM_SERVO_3_OC_BIT (1<<2)
344 #else
345 #define PWM_SERVO_3_OC_BIT 0
346 #endif
347 
348 #if USE_PWM4
349 #define PWM_SERVO_4 3
350 #define PWM_SERVO_4_TIMER TIM3
351 #define PWM_SERVO_4_GPIO GPIOB
352 #define PWM_SERVO_4_PIN GPIO1
353 #define PWM_SERVO_4_AF GPIO_AF2
354 #define PWM_SERVO_4_OC TIM_OC4
355 #define PWM_SERVO_4_OC_BIT (1<<3)
356 #else
357 #define PWM_SERVO_4_OC_BIT 0
358 #endif
359 
360 #if USE_PWM5
361 #define PWM_SERVO_5 4
362 #define PWM_SERVO_5_TIMER TIM8
363 #define PWM_SERVO_5_GPIO GPIOC
364 #define PWM_SERVO_5_PIN GPIO8
365 #define PWM_SERVO_5_AF GPIO_AF3
366 #define PWM_SERVO_5_OC TIM_OC3
367 #define PWM_SERVO_5_OC_BIT (1<<2)
368 #else
369 #define PWM_SERVO_5_OC_BIT 0
370 #endif
371 
372 #if USE_PWM6
373 #define PWM_SERVO_6 5
374 #define PWM_SERVO_6_TIMER TIM8
375 #define PWM_SERVO_6_GPIO GPIOC
376 #define PWM_SERVO_6_PIN GPIO9
377 #define PWM_SERVO_6_AF GPIO_AF3
378 #define PWM_SERVO_6_OC TIM_OC4
379 #define PWM_SERVO_6_OC_BIT (1<<3)
380 #else
381 #define PWM_SERVO_6_OC_BIT 0
382 #endif
383 
384 #if USE_PWM7
385 #define PWM_SERVO_7 6
386 #define PWM_SERVO_7_TIMER TIM12
387 #define PWM_SERVO_7_GPIO GPIOB
388 #define PWM_SERVO_7_PIN GPIO14
389 #define PWM_SERVO_7_AF GPIO_AF9
390 #define PWM_SERVO_7_OC TIM_OC1
391 #define PWM_SERVO_7_OC_BIT (1<<0)
392 #else
393 #define PWM_SERVO_7_OC_BIT 0
394 #endif
395 
396 #if USE_PWM8
397 #define PWM_SERVO_8 7
398 #define PWM_SERVO_8_TIMER TIM12
399 #define PWM_SERVO_8_GPIO GPIOB
400 #define PWM_SERVO_8_PIN GPIO15
401 #define PWM_SERVO_8_AF GPIO_AF9
402 #define PWM_SERVO_8_OC TIM_OC2
403 #define PWM_SERVO_8_OC_BIT (1<<1)
404 #else
405 #define PWM_SERVO_8_OC_BIT 0
406 #endif
407 
408 #if USE_PWM9
409 #define PWM_SERVO_9 8
410 #define PWM_SERVO_9_TIMER TIM1
411 #define PWM_SERVO_9_GPIO GPIOA
412 #define PWM_SERVO_9_PIN GPIO8
413 #define PWM_SERVO_9_AF GPIO_AF1
414 #define PWM_SERVO_9_OC TIM_OC1
415 #define PWM_SERVO_9_OC_BIT (1<<0)
416 #else
417 #define PWM_SERVO_9_OC_BIT 0
418 #endif
419 
420 
421 // servos 1-2 on TIM4
422 #define PWM_TIM4_CHAN_MASK (PWM_SERVO_1_OC_BIT | PWM_SERVO_2_OC_BIT)
423 // servos 3-4 on TIM3
424 #define PWM_TIM3_CHAN_MASK (PWM_SERVO_3_OC_BIT | PWM_SERVO_4_OC_BIT)
425 // servos 5-6 on TIM8
426 #define PWM_TIM8_CHAN_MASK (PWM_SERVO_5_OC_BIT | PWM_SERVO_6_OC_BIT)
427 // servos 7-8 on TIM12
428 #define PWM_TIM12_CHAN_MASK (PWM_SERVO_7_OC_BIT | PWM_SERVO_8_OC_BIT)
429 // servo 9 on TIM1
430 #if USE_PWM9
431 #define PWM_TIM1_CHAN_MASK (PWM_SERVO_9_OC_BIT)
432 #endif
433 
434 
435 /*
436  * Spektrum
437  */
438 /* The line that is pulled low at power up to initiate the bind process */
439 #define SPEKTRUM_BIND_PIN GPIO0
440 #define SPEKTRUM_BIND_PIN_PORT GPIOB
441 
442 #define SPEKTRUM_UART1_RCC RCC_USART1
443 #define SPEKTRUM_UART1_BANK GPIOA
444 #define SPEKTRUM_UART1_PIN GPIO10
445 #define SPEKTRUM_UART1_AF GPIO_AF7
446 #define SPEKTRUM_UART1_IRQ NVIC_USART1_IRQ
447 #define SPEKTRUM_UART1_ISR usart1_isr
448 #define SPEKTRUM_UART1_DEV USART1
449 
450 #define SPEKTRUM_UART2_RCC RCC_USART2
451 #define SPEKTRUM_UART2_BANK GPIOA
452 #define SPEKTRUM_UART2_PIN GPIO3
453 #define SPEKTRUM_UART2_AF GPIO_AF8
454 #define SPEKTRUM_UART2_IRQ NVIC_USART2_IRQ
455 #define SPEKTRUM_UART2_ISR usart2_isr
456 #define SPEKTRUM_UART2_DEV USART2
457 
458 #define SPEKTRUM_UART5_RCC RCC_UART5
459 #define SPEKTRUM_UART5_BANK GPIOD
460 #define SPEKTRUM_UART5_PIN GPIO2
461 #define SPEKTRUM_UART5_AF GPIO_AF8
462 #define SPEKTRUM_UART5_IRQ NVIC_UART5_IRQ
463 #define SPEKTRUM_UART5_ISR uart5_isr
464 #define SPEKTRUM_UART5_DEV UART5
465 
466 
467 
468 #endif // CONFIG_MATEK_F405_WING_1_0_H