2 ******************************************************************************
3 * @file board_hw_defs.c
4 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
5 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012
7 * @addtogroup OpenPilotSystem OpenPilot System
9 * @addtogroup OpenPilotCore OpenPilot Core
11 * @brief Defines board specific static initializers for hardware for the Revolution board.
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #if defined(PIOS_INCLUDE_LED)
31 #include <pios_led_priv.h>
32 static const struct pios_gpio pios_leds
[] = {
33 [PIOS_LED_HEARTBEAT
] = {
37 .GPIO_Pin
= GPIO_Pin_12
,
38 .GPIO_Speed
= GPIO_Speed_50MHz
,
39 .GPIO_Mode
= GPIO_Mode_OUT
,
40 .GPIO_OType
= GPIO_OType_PP
,
41 .GPIO_PuPd
= GPIO_PuPd_UP
50 .GPIO_Pin
= GPIO_Pin_6
,
51 .GPIO_Speed
= GPIO_Speed_50MHz
,
52 .GPIO_Mode
= GPIO_Mode_OUT
,
53 .GPIO_OType
= GPIO_OType_PP
,
54 .GPIO_PuPd
= GPIO_PuPd_UP
59 #ifdef PIOS_RFM22B_DEBUG_ON_TELEM
64 .GPIO_Pin
= GPIO_Pin_6
,
65 .GPIO_Speed
= GPIO_Speed_50MHz
,
66 .GPIO_Mode
= GPIO_Mode_OUT
,
67 .GPIO_OType
= GPIO_OType_PP
,
68 .GPIO_PuPd
= GPIO_PuPd_UP
76 .GPIO_Pin
= GPIO_Pin_7
,
77 .GPIO_Speed
= GPIO_Speed_50MHz
,
78 .GPIO_Mode
= GPIO_Mode_OUT
,
79 .GPIO_OType
= GPIO_OType_PP
,
80 .GPIO_PuPd
= GPIO_PuPd_UP
88 .GPIO_Pin
= GPIO_Pin_8
,
89 .GPIO_Speed
= GPIO_Speed_50MHz
,
90 .GPIO_Mode
= GPIO_Mode_OUT
,
91 .GPIO_OType
= GPIO_OType_PP
,
92 .GPIO_PuPd
= GPIO_PuPd_UP
100 .GPIO_Pin
= GPIO_Pin_9
,
101 .GPIO_Speed
= GPIO_Speed_50MHz
,
102 .GPIO_Mode
= GPIO_Mode_OUT
,
103 .GPIO_OType
= GPIO_OType_PP
,
104 .GPIO_PuPd
= GPIO_PuPd_UP
108 #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */
111 static const struct pios_gpio_cfg pios_led_cfg
= {
113 .num_gpios
= NELEMENTS(pios_leds
),
116 static const struct pios_gpio pios_leds_v2
[] = {
117 [PIOS_LED_HEARTBEAT
] = {
121 .GPIO_Pin
= GPIO_Pin_5
,
122 .GPIO_Speed
= GPIO_Speed_50MHz
,
123 .GPIO_Mode
= GPIO_Mode_OUT
,
124 .GPIO_OType
= GPIO_OType_PP
,
125 .GPIO_PuPd
= GPIO_PuPd_UP
134 .GPIO_Pin
= GPIO_Pin_4
,
135 .GPIO_Speed
= GPIO_Speed_50MHz
,
136 .GPIO_Mode
= GPIO_Mode_OUT
,
137 .GPIO_OType
= GPIO_OType_PP
,
138 .GPIO_PuPd
= GPIO_PuPd_UP
143 #ifdef PIOS_RFM22B_DEBUG_ON_TELEM
148 .GPIO_Pin
= GPIO_Pin_13
,
149 .GPIO_Speed
= GPIO_Speed_50MHz
,
150 .GPIO_Mode
= GPIO_Mode_OUT
,
151 .GPIO_OType
= GPIO_OType_PP
,
152 .GPIO_PuPd
= GPIO_PuPd_UP
160 .GPIO_Pin
= GPIO_Pin_14
,
161 .GPIO_Speed
= GPIO_Speed_50MHz
,
162 .GPIO_Mode
= GPIO_Mode_OUT
,
163 .GPIO_OType
= GPIO_OType_PP
,
164 .GPIO_PuPd
= GPIO_PuPd_UP
172 .GPIO_Pin
= GPIO_Pin_15
,
173 .GPIO_Speed
= GPIO_Speed_50MHz
,
174 .GPIO_Mode
= GPIO_Mode_OUT
,
175 .GPIO_OType
= GPIO_OType_PP
,
176 .GPIO_PuPd
= GPIO_PuPd_UP
184 .GPIO_Pin
= GPIO_Pin_6
,
185 .GPIO_Speed
= GPIO_Speed_50MHz
,
186 .GPIO_Mode
= GPIO_Mode_OUT
,
187 .GPIO_OType
= GPIO_OType_PP
,
188 .GPIO_PuPd
= GPIO_PuPd_UP
192 #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */
195 static const struct pios_gpio_cfg pios_led_v2_cfg
= {
196 .gpios
= pios_leds_v2
,
197 .num_gpios
= NELEMENTS(pios_leds_v2
),
200 const struct pios_gpio_cfg
*PIOS_BOARD_HW_DEFS_GetLedCfg(uint32_t board_revision
)
202 switch (board_revision
) {
204 return &pios_led_cfg
;
208 return &pios_led_v2_cfg
;
212 PIOS_DEBUG_Assert(0);
217 #endif /* PIOS_INCLUDE_LED */
219 #if defined(PIOS_INCLUDE_SPI)
220 #include <pios_spi_priv.h>
222 #if defined(PIOS_OVERO_SPI)
224 * - Used for Flexi/IO/Overo communications
225 3: PB12 = SPI2 NSS, CAN2 RX
226 4: PB13 = SPI2 SCK, CAN2 TX, USART3 CTS
227 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
228 6: PB15 = SPI2 MOSI, TIM12 CH2
230 #include <pios_overo_priv.h>
231 void PIOS_OVERO_irq_handler(void);
232 void DMA1_Stream7_IRQHandler(void) __attribute__((alias("PIOS_OVERO_irq_handler")));
233 static const struct pios_overo_cfg pios_overo_cfg
= {
235 .remap
= GPIO_AF_SPI2
,
237 .SPI_Mode
= SPI_Mode_Slave
,
238 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
239 .SPI_DataSize
= SPI_DataSize_8b
,
240 .SPI_NSS
= SPI_NSS_Hard
,
241 .SPI_FirstBit
= SPI_FirstBit_MSB
,
242 .SPI_CRCPolynomial
= 7,
243 .SPI_CPOL
= SPI_CPOL_High
,
244 .SPI_CPHA
= SPI_CPHA_2Edge
,
245 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_2
,
250 // Note this is the stream ID that triggers interrupts (in this case TX)
251 .flags
= (DMA_IT_TCIF7
),
253 .NVIC_IRQChannel
= DMA1_Stream7_IRQn
,
254 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
255 .NVIC_IRQChannelSubPriority
= 0,
256 .NVIC_IRQChannelCmd
= ENABLE
,
261 .channel
= DMA1_Stream0
,
263 .DMA_Channel
= DMA_Channel_0
,
264 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI2
->DR
),
265 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
266 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
267 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
268 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
269 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
270 .DMA_Mode
= DMA_Mode_Circular
,
271 .DMA_Priority
= DMA_Priority_Medium
,
273 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
274 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
275 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
276 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
280 .channel
= DMA1_Stream7
,
282 .DMA_Channel
= DMA_Channel_0
,
283 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI2
->DR
),
284 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
285 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
286 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
287 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
288 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
289 .DMA_Mode
= DMA_Mode_Circular
,
290 .DMA_Priority
= DMA_Priority_Medium
,
291 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
292 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
293 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
294 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
301 .GPIO_Pin
= GPIO_Pin_13
,
302 .GPIO_Speed
= GPIO_Speed_100MHz
,
303 .GPIO_Mode
= GPIO_Mode_AF
,
304 .GPIO_OType
= GPIO_OType_PP
,
305 .GPIO_PuPd
= GPIO_PuPd_NOPULL
311 .GPIO_Pin
= GPIO_Pin_14
,
312 .GPIO_Speed
= GPIO_Speed_50MHz
,
313 .GPIO_Mode
= GPIO_Mode_AF
,
314 .GPIO_OType
= GPIO_OType_PP
,
315 .GPIO_PuPd
= GPIO_PuPd_NOPULL
321 .GPIO_Pin
= GPIO_Pin_15
,
322 .GPIO_Speed
= GPIO_Speed_50MHz
,
323 .GPIO_Mode
= GPIO_Mode_AF
,
324 .GPIO_OType
= GPIO_OType_PP
,
325 .GPIO_PuPd
= GPIO_PuPd_NOPULL
333 .GPIO_Pin
= GPIO_Pin_12
,
334 .GPIO_Speed
= GPIO_Speed_50MHz
,
335 .GPIO_Mode
= GPIO_Mode_OUT
,
336 .GPIO_OType
= GPIO_OType_PP
,
337 .GPIO_PuPd
= GPIO_PuPd_UP
342 uint32_t pios_overo_id
= 0;
343 void PIOS_OVERO_irq_handler(void)
345 /* Call into the generic code to handle the IRQ for this specific device */
346 PIOS_OVERO_DMA_irq_handler(pios_overo_id
);
349 #endif /* PIOS_OVERO_SPI */
353 * Used for MPU6000 gyro and accelerometer
355 void PIOS_SPI_gyro_irq_handler(void);
356 void DMA2_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
357 void DMA2_Stream3_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
358 static const struct pios_spi_cfg pios_spi_gyro_cfg
= {
360 .remap
= GPIO_AF_SPI1
,
362 .SPI_Mode
= SPI_Mode_Master
,
363 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
364 .SPI_DataSize
= SPI_DataSize_8b
,
365 .SPI_NSS
= SPI_NSS_Soft
,
366 .SPI_FirstBit
= SPI_FirstBit_MSB
,
367 .SPI_CRCPolynomial
= 7,
368 .SPI_CPOL
= SPI_CPOL_High
,
369 .SPI_CPHA
= SPI_CPHA_2Edge
,
370 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_16
,
375 .flags
= (DMA_IT_TCIF0
| DMA_IT_TEIF0
| DMA_IT_HTIF0
),
377 .NVIC_IRQChannel
= DMA2_Stream0_IRQn
,
378 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
379 .NVIC_IRQChannelSubPriority
= 0,
380 .NVIC_IRQChannelCmd
= ENABLE
,
385 .channel
= DMA2_Stream0
,
387 .DMA_Channel
= DMA_Channel_3
,
388 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI1
->DR
),
389 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
390 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
391 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
392 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
393 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
394 .DMA_Mode
= DMA_Mode_Normal
,
395 .DMA_Priority
= DMA_Priority_Medium
,
396 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
397 /* .DMA_FIFOThreshold */
398 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
399 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
403 .channel
= DMA2_Stream3
,
405 .DMA_Channel
= DMA_Channel_3
,
406 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI1
->DR
),
407 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
408 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
409 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
410 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
411 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
412 .DMA_Mode
= DMA_Mode_Normal
,
413 .DMA_Priority
= DMA_Priority_High
,
414 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
415 /* .DMA_FIFOThreshold */
416 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
417 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
424 .GPIO_Pin
= GPIO_Pin_5
,
425 .GPIO_Speed
= GPIO_Speed_100MHz
,
426 .GPIO_Mode
= GPIO_Mode_AF
,
427 .GPIO_OType
= GPIO_OType_PP
,
428 .GPIO_PuPd
= GPIO_PuPd_UP
434 .GPIO_Pin
= GPIO_Pin_6
,
435 .GPIO_Speed
= GPIO_Speed_50MHz
,
436 .GPIO_Mode
= GPIO_Mode_AF
,
437 .GPIO_OType
= GPIO_OType_PP
,
438 .GPIO_PuPd
= GPIO_PuPd_UP
444 .GPIO_Pin
= GPIO_Pin_7
,
445 .GPIO_Speed
= GPIO_Speed_50MHz
,
446 .GPIO_Mode
= GPIO_Mode_AF
,
447 .GPIO_OType
= GPIO_OType_PP
,
448 .GPIO_PuPd
= GPIO_PuPd_UP
456 .GPIO_Pin
= GPIO_Pin_4
,
457 .GPIO_Speed
= GPIO_Speed_50MHz
,
458 .GPIO_Mode
= GPIO_Mode_OUT
,
459 .GPIO_OType
= GPIO_OType_PP
,
460 .GPIO_PuPd
= GPIO_PuPd_UP
466 static uint32_t pios_spi_gyro_id
;
467 void PIOS_SPI_gyro_irq_handler(void)
469 /* Call into the generic code to handle the IRQ for this specific device */
470 PIOS_SPI_IRQ_Handler(pios_spi_gyro_id
);
476 * Used for Flash and the RFM22B
478 void PIOS_SPI_telem_flash_irq_handler(void);
479 void DMA1_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
480 void DMA1_Stream5_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
481 static const struct pios_spi_cfg pios_spi_telem_flash_cfg
= {
483 .remap
= GPIO_AF_SPI3
,
485 .SPI_Mode
= SPI_Mode_Master
,
486 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
487 .SPI_DataSize
= SPI_DataSize_8b
,
488 .SPI_NSS
= SPI_NSS_Soft
,
489 .SPI_FirstBit
= SPI_FirstBit_MSB
,
490 .SPI_CRCPolynomial
= 7,
491 .SPI_CPOL
= SPI_CPOL_Low
,
492 .SPI_CPHA
= SPI_CPHA_1Edge
,
493 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_8
,
498 // Note this is the stream ID that triggers interrupts (in this case RX)
499 .flags
= (DMA_IT_TCIF0
| DMA_IT_TEIF0
| DMA_IT_HTIF0
),
501 .NVIC_IRQChannel
= DMA1_Stream0_IRQn
,
502 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
503 .NVIC_IRQChannelSubPriority
= 0,
504 .NVIC_IRQChannelCmd
= ENABLE
,
509 .channel
= DMA1_Stream0
,
511 .DMA_Channel
= DMA_Channel_0
,
512 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI3
->DR
),
513 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
514 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
515 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
516 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
517 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
518 .DMA_Mode
= DMA_Mode_Normal
,
519 .DMA_Priority
= DMA_Priority_Medium
,
521 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
522 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
523 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
524 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
528 .channel
= DMA1_Stream5
,
530 .DMA_Channel
= DMA_Channel_0
,
531 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI3
->DR
),
532 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
533 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
534 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
535 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
536 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
537 .DMA_Mode
= DMA_Mode_Normal
,
538 .DMA_Priority
= DMA_Priority_Medium
,
539 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
540 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
541 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
542 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
549 .GPIO_Pin
= GPIO_Pin_10
,
550 .GPIO_Speed
= GPIO_Speed_100MHz
,
551 .GPIO_Mode
= GPIO_Mode_AF
,
552 .GPIO_OType
= GPIO_OType_PP
,
553 .GPIO_PuPd
= GPIO_PuPd_NOPULL
559 .GPIO_Pin
= GPIO_Pin_11
,
560 .GPIO_Speed
= GPIO_Speed_50MHz
,
561 .GPIO_Mode
= GPIO_Mode_AF
,
562 .GPIO_OType
= GPIO_OType_PP
,
563 .GPIO_PuPd
= GPIO_PuPd_NOPULL
569 .GPIO_Pin
= GPIO_Pin_12
,
570 .GPIO_Speed
= GPIO_Speed_50MHz
,
571 .GPIO_Mode
= GPIO_Mode_AF
,
572 .GPIO_OType
= GPIO_OType_PP
,
573 .GPIO_PuPd
= GPIO_PuPd_NOPULL
581 .GPIO_Pin
= GPIO_Pin_15
,
582 .GPIO_Speed
= GPIO_Speed_50MHz
,
583 .GPIO_Mode
= GPIO_Mode_OUT
,
584 .GPIO_OType
= GPIO_OType_PP
,
585 .GPIO_PuPd
= GPIO_PuPd_UP
591 .GPIO_Pin
= GPIO_Pin_3
,
592 .GPIO_Speed
= GPIO_Speed_50MHz
,
593 .GPIO_Mode
= GPIO_Mode_OUT
,
594 .GPIO_OType
= GPIO_OType_PP
,
595 .GPIO_PuPd
= GPIO_PuPd_UP
601 uint32_t pios_spi_telem_flash_id
;
602 void PIOS_SPI_telem_flash_irq_handler(void)
604 /* Call into the generic code to handle the IRQ for this specific device */
605 PIOS_SPI_IRQ_Handler(pios_spi_telem_flash_id
);
609 #if defined(PIOS_INCLUDE_RFM22B)
610 #include <pios_rfm22b_priv.h>
612 static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config
= {
613 .vector
= PIOS_RFM22_EXT_Int
,
618 .GPIO_Pin
= GPIO_Pin_2
,
619 .GPIO_Speed
= GPIO_Speed_100MHz
,
620 .GPIO_Mode
= GPIO_Mode_IN
,
621 .GPIO_OType
= GPIO_OType_OD
,
622 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
627 .NVIC_IRQChannel
= EXTI2_IRQn
,
628 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_LOW
,
629 .NVIC_IRQChannelSubPriority
= 0,
630 .NVIC_IRQChannelCmd
= ENABLE
,
635 .EXTI_Line
= EXTI_Line2
, // matches above GPIO pin
636 .EXTI_Mode
= EXTI_Mode_Interrupt
,
637 .EXTI_Trigger
= EXTI_Trigger_Falling
,
638 .EXTI_LineCmd
= ENABLE
,
643 const struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg
= {
644 .spi_cfg
= &pios_spi_telem_flash_cfg
,
645 .exti_cfg
= &pios_exti_rfm22b_cfg
,
648 .gpio_direction
= GPIO0_RX_GPIO1_TX
,
651 const struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg
= {
652 .spi_cfg
= &pios_spi_telem_flash_cfg
,
653 .exti_cfg
= &pios_exti_rfm22b_cfg
,
656 .gpio_direction
= GPIO0_TX_GPIO1_RX
,
659 const struct pios_rfm22b_cfg
*PIOS_BOARD_HW_DEFS_GetRfm22Cfg(uint32_t board_revision
)
661 switch (board_revision
) {
663 return &pios_rfm22b_rm1_cfg
;
667 return &pios_rfm22b_rm2_cfg
;
671 PIOS_DEBUG_Assert(0);
676 #endif /* PIOS_INCLUDE_RFM22B */
678 #if defined(PIOS_INCLUDE_OPENLRS)
680 #include <pios_openlrs_priv.h>
682 static const struct pios_exti_cfg pios_exti_openlrs_cfg __exti_config
= {
683 .vector
= PIOS_OpenLRS_EXT_Int
,
688 .GPIO_Pin
= GPIO_Pin_2
,
689 .GPIO_Speed
= GPIO_Speed_100MHz
,
690 .GPIO_Mode
= GPIO_Mode_IN
,
691 .GPIO_OType
= GPIO_OType_OD
,
692 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
697 .NVIC_IRQChannel
= EXTI2_IRQn
,
698 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_LOW
,
699 .NVIC_IRQChannelSubPriority
= 0,
700 .NVIC_IRQChannelCmd
= ENABLE
,
705 .EXTI_Line
= EXTI_Line2
, // matches above GPIO pin
706 .EXTI_Mode
= EXTI_Mode_Interrupt
,
707 .EXTI_Trigger
= EXTI_Trigger_Falling
,
708 .EXTI_LineCmd
= ENABLE
,
713 const struct pios_openlrs_cfg pios_openlrs_rm1_cfg
= {
714 .spi_cfg
= &pios_spi_telem_flash_cfg
,
715 .exti_cfg
= &pios_exti_openlrs_cfg
,
716 .gpio_direction
= GPIO0_RX_GPIO1_TX
,
719 const struct pios_openlrs_cfg pios_openlrs_rm2_cfg
= {
720 .spi_cfg
= &pios_spi_telem_flash_cfg
,
721 .exti_cfg
= &pios_exti_openlrs_cfg
,
722 .gpio_direction
= GPIO0_TX_GPIO1_RX
,
725 const struct pios_openlrs_cfg
*PIOS_BOARD_HW_DEFS_GetOpenLRSCfg(uint32_t board_revision
)
727 switch (board_revision
) {
729 return &pios_openlrs_rm1_cfg
;
733 return &pios_openlrs_rm2_cfg
;
737 PIOS_DEBUG_Assert(0);
742 #endif /* PIOS_INCLUDE_OPENLRS */
744 #endif /* PIOS_INCLUDE_SPI */
746 #if defined(PIOS_INCLUDE_FLASH)
747 #include "pios_flashfs_logfs_priv.h"
748 #include "pios_flash_jedec_priv.h"
749 #include "pios_flash_internal_priv.h"
751 static const struct flashfs_logfs_cfg flashfs_external_user_cfg
= {
752 .fs_magic
= 0x99abceff,
753 .total_fs_size
= 0x001C0000, /* 2M bytes (32 sectors = entire chip) */
754 .arena_size
= 0x000E0000, /* biggest possible arena size fssize/2 */
755 .slot_size
= 0x00000100, /* 256 bytes */
757 .start_offset
= 0x00040000, /* start offset */
758 .sector_size
= 0x00010000, /* 64K bytes */
759 .page_size
= 0x00000100, /* 256 bytes */
762 static const struct flashfs_logfs_cfg flashfs_external_system_cfg
= {
763 .fs_magic
= 0x99bbcdef,
764 .total_fs_size
= 0x00040000, /* 2M bytes (32 sectors = entire chip) */
765 .arena_size
= 0x00010000, /* 256 * slot size */
766 .slot_size
= 0x00000100, /* 256 bytes */
768 .start_offset
= 0, /* start at the beginning of the chip */
769 .sector_size
= 0x00010000, /* 64K bytes */
770 .page_size
= 0x00000100, /* 256 bytes */
774 static const struct pios_flash_internal_cfg flash_internal_cfg
= {};
776 static const struct flashfs_logfs_cfg flashfs_internal_cfg
= {
777 .fs_magic
= 0x99abcfef,
778 .total_fs_size
= EE_BANK_SIZE
, /* 32K bytes (2x16KB sectors) */
779 .arena_size
= 0x00004000, /* 64 * slot size = 16K bytes = 1 sector */
780 .slot_size
= 0x00000100, /* 256 bytes */
782 .start_offset
= EE_BANK_BASE
, /* start after the bootloader */
783 .sector_size
= 0x00004000, /* 16K bytes */
784 .page_size
= 0x00004000, /* 16K bytes */
787 #endif /* PIOS_INCLUDE_FLASH */
789 #include <pios_usart_priv.h>
791 #ifdef PIOS_INCLUDE_COM_TELEM
796 static const struct pios_usart_cfg pios_usart_main_cfg
= {
798 .remap
= GPIO_AF_USART1
,
800 .USART_BaudRate
= 57600,
801 .USART_WordLength
= USART_WordLength_8b
,
802 .USART_Parity
= USART_Parity_No
,
803 .USART_StopBits
= USART_StopBits_1
,
804 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
805 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
809 .NVIC_IRQChannel
= USART1_IRQn
,
810 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
811 .NVIC_IRQChannelSubPriority
= 0,
812 .NVIC_IRQChannelCmd
= ENABLE
,
818 .GPIO_Pin
= GPIO_Pin_10
,
819 .GPIO_Speed
= GPIO_Speed_2MHz
,
820 .GPIO_Mode
= GPIO_Mode_AF
,
821 .GPIO_OType
= GPIO_OType_PP
,
822 .GPIO_PuPd
= GPIO_PuPd_UP
828 .GPIO_Pin
= GPIO_Pin_9
,
829 .GPIO_Speed
= GPIO_Speed_2MHz
,
830 .GPIO_Mode
= GPIO_Mode_AF
,
831 .GPIO_OType
= GPIO_OType_PP
,
832 .GPIO_PuPd
= GPIO_PuPd_UP
836 #endif /* PIOS_INCLUDE_COM_TELEM */
838 #ifdef PIOS_INCLUDE_DSM
840 #include "pios_dsm_priv.h"
841 static const struct pios_usart_cfg pios_usart_dsm_main_cfg
= {
843 .remap
= GPIO_AF_USART1
,
845 .USART_BaudRate
= 115200,
846 .USART_WordLength
= USART_WordLength_8b
,
847 .USART_Parity
= USART_Parity_No
,
848 .USART_StopBits
= USART_StopBits_1
,
849 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
850 .USART_Mode
= USART_Mode_Rx
,
854 .NVIC_IRQChannel
= USART1_IRQn
,
855 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
856 .NVIC_IRQChannelSubPriority
= 0,
857 .NVIC_IRQChannelCmd
= ENABLE
,
863 .GPIO_Pin
= GPIO_Pin_10
,
864 .GPIO_Speed
= GPIO_Speed_2MHz
,
865 .GPIO_Mode
= GPIO_Mode_AF
,
866 .GPIO_OType
= GPIO_OType_PP
,
867 .GPIO_PuPd
= GPIO_PuPd_UP
873 .GPIO_Pin
= GPIO_Pin_9
,
874 .GPIO_Speed
= GPIO_Speed_2MHz
,
875 .GPIO_Mode
= GPIO_Mode_AF
,
876 .GPIO_OType
= GPIO_OType_PP
,
877 .GPIO_PuPd
= GPIO_PuPd_UP
882 // Because of the inverter on the main port this will not
883 // work. Notice the mode is set to IN to maintain API
884 // compatibility but protect the pins
885 static const struct pios_dsm_cfg pios_dsm_main_cfg
= {
889 .GPIO_Pin
= GPIO_Pin_10
,
890 .GPIO_Speed
= GPIO_Speed_2MHz
,
891 .GPIO_Mode
= GPIO_Mode_IN
,
892 .GPIO_OType
= GPIO_OType_PP
,
893 .GPIO_PuPd
= GPIO_PuPd_NOPULL
898 #endif /* PIOS_INCLUDE_DSM */
900 #include <pios_sbus_priv.h>
901 #if defined(PIOS_INCLUDE_SBUS)
905 #include <pios_sbus_priv.h>
907 static const struct pios_usart_cfg pios_usart_sbus_main_cfg
= {
909 .remap
= GPIO_AF_USART1
,
911 .USART_BaudRate
= 100000,
912 .USART_WordLength
= USART_WordLength_8b
,
913 .USART_Parity
= USART_Parity_Even
,
914 .USART_StopBits
= USART_StopBits_2
,
915 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
916 .USART_Mode
= USART_Mode_Rx
,
920 .NVIC_IRQChannel
= USART1_IRQn
,
921 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
922 .NVIC_IRQChannelSubPriority
= 0,
923 .NVIC_IRQChannelCmd
= ENABLE
,
929 .GPIO_Pin
= GPIO_Pin_10
,
930 .GPIO_Speed
= GPIO_Speed_2MHz
,
931 .GPIO_Mode
= GPIO_Mode_AF
,
932 .GPIO_OType
= GPIO_OType_PP
,
933 .GPIO_PuPd
= GPIO_PuPd_UP
939 .GPIO_Pin
= GPIO_Pin_9
,
940 .GPIO_Speed
= GPIO_Speed_2MHz
,
941 .GPIO_Mode
= GPIO_Mode_OUT
,
942 .GPIO_OType
= GPIO_OType_PP
,
943 .GPIO_PuPd
= GPIO_PuPd_NOPULL
948 #endif /* PIOS_INCLUDE_SBUS */
950 // Need this defined regardless to be able to turn it off
951 static const struct pios_sbus_cfg pios_sbus_cfg
= {
952 /* Inverter configuration */
956 .GPIO_Pin
= GPIO_Pin_0
,
957 .GPIO_Speed
= GPIO_Speed_2MHz
,
958 .GPIO_Mode
= GPIO_Mode_OUT
,
959 .GPIO_OType
= GPIO_OType_PP
,
960 .GPIO_PuPd
= GPIO_PuPd_UP
963 .gpio_inv_enable
= Bit_SET
,
964 .gpio_inv_disable
= Bit_RESET
,
965 .gpio_clk_func
= RCC_AHB1PeriphClockCmd
,
966 .gpio_clk_periph
= RCC_AHB1Periph_GPIOC
,
969 #ifdef PIOS_INCLUDE_COM_FLEXI
973 static const struct pios_usart_cfg pios_usart_flexi_cfg
= {
975 .remap
= GPIO_AF_USART3
,
977 .USART_BaudRate
= 57600,
978 .USART_WordLength
= USART_WordLength_8b
,
979 .USART_Parity
= USART_Parity_No
,
980 .USART_StopBits
= USART_StopBits_1
,
981 .USART_HardwareFlowControl
=
982 USART_HardwareFlowControl_None
,
983 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
987 .NVIC_IRQChannel
= USART3_IRQn
,
988 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
989 .NVIC_IRQChannelSubPriority
= 0,
990 .NVIC_IRQChannelCmd
= ENABLE
,
996 .GPIO_Pin
= GPIO_Pin_11
,
997 .GPIO_Speed
= GPIO_Speed_2MHz
,
998 .GPIO_Mode
= GPIO_Mode_AF
,
999 .GPIO_OType
= GPIO_OType_PP
,
1000 .GPIO_PuPd
= GPIO_PuPd_UP
1006 .GPIO_Pin
= GPIO_Pin_10
,
1007 .GPIO_Speed
= GPIO_Speed_2MHz
,
1008 .GPIO_Mode
= GPIO_Mode_AF
,
1009 .GPIO_OType
= GPIO_OType_PP
,
1010 .GPIO_PuPd
= GPIO_PuPd_UP
1015 #endif /* PIOS_INCLUDE_COM_FLEXI */
1017 #ifdef PIOS_INCLUDE_DSM
1019 #include "pios_dsm_priv.h"
1020 static const struct pios_usart_cfg pios_usart_dsm_flexi_cfg
= {
1022 .remap
= GPIO_AF_USART3
,
1024 .USART_BaudRate
= 115200,
1025 .USART_WordLength
= USART_WordLength_8b
,
1026 .USART_Parity
= USART_Parity_No
,
1027 .USART_StopBits
= USART_StopBits_1
,
1028 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1029 .USART_Mode
= USART_Mode_Rx
,
1033 .NVIC_IRQChannel
= USART3_IRQn
,
1034 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1035 .NVIC_IRQChannelSubPriority
= 0,
1036 .NVIC_IRQChannelCmd
= ENABLE
,
1042 .GPIO_Pin
= GPIO_Pin_11
,
1043 .GPIO_Speed
= GPIO_Speed_2MHz
,
1044 .GPIO_Mode
= GPIO_Mode_AF
,
1045 .GPIO_OType
= GPIO_OType_PP
,
1046 .GPIO_PuPd
= GPIO_PuPd_UP
1052 .GPIO_Pin
= GPIO_Pin_10
,
1053 .GPIO_Speed
= GPIO_Speed_2MHz
,
1054 .GPIO_Mode
= GPIO_Mode_AF
,
1055 .GPIO_OType
= GPIO_OType_PP
,
1056 .GPIO_PuPd
= GPIO_PuPd_UP
1061 static const struct pios_dsm_cfg pios_dsm_flexi_cfg
= {
1065 .GPIO_Pin
= GPIO_Pin_11
,
1066 .GPIO_Speed
= GPIO_Speed_2MHz
,
1067 .GPIO_Mode
= GPIO_Mode_OUT
,
1068 .GPIO_OType
= GPIO_OType_PP
,
1069 .GPIO_PuPd
= GPIO_PuPd_NOPULL
1074 #endif /* PIOS_INCLUDE_DSM */
1076 #if defined(PIOS_INCLUDE_SRXL)
1080 #include <pios_srxl_priv.h>
1082 static const struct pios_usart_cfg pios_usart_srxl_flexi_cfg
= {
1084 .remap
= GPIO_AF_USART3
,
1086 .USART_BaudRate
= 115200,
1087 .USART_WordLength
= USART_WordLength_8b
,
1088 .USART_Parity
= USART_Parity_No
,
1089 .USART_StopBits
= USART_StopBits_1
,
1090 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1091 .USART_Mode
= USART_Mode_Rx
,
1095 .NVIC_IRQChannel
= USART3_IRQn
,
1096 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1097 .NVIC_IRQChannelSubPriority
= 0,
1098 .NVIC_IRQChannelCmd
= ENABLE
,
1104 .GPIO_Pin
= GPIO_Pin_11
,
1105 .GPIO_Speed
= GPIO_Speed_2MHz
,
1106 .GPIO_Mode
= GPIO_Mode_AF
,
1107 .GPIO_OType
= GPIO_OType_PP
,
1108 .GPIO_PuPd
= GPIO_PuPd_UP
1114 .GPIO_Pin
= GPIO_Pin_10
,
1115 .GPIO_Speed
= GPIO_Speed_2MHz
,
1116 .GPIO_Mode
= GPIO_Mode_OUT
,
1117 .GPIO_OType
= GPIO_OType_PP
,
1118 .GPIO_PuPd
= GPIO_PuPd_UP
1123 #endif /* PIOS_INCLUDE_SRXL */
1125 #if defined(PIOS_INCLUDE_HOTT)
1129 #include <pios_hott_priv.h>
1131 static const struct pios_usart_cfg pios_usart_hott_flexi_cfg
= {
1133 .remap
= GPIO_AF_USART3
,
1135 .USART_BaudRate
= 115200,
1136 .USART_WordLength
= USART_WordLength_8b
,
1137 .USART_Parity
= USART_Parity_No
,
1138 .USART_StopBits
= USART_StopBits_1
,
1139 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1140 .USART_Mode
= USART_Mode_Rx
,
1144 .NVIC_IRQChannel
= USART3_IRQn
,
1145 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1146 .NVIC_IRQChannelSubPriority
= 0,
1147 .NVIC_IRQChannelCmd
= ENABLE
,
1153 .GPIO_Pin
= GPIO_Pin_11
,
1154 .GPIO_Speed
= GPIO_Speed_2MHz
,
1155 .GPIO_Mode
= GPIO_Mode_AF
,
1156 .GPIO_OType
= GPIO_OType_PP
,
1157 .GPIO_PuPd
= GPIO_PuPd_UP
1163 .GPIO_Pin
= GPIO_Pin_10
,
1164 .GPIO_Speed
= GPIO_Speed_2MHz
,
1165 .GPIO_Mode
= GPIO_Mode_OUT
,
1166 .GPIO_OType
= GPIO_OType_PP
,
1167 .GPIO_PuPd
= GPIO_PuPd_UP
1172 #endif /* PIOS_INCLUDE_HOTT */
1174 #if defined(PIOS_INCLUDE_IBUS)
1178 #include <pios_ibus_priv.h>
1180 static const struct pios_usart_cfg pios_usart_ibus_flexi_cfg
= {
1182 .remap
= GPIO_AF_USART3
,
1184 .USART_BaudRate
= 115200,
1185 .USART_WordLength
= USART_WordLength_8b
,
1186 .USART_Parity
= USART_Parity_No
,
1187 .USART_StopBits
= USART_StopBits_1
,
1188 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1189 .USART_Mode
= USART_Mode_Rx
,
1193 .NVIC_IRQChannel
= USART3_IRQn
,
1194 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1195 .NVIC_IRQChannelSubPriority
= 0,
1196 .NVIC_IRQChannelCmd
= ENABLE
,
1202 .GPIO_Pin
= GPIO_Pin_11
,
1203 .GPIO_Speed
= GPIO_Speed_2MHz
,
1204 .GPIO_Mode
= GPIO_Mode_AF
,
1205 .GPIO_OType
= GPIO_OType_PP
,
1206 .GPIO_PuPd
= GPIO_PuPd_UP
1212 .GPIO_Pin
= GPIO_Pin_10
,
1213 .GPIO_Speed
= GPIO_Speed_2MHz
,
1214 .GPIO_Mode
= GPIO_Mode_OUT
,
1215 .GPIO_OType
= GPIO_OType_PP
,
1216 .GPIO_PuPd
= GPIO_PuPd_UP
1221 static const struct pios_usart_cfg pios_usart_ibus_rcvr_cfg
= {
1223 .remap
= GPIO_AF_USART6
,
1225 .USART_BaudRate
= 115200,
1226 .USART_WordLength
= USART_WordLength_8b
,
1227 .USART_Parity
= USART_Parity_No
,
1228 .USART_StopBits
= USART_StopBits_1
,
1229 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1230 .USART_Mode
= USART_Mode_Rx
,
1234 .NVIC_IRQChannel
= USART6_IRQn
,
1235 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1236 .NVIC_IRQChannelSubPriority
= 0,
1237 .NVIC_IRQChannelCmd
= ENABLE
,
1243 .GPIO_Pin
= GPIO_Pin_7
,
1244 .GPIO_Speed
= GPIO_Speed_2MHz
,
1245 .GPIO_Mode
= GPIO_Mode_AF
,
1246 .GPIO_OType
= GPIO_OType_PP
,
1247 .GPIO_PuPd
= GPIO_PuPd_UP
1252 #endif /* PIOS_INCLUDE_IBUS */
1254 #if defined(PIOS_INCLUDE_EXBUS)
1258 #include <pios_exbus_priv.h>
1260 static const struct pios_usart_cfg pios_usart_exbus_flexi_cfg
= {
1262 .remap
= GPIO_AF_USART3
,
1264 .USART_BaudRate
= 125000,
1265 .USART_WordLength
= USART_WordLength_8b
,
1266 .USART_Parity
= USART_Parity_No
,
1267 .USART_StopBits
= USART_StopBits_1
,
1268 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1269 .USART_Mode
= USART_Mode_Rx
,
1273 .NVIC_IRQChannel
= USART3_IRQn
,
1274 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1275 .NVIC_IRQChannelSubPriority
= 0,
1276 .NVIC_IRQChannelCmd
= ENABLE
,
1282 .GPIO_Pin
= GPIO_Pin_11
,
1283 .GPIO_Speed
= GPIO_Speed_2MHz
,
1284 .GPIO_Mode
= GPIO_Mode_AF
,
1285 .GPIO_OType
= GPIO_OType_PP
,
1286 .GPIO_PuPd
= GPIO_PuPd_UP
1292 .GPIO_Pin
= GPIO_Pin_10
,
1293 .GPIO_Speed
= GPIO_Speed_2MHz
,
1294 .GPIO_Mode
= GPIO_Mode_OUT
,
1295 .GPIO_OType
= GPIO_OType_PP
,
1296 .GPIO_PuPd
= GPIO_PuPd_UP
1301 #endif /* PIOS_INCLUDE_EXBUS */
1306 static const struct pios_usart_cfg pios_usart_hkosd_main_cfg
= {
1308 .remap
= GPIO_AF_USART1
,
1310 .USART_BaudRate
= 57600,
1311 .USART_WordLength
= USART_WordLength_8b
,
1312 .USART_Parity
= USART_Parity_No
,
1313 .USART_StopBits
= USART_StopBits_1
,
1314 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1315 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
1319 .NVIC_IRQChannel
= USART1_IRQn
,
1320 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1321 .NVIC_IRQChannelSubPriority
= 0,
1322 .NVIC_IRQChannelCmd
= ENABLE
,
1328 .GPIO_Pin
= GPIO_Pin_10
,
1329 .GPIO_Speed
= GPIO_Speed_2MHz
,
1330 .GPIO_Mode
= GPIO_Mode_AF
,
1331 .GPIO_OType
= GPIO_OType_PP
,
1332 .GPIO_PuPd
= GPIO_PuPd_UP
1338 .GPIO_Pin
= GPIO_Pin_9
,
1339 .GPIO_Speed
= GPIO_Speed_2MHz
,
1340 .GPIO_Mode
= GPIO_Mode_AF
,
1341 .GPIO_OType
= GPIO_OType_PP
,
1342 .GPIO_PuPd
= GPIO_PuPd_UP
1347 static const struct pios_usart_cfg pios_usart_hkosd_flexi_cfg
= {
1349 .remap
= GPIO_AF_USART3
,
1351 .USART_BaudRate
= 57600,
1352 .USART_WordLength
= USART_WordLength_8b
,
1353 .USART_Parity
= USART_Parity_No
,
1354 .USART_StopBits
= USART_StopBits_1
,
1355 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1356 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
1360 .NVIC_IRQChannel
= USART3_IRQn
,
1361 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1362 .NVIC_IRQChannelSubPriority
= 0,
1363 .NVIC_IRQChannelCmd
= ENABLE
,
1369 .GPIO_Pin
= GPIO_Pin_11
,
1370 .GPIO_Speed
= GPIO_Speed_2MHz
,
1371 .GPIO_Mode
= GPIO_Mode_AF
,
1372 .GPIO_OType
= GPIO_OType_PP
,
1373 .GPIO_PuPd
= GPIO_PuPd_UP
1379 .GPIO_Pin
= GPIO_Pin_10
,
1380 .GPIO_Speed
= GPIO_Speed_2MHz
,
1381 .GPIO_Mode
= GPIO_Mode_AF
,
1382 .GPIO_OType
= GPIO_OType_PP
,
1383 .GPIO_PuPd
= GPIO_PuPd_UP
1388 static const struct pios_usart_cfg pios_usart_rcvrport_cfg
= {
1390 .remap
= GPIO_AF_USART6
,
1392 .USART_BaudRate
= 57600,
1393 .USART_WordLength
= USART_WordLength_8b
,
1394 .USART_Parity
= USART_Parity_No
,
1395 .USART_StopBits
= USART_StopBits_1
,
1396 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1397 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
1401 .NVIC_IRQChannel
= USART6_IRQn
,
1402 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1403 .NVIC_IRQChannelSubPriority
= 0,
1404 .NVIC_IRQChannelCmd
= ENABLE
,
1412 .GPIO_Pin
= GPIO_Pin_8
,
1413 .GPIO_Speed
= GPIO_Speed_25MHz
,
1414 .GPIO_Mode
= GPIO_Mode_OUT
,
1415 .GPIO_OType
= GPIO_OType_PP
,
1420 // * 7: PC6 = TIM8 CH1, USART6 TX
1423 .GPIO_Pin
= GPIO_Pin_6
,
1424 .GPIO_Speed
= GPIO_Speed_2MHz
,
1425 .GPIO_Mode
= GPIO_Mode_AF
,
1426 .GPIO_OType
= GPIO_OType_PP
,
1427 .GPIO_PuPd
= GPIO_PuPd_UP
1429 .pin_source
= GPIO_PinSource6
,
1433 // * 8: PC7 = TIM8 CH2, USART6 RX
1436 .GPIO_Pin
= GPIO_Pin_7
,
1437 .GPIO_Speed
= GPIO_Speed_2MHz
,
1438 .GPIO_Mode
= GPIO_Mode_AF
,
1439 .GPIO_OType
= GPIO_OType_PP
,
1440 .GPIO_PuPd
= GPIO_PuPd_UP
1442 .pin_source
= GPIO_PinSource7
,
1446 #if defined(PIOS_INCLUDE_COM)
1448 #include <pios_com_priv.h>
1450 #endif /* PIOS_INCLUDE_COM */
1452 #if defined(PIOS_INCLUDE_I2C)
1454 #include <pios_i2c_priv.h>
1459 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void);
1460 void PIOS_I2C_mag_pressureadapter_er_irq_handler(void);
1461 void I2C1_EV_IRQHandler()
1462 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_ev_irq_handler")));
1463 void I2C1_ER_IRQHandler()
1464 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler")));
1466 static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg
= {
1468 .remapSCL
= GPIO_AF_I2C1
,
1469 .remapSDA
= GPIO_AF_I2C1
,
1471 .I2C_Mode
= I2C_Mode_I2C
,
1472 .I2C_OwnAddress1
= 0,
1473 .I2C_Ack
= I2C_Ack_Enable
,
1474 .I2C_AcknowledgedAddress
= I2C_AcknowledgedAddress_7bit
,
1475 .I2C_DutyCycle
= I2C_DutyCycle_2
,
1476 .I2C_ClockSpeed
= 400000, /* bits/s */
1478 .transfer_timeout_ms
= 50,
1482 .GPIO_Pin
= GPIO_Pin_8
,
1483 .GPIO_Mode
= GPIO_Mode_AF
,
1484 .GPIO_Speed
= GPIO_Speed_50MHz
,
1485 .GPIO_OType
= GPIO_OType_OD
,
1486 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
1492 .GPIO_Pin
= GPIO_Pin_9
,
1493 .GPIO_Mode
= GPIO_Mode_AF
,
1494 .GPIO_Speed
= GPIO_Speed_50MHz
,
1495 .GPIO_OType
= GPIO_OType_OD
,
1496 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
1500 .flags
= 0, /* FIXME: check this */
1502 .NVIC_IRQChannel
= I2C1_EV_IRQn
,
1503 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1504 .NVIC_IRQChannelSubPriority
= 0,
1505 .NVIC_IRQChannelCmd
= ENABLE
,
1509 .flags
= 0, /* FIXME: check this */
1511 .NVIC_IRQChannel
= I2C1_ER_IRQn
,
1512 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1513 .NVIC_IRQChannelSubPriority
= 0,
1514 .NVIC_IRQChannelCmd
= ENABLE
,
1519 uint32_t pios_i2c_mag_pressure_adapter_id
;
1520 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void)
1522 /* Call into the generic code to handle the IRQ for this specific device */
1523 PIOS_I2C_EV_IRQ_Handler(pios_i2c_mag_pressure_adapter_id
);
1526 void PIOS_I2C_mag_pressure_adapter_er_irq_handler(void)
1528 /* Call into the generic code to handle the IRQ for this specific device */
1529 PIOS_I2C_ER_IRQ_Handler(pios_i2c_mag_pressure_adapter_id
);
1533 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void);
1534 void PIOS_I2C_flexiport_adapter_er_irq_handler(void);
1535 void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_irq_handler")));
1536 void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler")));
1538 static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg
= {
1540 .remapSCL
= GPIO_AF_I2C2
,
1541 .remapSDA
= GPIO_AF_I2C2
,
1543 .I2C_Mode
= I2C_Mode_I2C
,
1544 .I2C_OwnAddress1
= 0,
1545 .I2C_Ack
= I2C_Ack_Enable
,
1546 .I2C_AcknowledgedAddress
= I2C_AcknowledgedAddress_7bit
,
1547 .I2C_DutyCycle
= I2C_DutyCycle_2
,
1548 .I2C_ClockSpeed
= 400000, /* bits/s */
1550 .transfer_timeout_ms
= 50,
1554 .GPIO_Pin
= GPIO_Pin_10
,
1555 .GPIO_Mode
= GPIO_Mode_AF
,
1556 .GPIO_Speed
= GPIO_Speed_50MHz
,
1557 .GPIO_OType
= GPIO_OType_OD
,
1558 .GPIO_PuPd
= GPIO_PuPd_UP
,
1564 .GPIO_Pin
= GPIO_Pin_11
,
1565 .GPIO_Mode
= GPIO_Mode_AF
,
1566 .GPIO_Speed
= GPIO_Speed_50MHz
,
1567 .GPIO_OType
= GPIO_OType_OD
,
1568 .GPIO_PuPd
= GPIO_PuPd_UP
,
1572 .flags
= 0, /* FIXME: check this */
1574 .NVIC_IRQChannel
= I2C2_EV_IRQn
,
1575 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1576 .NVIC_IRQChannelSubPriority
= 0,
1577 .NVIC_IRQChannelCmd
= ENABLE
,
1581 .flags
= 0, /* FIXME: check this */
1583 .NVIC_IRQChannel
= I2C2_ER_IRQn
,
1584 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1585 .NVIC_IRQChannelSubPriority
= 0,
1586 .NVIC_IRQChannelCmd
= ENABLE
,
1591 uint32_t pios_i2c_flexiport_adapter_id
;
1592 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void)
1594 /* Call into the generic code to handle the IRQ for this specific device */
1595 PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexiport_adapter_id
);
1598 void PIOS_I2C_flexiport_adapter_er_irq_handler(void)
1600 /* Call into the generic code to handle the IRQ for this specific device */
1601 PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexiport_adapter_id
);
1605 void PIOS_I2C_pressure_adapter_ev_irq_handler(void);
1606 void PIOS_I2C_pressure_adapter_er_irq_handler(void);
1608 #endif /* PIOS_INCLUDE_I2C */
1610 #if defined(PIOS_INCLUDE_RTC)
1612 * Realtime Clock (RTC)
1614 #include <pios_rtc_priv.h>
1616 void PIOS_RTC_IRQ_Handler(void);
1617 void RTC_WKUP_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
1618 static const struct pios_rtc_cfg pios_rtc_main_cfg
= {
1619 .clksrc
= RCC_RTCCLKSource_HSE_Div8
, // Divide 8 Mhz crystal down to 1
1620 // For some reason it's acting like crystal is 16 Mhz. This clock is then divided
1621 // by another 16 to give a nominal 62.5 khz clock
1622 .prescaler
= 100, // Every 100 cycles gives 625 Hz
1625 .NVIC_IRQChannel
= RTC_WKUP_IRQn
,
1626 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1627 .NVIC_IRQChannelSubPriority
= 0,
1628 .NVIC_IRQChannelCmd
= ENABLE
,
1633 void PIOS_RTC_IRQ_Handler(void)
1635 PIOS_RTC_irq_handler();
1638 #endif /* if defined(PIOS_INCLUDE_RTC) */
1640 #include "pios_tim_priv.h"
1642 static const TIM_TimeBaseInitTypeDef tim_3_5_time_base
= {
1643 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB1_CLOCK
/ 1000000) - 1,
1644 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1645 .TIM_CounterMode
= TIM_CounterMode_Up
,
1646 .TIM_Period
= ((1000000 / PIOS_SERVO_UPDATE_HZ
) - 1),
1647 .TIM_RepetitionCounter
= 0x0000,
1649 static const TIM_TimeBaseInitTypeDef tim_9_10_11_time_base
= {
1650 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB2_CLOCK
/ 1000000) - 1,
1651 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1652 .TIM_CounterMode
= TIM_CounterMode_Up
,
1653 .TIM_Period
= ((1000000 / PIOS_SERVO_UPDATE_HZ
) - 1),
1654 .TIM_RepetitionCounter
= 0x0000,
1657 static const struct pios_tim_clock_cfg tim_3_cfg
= {
1659 .time_base_init
= &tim_3_5_time_base
,
1662 .NVIC_IRQChannel
= TIM3_IRQn
,
1663 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1664 .NVIC_IRQChannelSubPriority
= 0,
1665 .NVIC_IRQChannelCmd
= ENABLE
,
1670 static const struct pios_tim_clock_cfg tim_5_cfg
= {
1672 .time_base_init
= &tim_3_5_time_base
,
1675 .NVIC_IRQChannel
= TIM5_IRQn
,
1676 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1677 .NVIC_IRQChannelSubPriority
= 0,
1678 .NVIC_IRQChannelCmd
= ENABLE
,
1683 static const struct pios_tim_clock_cfg tim_9_cfg
= {
1685 .time_base_init
= &tim_9_10_11_time_base
,
1688 .NVIC_IRQChannel
= TIM1_BRK_TIM9_IRQn
,
1689 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1690 .NVIC_IRQChannelSubPriority
= 0,
1691 .NVIC_IRQChannelCmd
= ENABLE
,
1696 static const struct pios_tim_clock_cfg tim_10_cfg
= {
1698 .time_base_init
= &tim_9_10_11_time_base
,
1701 .NVIC_IRQChannel
= TIM1_UP_TIM10_IRQn
,
1702 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1703 .NVIC_IRQChannelSubPriority
= 0,
1704 .NVIC_IRQChannelCmd
= ENABLE
,
1709 static const struct pios_tim_clock_cfg tim_11_cfg
= {
1711 .time_base_init
= &tim_9_10_11_time_base
,
1714 .NVIC_IRQChannel
= TIM1_TRG_COM_TIM11_IRQn
,
1715 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1716 .NVIC_IRQChannelSubPriority
= 0,
1717 .NVIC_IRQChannelCmd
= ENABLE
,
1722 // Set up timers that only have inputs on APB1
1723 // TIM2,3,4,5,6,7,12,13,14
1724 static const TIM_TimeBaseInitTypeDef tim_apb1_time_base
= {
1725 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB1_CLOCK
/ 1000000) - 1,
1726 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1727 .TIM_CounterMode
= TIM_CounterMode_Up
,
1728 .TIM_Period
= 0xFFFF,
1729 .TIM_RepetitionCounter
= 0x0000,
1733 // Set up timers that only have inputs on APB2
1735 static const TIM_TimeBaseInitTypeDef tim_apb2_time_base
= {
1736 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB2_CLOCK
/ 1000000) - 1,
1737 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1738 .TIM_CounterMode
= TIM_CounterMode_Up
,
1739 .TIM_Period
= 0xFFFF,
1740 .TIM_RepetitionCounter
= 0x0000,
1743 static const struct pios_tim_clock_cfg tim_1_cfg
= {
1745 .time_base_init
= &tim_apb2_time_base
,
1748 .NVIC_IRQChannel
= TIM1_CC_IRQn
,
1749 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1750 .NVIC_IRQChannelSubPriority
= 0,
1751 .NVIC_IRQChannelCmd
= ENABLE
,
1756 static const struct pios_tim_clock_cfg tim_4_cfg
= {
1758 .time_base_init
= &tim_apb1_time_base
,
1761 .NVIC_IRQChannel
= TIM4_IRQn
,
1762 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1763 .NVIC_IRQChannelSubPriority
= 0,
1764 .NVIC_IRQChannelCmd
= ENABLE
,
1768 static const struct pios_tim_clock_cfg tim_8_cfg
= {
1770 .time_base_init
= &tim_apb2_time_base
,
1773 .NVIC_IRQChannel
= TIM8_CC_IRQn
,
1774 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1775 .NVIC_IRQChannelSubPriority
= 0,
1776 .NVIC_IRQChannelCmd
= ENABLE
,
1781 static const struct pios_tim_clock_cfg tim_12_cfg
= {
1783 .time_base_init
= &tim_apb1_time_base
,
1786 .NVIC_IRQChannel
= TIM8_BRK_TIM12_IRQn
,
1787 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1788 .NVIC_IRQChannelSubPriority
= 0,
1789 .NVIC_IRQChannelCmd
= ENABLE
,
1796 * Pios servo configuration structures
1797 * Using TIM3, TIM9, TIM2, TIM5
1799 #include <pios_servo_priv.h>
1800 static const struct pios_tim_channel pios_tim_servoport_all_pins
[] = {
1803 .timer_chan
= TIM_Channel_3
,
1807 .GPIO_Pin
= GPIO_Pin_0
,
1808 .GPIO_Speed
= GPIO_Speed_2MHz
,
1809 .GPIO_Mode
= GPIO_Mode_AF
,
1810 .GPIO_OType
= GPIO_OType_PP
,
1811 .GPIO_PuPd
= GPIO_PuPd_UP
1813 .pin_source
= GPIO_PinSource0
,
1815 .remap
= GPIO_AF_TIM3
,
1819 .timer_chan
= TIM_Channel_4
,
1823 .GPIO_Pin
= GPIO_Pin_1
,
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_PinSource1
,
1831 .remap
= GPIO_AF_TIM3
,
1835 .timer_chan
= TIM_Channel_2
,
1839 .GPIO_Pin
= GPIO_Pin_3
,
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_PinSource3
,
1847 .remap
= GPIO_AF_TIM9
,
1851 .timer_chan
= TIM_Channel_3
,
1855 .GPIO_Pin
= GPIO_Pin_2
,
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_PinSource2
,
1863 .remap
= GPIO_AF_TIM2
,
1867 .timer_chan
= TIM_Channel_2
,
1871 .GPIO_Pin
= GPIO_Pin_1
,
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_PinSource1
,
1879 .remap
= GPIO_AF_TIM5
,
1883 .timer_chan
= TIM_Channel_1
,
1887 .GPIO_Pin
= GPIO_Pin_0
,
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_PinSource0
,
1895 .remap
= GPIO_AF_TIM5
,
1897 // PWM pins on FlexiIO(receiver) port
1899 // * 6: PB15 = SPI2 MOSI, TIM12 CH2
1902 .timer_chan
= TIM_Channel_2
,
1906 .GPIO_Pin
= GPIO_Pin_15
,
1907 .GPIO_Speed
= GPIO_Speed_2MHz
,
1908 .GPIO_Mode
= GPIO_Mode_AF
,
1909 .GPIO_OType
= GPIO_OType_PP
,
1910 .GPIO_PuPd
= GPIO_PuPd_UP
1912 .pin_source
= GPIO_PinSource15
,
1914 .remap
= GPIO_AF_TIM12
,
1917 // * 7: PC6 = TIM8 CH1, USART6 TX
1919 .timer_chan
= TIM_Channel_1
,
1923 .GPIO_Pin
= GPIO_Pin_6
,
1924 .GPIO_Speed
= GPIO_Speed_2MHz
,
1925 .GPIO_Mode
= GPIO_Mode_AF
,
1926 .GPIO_OType
= GPIO_OType_PP
,
1927 .GPIO_PuPd
= GPIO_PuPd_UP
1929 .pin_source
= GPIO_PinSource6
,
1931 .remap
= GPIO_AF_TIM8
,
1935 // * 8: PC7 = TIM8 CH2, USART6 RX
1937 .timer_chan
= TIM_Channel_2
,
1941 .GPIO_Pin
= GPIO_Pin_7
,
1942 .GPIO_Speed
= GPIO_Speed_2MHz
,
1943 .GPIO_Mode
= GPIO_Mode_AF
,
1944 .GPIO_OType
= GPIO_OType_PP
,
1945 .GPIO_PuPd
= GPIO_PuPd_UP
1947 .pin_source
= GPIO_PinSource7
,
1949 .remap
= GPIO_AF_TIM8
,
1953 // * 9: PC8 = TIM8 CH3
1955 .timer_chan
= TIM_Channel_3
,
1959 .GPIO_Pin
= GPIO_Pin_8
,
1960 .GPIO_Speed
= GPIO_Speed_2MHz
,
1961 .GPIO_Mode
= GPIO_Mode_AF
,
1962 .GPIO_OType
= GPIO_OType_PP
,
1963 .GPIO_PuPd
= GPIO_PuPd_UP
1965 .pin_source
= GPIO_PinSource8
,
1967 .remap
= GPIO_AF_TIM8
,
1971 // * 10: PC9 = TIM8 CH4
1973 .timer_chan
= TIM_Channel_4
,
1977 .GPIO_Pin
= GPIO_Pin_9
,
1978 .GPIO_Speed
= GPIO_Speed_2MHz
,
1979 .GPIO_Mode
= GPIO_Mode_AF
,
1980 .GPIO_OType
= GPIO_OType_PP
,
1981 .GPIO_PuPd
= GPIO_PuPd_UP
1983 .pin_source
= GPIO_PinSource9
,
1985 .remap
= GPIO_AF_TIM8
,
1989 // * 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
1991 .timer_chan
= TIM_Channel_1
,
1995 .GPIO_Pin
= GPIO_Pin_14
,
1996 .GPIO_Speed
= GPIO_Speed_2MHz
,
1997 .GPIO_Mode
= GPIO_Mode_AF
,
1998 .GPIO_OType
= GPIO_OType_PP
,
1999 .GPIO_PuPd
= GPIO_PuPd_UP
2001 .pin_source
= GPIO_PinSource14
,
2003 .remap
= GPIO_AF_TIM12
,
2006 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT 6
2007 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM 11
2008 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN 12
2010 const struct pios_servo_cfg pios_servo_cfg_out
= {
2012 .TIM_OCMode
= TIM_OCMode_PWM1
,
2013 .TIM_OutputState
= TIM_OutputState_Enable
,
2014 .TIM_OutputNState
= TIM_OutputNState_Disable
,
2015 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
2016 .TIM_OCPolarity
= TIM_OCPolarity_High
,
2017 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
2018 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
2019 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
2021 .channels
= pios_tim_servoport_all_pins
,
2022 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT
,
2024 // All servo outputs, servo input ch1 ppm, ch2-6 outputs
2025 const struct pios_servo_cfg pios_servo_cfg_out_in_ppm
= {
2027 .TIM_OCMode
= TIM_OCMode_PWM1
,
2028 .TIM_OutputState
= TIM_OutputState_Enable
,
2029 .TIM_OutputNState
= TIM_OutputNState_Disable
,
2030 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
2031 .TIM_OCPolarity
= TIM_OCPolarity_High
,
2032 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
2033 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
2034 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
2036 .channels
= pios_tim_servoport_all_pins
,
2037 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM
,
2039 // All servo outputs, servo inputs ch1-6 Outputs
2040 const struct pios_servo_cfg pios_servo_cfg_out_in
= {
2042 .TIM_OCMode
= TIM_OCMode_PWM1
,
2043 .TIM_OutputState
= TIM_OutputState_Enable
,
2044 .TIM_OutputNState
= TIM_OutputNState_Disable
,
2045 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
2046 .TIM_OCPolarity
= TIM_OCPolarity_High
,
2047 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
2048 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
2049 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
2051 .channels
= pios_tim_servoport_all_pins
,
2052 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN
,
2060 #if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM)
2061 #include <pios_pwm_priv.h>
2062 static const struct pios_tim_channel pios_tim_rcvrport_all_channels
[] = {
2065 .timer_chan
= TIM_Channel_1
,
2069 .GPIO_Pin
= GPIO_Pin_14
,
2070 .GPIO_Speed
= GPIO_Speed_2MHz
,
2071 .GPIO_Mode
= GPIO_Mode_AF
,
2072 .GPIO_OType
= GPIO_OType_PP
,
2073 .GPIO_PuPd
= GPIO_PuPd_UP
2075 .pin_source
= GPIO_PinSource14
,
2077 .remap
= GPIO_AF_TIM12
,
2081 .timer_chan
= TIM_Channel_2
,
2085 .GPIO_Pin
= GPIO_Pin_15
,
2086 .GPIO_Speed
= GPIO_Speed_2MHz
,
2087 .GPIO_Mode
= GPIO_Mode_AF
,
2088 .GPIO_OType
= GPIO_OType_PP
,
2089 .GPIO_PuPd
= GPIO_PuPd_UP
2091 .pin_source
= GPIO_PinSource15
,
2093 .remap
= GPIO_AF_TIM12
,
2097 .timer_chan
= TIM_Channel_1
,
2101 .GPIO_Pin
= GPIO_Pin_6
,
2102 .GPIO_Speed
= GPIO_Speed_2MHz
,
2103 .GPIO_Mode
= GPIO_Mode_AF
,
2104 .GPIO_OType
= GPIO_OType_PP
,
2105 .GPIO_PuPd
= GPIO_PuPd_UP
2107 .pin_source
= GPIO_PinSource6
,
2109 .remap
= GPIO_AF_TIM8
,
2113 .timer_chan
= TIM_Channel_2
,
2117 .GPIO_Pin
= GPIO_Pin_7
,
2118 .GPIO_Speed
= GPIO_Speed_2MHz
,
2119 .GPIO_Mode
= GPIO_Mode_AF
,
2120 .GPIO_OType
= GPIO_OType_PP
,
2121 .GPIO_PuPd
= GPIO_PuPd_UP
2123 .pin_source
= GPIO_PinSource7
,
2125 .remap
= GPIO_AF_TIM8
,
2129 .timer_chan
= TIM_Channel_3
,
2133 .GPIO_Pin
= GPIO_Pin_8
,
2134 .GPIO_Speed
= GPIO_Speed_2MHz
,
2135 .GPIO_Mode
= GPIO_Mode_AF
,
2136 .GPIO_OType
= GPIO_OType_PP
,
2137 .GPIO_PuPd
= GPIO_PuPd_UP
2139 .pin_source
= GPIO_PinSource8
,
2141 .remap
= GPIO_AF_TIM8
,
2145 .timer_chan
= TIM_Channel_4
,
2149 .GPIO_Pin
= GPIO_Pin_9
,
2150 .GPIO_Speed
= GPIO_Speed_2MHz
,
2151 .GPIO_Mode
= GPIO_Mode_AF
,
2152 .GPIO_OType
= GPIO_OType_PP
,
2153 .GPIO_PuPd
= GPIO_PuPd_UP
2155 .pin_source
= GPIO_PinSource9
,
2157 .remap
= GPIO_AF_TIM8
,
2161 const struct pios_pwm_cfg pios_pwm_cfg
= {
2163 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
2164 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
2165 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
2166 .TIM_ICFilter
= 0x0,
2168 .channels
= pios_tim_rcvrport_all_channels
,
2169 .num_channels
= NELEMENTS(pios_tim_rcvrport_all_channels
),
2171 // this configures outputs 2-6 as pwm inputs
2172 const struct pios_pwm_cfg pios_pwm_ppm_cfg
= {
2174 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
2175 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
2176 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
2177 .TIM_ICFilter
= 0x0,
2179 .channels
= &pios_tim_rcvrport_all_channels
[1],
2180 .num_channels
= NELEMENTS(pios_tim_rcvrport_all_channels
) - 1,
2183 #endif /* if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM) */
2188 #if defined(PIOS_INCLUDE_PPM)
2189 #include <pios_ppm_priv.h>
2190 static const struct pios_ppm_cfg pios_ppm_cfg
= {
2192 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
2193 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
2194 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
2195 .TIM_ICFilter
= 0x0,
2196 .TIM_Channel
= TIM_Channel_1
,
2198 /* Use only the first channel for ppm */
2199 .channels
= &pios_tim_rcvrport_all_channels
[0],
2205 #if defined(PIOS_INCLUDE_GCSRCVR)
2206 #include "pios_gcsrcvr_priv.h"
2207 #endif /* PIOS_INCLUDE_GCSRCVR */
2209 #if defined(PIOS_INCLUDE_RCVR)
2210 #include "pios_rcvr_priv.h"
2211 #endif /* PIOS_INCLUDE_RCVR */
2213 #if defined(PIOS_INCLUDE_USB)
2214 #include "pios_usb_priv.h"
2216 static const struct pios_usb_cfg pios_usb_main_rm1_cfg
= {
2219 .NVIC_IRQChannel
= OTG_FS_IRQn
,
2220 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
2221 .NVIC_IRQChannelSubPriority
= 0, // PriorityGroup=4
2222 .NVIC_IRQChannelCmd
= ENABLE
,
2228 .GPIO_Pin
= GPIO_Pin_13
,
2229 .GPIO_Speed
= GPIO_Speed_25MHz
,
2230 .GPIO_Mode
= GPIO_Mode_IN
,
2231 .GPIO_OType
= GPIO_OType_OD
,
2234 .vsense_active_low
= false
2237 static const struct pios_usb_cfg pios_usb_main_rm2_cfg
= {
2240 .NVIC_IRQChannel
= OTG_FS_IRQn
,
2241 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
2242 .NVIC_IRQChannelSubPriority
= 0, // PriorityGroup=4
2243 .NVIC_IRQChannelCmd
= ENABLE
,
2249 .GPIO_Pin
= GPIO_Pin_5
,
2250 .GPIO_Speed
= GPIO_Speed_25MHz
,
2251 .GPIO_Mode
= GPIO_Mode_IN
,
2252 .GPIO_OType
= GPIO_OType_OD
,
2255 .vsense_active_low
= false
2258 const struct pios_usb_cfg
*PIOS_BOARD_HW_DEFS_GetUsbCfg(uint32_t board_revision
)
2260 switch (board_revision
) {
2262 return &pios_usb_main_rm1_cfg
;
2266 return &pios_usb_main_rm2_cfg
;
2270 PIOS_DEBUG_Assert(0);
2275 #include "pios_usb_board_data_priv.h"
2276 #include "pios_usb_desc_hid_cdc_priv.h"
2277 #include "pios_usb_desc_hid_only_priv.h"
2278 #include "pios_usbhook.h"
2280 #endif /* PIOS_INCLUDE_USB */
2282 #if defined(PIOS_INCLUDE_COM_MSG)
2284 #include <pios_com_msg_priv.h>
2286 #endif /* PIOS_INCLUDE_COM_MSG */
2288 #if defined(PIOS_INCLUDE_USB_HID) && !defined(PIOS_INCLUDE_USB_CDC)
2289 #include <pios_usb_hid_priv.h>
2291 const struct pios_usb_hid_cfg pios_usb_hid_cfg
= {
2296 #endif /* PIOS_INCLUDE_USB_HID && !PIOS_INCLUDE_USB_CDC */
2298 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_USB_CDC)
2299 #include <pios_usb_cdc_priv.h>
2301 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg
= {
2310 #include <pios_usb_hid_priv.h>
2312 const struct pios_usb_hid_cfg pios_usb_hid_cfg
= {
2317 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
2319 #ifdef PIOS_INCLUDE_WS2811
2320 #include <pios_ws2811_cfg.h>
2321 #include <hwsettings.h>
2322 #define PIOS_WS2811_TIM_DIVIDER (PIOS_PERIPHERAL_APB2_CLOCK / (800000 * PIOS_WS2811_TIM_PERIOD))
2324 void DMA2_Stream1_IRQHandler(void) __attribute__((alias("PIOS_WS2811_irq_handler")));
2325 // list of pin configurable as ws281x outputs.
2326 // this will not clash with PWM in or servo output as
2327 // pins will be reconfigured as _OUT so the alternate function is disabled.
2328 const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg
[] = {
2329 [HWSETTINGS_WS2811LED_OUT_SERVOOUT1
] = {
2332 .GPIO_Pin
= GPIO_Pin_0
,
2333 .GPIO_Speed
= GPIO_Speed_25MHz
,
2334 .GPIO_Mode
= GPIO_Mode_OUT
,
2335 .GPIO_OType
= GPIO_OType_PP
,
2338 [HWSETTINGS_WS2811LED_OUT_SERVOOUT2
] = {
2341 .GPIO_Pin
= GPIO_Pin_1
,
2342 .GPIO_Speed
= GPIO_Speed_25MHz
,
2343 .GPIO_Mode
= GPIO_Mode_OUT
,
2344 .GPIO_OType
= GPIO_OType_PP
,
2347 [HWSETTINGS_WS2811LED_OUT_SERVOOUT3
] = {
2350 .GPIO_Pin
= GPIO_Pin_3
,
2351 .GPIO_Speed
= GPIO_Speed_25MHz
,
2352 .GPIO_Mode
= GPIO_Mode_OUT
,
2353 .GPIO_OType
= GPIO_OType_PP
,
2356 [HWSETTINGS_WS2811LED_OUT_SERVOOUT4
] = {
2359 .GPIO_Pin
= GPIO_Pin_2
,
2360 .GPIO_Speed
= GPIO_Speed_25MHz
,
2361 .GPIO_Mode
= GPIO_Mode_OUT
,
2362 .GPIO_OType
= GPIO_OType_PP
,
2365 [HWSETTINGS_WS2811LED_OUT_SERVOOUT5
] = {
2368 .GPIO_Pin
= GPIO_Pin_1
,
2369 .GPIO_Speed
= GPIO_Speed_25MHz
,
2370 .GPIO_Mode
= GPIO_Mode_OUT
,
2371 .GPIO_OType
= GPIO_OType_PP
,
2374 [HWSETTINGS_WS2811LED_OUT_SERVOOUT6
] = {
2377 .GPIO_Pin
= GPIO_Pin_0
,
2378 .GPIO_Speed
= GPIO_Speed_25MHz
,
2379 .GPIO_Mode
= GPIO_Mode_OUT
,
2380 .GPIO_OType
= GPIO_OType_PP
,
2383 [HWSETTINGS_WS2811LED_OUT_FLEXIIOPIN3
] = {
2386 .GPIO_Pin
= GPIO_Pin_12
,
2387 .GPIO_Speed
= GPIO_Speed_25MHz
,
2388 .GPIO_Mode
= GPIO_Mode_OUT
,
2389 .GPIO_OType
= GPIO_OType_PP
,
2392 [HWSETTINGS_WS2811LED_OUT_FLEXIIOPIN4
] = {
2395 .GPIO_Pin
= GPIO_Pin_13
,
2396 .GPIO_Speed
= GPIO_Speed_25MHz
,
2397 .GPIO_Mode
= GPIO_Mode_OUT
,
2398 .GPIO_OType
= GPIO_OType_PP
,
2403 const struct pios_ws2811_cfg pios_ws2811_cfg
= {
2406 .TIM_Prescaler
= PIOS_WS2811_TIM_DIVIDER
- 1,
2407 .TIM_ClockDivision
= TIM_CKD_DIV1
,
2408 .TIM_CounterMode
= TIM_CounterMode_Up
,
2409 // period (1.25 uS per period
2410 .TIM_Period
= PIOS_WS2811_TIM_PERIOD
,
2411 .TIM_RepetitionCounter
= 0x0000,
2415 .streamCh1
= DMA2_Stream1
,
2417 .streamCh2
= DMA2_Stream6
,
2418 .streamUpdate
= DMA2_Stream5
,
2420 // DMA streamCh1, triggered by timerCh1 pwm signal.
2421 // if FrameBuffer indicates, reset output value early to indicate "0" bit to ws2812
2422 .dmaInitCh1
= PIOS_WS2811_DMA_CH1_CONFIG(DMA_Channel_6
),
2423 .dmaItCh1
= DMA_IT_TEIF1
| DMA_IT_TCIF1
,
2425 // DMA streamCh2, triggered by timerCh2 pwm signal.
2426 // Reset output value late to indicate "1" bit to ws2812.
2427 .dmaInitCh2
= PIOS_WS2811_DMA_CH2_CONFIG(DMA_Channel_6
),
2428 .dmaItCh2
= DMA_IT_TEIF6
| DMA_IT_TCIF6
,
2430 // DMA streamUpdate Triggered by timer update event
2431 // Outputs a high logic level at beginning of a cycle
2432 .dmaInitUpdate
= PIOS_WS2811_DMA_UPDATE_CONFIG(DMA_Channel_6
),
2433 .dmaItUpdate
= DMA_IT_TEIF5
| DMA_IT_TCIF5
,
2434 .dmaSource
= TIM_DMA_CC1
| TIM_DMA_CC3
| TIM_DMA_Update
,
2436 // DMAInitCh1 interrupt vector, used to block timer at end of framebuffer transfer
2438 .flags
= (DMA_IT_TCIF1
),
2440 .NVIC_IRQChannel
= DMA2_Stream1_IRQn
,
2441 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
2442 .NVIC_IRQChannelSubPriority
= 0,
2443 .NVIC_IRQChannelCmd
= ENABLE
,
2448 void PIOS_WS2811_irq_handler(void)
2450 PIOS_WS2811_DMA_irq_handler();
2452 #endif // PIOS_INCLUDE_WS2811