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
8 * @addtogroup OpenPilotCore OpenPilot Core
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
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
] = {
36 .GPIO_Pin
= GPIO_Pin_15
,
37 .GPIO_Speed
= GPIO_Speed_50MHz
,
38 .GPIO_Mode
= GPIO_Mode_OUT
,
39 .GPIO_OType
= GPIO_OType_PP
,
40 .GPIO_PuPd
= GPIO_PuPd_UP
49 .GPIO_Pin
= GPIO_Pin_14
,
50 .GPIO_Speed
= GPIO_Speed_50MHz
,
51 .GPIO_Mode
= GPIO_Mode_OUT
,
52 .GPIO_OType
= GPIO_OType_PP
,
53 .GPIO_PuPd
= GPIO_PuPd_UP
62 .GPIO_Pin
= GPIO_Pin_13
,
63 .GPIO_Speed
= GPIO_Speed_50MHz
,
64 .GPIO_Mode
= GPIO_Mode_OUT
,
65 .GPIO_OType
= GPIO_OType_PP
,
66 .GPIO_PuPd
= GPIO_PuPd_UP
75 .GPIO_Pin
= GPIO_Pin_12
,
76 .GPIO_Speed
= GPIO_Speed_50MHz
,
77 .GPIO_Mode
= GPIO_Mode_OUT
,
78 .GPIO_OType
= GPIO_OType_PP
,
79 .GPIO_PuPd
= GPIO_PuPd_UP
86 static const struct pios_gpio_cfg pios_led_cfg
= {
88 .num_gpios
= NELEMENTS(pios_leds
),
92 const struct pios_gpio_cfg
*PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused
)) uint32_t board_revision
)
97 #endif /* PIOS_INCLUDE_LED */
99 #if defined(PIOS_INCLUDE_SPI)
100 #include <pios_spi_priv.h>
102 #if defined(PIOS_OVERO_SPI)
104 * - Used for Flexi/IO/Overo communications
105 3: PB12 = SPI2 NSS, CAN2 RX
106 4: PB13 = SPI2 SCK, CAN2 TX, USART3 CTS
107 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
108 6: PB15 = SPI2 MOSI, TIM12 CH2
110 #include <pios_overo_priv.h>
111 void PIOS_OVERO_irq_handler(void);
112 void DMA1_Stream7_IRQHandler(void) __attribute__((alias("PIOS_OVERO_irq_handler")));
113 static const struct pios_overo_cfg pios_overo_cfg
= {
115 .remap
= GPIO_AF_SPI2
,
117 .SPI_Mode
= SPI_Mode_Slave
,
118 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
119 .SPI_DataSize
= SPI_DataSize_8b
,
120 .SPI_NSS
= SPI_NSS_Hard
,
121 .SPI_FirstBit
= SPI_FirstBit_MSB
,
122 .SPI_CRCPolynomial
= 7,
123 .SPI_CPOL
= SPI_CPOL_High
,
124 .SPI_CPHA
= SPI_CPHA_2Edge
,
125 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_2
,
130 // Note this is the stream ID that triggers interrupts (in this case TX)
131 .flags
= (DMA_IT_TCIF7
),
133 .NVIC_IRQChannel
= DMA1_Stream7_IRQn
,
134 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
135 .NVIC_IRQChannelSubPriority
= 0,
136 .NVIC_IRQChannelCmd
= ENABLE
,
141 .channel
= DMA1_Stream0
,
143 .DMA_Channel
= DMA_Channel_0
,
144 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI2
->DR
),
145 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
146 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
147 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
148 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
149 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
150 .DMA_Mode
= DMA_Mode_Circular
,
151 .DMA_Priority
= DMA_Priority_Medium
,
153 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
154 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
155 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
156 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
160 .channel
= DMA1_Stream7
,
162 .DMA_Channel
= DMA_Channel_0
,
163 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI2
->DR
),
164 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
165 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
166 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
167 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
168 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
169 .DMA_Mode
= DMA_Mode_Circular
,
170 .DMA_Priority
= DMA_Priority_Medium
,
171 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
172 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
173 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
174 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
181 .GPIO_Pin
= GPIO_Pin_13
,
182 .GPIO_Speed
= GPIO_Speed_100MHz
,
183 .GPIO_Mode
= GPIO_Mode_AF
,
184 .GPIO_OType
= GPIO_OType_PP
,
185 .GPIO_PuPd
= GPIO_PuPd_NOPULL
191 .GPIO_Pin
= GPIO_Pin_14
,
192 .GPIO_Speed
= GPIO_Speed_50MHz
,
193 .GPIO_Mode
= GPIO_Mode_AF
,
194 .GPIO_OType
= GPIO_OType_PP
,
195 .GPIO_PuPd
= GPIO_PuPd_NOPULL
201 .GPIO_Pin
= GPIO_Pin_15
,
202 .GPIO_Speed
= GPIO_Speed_50MHz
,
203 .GPIO_Mode
= GPIO_Mode_AF
,
204 .GPIO_OType
= GPIO_OType_PP
,
205 .GPIO_PuPd
= GPIO_PuPd_NOPULL
213 .GPIO_Pin
= GPIO_Pin_12
,
214 .GPIO_Speed
= GPIO_Speed_50MHz
,
215 .GPIO_Mode
= GPIO_Mode_OUT
,
216 .GPIO_OType
= GPIO_OType_PP
,
217 .GPIO_PuPd
= GPIO_PuPd_UP
222 uint32_t pios_overo_id
= 0;
223 void PIOS_OVERO_irq_handler(void)
225 /* Call into the generic code to handle the IRQ for this specific device */
226 PIOS_OVERO_DMA_irq_handler(pios_overo_id
);
229 #endif /* PIOS_OVERO_SPI */
233 * Used for MPU6000 gyro and accelerometer
235 void PIOS_SPI_gyro_irq_handler(void);
236 void DMA2_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
237 void DMA2_Stream3_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
238 static const struct pios_spi_cfg pios_spi_gyro_cfg
= {
240 .remap
= GPIO_AF_SPI1
,
242 .SPI_Mode
= SPI_Mode_Master
,
243 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
244 .SPI_DataSize
= SPI_DataSize_8b
,
245 .SPI_NSS
= SPI_NSS_Soft
,
246 .SPI_FirstBit
= SPI_FirstBit_MSB
,
247 .SPI_CRCPolynomial
= 7,
248 .SPI_CPOL
= SPI_CPOL_High
,
249 .SPI_CPHA
= SPI_CPHA_2Edge
,
250 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_16
,
255 .flags
= (DMA_IT_TCIF0
| DMA_IT_TEIF0
| DMA_IT_HTIF0
),
257 .NVIC_IRQChannel
= DMA2_Stream0_IRQn
,
258 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
259 .NVIC_IRQChannelSubPriority
= 0,
260 .NVIC_IRQChannelCmd
= ENABLE
,
265 .channel
= DMA2_Stream0
,
267 .DMA_Channel
= DMA_Channel_3
,
268 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI1
->DR
),
269 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
270 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
271 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
272 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
273 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
274 .DMA_Mode
= DMA_Mode_Normal
,
275 .DMA_Priority
= DMA_Priority_Medium
,
276 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
277 /* .DMA_FIFOThreshold */
278 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
279 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
283 .channel
= DMA2_Stream3
,
285 .DMA_Channel
= DMA_Channel_3
,
286 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI1
->DR
),
287 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
288 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
289 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
290 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
291 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
292 .DMA_Mode
= DMA_Mode_Normal
,
293 .DMA_Priority
= DMA_Priority_High
,
294 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
295 /* .DMA_FIFOThreshold */
296 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
297 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
304 .GPIO_Pin
= GPIO_Pin_5
,
305 .GPIO_Speed
= GPIO_Speed_100MHz
,
306 .GPIO_Mode
= GPIO_Mode_AF
,
307 .GPIO_OType
= GPIO_OType_PP
,
308 .GPIO_PuPd
= GPIO_PuPd_UP
314 .GPIO_Pin
= GPIO_Pin_6
,
315 .GPIO_Speed
= GPIO_Speed_50MHz
,
316 .GPIO_Mode
= GPIO_Mode_AF
,
317 .GPIO_OType
= GPIO_OType_PP
,
318 .GPIO_PuPd
= GPIO_PuPd_UP
324 .GPIO_Pin
= GPIO_Pin_7
,
325 .GPIO_Speed
= GPIO_Speed_50MHz
,
326 .GPIO_Mode
= GPIO_Mode_AF
,
327 .GPIO_OType
= GPIO_OType_PP
,
328 .GPIO_PuPd
= GPIO_PuPd_UP
336 .GPIO_Pin
= GPIO_Pin_4
,
337 .GPIO_Speed
= GPIO_Speed_50MHz
,
338 .GPIO_Mode
= GPIO_Mode_OUT
,
339 .GPIO_OType
= GPIO_OType_PP
,
340 .GPIO_PuPd
= GPIO_PuPd_UP
346 static uint32_t pios_spi_gyro_id
;
347 void PIOS_SPI_gyro_irq_handler(void)
349 /* Call into the generic code to handle the IRQ for this specific device */
350 PIOS_SPI_IRQ_Handler(pios_spi_gyro_id
);
357 * Used for Flash and the RFM22B
359 void PIOS_SPI_telem_flash_irq_handler(void);
360 void DMA1_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
361 void DMA1_Stream5_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
362 static const struct pios_spi_cfg pios_spi_telem_flash_cfg
= {
364 .remap
= GPIO_AF_SPI3
,
366 .SPI_Mode
= SPI_Mode_Master
,
367 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
368 .SPI_DataSize
= SPI_DataSize_8b
,
369 .SPI_NSS
= SPI_NSS_Soft
,
370 .SPI_FirstBit
= SPI_FirstBit_MSB
,
371 .SPI_CRCPolynomial
= 7,
372 .SPI_CPOL
= SPI_CPOL_Low
,
373 .SPI_CPHA
= SPI_CPHA_1Edge
,
374 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_8
,
379 // Note this is the stream ID that triggers interrupts (in this case RX)
380 .flags
= (DMA_IT_TCIF0
| DMA_IT_TEIF0
| DMA_IT_HTIF0
),
382 .NVIC_IRQChannel
= DMA1_Stream0_IRQn
,
383 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
384 .NVIC_IRQChannelSubPriority
= 0,
385 .NVIC_IRQChannelCmd
= ENABLE
,
390 .channel
= DMA1_Stream0
,
392 .DMA_Channel
= DMA_Channel_0
,
393 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI3
->DR
),
394 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
395 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
396 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
397 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
398 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
399 .DMA_Mode
= DMA_Mode_Normal
,
400 .DMA_Priority
= DMA_Priority_Medium
,
402 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
403 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
404 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
405 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
409 .channel
= DMA1_Stream5
,
411 .DMA_Channel
= DMA_Channel_0
,
412 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI3
->DR
),
413 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
414 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
415 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
416 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
417 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
418 .DMA_Mode
= DMA_Mode_Normal
,
419 .DMA_Priority
= DMA_Priority_Medium
,
420 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
421 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
422 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
423 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
430 .GPIO_Pin
= GPIO_Pin_10
,
431 .GPIO_Speed
= GPIO_Speed_100MHz
,
432 .GPIO_Mode
= GPIO_Mode_AF
,
433 .GPIO_OType
= GPIO_OType_PP
,
434 .GPIO_PuPd
= GPIO_PuPd_NOPULL
440 .GPIO_Pin
= GPIO_Pin_11
,
441 .GPIO_Speed
= GPIO_Speed_50MHz
,
442 .GPIO_Mode
= GPIO_Mode_AF
,
443 .GPIO_OType
= GPIO_OType_PP
,
444 .GPIO_PuPd
= GPIO_PuPd_NOPULL
450 .GPIO_Pin
= GPIO_Pin_12
,
451 .GPIO_Speed
= GPIO_Speed_50MHz
,
452 .GPIO_Mode
= GPIO_Mode_AF
,
453 .GPIO_OType
= GPIO_OType_PP
,
454 .GPIO_PuPd
= GPIO_PuPd_NOPULL
462 .GPIO_Pin
= GPIO_Pin_15
,
463 .GPIO_Speed
= GPIO_Speed_50MHz
,
464 .GPIO_Mode
= GPIO_Mode_OUT
,
465 .GPIO_OType
= GPIO_OType_PP
,
466 .GPIO_PuPd
= GPIO_PuPd_UP
472 .GPIO_Pin
= GPIO_Pin_3
,
473 .GPIO_Speed
= GPIO_Speed_50MHz
,
474 .GPIO_Mode
= GPIO_Mode_OUT
,
475 .GPIO_OType
= GPIO_OType_PP
,
476 .GPIO_PuPd
= GPIO_PuPd_UP
482 uint32_t pios_spi_telem_flash_id
;
483 void PIOS_SPI_telem_flash_irq_handler(void)
485 /* Call into the generic code to handle the IRQ for this specific device */
486 PIOS_SPI_IRQ_Handler(pios_spi_telem_flash_id
);
490 #if defined(PIOS_INCLUDE_RFM22B)
491 #include <pios_rfm22b_priv.h>
493 static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config
= {
494 .vector
= PIOS_RFM22_EXT_Int
,
499 .GPIO_Pin
= GPIO_Pin_2
,
500 .GPIO_Speed
= GPIO_Speed_100MHz
,
501 .GPIO_Mode
= GPIO_Mode_IN
,
502 .GPIO_OType
= GPIO_OType_OD
,
503 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
508 .NVIC_IRQChannel
= EXTI2_IRQn
,
509 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_LOW
,
510 .NVIC_IRQChannelSubPriority
= 0,
511 .NVIC_IRQChannelCmd
= ENABLE
,
516 .EXTI_Line
= EXTI_Line2
, // matches above GPIO pin
517 .EXTI_Mode
= EXTI_Mode_Interrupt
,
518 .EXTI_Trigger
= EXTI_Trigger_Falling
,
519 .EXTI_LineCmd
= ENABLE
,
524 const struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg
= {
525 .spi_cfg
= &pios_spi_telem_flash_cfg
,
526 .exti_cfg
= &pios_exti_rfm22b_cfg
,
529 .gpio_direction
= GPIO0_RX_GPIO1_TX
,
532 const struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg
= {
533 .spi_cfg
= &pios_spi_telem_flash_cfg
,
534 .exti_cfg
= &pios_exti_rfm22b_cfg
,
537 .gpio_direction
= GPIO0_TX_GPIO1_RX
,
540 const struct pios_rfm22b_cfg
*PIOS_BOARD_HW_DEFS_GetRfm22Cfg(uint32_t board_revision
)
542 switch (board_revision
) {
544 return &pios_rfm22b_rm1_cfg
;
548 return &pios_rfm22b_rm2_cfg
;
552 PIOS_DEBUG_Assert(0);
557 #endif /* PIOS_INCLUDE_RFM22B */
559 #endif /* PIOS_INCLUDE_SPI */
561 #if defined(PIOS_INCLUDE_FLASH)
562 #include "pios_flashfs_logfs_priv.h"
563 #include "pios_flash_jedec_priv.h"
564 #include "pios_flash_internal_priv.h"
566 static const struct flashfs_logfs_cfg flashfs_external_cfg
= {
567 .fs_magic
= 0x99abceef,
568 .total_fs_size
= 0x00200000, /* 2M bytes (32 sectors = entire chip) */
569 .arena_size
= 0x00010000, /* 256 * slot size */
570 .slot_size
= 0x00000100, /* 256 bytes */
572 .start_offset
= 0, /* start at the beginning of the chip */
573 .sector_size
= 0x00010000, /* 64K bytes */
574 .page_size
= 0x00000100, /* 256 bytes */
578 static const struct pios_flash_internal_cfg flash_internal_system_cfg
= {};
580 static const struct flashfs_logfs_cfg flashfs_internal_cfg
= {
581 .fs_magic
= 0x99abcfef,
582 .total_fs_size
= EE_BANK_SIZE
, /* 32K bytes (2x16KB sectors) */
583 .arena_size
= 0x00004000, /* 64 * slot size = 16K bytes = 1 sector */
584 .slot_size
= 0x00000100, /* 256 bytes */
586 .start_offset
= EE_BANK_BASE
, /* start after the bootloader */
587 .sector_size
= 0x00004000, /* 16K bytes */
588 .page_size
= 0x00004000, /* 16K bytes */
591 static const struct flashfs_logfs_cfg flashfs_internal_user_cfg
= {
592 .fs_magic
= 0x99abcfef,
593 .total_fs_size
= USER_EE_BANK_SIZE
, /* 128K bytes (2x16KB sectors) */
594 .arena_size
= 0x00020000, /* 64 * slot size = 16K bytes = 1 sector */
595 .slot_size
= 0x00000100, /* 256 bytes */
597 .start_offset
= USER_EE_BANK_BASE
, /* start after the bootloader */
598 .sector_size
= 0x00020000, /* 128K bytes */
599 .page_size
= 0x00020000, /* 128K bytes */
601 #endif /* PIOS_INCLUDE_FLASH */
603 #include <pios_usart_priv.h>
605 #ifdef PIOS_INCLUDE_COM_TELEM
610 static const struct pios_usart_cfg pios_usart_main_cfg
= {
612 .remap
= GPIO_AF_USART1
,
614 .USART_BaudRate
= 57600,
615 .USART_WordLength
= USART_WordLength_8b
,
616 .USART_Parity
= USART_Parity_No
,
617 .USART_StopBits
= USART_StopBits_1
,
618 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
619 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
623 .NVIC_IRQChannel
= USART1_IRQn
,
624 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
625 .NVIC_IRQChannelSubPriority
= 0,
626 .NVIC_IRQChannelCmd
= ENABLE
,
632 .GPIO_Pin
= GPIO_Pin_10
,
633 .GPIO_Speed
= GPIO_Speed_2MHz
,
634 .GPIO_Mode
= GPIO_Mode_AF
,
635 .GPIO_OType
= GPIO_OType_PP
,
636 .GPIO_PuPd
= GPIO_PuPd_UP
642 .GPIO_Pin
= GPIO_Pin_9
,
643 .GPIO_Speed
= GPIO_Speed_2MHz
,
644 .GPIO_Mode
= GPIO_Mode_AF
,
645 .GPIO_OType
= GPIO_OType_PP
,
646 .GPIO_PuPd
= GPIO_PuPd_UP
650 #endif /* PIOS_INCLUDE_COM_TELEM */
652 #ifdef PIOS_INCLUDE_DSM
654 #include "pios_dsm_priv.h"
655 static const struct pios_usart_cfg pios_usart_dsm_main_cfg
= {
657 .remap
= GPIO_AF_USART1
,
659 .USART_BaudRate
= 115200,
660 .USART_WordLength
= USART_WordLength_8b
,
661 .USART_Parity
= USART_Parity_No
,
662 .USART_StopBits
= USART_StopBits_1
,
663 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
664 .USART_Mode
= USART_Mode_Rx
,
668 .NVIC_IRQChannel
= USART1_IRQn
,
669 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
670 .NVIC_IRQChannelSubPriority
= 0,
671 .NVIC_IRQChannelCmd
= ENABLE
,
677 .GPIO_Pin
= GPIO_Pin_10
,
678 .GPIO_Speed
= GPIO_Speed_2MHz
,
679 .GPIO_Mode
= GPIO_Mode_AF
,
680 .GPIO_OType
= GPIO_OType_PP
,
681 .GPIO_PuPd
= GPIO_PuPd_UP
687 .GPIO_Pin
= GPIO_Pin_9
,
688 .GPIO_Speed
= GPIO_Speed_2MHz
,
689 .GPIO_Mode
= GPIO_Mode_AF
,
690 .GPIO_OType
= GPIO_OType_PP
,
691 .GPIO_PuPd
= GPIO_PuPd_UP
696 // Because of the inverter on the main port this will not
697 // work. Notice the mode is set to IN to maintain API
698 // compatibility but protect the pins
699 static const struct pios_dsm_cfg pios_dsm_main_cfg
= {
703 .GPIO_Pin
= GPIO_Pin_10
,
704 .GPIO_Speed
= GPIO_Speed_2MHz
,
705 .GPIO_Mode
= GPIO_Mode_IN
,
706 .GPIO_OType
= GPIO_OType_PP
,
707 .GPIO_PuPd
= GPIO_PuPd_NOPULL
712 #endif /* PIOS_INCLUDE_DSM */
714 #include <pios_sbus_priv.h>
715 #if defined(PIOS_INCLUDE_SBUS)
719 #include <pios_sbus_priv.h>
721 static const struct pios_usart_cfg pios_usart_sbus_main_cfg
= {
723 .remap
= GPIO_AF_USART1
,
725 .USART_BaudRate
= 100000,
726 .USART_WordLength
= USART_WordLength_8b
,
727 .USART_Parity
= USART_Parity_Even
,
728 .USART_StopBits
= USART_StopBits_2
,
729 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
730 .USART_Mode
= USART_Mode_Rx
,
734 .NVIC_IRQChannel
= USART1_IRQn
,
735 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
736 .NVIC_IRQChannelSubPriority
= 0,
737 .NVIC_IRQChannelCmd
= ENABLE
,
743 .GPIO_Pin
= GPIO_Pin_10
,
744 .GPIO_Speed
= GPIO_Speed_2MHz
,
745 .GPIO_Mode
= GPIO_Mode_AF
,
746 .GPIO_OType
= GPIO_OType_PP
,
747 .GPIO_PuPd
= GPIO_PuPd_UP
753 .GPIO_Pin
= GPIO_Pin_9
,
754 .GPIO_Speed
= GPIO_Speed_2MHz
,
755 .GPIO_Mode
= GPIO_Mode_OUT
,
756 .GPIO_OType
= GPIO_OType_PP
,
757 .GPIO_PuPd
= GPIO_PuPd_NOPULL
762 #endif /* PIOS_INCLUDE_SBUS */
764 // Need this defined regardless to be able to turn it off
765 static const struct pios_sbus_cfg pios_sbus_cfg
= {
766 /* Inverter configuration */
770 .GPIO_Pin
= GPIO_Pin_0
,
771 .GPIO_Speed
= GPIO_Speed_2MHz
,
772 .GPIO_Mode
= GPIO_Mode_OUT
,
773 .GPIO_OType
= GPIO_OType_PP
,
774 .GPIO_PuPd
= GPIO_PuPd_UP
777 .gpio_inv_enable
= Bit_SET
,
778 .gpio_inv_disable
= Bit_RESET
,
779 .gpio_clk_func
= RCC_AHB1PeriphClockCmd
,
780 .gpio_clk_periph
= RCC_AHB1Periph_GPIOC
,
784 #ifdef PIOS_INCLUDE_COM_FLEXI
788 static const struct pios_usart_cfg pios_usart_flexi_cfg
= {
790 .remap
= GPIO_AF_USART3
,
792 .USART_BaudRate
= 57600,
793 .USART_WordLength
= USART_WordLength_8b
,
794 .USART_Parity
= USART_Parity_No
,
795 .USART_StopBits
= USART_StopBits_1
,
796 .USART_HardwareFlowControl
=
797 USART_HardwareFlowControl_None
,
798 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
802 .NVIC_IRQChannel
= USART3_IRQn
,
803 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
804 .NVIC_IRQChannelSubPriority
= 0,
805 .NVIC_IRQChannelCmd
= ENABLE
,
811 .GPIO_Pin
= GPIO_Pin_11
,
812 .GPIO_Speed
= GPIO_Speed_2MHz
,
813 .GPIO_Mode
= GPIO_Mode_AF
,
814 .GPIO_OType
= GPIO_OType_PP
,
815 .GPIO_PuPd
= GPIO_PuPd_UP
821 .GPIO_Pin
= GPIO_Pin_10
,
822 .GPIO_Speed
= GPIO_Speed_2MHz
,
823 .GPIO_Mode
= GPIO_Mode_AF
,
824 .GPIO_OType
= GPIO_OType_PP
,
825 .GPIO_PuPd
= GPIO_PuPd_UP
830 #endif /* PIOS_INCLUDE_COM_FLEXI */
832 #ifdef PIOS_INCLUDE_DSM
834 #include "pios_dsm_priv.h"
835 static const struct pios_usart_cfg pios_usart_dsm_flexi_cfg
= {
837 .remap
= GPIO_AF_USART3
,
839 .USART_BaudRate
= 115200,
840 .USART_WordLength
= USART_WordLength_8b
,
841 .USART_Parity
= USART_Parity_No
,
842 .USART_StopBits
= USART_StopBits_1
,
843 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
844 .USART_Mode
= USART_Mode_Rx
,
848 .NVIC_IRQChannel
= USART3_IRQn
,
849 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
850 .NVIC_IRQChannelSubPriority
= 0,
851 .NVIC_IRQChannelCmd
= ENABLE
,
857 .GPIO_Pin
= GPIO_Pin_11
,
858 .GPIO_Speed
= GPIO_Speed_2MHz
,
859 .GPIO_Mode
= GPIO_Mode_AF
,
860 .GPIO_OType
= GPIO_OType_PP
,
861 .GPIO_PuPd
= GPIO_PuPd_UP
867 .GPIO_Pin
= GPIO_Pin_10
,
868 .GPIO_Speed
= GPIO_Speed_2MHz
,
869 .GPIO_Mode
= GPIO_Mode_AF
,
870 .GPIO_OType
= GPIO_OType_PP
,
871 .GPIO_PuPd
= GPIO_PuPd_UP
876 static const struct pios_dsm_cfg pios_dsm_flexi_cfg
= {
880 .GPIO_Pin
= GPIO_Pin_11
,
881 .GPIO_Speed
= GPIO_Speed_2MHz
,
882 .GPIO_Mode
= GPIO_Mode_OUT
,
883 .GPIO_OType
= GPIO_OType_PP
,
884 .GPIO_PuPd
= GPIO_PuPd_NOPULL
889 #endif /* PIOS_INCLUDE_DSM */
894 static const struct pios_usart_cfg pios_usart_hkosd_main_cfg
= {
896 .remap
= GPIO_AF_USART1
,
898 .USART_BaudRate
= 57600,
899 .USART_WordLength
= USART_WordLength_8b
,
900 .USART_Parity
= USART_Parity_No
,
901 .USART_StopBits
= USART_StopBits_1
,
902 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
903 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
907 .NVIC_IRQChannel
= USART1_IRQn
,
908 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
909 .NVIC_IRQChannelSubPriority
= 0,
910 .NVIC_IRQChannelCmd
= ENABLE
,
916 .GPIO_Pin
= GPIO_Pin_10
,
917 .GPIO_Speed
= GPIO_Speed_2MHz
,
918 .GPIO_Mode
= GPIO_Mode_AF
,
919 .GPIO_OType
= GPIO_OType_PP
,
920 .GPIO_PuPd
= GPIO_PuPd_UP
926 .GPIO_Pin
= GPIO_Pin_9
,
927 .GPIO_Speed
= GPIO_Speed_2MHz
,
928 .GPIO_Mode
= GPIO_Mode_AF
,
929 .GPIO_OType
= GPIO_OType_PP
,
930 .GPIO_PuPd
= GPIO_PuPd_UP
935 static const struct pios_usart_cfg pios_usart_hkosd_flexi_cfg
= {
937 .remap
= GPIO_AF_USART3
,
939 .USART_BaudRate
= 57600,
940 .USART_WordLength
= USART_WordLength_8b
,
941 .USART_Parity
= USART_Parity_No
,
942 .USART_StopBits
= USART_StopBits_1
,
943 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
944 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
948 .NVIC_IRQChannel
= USART3_IRQn
,
949 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
950 .NVIC_IRQChannelSubPriority
= 0,
951 .NVIC_IRQChannelCmd
= ENABLE
,
957 .GPIO_Pin
= GPIO_Pin_11
,
958 .GPIO_Speed
= GPIO_Speed_2MHz
,
959 .GPIO_Mode
= GPIO_Mode_AF
,
960 .GPIO_OType
= GPIO_OType_PP
,
961 .GPIO_PuPd
= GPIO_PuPd_UP
967 .GPIO_Pin
= GPIO_Pin_10
,
968 .GPIO_Speed
= GPIO_Speed_2MHz
,
969 .GPIO_Mode
= GPIO_Mode_AF
,
970 .GPIO_OType
= GPIO_OType_PP
,
971 .GPIO_PuPd
= GPIO_PuPd_UP
976 static const struct pios_usart_cfg pios_usart_rcvrport_cfg
= {
978 .remap
= GPIO_AF_USART6
,
980 .USART_BaudRate
= 57600,
981 .USART_WordLength
= USART_WordLength_8b
,
982 .USART_Parity
= USART_Parity_No
,
983 .USART_StopBits
= USART_StopBits_1
,
984 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
985 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
989 .NVIC_IRQChannel
= USART6_IRQn
,
990 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
991 .NVIC_IRQChannelSubPriority
= 0,
992 .NVIC_IRQChannelCmd
= ENABLE
,
1000 .GPIO_Pin
= GPIO_Pin_8
,
1001 .GPIO_Speed
= GPIO_Speed_25MHz
,
1002 .GPIO_Mode
= GPIO_Mode_OUT
,
1003 .GPIO_OType
= GPIO_OType_PP
,
1008 // * 7: PC6 = TIM8 CH1, USART6 TX
1011 .GPIO_Pin
= GPIO_Pin_6
,
1012 .GPIO_Speed
= GPIO_Speed_2MHz
,
1013 .GPIO_Mode
= GPIO_Mode_AF
,
1014 .GPIO_OType
= GPIO_OType_PP
,
1015 .GPIO_PuPd
= GPIO_PuPd_UP
1017 .pin_source
= GPIO_PinSource6
,
1021 // * 8: PC7 = TIM8 CH2, USART6 RX
1024 .GPIO_Pin
= GPIO_Pin_7
,
1025 .GPIO_Speed
= GPIO_Speed_2MHz
,
1026 .GPIO_Mode
= GPIO_Mode_AF
,
1027 .GPIO_OType
= GPIO_OType_PP
,
1028 .GPIO_PuPd
= GPIO_PuPd_UP
1030 .pin_source
= GPIO_PinSource7
,
1034 #if defined(PIOS_INCLUDE_COM)
1036 #include <pios_com_priv.h>
1038 #endif /* PIOS_INCLUDE_COM */
1040 #if defined(PIOS_INCLUDE_I2C)
1042 #include <pios_i2c_priv.h>
1047 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void);
1048 void PIOS_I2C_mag_pressureadapter_er_irq_handler(void);
1049 void I2C1_EV_IRQHandler()
1050 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_ev_irq_handler")));
1051 void I2C1_ER_IRQHandler()
1052 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler")));
1054 static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg
= {
1056 .remapSCL
= GPIO_AF_I2C1
,
1057 .remapSDA
= GPIO_AF_I2C1
,
1059 .I2C_Mode
= I2C_Mode_I2C
,
1060 .I2C_OwnAddress1
= 0,
1061 .I2C_Ack
= I2C_Ack_Enable
,
1062 .I2C_AcknowledgedAddress
= I2C_AcknowledgedAddress_7bit
,
1063 .I2C_DutyCycle
= I2C_DutyCycle_2
,
1064 .I2C_ClockSpeed
= 400000, /* bits/s */
1066 .transfer_timeout_ms
= 50,
1070 .GPIO_Pin
= GPIO_Pin_8
,
1071 .GPIO_Mode
= GPIO_Mode_AF
,
1072 .GPIO_Speed
= GPIO_Speed_50MHz
,
1073 .GPIO_OType
= GPIO_OType_OD
,
1074 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
1080 .GPIO_Pin
= GPIO_Pin_9
,
1081 .GPIO_Mode
= GPIO_Mode_AF
,
1082 .GPIO_Speed
= GPIO_Speed_50MHz
,
1083 .GPIO_OType
= GPIO_OType_OD
,
1084 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
1088 .flags
= 0, /* FIXME: check this */
1090 .NVIC_IRQChannel
= I2C1_EV_IRQn
,
1091 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1092 .NVIC_IRQChannelSubPriority
= 0,
1093 .NVIC_IRQChannelCmd
= ENABLE
,
1097 .flags
= 0, /* FIXME: check this */
1099 .NVIC_IRQChannel
= I2C1_ER_IRQn
,
1100 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1101 .NVIC_IRQChannelSubPriority
= 0,
1102 .NVIC_IRQChannelCmd
= ENABLE
,
1107 uint32_t pios_i2c_mag_pressure_adapter_id
;
1108 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void)
1110 /* Call into the generic code to handle the IRQ for this specific device */
1111 PIOS_I2C_EV_IRQ_Handler(pios_i2c_mag_pressure_adapter_id
);
1114 void PIOS_I2C_mag_pressure_adapter_er_irq_handler(void)
1116 /* Call into the generic code to handle the IRQ for this specific device */
1117 PIOS_I2C_ER_IRQ_Handler(pios_i2c_mag_pressure_adapter_id
);
1121 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void);
1122 void PIOS_I2C_flexiport_adapter_er_irq_handler(void);
1123 void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_irq_handler")));
1124 void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler")));
1126 static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg
= {
1128 .remapSCL
= GPIO_AF_I2C2
,
1129 .remapSDA
= GPIO_AF_I2C2
,
1131 .I2C_Mode
= I2C_Mode_I2C
,
1132 .I2C_OwnAddress1
= 0,
1133 .I2C_Ack
= I2C_Ack_Enable
,
1134 .I2C_AcknowledgedAddress
= I2C_AcknowledgedAddress_7bit
,
1135 .I2C_DutyCycle
= I2C_DutyCycle_2
,
1136 .I2C_ClockSpeed
= 400000, /* bits/s */
1138 .transfer_timeout_ms
= 50,
1142 .GPIO_Pin
= GPIO_Pin_10
,
1143 .GPIO_Mode
= GPIO_Mode_AF
,
1144 .GPIO_Speed
= GPIO_Speed_50MHz
,
1145 .GPIO_OType
= GPIO_OType_OD
,
1146 .GPIO_PuPd
= GPIO_PuPd_UP
,
1152 .GPIO_Pin
= GPIO_Pin_11
,
1153 .GPIO_Mode
= GPIO_Mode_AF
,
1154 .GPIO_Speed
= GPIO_Speed_50MHz
,
1155 .GPIO_OType
= GPIO_OType_OD
,
1156 .GPIO_PuPd
= GPIO_PuPd_UP
,
1160 .flags
= 0, /* FIXME: check this */
1162 .NVIC_IRQChannel
= I2C2_EV_IRQn
,
1163 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1164 .NVIC_IRQChannelSubPriority
= 0,
1165 .NVIC_IRQChannelCmd
= ENABLE
,
1169 .flags
= 0, /* FIXME: check this */
1171 .NVIC_IRQChannel
= I2C2_ER_IRQn
,
1172 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1173 .NVIC_IRQChannelSubPriority
= 0,
1174 .NVIC_IRQChannelCmd
= ENABLE
,
1179 uint32_t pios_i2c_flexiport_adapter_id
;
1180 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void)
1182 /* Call into the generic code to handle the IRQ for this specific device */
1183 PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexiport_adapter_id
);
1186 void PIOS_I2C_flexiport_adapter_er_irq_handler(void)
1188 /* Call into the generic code to handle the IRQ for this specific device */
1189 PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexiport_adapter_id
);
1193 void PIOS_I2C_pressure_adapter_ev_irq_handler(void);
1194 void PIOS_I2C_pressure_adapter_er_irq_handler(void);
1196 #endif /* PIOS_INCLUDE_I2C */
1198 #if defined(PIOS_INCLUDE_RTC)
1200 * Realtime Clock (RTC)
1202 #include <pios_rtc_priv.h>
1204 void PIOS_RTC_IRQ_Handler(void);
1205 void RTC_WKUP_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
1206 static const struct pios_rtc_cfg pios_rtc_main_cfg
= {
1207 .clksrc
= RCC_RTCCLKSource_HSE_Div8
, // Divide 8 Mhz crystal down to 1
1208 // For some reason it's acting like crystal is 16 Mhz. This clock is then divided
1209 // by another 16 to give a nominal 62.5 khz clock
1210 .prescaler
= 100, // Every 100 cycles gives 625 Hz
1213 .NVIC_IRQChannel
= RTC_WKUP_IRQn
,
1214 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1215 .NVIC_IRQChannelSubPriority
= 0,
1216 .NVIC_IRQChannelCmd
= ENABLE
,
1221 void PIOS_RTC_IRQ_Handler(void)
1223 PIOS_RTC_irq_handler();
1226 #endif /* if defined(PIOS_INCLUDE_RTC) */
1228 #include "pios_tim_priv.h"
1230 static const TIM_TimeBaseInitTypeDef tim_3_5_time_base
= {
1231 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB1_CLOCK
/ 1000000) - 1,
1232 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1233 .TIM_CounterMode
= TIM_CounterMode_Up
,
1234 .TIM_Period
= ((1000000 / PIOS_SERVO_UPDATE_HZ
) - 1),
1235 .TIM_RepetitionCounter
= 0x0000,
1237 static const TIM_TimeBaseInitTypeDef tim_9_10_11_time_base
= {
1238 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB2_CLOCK
/ 1000000) - 1,
1239 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1240 .TIM_CounterMode
= TIM_CounterMode_Up
,
1241 .TIM_Period
= ((1000000 / PIOS_SERVO_UPDATE_HZ
) - 1),
1242 .TIM_RepetitionCounter
= 0x0000,
1245 static const struct pios_tim_clock_cfg tim_3_cfg
= {
1247 .time_base_init
= &tim_3_5_time_base
,
1250 .NVIC_IRQChannel
= TIM3_IRQn
,
1251 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1252 .NVIC_IRQChannelSubPriority
= 0,
1253 .NVIC_IRQChannelCmd
= ENABLE
,
1258 static const struct pios_tim_clock_cfg tim_5_cfg
= {
1260 .time_base_init
= &tim_3_5_time_base
,
1263 .NVIC_IRQChannel
= TIM5_IRQn
,
1264 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1265 .NVIC_IRQChannelSubPriority
= 0,
1266 .NVIC_IRQChannelCmd
= ENABLE
,
1271 static const struct pios_tim_clock_cfg tim_9_cfg
= {
1273 .time_base_init
= &tim_9_10_11_time_base
,
1276 .NVIC_IRQChannel
= TIM1_BRK_TIM9_IRQn
,
1277 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1278 .NVIC_IRQChannelSubPriority
= 0,
1279 .NVIC_IRQChannelCmd
= ENABLE
,
1284 static const struct pios_tim_clock_cfg tim_10_cfg
= {
1286 .time_base_init
= &tim_9_10_11_time_base
,
1289 .NVIC_IRQChannel
= TIM1_UP_TIM10_IRQn
,
1290 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1291 .NVIC_IRQChannelSubPriority
= 0,
1292 .NVIC_IRQChannelCmd
= ENABLE
,
1297 static const struct pios_tim_clock_cfg tim_11_cfg
= {
1299 .time_base_init
= &tim_9_10_11_time_base
,
1302 .NVIC_IRQChannel
= TIM1_TRG_COM_TIM11_IRQn
,
1303 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1304 .NVIC_IRQChannelSubPriority
= 0,
1305 .NVIC_IRQChannelCmd
= ENABLE
,
1310 // Set up timers that only have inputs on APB1
1311 // TIM2,3,4,5,6,7,12,13,14
1312 static const TIM_TimeBaseInitTypeDef tim_apb1_time_base
= {
1313 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB1_CLOCK
/ 1000000) - 1,
1314 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1315 .TIM_CounterMode
= TIM_CounterMode_Up
,
1316 .TIM_Period
= 0xFFFF,
1317 .TIM_RepetitionCounter
= 0x0000,
1321 // Set up timers that only have inputs on APB2
1323 static const TIM_TimeBaseInitTypeDef tim_apb2_time_base
= {
1324 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB2_CLOCK
/ 1000000) - 1,
1325 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1326 .TIM_CounterMode
= TIM_CounterMode_Up
,
1327 .TIM_Period
= 0xFFFF,
1328 .TIM_RepetitionCounter
= 0x0000,
1331 static const struct pios_tim_clock_cfg tim_1_cfg
= {
1333 .time_base_init
= &tim_apb2_time_base
,
1336 .NVIC_IRQChannel
= TIM1_CC_IRQn
,
1337 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1338 .NVIC_IRQChannelSubPriority
= 0,
1339 .NVIC_IRQChannelCmd
= ENABLE
,
1344 static const struct pios_tim_clock_cfg tim_4_cfg
= {
1346 .time_base_init
= &tim_apb1_time_base
,
1349 .NVIC_IRQChannel
= TIM4_IRQn
,
1350 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1351 .NVIC_IRQChannelSubPriority
= 0,
1352 .NVIC_IRQChannelCmd
= ENABLE
,
1356 static const struct pios_tim_clock_cfg tim_8_cfg
= {
1358 .time_base_init
= &tim_apb2_time_base
,
1361 .NVIC_IRQChannel
= TIM8_CC_IRQn
,
1362 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1363 .NVIC_IRQChannelSubPriority
= 0,
1364 .NVIC_IRQChannelCmd
= ENABLE
,
1369 static const struct pios_tim_clock_cfg tim_12_cfg
= {
1371 .time_base_init
= &tim_apb1_time_base
,
1374 .NVIC_IRQChannel
= TIM8_BRK_TIM12_IRQn
,
1375 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1376 .NVIC_IRQChannelSubPriority
= 0,
1377 .NVIC_IRQChannelCmd
= ENABLE
,
1384 * Pios servo configuration structures
1385 * Using TIM3, TIM9, TIM2, TIM5
1387 #include <pios_servo_priv.h>
1388 static const struct pios_tim_channel pios_tim_servoport_all_pins
[] = {
1391 .timer_chan
= TIM_Channel_3
,
1395 .GPIO_Pin
= GPIO_Pin_0
,
1396 .GPIO_Speed
= GPIO_Speed_2MHz
,
1397 .GPIO_Mode
= GPIO_Mode_AF
,
1398 .GPIO_OType
= GPIO_OType_PP
,
1399 .GPIO_PuPd
= GPIO_PuPd_UP
1401 .pin_source
= GPIO_PinSource0
,
1403 .remap
= GPIO_AF_TIM3
,
1407 .timer_chan
= TIM_Channel_4
,
1411 .GPIO_Pin
= GPIO_Pin_1
,
1412 .GPIO_Speed
= GPIO_Speed_2MHz
,
1413 .GPIO_Mode
= GPIO_Mode_AF
,
1414 .GPIO_OType
= GPIO_OType_PP
,
1415 .GPIO_PuPd
= GPIO_PuPd_UP
1417 .pin_source
= GPIO_PinSource1
,
1419 .remap
= GPIO_AF_TIM3
,
1423 .timer_chan
= TIM_Channel_2
,
1427 .GPIO_Pin
= GPIO_Pin_3
,
1428 .GPIO_Speed
= GPIO_Speed_2MHz
,
1429 .GPIO_Mode
= GPIO_Mode_AF
,
1430 .GPIO_OType
= GPIO_OType_PP
,
1431 .GPIO_PuPd
= GPIO_PuPd_UP
1433 .pin_source
= GPIO_PinSource3
,
1435 .remap
= GPIO_AF_TIM9
,
1439 .timer_chan
= TIM_Channel_3
,
1443 .GPIO_Pin
= GPIO_Pin_2
,
1444 .GPIO_Speed
= GPIO_Speed_2MHz
,
1445 .GPIO_Mode
= GPIO_Mode_AF
,
1446 .GPIO_OType
= GPIO_OType_PP
,
1447 .GPIO_PuPd
= GPIO_PuPd_UP
1449 .pin_source
= GPIO_PinSource2
,
1451 .remap
= GPIO_AF_TIM2
,
1455 .timer_chan
= TIM_Channel_2
,
1459 .GPIO_Pin
= GPIO_Pin_1
,
1460 .GPIO_Speed
= GPIO_Speed_2MHz
,
1461 .GPIO_Mode
= GPIO_Mode_AF
,
1462 .GPIO_OType
= GPIO_OType_PP
,
1463 .GPIO_PuPd
= GPIO_PuPd_UP
1465 .pin_source
= GPIO_PinSource1
,
1467 .remap
= GPIO_AF_TIM5
,
1471 .timer_chan
= TIM_Channel_1
,
1475 .GPIO_Pin
= GPIO_Pin_0
,
1476 .GPIO_Speed
= GPIO_Speed_2MHz
,
1477 .GPIO_Mode
= GPIO_Mode_AF
,
1478 .GPIO_OType
= GPIO_OType_PP
,
1479 .GPIO_PuPd
= GPIO_PuPd_UP
1481 .pin_source
= GPIO_PinSource0
,
1483 .remap
= GPIO_AF_TIM5
,
1485 // PWM pins on FlexiIO(receiver) port
1487 // * 6: PB15 = SPI2 MOSI, TIM12 CH2
1490 .timer_chan
= TIM_Channel_2
,
1494 .GPIO_Pin
= GPIO_Pin_15
,
1495 .GPIO_Speed
= GPIO_Speed_2MHz
,
1496 .GPIO_Mode
= GPIO_Mode_AF
,
1497 .GPIO_OType
= GPIO_OType_PP
,
1498 .GPIO_PuPd
= GPIO_PuPd_UP
1500 .pin_source
= GPIO_PinSource15
,
1502 .remap
= GPIO_AF_TIM12
,
1505 // * 7: PC6 = TIM8 CH1, USART6 TX
1507 .timer_chan
= TIM_Channel_1
,
1511 .GPIO_Pin
= GPIO_Pin_6
,
1512 .GPIO_Speed
= GPIO_Speed_2MHz
,
1513 .GPIO_Mode
= GPIO_Mode_AF
,
1514 .GPIO_OType
= GPIO_OType_PP
,
1515 .GPIO_PuPd
= GPIO_PuPd_UP
1517 .pin_source
= GPIO_PinSource6
,
1519 .remap
= GPIO_AF_TIM8
,
1523 // * 8: PC7 = TIM8 CH2, USART6 RX
1525 .timer_chan
= TIM_Channel_2
,
1529 .GPIO_Pin
= GPIO_Pin_7
,
1530 .GPIO_Speed
= GPIO_Speed_2MHz
,
1531 .GPIO_Mode
= GPIO_Mode_AF
,
1532 .GPIO_OType
= GPIO_OType_PP
,
1533 .GPIO_PuPd
= GPIO_PuPd_UP
1535 .pin_source
= GPIO_PinSource7
,
1537 .remap
= GPIO_AF_TIM8
,
1541 // * 9: PC8 = TIM8 CH3
1543 .timer_chan
= TIM_Channel_3
,
1547 .GPIO_Pin
= GPIO_Pin_8
,
1548 .GPIO_Speed
= GPIO_Speed_2MHz
,
1549 .GPIO_Mode
= GPIO_Mode_AF
,
1550 .GPIO_OType
= GPIO_OType_PP
,
1551 .GPIO_PuPd
= GPIO_PuPd_UP
1553 .pin_source
= GPIO_PinSource8
,
1555 .remap
= GPIO_AF_TIM8
,
1559 // * 10: PC9 = TIM8 CH4
1561 .timer_chan
= TIM_Channel_4
,
1565 .GPIO_Pin
= GPIO_Pin_9
,
1566 .GPIO_Speed
= GPIO_Speed_2MHz
,
1567 .GPIO_Mode
= GPIO_Mode_AF
,
1568 .GPIO_OType
= GPIO_OType_PP
,
1569 .GPIO_PuPd
= GPIO_PuPd_UP
1571 .pin_source
= GPIO_PinSource9
,
1573 .remap
= GPIO_AF_TIM8
,
1577 // * 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
1579 .timer_chan
= TIM_Channel_1
,
1583 .GPIO_Pin
= GPIO_Pin_14
,
1584 .GPIO_Speed
= GPIO_Speed_2MHz
,
1585 .GPIO_Mode
= GPIO_Mode_AF
,
1586 .GPIO_OType
= GPIO_OType_PP
,
1587 .GPIO_PuPd
= GPIO_PuPd_UP
1589 .pin_source
= GPIO_PinSource14
,
1591 .remap
= GPIO_AF_TIM12
,
1594 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT 6
1595 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM 11
1596 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN 12
1598 const struct pios_servo_cfg pios_servo_cfg_out
= {
1600 .TIM_OCMode
= TIM_OCMode_PWM1
,
1601 .TIM_OutputState
= TIM_OutputState_Enable
,
1602 .TIM_OutputNState
= TIM_OutputNState_Disable
,
1603 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
1604 .TIM_OCPolarity
= TIM_OCPolarity_High
,
1605 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
1606 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
1607 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
1609 .channels
= pios_tim_servoport_all_pins
,
1610 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT
,
1612 // All servo outputs, servo input ch1 ppm, ch2-6 outputs
1613 const struct pios_servo_cfg pios_servo_cfg_out_in_ppm
= {
1615 .TIM_OCMode
= TIM_OCMode_PWM1
,
1616 .TIM_OutputState
= TIM_OutputState_Enable
,
1617 .TIM_OutputNState
= TIM_OutputNState_Disable
,
1618 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
1619 .TIM_OCPolarity
= TIM_OCPolarity_High
,
1620 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
1621 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
1622 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
1624 .channels
= pios_tim_servoport_all_pins
,
1625 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM
,
1627 // All servo outputs, servo inputs ch1-6 Outputs
1628 const struct pios_servo_cfg pios_servo_cfg_out_in
= {
1630 .TIM_OCMode
= TIM_OCMode_PWM1
,
1631 .TIM_OutputState
= TIM_OutputState_Enable
,
1632 .TIM_OutputNState
= TIM_OutputNState_Disable
,
1633 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
1634 .TIM_OCPolarity
= TIM_OCPolarity_High
,
1635 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
1636 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
1637 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
1639 .channels
= pios_tim_servoport_all_pins
,
1640 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN
,
1648 #if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM)
1649 #include <pios_pwm_priv.h>
1650 static const struct pios_tim_channel pios_tim_rcvrport_all_channels
[] = {
1653 .timer_chan
= TIM_Channel_1
,
1657 .GPIO_Pin
= GPIO_Pin_14
,
1658 .GPIO_Speed
= GPIO_Speed_2MHz
,
1659 .GPIO_Mode
= GPIO_Mode_AF
,
1660 .GPIO_OType
= GPIO_OType_PP
,
1661 .GPIO_PuPd
= GPIO_PuPd_UP
1663 .pin_source
= GPIO_PinSource14
,
1665 .remap
= GPIO_AF_TIM12
,
1669 .timer_chan
= TIM_Channel_2
,
1673 .GPIO_Pin
= GPIO_Pin_15
,
1674 .GPIO_Speed
= GPIO_Speed_2MHz
,
1675 .GPIO_Mode
= GPIO_Mode_AF
,
1676 .GPIO_OType
= GPIO_OType_PP
,
1677 .GPIO_PuPd
= GPIO_PuPd_UP
1679 .pin_source
= GPIO_PinSource15
,
1681 .remap
= GPIO_AF_TIM12
,
1685 .timer_chan
= TIM_Channel_1
,
1689 .GPIO_Pin
= GPIO_Pin_6
,
1690 .GPIO_Speed
= GPIO_Speed_2MHz
,
1691 .GPIO_Mode
= GPIO_Mode_AF
,
1692 .GPIO_OType
= GPIO_OType_PP
,
1693 .GPIO_PuPd
= GPIO_PuPd_UP
1695 .pin_source
= GPIO_PinSource6
,
1697 .remap
= GPIO_AF_TIM8
,
1701 .timer_chan
= TIM_Channel_2
,
1705 .GPIO_Pin
= GPIO_Pin_7
,
1706 .GPIO_Speed
= GPIO_Speed_2MHz
,
1707 .GPIO_Mode
= GPIO_Mode_AF
,
1708 .GPIO_OType
= GPIO_OType_PP
,
1709 .GPIO_PuPd
= GPIO_PuPd_UP
1711 .pin_source
= GPIO_PinSource7
,
1713 .remap
= GPIO_AF_TIM8
,
1717 .timer_chan
= TIM_Channel_3
,
1721 .GPIO_Pin
= GPIO_Pin_8
,
1722 .GPIO_Speed
= GPIO_Speed_2MHz
,
1723 .GPIO_Mode
= GPIO_Mode_AF
,
1724 .GPIO_OType
= GPIO_OType_PP
,
1725 .GPIO_PuPd
= GPIO_PuPd_UP
1727 .pin_source
= GPIO_PinSource8
,
1729 .remap
= GPIO_AF_TIM8
,
1733 .timer_chan
= TIM_Channel_4
,
1737 .GPIO_Pin
= GPIO_Pin_9
,
1738 .GPIO_Speed
= GPIO_Speed_2MHz
,
1739 .GPIO_Mode
= GPIO_Mode_AF
,
1740 .GPIO_OType
= GPIO_OType_PP
,
1741 .GPIO_PuPd
= GPIO_PuPd_UP
1743 .pin_source
= GPIO_PinSource9
,
1745 .remap
= GPIO_AF_TIM8
,
1749 const struct pios_pwm_cfg pios_pwm_cfg
= {
1751 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
1752 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
1753 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
1754 .TIM_ICFilter
= 0x0,
1756 .channels
= pios_tim_rcvrport_all_channels
,
1757 .num_channels
= NELEMENTS(pios_tim_rcvrport_all_channels
),
1759 // this configures outputs 2-6 as pwm inputs
1760 const struct pios_pwm_cfg pios_pwm_ppm_cfg
= {
1762 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
1763 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
1764 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
1765 .TIM_ICFilter
= 0x0,
1767 .channels
= &pios_tim_rcvrport_all_channels
[1],
1768 .num_channels
= NELEMENTS(pios_tim_rcvrport_all_channels
) - 1,
1771 #endif /* if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM) */
1776 #if defined(PIOS_INCLUDE_PPM)
1777 #include <pios_ppm_priv.h>
1778 static const struct pios_ppm_cfg pios_ppm_cfg
= {
1780 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
1781 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
1782 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
1783 .TIM_ICFilter
= 0x0,
1784 .TIM_Channel
= TIM_Channel_1
,
1786 /* Use only the first channel for ppm */
1787 .channels
= &pios_tim_rcvrport_all_channels
[0],
1793 #if defined(PIOS_INCLUDE_GCSRCVR)
1794 #include "pios_gcsrcvr_priv.h"
1795 #endif /* PIOS_INCLUDE_GCSRCVR */
1797 #if defined(PIOS_INCLUDE_RCVR)
1798 #include "pios_rcvr_priv.h"
1799 #endif /* PIOS_INCLUDE_RCVR */
1801 #if defined(PIOS_INCLUDE_USB)
1802 #include "pios_usb_priv.h"
1804 static const struct pios_usb_cfg pios_usb_discovery_cfg
= {
1807 .NVIC_IRQChannel
= OTG_FS_IRQn
,
1808 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1809 .NVIC_IRQChannelSubPriority
= 0, // PriorityGroup=4
1810 .NVIC_IRQChannelCmd
= ENABLE
,
1816 .GPIO_Pin
= GPIO_Pin_9
,
1817 .GPIO_Speed
= GPIO_Speed_25MHz
,
1818 .GPIO_Mode
= GPIO_Mode_IN
,
1819 .GPIO_OType
= GPIO_OType_OD
,
1822 .vsense_active_low
= false
1825 const struct pios_usb_cfg
*PIOS_BOARD_HW_DEFS_GetUsbCfg(__attribute__((unused
)) uint32_t board_revision
)
1827 return &pios_usb_discovery_cfg
;
1830 #include "pios_usb_board_data_priv.h"
1831 #include "pios_usb_desc_hid_cdc_priv.h"
1832 #include "pios_usb_desc_hid_only_priv.h"
1833 #include "pios_usbhook.h"
1835 #endif /* PIOS_INCLUDE_USB */
1837 #if defined(PIOS_INCLUDE_COM_MSG)
1839 #include <pios_com_msg_priv.h>
1841 #endif /* PIOS_INCLUDE_COM_MSG */
1843 #if defined(PIOS_INCLUDE_USB_HID) && !defined(PIOS_INCLUDE_USB_CDC)
1844 #include <pios_usb_hid_priv.h>
1846 const struct pios_usb_hid_cfg pios_usb_hid_cfg
= {
1851 #endif /* PIOS_INCLUDE_USB_HID && !PIOS_INCLUDE_USB_CDC */
1853 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_USB_CDC)
1854 #include <pios_usb_cdc_priv.h>
1856 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg
= {
1865 #include <pios_usb_hid_priv.h>
1867 const struct pios_usb_hid_cfg pios_usb_hid_cfg
= {
1872 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
1873 #ifdef PIOS_INCLUDE_WS2811
1874 #include <pios_ws2811_cfg.h>
1875 #define PIOS_WS2811_TIM_DIVIDER (PIOS_PERIPHERAL_APB2_CLOCK / (800000 * PIOS_WS2811_TIM_PERIOD))
1877 void DMA2_Stream1_IRQHandler(void) __attribute__((alias("PIOS_WS2811_irq_handler")));
1879 const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg
= {
1882 .GPIO_Pin
= GPIO_Pin_3
,
1883 .GPIO_Speed
= GPIO_Speed_50MHz
,
1884 .GPIO_Mode
= GPIO_Mode_OUT
,
1885 .GPIO_OType
= GPIO_OType_PP
,
1889 const struct pios_ws2811_cfg pios_ws2811_cfg
= {
1892 .TIM_Prescaler
= PIOS_WS2811_TIM_DIVIDER
- 1,
1893 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1894 .TIM_CounterMode
= TIM_CounterMode_Up
,
1895 // period (1.25 uS per period
1896 .TIM_Period
= PIOS_WS2811_TIM_PERIOD
,
1897 .TIM_RepetitionCounter
= 0x0000,
1901 .streamCh1
= DMA2_Stream1
,
1903 .streamCh2
= DMA2_Stream6
,
1904 .streamUpdate
= DMA2_Stream5
,
1906 // DMA streamCh1, triggered by timerCh1 pwm signal.
1907 // if FrameBuffer indicates, reset output value early to indicate "0" bit to ws2812
1908 .dmaInitCh1
= PIOS_WS2811_DMA_CH1_CONFIG(DMA_Channel_6
),
1909 .dmaItCh1
= DMA_IT_TEIF1
| DMA_IT_TCIF1
,
1911 // DMA streamCh2, triggered by timerCh2 pwm signal.
1912 // Reset output value late to indicate "1" bit to ws2812.
1913 .dmaInitCh2
= PIOS_WS2811_DMA_CH2_CONFIG(DMA_Channel_6
),
1914 .dmaItCh2
= DMA_IT_TEIF6
| DMA_IT_TCIF6
,
1916 // DMA streamUpdate Triggered by timer update event
1917 // Outputs a high logic level at beginning of a cycle
1918 .dmaInitUpdate
= PIOS_WS2811_DMA_UPDATE_CONFIG(DMA_Channel_6
),
1919 .dmaItUpdate
= DMA_IT_TEIF5
| DMA_IT_TCIF5
,
1920 .dmaSource
= TIM_DMA_CC1
| TIM_DMA_CC3
| TIM_DMA_Update
,
1922 // DMA streamCh1 interrupt vector, used to block timer at end of framebuffer transfer
1924 .flags
= (DMA_IT_TCIF1
),
1926 .NVIC_IRQChannel
= DMA2_Stream1_IRQn
,
1927 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1928 .NVIC_IRQChannelSubPriority
= 0,
1929 .NVIC_IRQChannelCmd
= ENABLE
,
1934 void PIOS_WS2811_irq_handler(void)
1936 PIOS_WS2811_DMA_irq_handler();
1938 #endif // PIOS_INCLUDE_WS2811