REVONANO - Support distinct remaps for SDA and SCL
[librepilot.git] / flight / targets / boards / revolution / board_hw_defs.c
blobd776661473b4d52065cd388f160ae6e415eb99c6
1 /**
2 ******************************************************************************
3 * @file board_hw_defs.c
4 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
5 * @author PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012
6 * @addtogroup OpenPilotSystem OpenPilot System
7 * @{
8 * @addtogroup OpenPilotCore OpenPilot Core
9 * @{
10 * @brief Defines board specific static initializers for hardware for the Revolution board.
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #if defined(PIOS_INCLUDE_LED)
30 #include <pios_led_priv.h>
31 static const struct pios_gpio pios_leds[] = {
32 [PIOS_LED_HEARTBEAT] = {
33 .pin = {
34 .gpio = GPIOB,
35 .init = {
36 .GPIO_Pin = GPIO_Pin_12,
37 .GPIO_Speed = GPIO_Speed_50MHz,
38 .GPIO_Mode = GPIO_Mode_OUT,
39 .GPIO_OType = GPIO_OType_PP,
40 .GPIO_PuPd = GPIO_PuPd_UP
43 .active_low = true
45 [PIOS_LED_ALARM] = {
46 .pin = {
47 .gpio = GPIOB,
48 .init = {
49 .GPIO_Pin = GPIO_Pin_6,
50 .GPIO_Speed = GPIO_Speed_50MHz,
51 .GPIO_Mode = GPIO_Mode_OUT,
52 .GPIO_OType = GPIO_OType_PP,
53 .GPIO_PuPd = GPIO_PuPd_UP
56 .active_low = true
58 #ifdef PIOS_RFM22B_DEBUG_ON_TELEM
59 [PIOS_LED_D1] = {
60 .pin = {
61 .gpio = GPIOC,
62 .init = {
63 .GPIO_Pin = GPIO_Pin_6,
64 .GPIO_Speed = GPIO_Speed_50MHz,
65 .GPIO_Mode = GPIO_Mode_OUT,
66 .GPIO_OType = GPIO_OType_PP,
67 .GPIO_PuPd = GPIO_PuPd_UP
71 [PIOS_LED_D2] = {
72 .pin = {
73 .gpio = GPIOC,
74 .init = {
75 .GPIO_Pin = GPIO_Pin_7,
76 .GPIO_Speed = GPIO_Speed_50MHz,
77 .GPIO_Mode = GPIO_Mode_OUT,
78 .GPIO_OType = GPIO_OType_PP,
79 .GPIO_PuPd = GPIO_PuPd_UP
83 [PIOS_LED_D3] = {
84 .pin = {
85 .gpio = GPIOC,
86 .init = {
87 .GPIO_Pin = GPIO_Pin_8,
88 .GPIO_Speed = GPIO_Speed_50MHz,
89 .GPIO_Mode = GPIO_Mode_OUT,
90 .GPIO_OType = GPIO_OType_PP,
91 .GPIO_PuPd = GPIO_PuPd_UP
95 [PIOS_LED_D4] = {
96 .pin = {
97 .gpio = GPIOC,
98 .init = {
99 .GPIO_Pin = GPIO_Pin_9,
100 .GPIO_Speed = GPIO_Speed_50MHz,
101 .GPIO_Mode = GPIO_Mode_OUT,
102 .GPIO_OType = GPIO_OType_PP,
103 .GPIO_PuPd = GPIO_PuPd_UP
107 #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */
110 static const struct pios_gpio_cfg pios_led_cfg = {
111 .gpios = pios_leds,
112 .num_gpios = NELEMENTS(pios_leds),
115 static const struct pios_gpio pios_leds_v2[] = {
116 [PIOS_LED_HEARTBEAT] = {
117 .pin = {
118 .gpio = GPIOB,
119 .init = {
120 .GPIO_Pin = GPIO_Pin_5,
121 .GPIO_Speed = GPIO_Speed_50MHz,
122 .GPIO_Mode = GPIO_Mode_OUT,
123 .GPIO_OType = GPIO_OType_PP,
124 .GPIO_PuPd = GPIO_PuPd_UP
127 .active_low = true
129 [PIOS_LED_ALARM] = {
130 .pin = {
131 .gpio = GPIOB,
132 .init = {
133 .GPIO_Pin = GPIO_Pin_4,
134 .GPIO_Speed = GPIO_Speed_50MHz,
135 .GPIO_Mode = GPIO_Mode_OUT,
136 .GPIO_OType = GPIO_OType_PP,
137 .GPIO_PuPd = GPIO_PuPd_UP
140 .active_low = true
142 #ifdef PIOS_RFM22B_DEBUG_ON_TELEM
143 [PIOS_LED_D1] = {
144 .pin = {
145 .gpio = GPIOB,
146 .init = {
147 .GPIO_Pin = GPIO_Pin_13,
148 .GPIO_Speed = GPIO_Speed_50MHz,
149 .GPIO_Mode = GPIO_Mode_OUT,
150 .GPIO_OType = GPIO_OType_PP,
151 .GPIO_PuPd = GPIO_PuPd_UP
155 [PIOS_LED_D2] = {
156 .pin = {
157 .gpio = GPIOB,
158 .init = {
159 .GPIO_Pin = GPIO_Pin_14,
160 .GPIO_Speed = GPIO_Speed_50MHz,
161 .GPIO_Mode = GPIO_Mode_OUT,
162 .GPIO_OType = GPIO_OType_PP,
163 .GPIO_PuPd = GPIO_PuPd_UP
167 [PIOS_LED_D3] = {
168 .pin = {
169 .gpio = GPIOB,
170 .init = {
171 .GPIO_Pin = GPIO_Pin_15,
172 .GPIO_Speed = GPIO_Speed_50MHz,
173 .GPIO_Mode = GPIO_Mode_OUT,
174 .GPIO_OType = GPIO_OType_PP,
175 .GPIO_PuPd = GPIO_PuPd_UP
179 [PIOS_LED_D4] = {
180 .pin = {
181 .gpio = GPIOC,
182 .init = {
183 .GPIO_Pin = GPIO_Pin_6,
184 .GPIO_Speed = GPIO_Speed_50MHz,
185 .GPIO_Mode = GPIO_Mode_OUT,
186 .GPIO_OType = GPIO_OType_PP,
187 .GPIO_PuPd = GPIO_PuPd_UP
191 #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */
194 static const struct pios_gpio_cfg pios_led_v2_cfg = {
195 .gpios = pios_leds_v2,
196 .num_gpios = NELEMENTS(pios_leds_v2),
199 const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(uint32_t board_revision)
201 switch (board_revision) {
202 case 2:
203 return &pios_led_cfg;
205 break;
206 case 3:
207 return &pios_led_v2_cfg;
209 break;
210 default:
211 PIOS_DEBUG_Assert(0);
213 return NULL;
216 #endif /* PIOS_INCLUDE_LED */
218 #if defined(PIOS_INCLUDE_SPI)
219 #include <pios_spi_priv.h>
221 #if defined(PIOS_OVERO_SPI)
222 /* SPI2 Interface
223 * - Used for Flexi/IO/Overo communications
224 3: PB12 = SPI2 NSS, CAN2 RX
225 4: PB13 = SPI2 SCK, CAN2 TX, USART3 CTS
226 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
227 6: PB15 = SPI2 MOSI, TIM12 CH2
229 #include <pios_overo_priv.h>
230 void PIOS_OVERO_irq_handler(void);
231 void DMA1_Stream7_IRQHandler(void) __attribute__((alias("PIOS_OVERO_irq_handler")));
232 static const struct pios_overo_cfg pios_overo_cfg = {
233 .regs = SPI2,
234 .remap = GPIO_AF_SPI2,
235 .init = {
236 .SPI_Mode = SPI_Mode_Slave,
237 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
238 .SPI_DataSize = SPI_DataSize_8b,
239 .SPI_NSS = SPI_NSS_Hard,
240 .SPI_FirstBit = SPI_FirstBit_MSB,
241 .SPI_CRCPolynomial = 7,
242 .SPI_CPOL = SPI_CPOL_High,
243 .SPI_CPHA = SPI_CPHA_2Edge,
244 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2,
246 .use_crc = false,
247 .dma = {
248 .irq = {
249 // Note this is the stream ID that triggers interrupts (in this case TX)
250 .flags = (DMA_IT_TCIF7),
251 .init = {
252 .NVIC_IRQChannel = DMA1_Stream7_IRQn,
253 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
254 .NVIC_IRQChannelSubPriority = 0,
255 .NVIC_IRQChannelCmd = ENABLE,
259 .rx = {
260 .channel = DMA1_Stream0,
261 .init = {
262 .DMA_Channel = DMA_Channel_0,
263 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
264 .DMA_DIR = DMA_DIR_PeripheralToMemory,
265 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
266 .DMA_MemoryInc = DMA_MemoryInc_Enable,
267 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
268 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
269 .DMA_Mode = DMA_Mode_Circular,
270 .DMA_Priority = DMA_Priority_Medium,
271 // TODO: Enable FIFO
272 .DMA_FIFOMode = DMA_FIFOMode_Disable,
273 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
274 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
275 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
278 .tx = {
279 .channel = DMA1_Stream7,
280 .init = {
281 .DMA_Channel = DMA_Channel_0,
282 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
283 .DMA_DIR = DMA_DIR_MemoryToPeripheral,
284 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
285 .DMA_MemoryInc = DMA_MemoryInc_Enable,
286 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
287 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
288 .DMA_Mode = DMA_Mode_Circular,
289 .DMA_Priority = DMA_Priority_Medium,
290 .DMA_FIFOMode = DMA_FIFOMode_Disable,
291 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
292 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
293 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
297 .sclk = {
298 .gpio = GPIOB,
299 .init = {
300 .GPIO_Pin = GPIO_Pin_13,
301 .GPIO_Speed = GPIO_Speed_100MHz,
302 .GPIO_Mode = GPIO_Mode_AF,
303 .GPIO_OType = GPIO_OType_PP,
304 .GPIO_PuPd = GPIO_PuPd_NOPULL
307 .miso = {
308 .gpio = GPIOB,
309 .init = {
310 .GPIO_Pin = GPIO_Pin_14,
311 .GPIO_Speed = GPIO_Speed_50MHz,
312 .GPIO_Mode = GPIO_Mode_AF,
313 .GPIO_OType = GPIO_OType_PP,
314 .GPIO_PuPd = GPIO_PuPd_NOPULL
317 .mosi = {
318 .gpio = GPIOB,
319 .init = {
320 .GPIO_Pin = GPIO_Pin_15,
321 .GPIO_Speed = GPIO_Speed_50MHz,
322 .GPIO_Mode = GPIO_Mode_AF,
323 .GPIO_OType = GPIO_OType_PP,
324 .GPIO_PuPd = GPIO_PuPd_NOPULL
327 .slave_count = 1,
328 .ssel = {
330 .gpio = GPIOB,
331 .init = {
332 .GPIO_Pin = GPIO_Pin_12,
333 .GPIO_Speed = GPIO_Speed_50MHz,
334 .GPIO_Mode = GPIO_Mode_OUT,
335 .GPIO_OType = GPIO_OType_PP,
336 .GPIO_PuPd = GPIO_PuPd_UP
341 uint32_t pios_overo_id = 0;
342 void PIOS_OVERO_irq_handler(void)
344 /* Call into the generic code to handle the IRQ for this specific device */
345 PIOS_OVERO_DMA_irq_handler(pios_overo_id);
348 #endif /* PIOS_OVERO_SPI */
351 * SPI1 Interface
352 * Used for MPU6000 gyro and accelerometer
354 void PIOS_SPI_gyro_irq_handler(void);
355 void DMA2_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
356 void DMA2_Stream3_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
357 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
358 .regs = SPI1,
359 .remap = GPIO_AF_SPI1,
360 .init = {
361 .SPI_Mode = SPI_Mode_Master,
362 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
363 .SPI_DataSize = SPI_DataSize_8b,
364 .SPI_NSS = SPI_NSS_Soft,
365 .SPI_FirstBit = SPI_FirstBit_MSB,
366 .SPI_CRCPolynomial = 7,
367 .SPI_CPOL = SPI_CPOL_High,
368 .SPI_CPHA = SPI_CPHA_2Edge,
369 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16,
371 .use_crc = false,
372 .dma = {
373 .irq = {
374 .flags = (DMA_IT_TCIF0 | DMA_IT_TEIF0 | DMA_IT_HTIF0),
375 .init = {
376 .NVIC_IRQChannel = DMA2_Stream0_IRQn,
377 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
378 .NVIC_IRQChannelSubPriority = 0,
379 .NVIC_IRQChannelCmd = ENABLE,
383 .rx = {
384 .channel = DMA2_Stream0,
385 .init = {
386 .DMA_Channel = DMA_Channel_3,
387 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
388 .DMA_DIR = DMA_DIR_PeripheralToMemory,
389 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
390 .DMA_MemoryInc = DMA_MemoryInc_Enable,
391 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
392 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
393 .DMA_Mode = DMA_Mode_Normal,
394 .DMA_Priority = DMA_Priority_Medium,
395 .DMA_FIFOMode = DMA_FIFOMode_Disable,
396 /* .DMA_FIFOThreshold */
397 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
398 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
401 .tx = {
402 .channel = DMA2_Stream3,
403 .init = {
404 .DMA_Channel = DMA_Channel_3,
405 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
406 .DMA_DIR = DMA_DIR_MemoryToPeripheral,
407 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
408 .DMA_MemoryInc = DMA_MemoryInc_Enable,
409 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
410 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
411 .DMA_Mode = DMA_Mode_Normal,
412 .DMA_Priority = DMA_Priority_High,
413 .DMA_FIFOMode = DMA_FIFOMode_Disable,
414 /* .DMA_FIFOThreshold */
415 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
416 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
420 .sclk = {
421 .gpio = GPIOA,
422 .init = {
423 .GPIO_Pin = GPIO_Pin_5,
424 .GPIO_Speed = GPIO_Speed_100MHz,
425 .GPIO_Mode = GPIO_Mode_AF,
426 .GPIO_OType = GPIO_OType_PP,
427 .GPIO_PuPd = GPIO_PuPd_UP
430 .miso = {
431 .gpio = GPIOA,
432 .init = {
433 .GPIO_Pin = GPIO_Pin_6,
434 .GPIO_Speed = GPIO_Speed_50MHz,
435 .GPIO_Mode = GPIO_Mode_AF,
436 .GPIO_OType = GPIO_OType_PP,
437 .GPIO_PuPd = GPIO_PuPd_UP
440 .mosi = {
441 .gpio = GPIOA,
442 .init = {
443 .GPIO_Pin = GPIO_Pin_7,
444 .GPIO_Speed = GPIO_Speed_50MHz,
445 .GPIO_Mode = GPIO_Mode_AF,
446 .GPIO_OType = GPIO_OType_PP,
447 .GPIO_PuPd = GPIO_PuPd_UP
450 .slave_count = 1,
451 .ssel = {
453 .gpio = GPIOA,
454 .init = {
455 .GPIO_Pin = GPIO_Pin_4,
456 .GPIO_Speed = GPIO_Speed_50MHz,
457 .GPIO_Mode = GPIO_Mode_OUT,
458 .GPIO_OType = GPIO_OType_PP,
459 .GPIO_PuPd = GPIO_PuPd_UP
465 static uint32_t pios_spi_gyro_id;
466 void PIOS_SPI_gyro_irq_handler(void)
468 /* Call into the generic code to handle the IRQ for this specific device */
469 PIOS_SPI_IRQ_Handler(pios_spi_gyro_id);
474 * SPI3 Interface
475 * Used for Flash and the RFM22B
477 void PIOS_SPI_telem_flash_irq_handler(void);
478 void DMA1_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
479 void DMA1_Stream5_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
480 static const struct pios_spi_cfg pios_spi_telem_flash_cfg = {
481 .regs = SPI3,
482 .remap = GPIO_AF_SPI3,
483 .init = {
484 .SPI_Mode = SPI_Mode_Master,
485 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
486 .SPI_DataSize = SPI_DataSize_8b,
487 .SPI_NSS = SPI_NSS_Soft,
488 .SPI_FirstBit = SPI_FirstBit_MSB,
489 .SPI_CRCPolynomial = 7,
490 .SPI_CPOL = SPI_CPOL_Low,
491 .SPI_CPHA = SPI_CPHA_1Edge,
492 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
494 .use_crc = false,
495 .dma = {
496 .irq = {
497 // Note this is the stream ID that triggers interrupts (in this case RX)
498 .flags = (DMA_IT_TCIF0 | DMA_IT_TEIF0 | DMA_IT_HTIF0),
499 .init = {
500 .NVIC_IRQChannel = DMA1_Stream0_IRQn,
501 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
502 .NVIC_IRQChannelSubPriority = 0,
503 .NVIC_IRQChannelCmd = ENABLE,
507 .rx = {
508 .channel = DMA1_Stream0,
509 .init = {
510 .DMA_Channel = DMA_Channel_0,
511 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI3->DR),
512 .DMA_DIR = DMA_DIR_PeripheralToMemory,
513 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
514 .DMA_MemoryInc = DMA_MemoryInc_Enable,
515 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
516 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
517 .DMA_Mode = DMA_Mode_Normal,
518 .DMA_Priority = DMA_Priority_Medium,
519 // TODO: Enable FIFO
520 .DMA_FIFOMode = DMA_FIFOMode_Disable,
521 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
522 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
523 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
526 .tx = {
527 .channel = DMA1_Stream5,
528 .init = {
529 .DMA_Channel = DMA_Channel_0,
530 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI3->DR),
531 .DMA_DIR = DMA_DIR_MemoryToPeripheral,
532 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
533 .DMA_MemoryInc = DMA_MemoryInc_Enable,
534 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
535 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
536 .DMA_Mode = DMA_Mode_Normal,
537 .DMA_Priority = DMA_Priority_Medium,
538 .DMA_FIFOMode = DMA_FIFOMode_Disable,
539 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
540 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
541 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
545 .sclk = {
546 .gpio = GPIOC,
547 .init = {
548 .GPIO_Pin = GPIO_Pin_10,
549 .GPIO_Speed = GPIO_Speed_100MHz,
550 .GPIO_Mode = GPIO_Mode_AF,
551 .GPIO_OType = GPIO_OType_PP,
552 .GPIO_PuPd = GPIO_PuPd_NOPULL
555 .miso = {
556 .gpio = GPIOC,
557 .init = {
558 .GPIO_Pin = GPIO_Pin_11,
559 .GPIO_Speed = GPIO_Speed_50MHz,
560 .GPIO_Mode = GPIO_Mode_AF,
561 .GPIO_OType = GPIO_OType_PP,
562 .GPIO_PuPd = GPIO_PuPd_NOPULL
565 .mosi = {
566 .gpio = GPIOC,
567 .init = {
568 .GPIO_Pin = GPIO_Pin_12,
569 .GPIO_Speed = GPIO_Speed_50MHz,
570 .GPIO_Mode = GPIO_Mode_AF,
571 .GPIO_OType = GPIO_OType_PP,
572 .GPIO_PuPd = GPIO_PuPd_NOPULL
575 .slave_count = 2,
576 .ssel = {
577 { // RFM22b
578 .gpio = GPIOA,
579 .init = {
580 .GPIO_Pin = GPIO_Pin_15,
581 .GPIO_Speed = GPIO_Speed_50MHz,
582 .GPIO_Mode = GPIO_Mode_OUT,
583 .GPIO_OType = GPIO_OType_PP,
584 .GPIO_PuPd = GPIO_PuPd_UP
587 { // Flash
588 .gpio = GPIOB,
589 .init = {
590 .GPIO_Pin = GPIO_Pin_3,
591 .GPIO_Speed = GPIO_Speed_50MHz,
592 .GPIO_Mode = GPIO_Mode_OUT,
593 .GPIO_OType = GPIO_OType_PP,
594 .GPIO_PuPd = GPIO_PuPd_UP
600 uint32_t pios_spi_telem_flash_id;
601 void PIOS_SPI_telem_flash_irq_handler(void)
603 /* Call into the generic code to handle the IRQ for this specific device */
604 PIOS_SPI_IRQ_Handler(pios_spi_telem_flash_id);
608 #if defined(PIOS_INCLUDE_RFM22B)
609 #include <pios_rfm22b_priv.h>
611 static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config = {
612 .vector = PIOS_RFM22_EXT_Int,
613 .line = EXTI_Line2,
614 .pin = {
615 .gpio = GPIOD,
616 .init = {
617 .GPIO_Pin = GPIO_Pin_2,
618 .GPIO_Speed = GPIO_Speed_100MHz,
619 .GPIO_Mode = GPIO_Mode_IN,
620 .GPIO_OType = GPIO_OType_OD,
621 .GPIO_PuPd = GPIO_PuPd_NOPULL,
624 .irq = {
625 .init = {
626 .NVIC_IRQChannel = EXTI2_IRQn,
627 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
628 .NVIC_IRQChannelSubPriority = 0,
629 .NVIC_IRQChannelCmd = ENABLE,
632 .exti = {
633 .init = {
634 .EXTI_Line = EXTI_Line2, // matches above GPIO pin
635 .EXTI_Mode = EXTI_Mode_Interrupt,
636 .EXTI_Trigger = EXTI_Trigger_Falling,
637 .EXTI_LineCmd = ENABLE,
642 const struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg = {
643 .spi_cfg = &pios_spi_telem_flash_cfg,
644 .exti_cfg = &pios_exti_rfm22b_cfg,
645 .RFXtalCap = 0x7f,
646 .slave_num = 0,
647 .gpio_direction = GPIO0_RX_GPIO1_TX,
650 const struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg = {
651 .spi_cfg = &pios_spi_telem_flash_cfg,
652 .exti_cfg = &pios_exti_rfm22b_cfg,
653 .RFXtalCap = 0x7f,
654 .slave_num = 0,
655 .gpio_direction = GPIO0_TX_GPIO1_RX,
658 const struct pios_rfm22b_cfg *PIOS_BOARD_HW_DEFS_GetRfm22Cfg(uint32_t board_revision)
660 switch (board_revision) {
661 case 2:
662 return &pios_rfm22b_rm1_cfg;
664 break;
665 case 3:
666 return &pios_rfm22b_rm2_cfg;
668 break;
669 default:
670 PIOS_DEBUG_Assert(0);
672 return NULL;
675 #endif /* PIOS_INCLUDE_RFM22B */
677 #endif /* PIOS_INCLUDE_SPI */
679 #if defined(PIOS_INCLUDE_FLASH)
680 #include "pios_flashfs_logfs_priv.h"
681 #include "pios_flash_jedec_priv.h"
682 #include "pios_flash_internal_priv.h"
684 static const struct flashfs_logfs_cfg flashfs_external_user_cfg = {
685 .fs_magic = 0x99abceff,
686 .total_fs_size = 0x001C0000, /* 2M bytes (32 sectors = entire chip) */
687 .arena_size = 0x000E0000, /* biggest possible arena size fssize/2 */
688 .slot_size = 0x00000100, /* 256 bytes */
690 .start_offset = 0x00040000, /* start offset */
691 .sector_size = 0x00010000, /* 64K bytes */
692 .page_size = 0x00000100, /* 256 bytes */
695 static const struct flashfs_logfs_cfg flashfs_external_system_cfg = {
696 .fs_magic = 0x99bbcdef,
697 .total_fs_size = 0x00040000, /* 2M bytes (32 sectors = entire chip) */
698 .arena_size = 0x00010000, /* 256 * slot size */
699 .slot_size = 0x00000100, /* 256 bytes */
701 .start_offset = 0, /* start at the beginning of the chip */
702 .sector_size = 0x00010000, /* 64K bytes */
703 .page_size = 0x00000100, /* 256 bytes */
707 static const struct pios_flash_internal_cfg flash_internal_cfg = {};
709 static const struct flashfs_logfs_cfg flashfs_internal_cfg = {
710 .fs_magic = 0x99abcfef,
711 .total_fs_size = EE_BANK_SIZE, /* 32K bytes (2x16KB sectors) */
712 .arena_size = 0x00004000, /* 64 * slot size = 16K bytes = 1 sector */
713 .slot_size = 0x00000100, /* 256 bytes */
715 .start_offset = EE_BANK_BASE, /* start after the bootloader */
716 .sector_size = 0x00004000, /* 16K bytes */
717 .page_size = 0x00004000, /* 16K bytes */
720 #endif /* PIOS_INCLUDE_FLASH */
722 #include <pios_usart_priv.h>
724 #ifdef PIOS_INCLUDE_COM_TELEM
727 * MAIN USART
729 static const struct pios_usart_cfg pios_usart_main_cfg = {
730 .regs = USART1,
731 .remap = GPIO_AF_USART1,
732 .init = {
733 .USART_BaudRate = 57600,
734 .USART_WordLength = USART_WordLength_8b,
735 .USART_Parity = USART_Parity_No,
736 .USART_StopBits = USART_StopBits_1,
737 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
738 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
740 .irq = {
741 .init = {
742 .NVIC_IRQChannel = USART1_IRQn,
743 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
744 .NVIC_IRQChannelSubPriority = 0,
745 .NVIC_IRQChannelCmd = ENABLE,
748 .rx = {
749 .gpio = GPIOA,
750 .init = {
751 .GPIO_Pin = GPIO_Pin_10,
752 .GPIO_Speed = GPIO_Speed_2MHz,
753 .GPIO_Mode = GPIO_Mode_AF,
754 .GPIO_OType = GPIO_OType_PP,
755 .GPIO_PuPd = GPIO_PuPd_UP
758 .tx = {
759 .gpio = GPIOA,
760 .init = {
761 .GPIO_Pin = GPIO_Pin_9,
762 .GPIO_Speed = GPIO_Speed_2MHz,
763 .GPIO_Mode = GPIO_Mode_AF,
764 .GPIO_OType = GPIO_OType_PP,
765 .GPIO_PuPd = GPIO_PuPd_UP
769 #endif /* PIOS_INCLUDE_COM_TELEM */
771 #ifdef PIOS_INCLUDE_DSM
773 #include "pios_dsm_priv.h"
774 static const struct pios_usart_cfg pios_usart_dsm_main_cfg = {
775 .regs = USART1,
776 .remap = GPIO_AF_USART1,
777 .init = {
778 .USART_BaudRate = 115200,
779 .USART_WordLength = USART_WordLength_8b,
780 .USART_Parity = USART_Parity_No,
781 .USART_StopBits = USART_StopBits_1,
782 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
783 .USART_Mode = USART_Mode_Rx,
785 .irq = {
786 .init = {
787 .NVIC_IRQChannel = USART1_IRQn,
788 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
789 .NVIC_IRQChannelSubPriority = 0,
790 .NVIC_IRQChannelCmd = ENABLE,
793 .rx = {
794 .gpio = GPIOA,
795 .init = {
796 .GPIO_Pin = GPIO_Pin_10,
797 .GPIO_Speed = GPIO_Speed_2MHz,
798 .GPIO_Mode = GPIO_Mode_AF,
799 .GPIO_OType = GPIO_OType_PP,
800 .GPIO_PuPd = GPIO_PuPd_UP
803 .tx = {
804 .gpio = GPIOA,
805 .init = {
806 .GPIO_Pin = GPIO_Pin_9,
807 .GPIO_Speed = GPIO_Speed_2MHz,
808 .GPIO_Mode = GPIO_Mode_AF,
809 .GPIO_OType = GPIO_OType_PP,
810 .GPIO_PuPd = GPIO_PuPd_UP
815 // Because of the inverter on the main port this will not
816 // work. Notice the mode is set to IN to maintain API
817 // compatibility but protect the pins
818 static const struct pios_dsm_cfg pios_dsm_main_cfg = {
819 .bind = {
820 .gpio = GPIOA,
821 .init = {
822 .GPIO_Pin = GPIO_Pin_10,
823 .GPIO_Speed = GPIO_Speed_2MHz,
824 .GPIO_Mode = GPIO_Mode_IN,
825 .GPIO_OType = GPIO_OType_PP,
826 .GPIO_PuPd = GPIO_PuPd_NOPULL
831 #endif /* PIOS_INCLUDE_DSM */
833 #include <pios_sbus_priv.h>
834 #if defined(PIOS_INCLUDE_SBUS)
836 * S.Bus USART
838 #include <pios_sbus_priv.h>
840 static const struct pios_usart_cfg pios_usart_sbus_main_cfg = {
841 .regs = USART1,
842 .remap = GPIO_AF_USART1,
843 .init = {
844 .USART_BaudRate = 100000,
845 .USART_WordLength = USART_WordLength_8b,
846 .USART_Parity = USART_Parity_Even,
847 .USART_StopBits = USART_StopBits_2,
848 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
849 .USART_Mode = USART_Mode_Rx,
851 .irq = {
852 .init = {
853 .NVIC_IRQChannel = USART1_IRQn,
854 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
855 .NVIC_IRQChannelSubPriority = 0,
856 .NVIC_IRQChannelCmd = ENABLE,
859 .rx = {
860 .gpio = GPIOA,
861 .init = {
862 .GPIO_Pin = GPIO_Pin_10,
863 .GPIO_Speed = GPIO_Speed_2MHz,
864 .GPIO_Mode = GPIO_Mode_AF,
865 .GPIO_OType = GPIO_OType_PP,
866 .GPIO_PuPd = GPIO_PuPd_UP
869 .tx = {
870 .gpio = GPIOA,
871 .init = {
872 .GPIO_Pin = GPIO_Pin_9,
873 .GPIO_Speed = GPIO_Speed_2MHz,
874 .GPIO_Mode = GPIO_Mode_OUT,
875 .GPIO_OType = GPIO_OType_PP,
876 .GPIO_PuPd = GPIO_PuPd_NOPULL
881 #endif /* PIOS_INCLUDE_SBUS */
883 // Need this defined regardless to be able to turn it off
884 static const struct pios_sbus_cfg pios_sbus_cfg = {
885 /* Inverter configuration */
886 .inv = {
887 .gpio = GPIOC,
888 .init = {
889 .GPIO_Pin = GPIO_Pin_0,
890 .GPIO_Speed = GPIO_Speed_2MHz,
891 .GPIO_Mode = GPIO_Mode_OUT,
892 .GPIO_OType = GPIO_OType_PP,
893 .GPIO_PuPd = GPIO_PuPd_UP
896 .gpio_inv_enable = Bit_SET,
897 .gpio_inv_disable = Bit_RESET,
898 .gpio_clk_func = RCC_AHB1PeriphClockCmd,
899 .gpio_clk_periph = RCC_AHB1Periph_GPIOC,
902 #ifdef PIOS_INCLUDE_COM_FLEXI
904 * FLEXI PORT
906 static const struct pios_usart_cfg pios_usart_flexi_cfg = {
907 .regs = USART3,
908 .remap = GPIO_AF_USART3,
909 .init = {
910 .USART_BaudRate = 57600,
911 .USART_WordLength = USART_WordLength_8b,
912 .USART_Parity = USART_Parity_No,
913 .USART_StopBits = USART_StopBits_1,
914 .USART_HardwareFlowControl =
915 USART_HardwareFlowControl_None,
916 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
918 .irq = {
919 .init = {
920 .NVIC_IRQChannel = USART3_IRQn,
921 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
922 .NVIC_IRQChannelSubPriority = 0,
923 .NVIC_IRQChannelCmd = ENABLE,
926 .rx = {
927 .gpio = GPIOB,
928 .init = {
929 .GPIO_Pin = GPIO_Pin_11,
930 .GPIO_Speed = GPIO_Speed_2MHz,
931 .GPIO_Mode = GPIO_Mode_AF,
932 .GPIO_OType = GPIO_OType_PP,
933 .GPIO_PuPd = GPIO_PuPd_UP
936 .tx = {
937 .gpio = GPIOB,
938 .init = {
939 .GPIO_Pin = GPIO_Pin_10,
940 .GPIO_Speed = GPIO_Speed_2MHz,
941 .GPIO_Mode = GPIO_Mode_AF,
942 .GPIO_OType = GPIO_OType_PP,
943 .GPIO_PuPd = GPIO_PuPd_UP
948 #endif /* PIOS_INCLUDE_COM_FLEXI */
950 #ifdef PIOS_INCLUDE_DSM
952 #include "pios_dsm_priv.h"
953 static const struct pios_usart_cfg pios_usart_dsm_flexi_cfg = {
954 .regs = USART3,
955 .remap = GPIO_AF_USART3,
956 .init = {
957 .USART_BaudRate = 115200,
958 .USART_WordLength = USART_WordLength_8b,
959 .USART_Parity = USART_Parity_No,
960 .USART_StopBits = USART_StopBits_1,
961 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
962 .USART_Mode = USART_Mode_Rx,
964 .irq = {
965 .init = {
966 .NVIC_IRQChannel = USART3_IRQn,
967 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
968 .NVIC_IRQChannelSubPriority = 0,
969 .NVIC_IRQChannelCmd = ENABLE,
972 .rx = {
973 .gpio = GPIOB,
974 .init = {
975 .GPIO_Pin = GPIO_Pin_11,
976 .GPIO_Speed = GPIO_Speed_2MHz,
977 .GPIO_Mode = GPIO_Mode_AF,
978 .GPIO_OType = GPIO_OType_PP,
979 .GPIO_PuPd = GPIO_PuPd_UP
982 .tx = {
983 .gpio = GPIOB,
984 .init = {
985 .GPIO_Pin = GPIO_Pin_10,
986 .GPIO_Speed = GPIO_Speed_2MHz,
987 .GPIO_Mode = GPIO_Mode_AF,
988 .GPIO_OType = GPIO_OType_PP,
989 .GPIO_PuPd = GPIO_PuPd_UP
994 static const struct pios_dsm_cfg pios_dsm_flexi_cfg = {
995 .bind = {
996 .gpio = GPIOB,
997 .init = {
998 .GPIO_Pin = GPIO_Pin_11,
999 .GPIO_Speed = GPIO_Speed_2MHz,
1000 .GPIO_Mode = GPIO_Mode_OUT,
1001 .GPIO_OType = GPIO_OType_PP,
1002 .GPIO_PuPd = GPIO_PuPd_NOPULL
1007 #endif /* PIOS_INCLUDE_DSM */
1009 #if defined(PIOS_INCLUDE_SRXL)
1011 * SRXL USART
1013 #include <pios_srxl_priv.h>
1015 static const struct pios_usart_cfg pios_usart_srxl_flexi_cfg = {
1016 .regs = USART3,
1017 .remap = GPIO_AF_USART3,
1018 .init = {
1019 .USART_BaudRate = 115200,
1020 .USART_WordLength = USART_WordLength_8b,
1021 .USART_Parity = USART_Parity_No,
1022 .USART_StopBits = USART_StopBits_1,
1023 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
1024 .USART_Mode = USART_Mode_Rx,
1026 .irq = {
1027 .init = {
1028 .NVIC_IRQChannel = USART3_IRQn,
1029 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
1030 .NVIC_IRQChannelSubPriority = 0,
1031 .NVIC_IRQChannelCmd = ENABLE,
1034 .rx = {
1035 .gpio = GPIOB,
1036 .init = {
1037 .GPIO_Pin = GPIO_Pin_11,
1038 .GPIO_Speed = GPIO_Speed_2MHz,
1039 .GPIO_Mode = GPIO_Mode_AF,
1040 .GPIO_OType = GPIO_OType_PP,
1041 .GPIO_PuPd = GPIO_PuPd_UP
1044 .tx = {
1045 .gpio = GPIOB,
1046 .init = {
1047 .GPIO_Pin = GPIO_Pin_10,
1048 .GPIO_Speed = GPIO_Speed_2MHz,
1049 .GPIO_Mode = GPIO_Mode_OUT,
1050 .GPIO_OType = GPIO_OType_PP,
1051 .GPIO_PuPd = GPIO_PuPd_UP
1056 #endif /* PIOS_INCLUDE_SRXL */
1058 * HK OSD
1060 static const struct pios_usart_cfg pios_usart_hkosd_main_cfg = {
1061 .regs = USART1,
1062 .remap = GPIO_AF_USART1,
1063 .init = {
1064 .USART_BaudRate = 57600,
1065 .USART_WordLength = USART_WordLength_8b,
1066 .USART_Parity = USART_Parity_No,
1067 .USART_StopBits = USART_StopBits_1,
1068 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
1069 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
1071 .irq = {
1072 .init = {
1073 .NVIC_IRQChannel = USART1_IRQn,
1074 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1075 .NVIC_IRQChannelSubPriority = 0,
1076 .NVIC_IRQChannelCmd = ENABLE,
1079 .rx = {
1080 .gpio = GPIOA,
1081 .init = {
1082 .GPIO_Pin = GPIO_Pin_10,
1083 .GPIO_Speed = GPIO_Speed_2MHz,
1084 .GPIO_Mode = GPIO_Mode_AF,
1085 .GPIO_OType = GPIO_OType_PP,
1086 .GPIO_PuPd = GPIO_PuPd_UP
1089 .tx = {
1090 .gpio = GPIOA,
1091 .init = {
1092 .GPIO_Pin = GPIO_Pin_9,
1093 .GPIO_Speed = GPIO_Speed_2MHz,
1094 .GPIO_Mode = GPIO_Mode_AF,
1095 .GPIO_OType = GPIO_OType_PP,
1096 .GPIO_PuPd = GPIO_PuPd_UP
1101 static const struct pios_usart_cfg pios_usart_hkosd_flexi_cfg = {
1102 .regs = USART3,
1103 .remap = GPIO_AF_USART3,
1104 .init = {
1105 .USART_BaudRate = 57600,
1106 .USART_WordLength = USART_WordLength_8b,
1107 .USART_Parity = USART_Parity_No,
1108 .USART_StopBits = USART_StopBits_1,
1109 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
1110 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
1112 .irq = {
1113 .init = {
1114 .NVIC_IRQChannel = USART3_IRQn,
1115 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1116 .NVIC_IRQChannelSubPriority = 0,
1117 .NVIC_IRQChannelCmd = ENABLE,
1120 .rx = {
1121 .gpio = GPIOB,
1122 .init = {
1123 .GPIO_Pin = GPIO_Pin_11,
1124 .GPIO_Speed = GPIO_Speed_2MHz,
1125 .GPIO_Mode = GPIO_Mode_AF,
1126 .GPIO_OType = GPIO_OType_PP,
1127 .GPIO_PuPd = GPIO_PuPd_UP
1130 .tx = {
1131 .gpio = GPIOB,
1132 .init = {
1133 .GPIO_Pin = GPIO_Pin_10,
1134 .GPIO_Speed = GPIO_Speed_2MHz,
1135 .GPIO_Mode = GPIO_Mode_AF,
1136 .GPIO_OType = GPIO_OType_PP,
1137 .GPIO_PuPd = GPIO_PuPd_UP
1142 static const struct pios_usart_cfg pios_usart_rcvrport_cfg = {
1143 .regs = USART6,
1144 .remap = GPIO_AF_USART6,
1145 .init = {
1146 .USART_BaudRate = 57600,
1147 .USART_WordLength = USART_WordLength_8b,
1148 .USART_Parity = USART_Parity_No,
1149 .USART_StopBits = USART_StopBits_1,
1150 .USART_HardwareFlowControl = USART_HardwareFlowControl_None,
1151 .USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
1153 .irq = {
1154 .init = {
1155 .NVIC_IRQChannel = USART6_IRQn,
1156 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1157 .NVIC_IRQChannelSubPriority = 0,
1158 .NVIC_IRQChannelCmd = ENABLE,
1162 .dtr = {
1163 // FlexIO pin 9
1164 .gpio = GPIOC,
1165 .init = {
1166 .GPIO_Pin = GPIO_Pin_8,
1167 .GPIO_Speed = GPIO_Speed_25MHz,
1168 .GPIO_Mode = GPIO_Mode_OUT,
1169 .GPIO_OType = GPIO_OType_PP,
1173 .tx = {
1174 // * 7: PC6 = TIM8 CH1, USART6 TX
1175 .gpio = GPIOC,
1176 .init = {
1177 .GPIO_Pin = GPIO_Pin_6,
1178 .GPIO_Speed = GPIO_Speed_2MHz,
1179 .GPIO_Mode = GPIO_Mode_AF,
1180 .GPIO_OType = GPIO_OType_PP,
1181 .GPIO_PuPd = GPIO_PuPd_UP
1183 .pin_source = GPIO_PinSource6,
1186 .rx = {
1187 // * 8: PC7 = TIM8 CH2, USART6 RX
1188 .gpio = GPIOC,
1189 .init = {
1190 .GPIO_Pin = GPIO_Pin_7,
1191 .GPIO_Speed = GPIO_Speed_2MHz,
1192 .GPIO_Mode = GPIO_Mode_AF,
1193 .GPIO_OType = GPIO_OType_PP,
1194 .GPIO_PuPd = GPIO_PuPd_UP
1196 .pin_source = GPIO_PinSource7,
1200 #if defined(PIOS_INCLUDE_COM)
1202 #include <pios_com_priv.h>
1204 #endif /* PIOS_INCLUDE_COM */
1206 #if defined(PIOS_INCLUDE_I2C)
1208 #include <pios_i2c_priv.h>
1211 * I2C Adapters
1213 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void);
1214 void PIOS_I2C_mag_pressureadapter_er_irq_handler(void);
1215 void I2C1_EV_IRQHandler()
1216 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_ev_irq_handler")));
1217 void I2C1_ER_IRQHandler()
1218 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler")));
1220 static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg = {
1221 .regs = I2C1,
1222 .remapSCL = GPIO_AF_I2C1,
1223 .remapSDA = GPIO_AF_I2C1,
1224 .init = {
1225 .I2C_Mode = I2C_Mode_I2C,
1226 .I2C_OwnAddress1 = 0,
1227 .I2C_Ack = I2C_Ack_Enable,
1228 .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
1229 .I2C_DutyCycle = I2C_DutyCycle_2,
1230 .I2C_ClockSpeed = 400000, /* bits/s */
1232 .transfer_timeout_ms = 50,
1233 .scl = {
1234 .gpio = GPIOB,
1235 .init = {
1236 .GPIO_Pin = GPIO_Pin_8,
1237 .GPIO_Mode = GPIO_Mode_AF,
1238 .GPIO_Speed = GPIO_Speed_50MHz,
1239 .GPIO_OType = GPIO_OType_OD,
1240 .GPIO_PuPd = GPIO_PuPd_NOPULL,
1243 .sda = {
1244 .gpio = GPIOB,
1245 .init = {
1246 .GPIO_Pin = GPIO_Pin_9,
1247 .GPIO_Mode = GPIO_Mode_AF,
1248 .GPIO_Speed = GPIO_Speed_50MHz,
1249 .GPIO_OType = GPIO_OType_OD,
1250 .GPIO_PuPd = GPIO_PuPd_NOPULL,
1253 .event = {
1254 .flags = 0, /* FIXME: check this */
1255 .init = {
1256 .NVIC_IRQChannel = I2C1_EV_IRQn,
1257 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1258 .NVIC_IRQChannelSubPriority = 0,
1259 .NVIC_IRQChannelCmd = ENABLE,
1262 .error = {
1263 .flags = 0, /* FIXME: check this */
1264 .init = {
1265 .NVIC_IRQChannel = I2C1_ER_IRQn,
1266 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1267 .NVIC_IRQChannelSubPriority = 0,
1268 .NVIC_IRQChannelCmd = ENABLE,
1273 uint32_t pios_i2c_mag_pressure_adapter_id;
1274 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void)
1276 /* Call into the generic code to handle the IRQ for this specific device */
1277 PIOS_I2C_EV_IRQ_Handler(pios_i2c_mag_pressure_adapter_id);
1280 void PIOS_I2C_mag_pressure_adapter_er_irq_handler(void)
1282 /* Call into the generic code to handle the IRQ for this specific device */
1283 PIOS_I2C_ER_IRQ_Handler(pios_i2c_mag_pressure_adapter_id);
1287 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void);
1288 void PIOS_I2C_flexiport_adapter_er_irq_handler(void);
1289 void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_irq_handler")));
1290 void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler")));
1292 static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = {
1293 .regs = I2C2,
1294 .remapSCL = GPIO_AF_I2C2,
1295 .remapSDA = GPIO_AF_I2C2,
1296 .init = {
1297 .I2C_Mode = I2C_Mode_I2C,
1298 .I2C_OwnAddress1 = 0,
1299 .I2C_Ack = I2C_Ack_Enable,
1300 .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
1301 .I2C_DutyCycle = I2C_DutyCycle_2,
1302 .I2C_ClockSpeed = 400000, /* bits/s */
1304 .transfer_timeout_ms = 50,
1305 .scl = {
1306 .gpio = GPIOB,
1307 .init = {
1308 .GPIO_Pin = GPIO_Pin_10,
1309 .GPIO_Mode = GPIO_Mode_AF,
1310 .GPIO_Speed = GPIO_Speed_50MHz,
1311 .GPIO_OType = GPIO_OType_OD,
1312 .GPIO_PuPd = GPIO_PuPd_NOPULL,
1315 .sda = {
1316 .gpio = GPIOB,
1317 .init = {
1318 .GPIO_Pin = GPIO_Pin_11,
1319 .GPIO_Mode = GPIO_Mode_AF,
1320 .GPIO_Speed = GPIO_Speed_50MHz,
1321 .GPIO_OType = GPIO_OType_OD,
1322 .GPIO_PuPd = GPIO_PuPd_NOPULL,
1325 .event = {
1326 .flags = 0, /* FIXME: check this */
1327 .init = {
1328 .NVIC_IRQChannel = I2C2_EV_IRQn,
1329 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1330 .NVIC_IRQChannelSubPriority = 0,
1331 .NVIC_IRQChannelCmd = ENABLE,
1334 .error = {
1335 .flags = 0, /* FIXME: check this */
1336 .init = {
1337 .NVIC_IRQChannel = I2C2_ER_IRQn,
1338 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1339 .NVIC_IRQChannelSubPriority = 0,
1340 .NVIC_IRQChannelCmd = ENABLE,
1345 uint32_t pios_i2c_flexiport_adapter_id;
1346 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void)
1348 /* Call into the generic code to handle the IRQ for this specific device */
1349 PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexiport_adapter_id);
1352 void PIOS_I2C_flexiport_adapter_er_irq_handler(void)
1354 /* Call into the generic code to handle the IRQ for this specific device */
1355 PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexiport_adapter_id);
1359 void PIOS_I2C_pressure_adapter_ev_irq_handler(void);
1360 void PIOS_I2C_pressure_adapter_er_irq_handler(void);
1362 #endif /* PIOS_INCLUDE_I2C */
1364 #if defined(PIOS_INCLUDE_RTC)
1366 * Realtime Clock (RTC)
1368 #include <pios_rtc_priv.h>
1370 void PIOS_RTC_IRQ_Handler(void);
1371 void RTC_WKUP_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
1372 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
1373 .clksrc = RCC_RTCCLKSource_HSE_Div8, // Divide 8 Mhz crystal down to 1
1374 // For some reason it's acting like crystal is 16 Mhz. This clock is then divided
1375 // by another 16 to give a nominal 62.5 khz clock
1376 .prescaler = 100, // Every 100 cycles gives 625 Hz
1377 .irq = {
1378 .init = {
1379 .NVIC_IRQChannel = RTC_WKUP_IRQn,
1380 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1381 .NVIC_IRQChannelSubPriority = 0,
1382 .NVIC_IRQChannelCmd = ENABLE,
1387 void PIOS_RTC_IRQ_Handler(void)
1389 PIOS_RTC_irq_handler();
1392 #endif /* if defined(PIOS_INCLUDE_RTC) */
1394 #include "pios_tim_priv.h"
1396 static const TIM_TimeBaseInitTypeDef tim_3_5_time_base = {
1397 .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000) - 1,
1398 .TIM_ClockDivision = TIM_CKD_DIV1,
1399 .TIM_CounterMode = TIM_CounterMode_Up,
1400 .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
1401 .TIM_RepetitionCounter = 0x0000,
1403 static const TIM_TimeBaseInitTypeDef tim_9_10_11_time_base = {
1404 .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
1405 .TIM_ClockDivision = TIM_CKD_DIV1,
1406 .TIM_CounterMode = TIM_CounterMode_Up,
1407 .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
1408 .TIM_RepetitionCounter = 0x0000,
1411 static const struct pios_tim_clock_cfg tim_3_cfg = {
1412 .timer = TIM3,
1413 .time_base_init = &tim_3_5_time_base,
1414 .irq = {
1415 .init = {
1416 .NVIC_IRQChannel = TIM3_IRQn,
1417 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1418 .NVIC_IRQChannelSubPriority = 0,
1419 .NVIC_IRQChannelCmd = ENABLE,
1424 static const struct pios_tim_clock_cfg tim_5_cfg = {
1425 .timer = TIM5,
1426 .time_base_init = &tim_3_5_time_base,
1427 .irq = {
1428 .init = {
1429 .NVIC_IRQChannel = TIM5_IRQn,
1430 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1431 .NVIC_IRQChannelSubPriority = 0,
1432 .NVIC_IRQChannelCmd = ENABLE,
1437 static const struct pios_tim_clock_cfg tim_9_cfg = {
1438 .timer = TIM9,
1439 .time_base_init = &tim_9_10_11_time_base,
1440 .irq = {
1441 .init = {
1442 .NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn,
1443 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1444 .NVIC_IRQChannelSubPriority = 0,
1445 .NVIC_IRQChannelCmd = ENABLE,
1450 static const struct pios_tim_clock_cfg tim_10_cfg = {
1451 .timer = TIM10,
1452 .time_base_init = &tim_9_10_11_time_base,
1453 .irq = {
1454 .init = {
1455 .NVIC_IRQChannel = TIM1_UP_TIM10_IRQn,
1456 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1457 .NVIC_IRQChannelSubPriority = 0,
1458 .NVIC_IRQChannelCmd = ENABLE,
1463 static const struct pios_tim_clock_cfg tim_11_cfg = {
1464 .timer = TIM11,
1465 .time_base_init = &tim_9_10_11_time_base,
1466 .irq = {
1467 .init = {
1468 .NVIC_IRQChannel = TIM1_TRG_COM_TIM11_IRQn,
1469 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1470 .NVIC_IRQChannelSubPriority = 0,
1471 .NVIC_IRQChannelCmd = ENABLE,
1476 // Set up timers that only have inputs on APB1
1477 // TIM2,3,4,5,6,7,12,13,14
1478 static const TIM_TimeBaseInitTypeDef tim_apb1_time_base = {
1479 .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000) - 1,
1480 .TIM_ClockDivision = TIM_CKD_DIV1,
1481 .TIM_CounterMode = TIM_CounterMode_Up,
1482 .TIM_Period = 0xFFFF,
1483 .TIM_RepetitionCounter = 0x0000,
1487 // Set up timers that only have inputs on APB2
1488 // TIM1,8,9,10,11
1489 static const TIM_TimeBaseInitTypeDef tim_apb2_time_base = {
1490 .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
1491 .TIM_ClockDivision = TIM_CKD_DIV1,
1492 .TIM_CounterMode = TIM_CounterMode_Up,
1493 .TIM_Period = 0xFFFF,
1494 .TIM_RepetitionCounter = 0x0000,
1497 static const struct pios_tim_clock_cfg tim_1_cfg = {
1498 .timer = TIM1,
1499 .time_base_init = &tim_apb2_time_base,
1500 .irq = {
1501 .init = {
1502 .NVIC_IRQChannel = TIM1_CC_IRQn,
1503 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1504 .NVIC_IRQChannelSubPriority = 0,
1505 .NVIC_IRQChannelCmd = ENABLE,
1510 static const struct pios_tim_clock_cfg tim_4_cfg = {
1511 .timer = TIM4,
1512 .time_base_init = &tim_apb1_time_base,
1513 .irq = {
1514 .init = {
1515 .NVIC_IRQChannel = TIM4_IRQn,
1516 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1517 .NVIC_IRQChannelSubPriority = 0,
1518 .NVIC_IRQChannelCmd = ENABLE,
1522 static const struct pios_tim_clock_cfg tim_8_cfg = {
1523 .timer = TIM8,
1524 .time_base_init = &tim_apb2_time_base,
1525 .irq = {
1526 .init = {
1527 .NVIC_IRQChannel = TIM8_CC_IRQn,
1528 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1529 .NVIC_IRQChannelSubPriority = 0,
1530 .NVIC_IRQChannelCmd = ENABLE,
1535 static const struct pios_tim_clock_cfg tim_12_cfg = {
1536 .timer = TIM12,
1537 .time_base_init = &tim_apb1_time_base,
1538 .irq = {
1539 .init = {
1540 .NVIC_IRQChannel = TIM8_BRK_TIM12_IRQn,
1541 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1542 .NVIC_IRQChannelSubPriority = 0,
1543 .NVIC_IRQChannelCmd = ENABLE,
1550 * Pios servo configuration structures
1551 * Using TIM3, TIM9, TIM2, TIM5
1553 #include <pios_servo_priv.h>
1554 static const struct pios_tim_channel pios_tim_servoport_all_pins[] = {
1556 .timer = TIM3,
1557 .timer_chan = TIM_Channel_3,
1558 .pin = {
1559 .gpio = GPIOB,
1560 .init = {
1561 .GPIO_Pin = GPIO_Pin_0,
1562 .GPIO_Speed = GPIO_Speed_2MHz,
1563 .GPIO_Mode = GPIO_Mode_AF,
1564 .GPIO_OType = GPIO_OType_PP,
1565 .GPIO_PuPd = GPIO_PuPd_UP
1567 .pin_source = GPIO_PinSource0,
1569 .remap = GPIO_AF_TIM3,
1572 .timer = TIM3,
1573 .timer_chan = TIM_Channel_4,
1574 .pin = {
1575 .gpio = GPIOB,
1576 .init = {
1577 .GPIO_Pin = GPIO_Pin_1,
1578 .GPIO_Speed = GPIO_Speed_2MHz,
1579 .GPIO_Mode = GPIO_Mode_AF,
1580 .GPIO_OType = GPIO_OType_PP,
1581 .GPIO_PuPd = GPIO_PuPd_UP
1583 .pin_source = GPIO_PinSource1,
1585 .remap = GPIO_AF_TIM3,
1588 .timer = TIM9,
1589 .timer_chan = TIM_Channel_2,
1590 .pin = {
1591 .gpio = GPIOA,
1592 .init = {
1593 .GPIO_Pin = GPIO_Pin_3,
1594 .GPIO_Speed = GPIO_Speed_2MHz,
1595 .GPIO_Mode = GPIO_Mode_AF,
1596 .GPIO_OType = GPIO_OType_PP,
1597 .GPIO_PuPd = GPIO_PuPd_UP
1599 .pin_source = GPIO_PinSource3,
1601 .remap = GPIO_AF_TIM9,
1604 .timer = TIM2,
1605 .timer_chan = TIM_Channel_3,
1606 .pin = {
1607 .gpio = GPIOA,
1608 .init = {
1609 .GPIO_Pin = GPIO_Pin_2,
1610 .GPIO_Speed = GPIO_Speed_2MHz,
1611 .GPIO_Mode = GPIO_Mode_AF,
1612 .GPIO_OType = GPIO_OType_PP,
1613 .GPIO_PuPd = GPIO_PuPd_UP
1615 .pin_source = GPIO_PinSource2,
1617 .remap = GPIO_AF_TIM2,
1620 .timer = TIM5,
1621 .timer_chan = TIM_Channel_2,
1622 .pin = {
1623 .gpio = GPIOA,
1624 .init = {
1625 .GPIO_Pin = GPIO_Pin_1,
1626 .GPIO_Speed = GPIO_Speed_2MHz,
1627 .GPIO_Mode = GPIO_Mode_AF,
1628 .GPIO_OType = GPIO_OType_PP,
1629 .GPIO_PuPd = GPIO_PuPd_UP
1631 .pin_source = GPIO_PinSource1,
1633 .remap = GPIO_AF_TIM5,
1636 .timer = TIM5,
1637 .timer_chan = TIM_Channel_1,
1638 .pin = {
1639 .gpio = GPIOA,
1640 .init = {
1641 .GPIO_Pin = GPIO_Pin_0,
1642 .GPIO_Speed = GPIO_Speed_2MHz,
1643 .GPIO_Mode = GPIO_Mode_AF,
1644 .GPIO_OType = GPIO_OType_PP,
1645 .GPIO_PuPd = GPIO_PuPd_UP
1647 .pin_source = GPIO_PinSource0,
1649 .remap = GPIO_AF_TIM5,
1651 // PWM pins on FlexiIO(receiver) port
1653 // * 6: PB15 = SPI2 MOSI, TIM12 CH2
1655 .timer = TIM12,
1656 .timer_chan = TIM_Channel_2,
1657 .pin = {
1658 .gpio = GPIOB,
1659 .init = {
1660 .GPIO_Pin = GPIO_Pin_15,
1661 .GPIO_Speed = GPIO_Speed_2MHz,
1662 .GPIO_Mode = GPIO_Mode_AF,
1663 .GPIO_OType = GPIO_OType_PP,
1664 .GPIO_PuPd = GPIO_PuPd_UP
1666 .pin_source = GPIO_PinSource15,
1668 .remap = GPIO_AF_TIM12,
1671 // * 7: PC6 = TIM8 CH1, USART6 TX
1672 .timer = TIM8,
1673 .timer_chan = TIM_Channel_1,
1674 .pin = {
1675 .gpio = GPIOC,
1676 .init = {
1677 .GPIO_Pin = GPIO_Pin_6,
1678 .GPIO_Speed = GPIO_Speed_2MHz,
1679 .GPIO_Mode = GPIO_Mode_AF,
1680 .GPIO_OType = GPIO_OType_PP,
1681 .GPIO_PuPd = GPIO_PuPd_UP
1683 .pin_source = GPIO_PinSource6,
1685 .remap = GPIO_AF_TIM8,
1689 // * 8: PC7 = TIM8 CH2, USART6 RX
1690 .timer = TIM8,
1691 .timer_chan = TIM_Channel_2,
1692 .pin = {
1693 .gpio = GPIOC,
1694 .init = {
1695 .GPIO_Pin = GPIO_Pin_7,
1696 .GPIO_Speed = GPIO_Speed_2MHz,
1697 .GPIO_Mode = GPIO_Mode_AF,
1698 .GPIO_OType = GPIO_OType_PP,
1699 .GPIO_PuPd = GPIO_PuPd_UP
1701 .pin_source = GPIO_PinSource7,
1703 .remap = GPIO_AF_TIM8,
1707 // * 9: PC8 = TIM8 CH3
1708 .timer = TIM8,
1709 .timer_chan = TIM_Channel_3,
1710 .pin = {
1711 .gpio = GPIOC,
1712 .init = {
1713 .GPIO_Pin = GPIO_Pin_8,
1714 .GPIO_Speed = GPIO_Speed_2MHz,
1715 .GPIO_Mode = GPIO_Mode_AF,
1716 .GPIO_OType = GPIO_OType_PP,
1717 .GPIO_PuPd = GPIO_PuPd_UP
1719 .pin_source = GPIO_PinSource8,
1721 .remap = GPIO_AF_TIM8,
1725 // * 10: PC9 = TIM8 CH4
1726 .timer = TIM8,
1727 .timer_chan = TIM_Channel_4,
1728 .pin = {
1729 .gpio = GPIOC,
1730 .init = {
1731 .GPIO_Pin = GPIO_Pin_9,
1732 .GPIO_Speed = GPIO_Speed_2MHz,
1733 .GPIO_Mode = GPIO_Mode_AF,
1734 .GPIO_OType = GPIO_OType_PP,
1735 .GPIO_PuPd = GPIO_PuPd_UP
1737 .pin_source = GPIO_PinSource9,
1739 .remap = GPIO_AF_TIM8,
1743 // * 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
1744 .timer = TIM12,
1745 .timer_chan = TIM_Channel_1,
1746 .pin = {
1747 .gpio = GPIOB,
1748 .init = {
1749 .GPIO_Pin = GPIO_Pin_14,
1750 .GPIO_Speed = GPIO_Speed_2MHz,
1751 .GPIO_Mode = GPIO_Mode_AF,
1752 .GPIO_OType = GPIO_OType_PP,
1753 .GPIO_PuPd = GPIO_PuPd_UP
1755 .pin_source = GPIO_PinSource14,
1757 .remap = GPIO_AF_TIM12,
1760 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT 6
1761 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM 11
1762 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN 12
1764 const struct pios_servo_cfg pios_servo_cfg_out = {
1765 .tim_oc_init = {
1766 .TIM_OCMode = TIM_OCMode_PWM1,
1767 .TIM_OutputState = TIM_OutputState_Enable,
1768 .TIM_OutputNState = TIM_OutputNState_Disable,
1769 .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1770 .TIM_OCPolarity = TIM_OCPolarity_High,
1771 .TIM_OCNPolarity = TIM_OCPolarity_High,
1772 .TIM_OCIdleState = TIM_OCIdleState_Reset,
1773 .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1775 .channels = pios_tim_servoport_all_pins,
1776 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT,
1778 // All servo outputs, servo input ch1 ppm, ch2-6 outputs
1779 const struct pios_servo_cfg pios_servo_cfg_out_in_ppm = {
1780 .tim_oc_init = {
1781 .TIM_OCMode = TIM_OCMode_PWM1,
1782 .TIM_OutputState = TIM_OutputState_Enable,
1783 .TIM_OutputNState = TIM_OutputNState_Disable,
1784 .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1785 .TIM_OCPolarity = TIM_OCPolarity_High,
1786 .TIM_OCNPolarity = TIM_OCPolarity_High,
1787 .TIM_OCIdleState = TIM_OCIdleState_Reset,
1788 .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1790 .channels = pios_tim_servoport_all_pins,
1791 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM,
1793 // All servo outputs, servo inputs ch1-6 Outputs
1794 const struct pios_servo_cfg pios_servo_cfg_out_in = {
1795 .tim_oc_init = {
1796 .TIM_OCMode = TIM_OCMode_PWM1,
1797 .TIM_OutputState = TIM_OutputState_Enable,
1798 .TIM_OutputNState = TIM_OutputNState_Disable,
1799 .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1800 .TIM_OCPolarity = TIM_OCPolarity_High,
1801 .TIM_OCNPolarity = TIM_OCPolarity_High,
1802 .TIM_OCIdleState = TIM_OCIdleState_Reset,
1803 .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1805 .channels = pios_tim_servoport_all_pins,
1806 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN,
1811 * PWM Inputs
1812 * TIM1, TIM8, TIM12
1814 #if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM)
1815 #include <pios_pwm_priv.h>
1816 static const struct pios_tim_channel pios_tim_rcvrport_all_channels[] = {
1818 .timer = TIM12,
1819 .timer_chan = TIM_Channel_1,
1820 .pin = {
1821 .gpio = GPIOB,
1822 .init = {
1823 .GPIO_Pin = GPIO_Pin_14,
1824 .GPIO_Speed = GPIO_Speed_2MHz,
1825 .GPIO_Mode = GPIO_Mode_AF,
1826 .GPIO_OType = GPIO_OType_PP,
1827 .GPIO_PuPd = GPIO_PuPd_UP
1829 .pin_source = GPIO_PinSource14,
1831 .remap = GPIO_AF_TIM12,
1834 .timer = TIM12,
1835 .timer_chan = TIM_Channel_2,
1836 .pin = {
1837 .gpio = GPIOB,
1838 .init = {
1839 .GPIO_Pin = GPIO_Pin_15,
1840 .GPIO_Speed = GPIO_Speed_2MHz,
1841 .GPIO_Mode = GPIO_Mode_AF,
1842 .GPIO_OType = GPIO_OType_PP,
1843 .GPIO_PuPd = GPIO_PuPd_UP
1845 .pin_source = GPIO_PinSource15,
1847 .remap = GPIO_AF_TIM12,
1850 .timer = TIM8,
1851 .timer_chan = TIM_Channel_1,
1852 .pin = {
1853 .gpio = GPIOC,
1854 .init = {
1855 .GPIO_Pin = GPIO_Pin_6,
1856 .GPIO_Speed = GPIO_Speed_2MHz,
1857 .GPIO_Mode = GPIO_Mode_AF,
1858 .GPIO_OType = GPIO_OType_PP,
1859 .GPIO_PuPd = GPIO_PuPd_UP
1861 .pin_source = GPIO_PinSource6,
1863 .remap = GPIO_AF_TIM8,
1866 .timer = TIM8,
1867 .timer_chan = TIM_Channel_2,
1868 .pin = {
1869 .gpio = GPIOC,
1870 .init = {
1871 .GPIO_Pin = GPIO_Pin_7,
1872 .GPIO_Speed = GPIO_Speed_2MHz,
1873 .GPIO_Mode = GPIO_Mode_AF,
1874 .GPIO_OType = GPIO_OType_PP,
1875 .GPIO_PuPd = GPIO_PuPd_UP
1877 .pin_source = GPIO_PinSource7,
1879 .remap = GPIO_AF_TIM8,
1882 .timer = TIM8,
1883 .timer_chan = TIM_Channel_3,
1884 .pin = {
1885 .gpio = GPIOC,
1886 .init = {
1887 .GPIO_Pin = GPIO_Pin_8,
1888 .GPIO_Speed = GPIO_Speed_2MHz,
1889 .GPIO_Mode = GPIO_Mode_AF,
1890 .GPIO_OType = GPIO_OType_PP,
1891 .GPIO_PuPd = GPIO_PuPd_UP
1893 .pin_source = GPIO_PinSource8,
1895 .remap = GPIO_AF_TIM8,
1898 .timer = TIM8,
1899 .timer_chan = TIM_Channel_4,
1900 .pin = {
1901 .gpio = GPIOC,
1902 .init = {
1903 .GPIO_Pin = GPIO_Pin_9,
1904 .GPIO_Speed = GPIO_Speed_2MHz,
1905 .GPIO_Mode = GPIO_Mode_AF,
1906 .GPIO_OType = GPIO_OType_PP,
1907 .GPIO_PuPd = GPIO_PuPd_UP
1909 .pin_source = GPIO_PinSource9,
1911 .remap = GPIO_AF_TIM8,
1915 const struct pios_pwm_cfg pios_pwm_cfg = {
1916 .tim_ic_init = {
1917 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1918 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1919 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1920 .TIM_ICFilter = 0x0,
1922 .channels = pios_tim_rcvrport_all_channels,
1923 .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels),
1925 // this configures outputs 2-6 as pwm inputs
1926 const struct pios_pwm_cfg pios_pwm_ppm_cfg = {
1927 .tim_ic_init = {
1928 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1929 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1930 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1931 .TIM_ICFilter = 0x0,
1933 .channels = &pios_tim_rcvrport_all_channels[1],
1934 .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels) - 1,
1937 #endif /* if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM) */
1940 * PPM Input
1942 #if defined(PIOS_INCLUDE_PPM)
1943 #include <pios_ppm_priv.h>
1944 static const struct pios_ppm_cfg pios_ppm_cfg = {
1945 .tim_ic_init = {
1946 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1947 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1948 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1949 .TIM_ICFilter = 0x0,
1950 .TIM_Channel = TIM_Channel_1,
1952 /* Use only the first channel for ppm */
1953 .channels = &pios_tim_rcvrport_all_channels[0],
1954 .num_channels = 1,
1957 #endif // PPM
1959 #if defined(PIOS_INCLUDE_GCSRCVR)
1960 #include "pios_gcsrcvr_priv.h"
1961 #endif /* PIOS_INCLUDE_GCSRCVR */
1963 #if defined(PIOS_INCLUDE_RCVR)
1964 #include "pios_rcvr_priv.h"
1965 #endif /* PIOS_INCLUDE_RCVR */
1967 #if defined(PIOS_INCLUDE_USB)
1968 #include "pios_usb_priv.h"
1970 static const struct pios_usb_cfg pios_usb_main_rm1_cfg = {
1971 .irq = {
1972 .init = {
1973 .NVIC_IRQChannel = OTG_FS_IRQn,
1974 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
1975 .NVIC_IRQChannelSubPriority = 0, // PriorityGroup=4
1976 .NVIC_IRQChannelCmd = ENABLE,
1979 .vsense = {
1980 .gpio = GPIOB,
1981 .init = {
1982 .GPIO_Pin = GPIO_Pin_13,
1983 .GPIO_Speed = GPIO_Speed_25MHz,
1984 .GPIO_Mode = GPIO_Mode_IN,
1985 .GPIO_OType = GPIO_OType_OD,
1988 .vsense_active_low = false
1991 static const struct pios_usb_cfg pios_usb_main_rm2_cfg = {
1992 .irq = {
1993 .init = {
1994 .NVIC_IRQChannel = OTG_FS_IRQn,
1995 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
1996 .NVIC_IRQChannelSubPriority = 0, // PriorityGroup=4
1997 .NVIC_IRQChannelCmd = ENABLE,
2000 .vsense = {
2001 .gpio = GPIOC,
2002 .init = {
2003 .GPIO_Pin = GPIO_Pin_5,
2004 .GPIO_Speed = GPIO_Speed_25MHz,
2005 .GPIO_Mode = GPIO_Mode_IN,
2006 .GPIO_OType = GPIO_OType_OD,
2009 .vsense_active_low = false
2012 const struct pios_usb_cfg *PIOS_BOARD_HW_DEFS_GetUsbCfg(uint32_t board_revision)
2014 switch (board_revision) {
2015 case 2:
2016 return &pios_usb_main_rm1_cfg;
2018 break;
2019 case 3:
2020 return &pios_usb_main_rm2_cfg;
2022 break;
2023 default:
2024 PIOS_DEBUG_Assert(0);
2026 return NULL;
2029 #include "pios_usb_board_data_priv.h"
2030 #include "pios_usb_desc_hid_cdc_priv.h"
2031 #include "pios_usb_desc_hid_only_priv.h"
2032 #include "pios_usbhook.h"
2034 #endif /* PIOS_INCLUDE_USB */
2036 #if defined(PIOS_INCLUDE_COM_MSG)
2038 #include <pios_com_msg_priv.h>
2040 #endif /* PIOS_INCLUDE_COM_MSG */
2042 #if defined(PIOS_INCLUDE_USB_HID) && !defined(PIOS_INCLUDE_USB_CDC)
2043 #include <pios_usb_hid_priv.h>
2045 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
2046 .data_if = 0,
2047 .data_rx_ep = 1,
2048 .data_tx_ep = 1,
2050 #endif /* PIOS_INCLUDE_USB_HID && !PIOS_INCLUDE_USB_CDC */
2052 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_USB_CDC)
2053 #include <pios_usb_cdc_priv.h>
2055 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
2056 .ctrl_if = 0,
2057 .ctrl_tx_ep = 2,
2059 .data_if = 1,
2060 .data_rx_ep = 3,
2061 .data_tx_ep = 3,
2064 #include <pios_usb_hid_priv.h>
2066 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
2067 .data_if = 2,
2068 .data_rx_ep = 1,
2069 .data_tx_ep = 1,
2071 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
2073 #ifdef PIOS_INCLUDE_WS2811
2074 #include <pios_ws2811_cfg.h>
2075 #include <hwsettings.h>
2076 #define PIOS_WS2811_TIM_DIVIDER (PIOS_PERIPHERAL_APB2_CLOCK / (800000 * PIOS_WS2811_TIM_PERIOD))
2078 void DMA2_Stream1_IRQHandler(void) __attribute__((alias("PIOS_WS2811_irq_handler")));
2079 // list of pin configurable as ws281x outputs.
2080 // this will not clash with PWM in or servo output as
2081 // pins will be reconfigured as _OUT so the alternate function is disabled.
2082 const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg[] = {
2083 [HWSETTINGS_WS2811LED_OUT_SERVOOUT1] = {
2084 .gpio = GPIOB,
2085 .gpioInit = {
2086 .GPIO_Pin = GPIO_Pin_0,
2087 .GPIO_Speed = GPIO_Speed_25MHz,
2088 .GPIO_Mode = GPIO_Mode_OUT,
2089 .GPIO_OType = GPIO_OType_PP,
2092 [HWSETTINGS_WS2811LED_OUT_SERVOOUT2] = {
2093 .gpio = GPIOB,
2094 .gpioInit = {
2095 .GPIO_Pin = GPIO_Pin_1,
2096 .GPIO_Speed = GPIO_Speed_25MHz,
2097 .GPIO_Mode = GPIO_Mode_OUT,
2098 .GPIO_OType = GPIO_OType_PP,
2101 [HWSETTINGS_WS2811LED_OUT_SERVOOUT3] = {
2102 .gpio = GPIOA,
2103 .gpioInit = {
2104 .GPIO_Pin = GPIO_Pin_3,
2105 .GPIO_Speed = GPIO_Speed_25MHz,
2106 .GPIO_Mode = GPIO_Mode_OUT,
2107 .GPIO_OType = GPIO_OType_PP,
2110 [HWSETTINGS_WS2811LED_OUT_SERVOOUT4] = {
2111 .gpio = GPIOA,
2112 .gpioInit = {
2113 .GPIO_Pin = GPIO_Pin_2,
2114 .GPIO_Speed = GPIO_Speed_25MHz,
2115 .GPIO_Mode = GPIO_Mode_OUT,
2116 .GPIO_OType = GPIO_OType_PP,
2119 [HWSETTINGS_WS2811LED_OUT_SERVOOUT5] = {
2120 .gpio = GPIOA,
2121 .gpioInit = {
2122 .GPIO_Pin = GPIO_Pin_1,
2123 .GPIO_Speed = GPIO_Speed_25MHz,
2124 .GPIO_Mode = GPIO_Mode_OUT,
2125 .GPIO_OType = GPIO_OType_PP,
2128 [HWSETTINGS_WS2811LED_OUT_SERVOOUT6] = {
2129 .gpio = GPIOA,
2130 .gpioInit = {
2131 .GPIO_Pin = GPIO_Pin_0,
2132 .GPIO_Speed = GPIO_Speed_25MHz,
2133 .GPIO_Mode = GPIO_Mode_OUT,
2134 .GPIO_OType = GPIO_OType_PP,
2137 [HWSETTINGS_WS2811LED_OUT_FLEXIIOPIN3] = {
2138 .gpio = GPIOB,
2139 .gpioInit = {
2140 .GPIO_Pin = GPIO_Pin_12,
2141 .GPIO_Speed = GPIO_Speed_25MHz,
2142 .GPIO_Mode = GPIO_Mode_OUT,
2143 .GPIO_OType = GPIO_OType_PP,
2146 [HWSETTINGS_WS2811LED_OUT_FLEXIIOPIN4] = {
2147 .gpio = GPIOB,
2148 .gpioInit = {
2149 .GPIO_Pin = GPIO_Pin_13,
2150 .GPIO_Speed = GPIO_Speed_25MHz,
2151 .GPIO_Mode = GPIO_Mode_OUT,
2152 .GPIO_OType = GPIO_OType_PP,
2157 const struct pios_ws2811_cfg pios_ws2811_cfg = {
2158 .timer = TIM1,
2159 .timerInit = {
2160 .TIM_Prescaler = PIOS_WS2811_TIM_DIVIDER - 1,
2161 .TIM_ClockDivision = TIM_CKD_DIV1,
2162 .TIM_CounterMode = TIM_CounterMode_Up,
2163 // period (1.25 uS per period
2164 .TIM_Period = PIOS_WS2811_TIM_PERIOD,
2165 .TIM_RepetitionCounter = 0x0000,
2168 .timerCh1 = 1,
2169 .streamCh1 = DMA2_Stream1,
2170 .timerCh2 = 3,
2171 .streamCh2 = DMA2_Stream6,
2172 .streamUpdate = DMA2_Stream5,
2174 // DMA streamCh1, triggered by timerCh1 pwm signal.
2175 // if FrameBuffer indicates, reset output value early to indicate "0" bit to ws2812
2176 .dmaInitCh1 = PIOS_WS2811_DMA_CH1_CONFIG(DMA_Channel_6),
2177 .dmaItCh1 = DMA_IT_TEIF1 | DMA_IT_TCIF1,
2179 // DMA streamCh2, triggered by timerCh2 pwm signal.
2180 // Reset output value late to indicate "1" bit to ws2812.
2181 .dmaInitCh2 = PIOS_WS2811_DMA_CH2_CONFIG(DMA_Channel_6),
2182 .dmaItCh2 = DMA_IT_TEIF6 | DMA_IT_TCIF6,
2184 // DMA streamUpdate Triggered by timer update event
2185 // Outputs a high logic level at beginning of a cycle
2186 .dmaInitUpdate = PIOS_WS2811_DMA_UPDATE_CONFIG(DMA_Channel_6),
2187 .dmaItUpdate = DMA_IT_TEIF5 | DMA_IT_TCIF5,
2188 .dmaSource = TIM_DMA_CC1 | TIM_DMA_CC3 | TIM_DMA_Update,
2190 // DMAInitCh1 interrupt vector, used to block timer at end of framebuffer transfer
2191 .irq = {
2192 .flags = (DMA_IT_TCIF1),
2193 .init = {
2194 .NVIC_IRQChannel = DMA2_Stream1_IRQn,
2195 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
2196 .NVIC_IRQChannelSubPriority = 0,
2197 .NVIC_IRQChannelCmd = ENABLE,
2202 void PIOS_WS2811_irq_handler(void)
2204 PIOS_WS2811_DMA_irq_handler();
2206 #endif // PIOS_INCLUDE_WS2811