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_12
,
37 .GPIO_Speed
= GPIO_Speed_50MHz
,
38 .GPIO_Mode
= GPIO_Mode_OUT
,
39 .GPIO_OType
= GPIO_OType_PP
,
40 .GPIO_PuPd
= GPIO_PuPd_UP
49 .GPIO_Pin
= GPIO_Pin_6
,
50 .GPIO_Speed
= GPIO_Speed_50MHz
,
51 .GPIO_Mode
= GPIO_Mode_OUT
,
52 .GPIO_OType
= GPIO_OType_PP
,
53 .GPIO_PuPd
= GPIO_PuPd_UP
58 #ifdef PIOS_RFM22B_DEBUG_ON_TELEM
63 .GPIO_Pin
= GPIO_Pin_6
,
64 .GPIO_Speed
= GPIO_Speed_50MHz
,
65 .GPIO_Mode
= GPIO_Mode_OUT
,
66 .GPIO_OType
= GPIO_OType_PP
,
67 .GPIO_PuPd
= GPIO_PuPd_UP
75 .GPIO_Pin
= GPIO_Pin_7
,
76 .GPIO_Speed
= GPIO_Speed_50MHz
,
77 .GPIO_Mode
= GPIO_Mode_OUT
,
78 .GPIO_OType
= GPIO_OType_PP
,
79 .GPIO_PuPd
= GPIO_PuPd_UP
87 .GPIO_Pin
= GPIO_Pin_8
,
88 .GPIO_Speed
= GPIO_Speed_50MHz
,
89 .GPIO_Mode
= GPIO_Mode_OUT
,
90 .GPIO_OType
= GPIO_OType_PP
,
91 .GPIO_PuPd
= GPIO_PuPd_UP
99 .GPIO_Pin
= GPIO_Pin_9
,
100 .GPIO_Speed
= GPIO_Speed_50MHz
,
101 .GPIO_Mode
= GPIO_Mode_OUT
,
102 .GPIO_OType
= GPIO_OType_PP
,
103 .GPIO_PuPd
= GPIO_PuPd_UP
107 #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */
110 static const struct pios_gpio_cfg pios_led_cfg
= {
112 .num_gpios
= NELEMENTS(pios_leds
),
115 static const struct pios_gpio pios_leds_v2
[] = {
116 [PIOS_LED_HEARTBEAT
] = {
120 .GPIO_Pin
= GPIO_Pin_5
,
121 .GPIO_Speed
= GPIO_Speed_50MHz
,
122 .GPIO_Mode
= GPIO_Mode_OUT
,
123 .GPIO_OType
= GPIO_OType_PP
,
124 .GPIO_PuPd
= GPIO_PuPd_UP
133 .GPIO_Pin
= GPIO_Pin_4
,
134 .GPIO_Speed
= GPIO_Speed_50MHz
,
135 .GPIO_Mode
= GPIO_Mode_OUT
,
136 .GPIO_OType
= GPIO_OType_PP
,
137 .GPIO_PuPd
= GPIO_PuPd_UP
142 #ifdef PIOS_RFM22B_DEBUG_ON_TELEM
147 .GPIO_Pin
= GPIO_Pin_13
,
148 .GPIO_Speed
= GPIO_Speed_50MHz
,
149 .GPIO_Mode
= GPIO_Mode_OUT
,
150 .GPIO_OType
= GPIO_OType_PP
,
151 .GPIO_PuPd
= GPIO_PuPd_UP
159 .GPIO_Pin
= GPIO_Pin_14
,
160 .GPIO_Speed
= GPIO_Speed_50MHz
,
161 .GPIO_Mode
= GPIO_Mode_OUT
,
162 .GPIO_OType
= GPIO_OType_PP
,
163 .GPIO_PuPd
= GPIO_PuPd_UP
171 .GPIO_Pin
= GPIO_Pin_15
,
172 .GPIO_Speed
= GPIO_Speed_50MHz
,
173 .GPIO_Mode
= GPIO_Mode_OUT
,
174 .GPIO_OType
= GPIO_OType_PP
,
175 .GPIO_PuPd
= GPIO_PuPd_UP
183 .GPIO_Pin
= GPIO_Pin_6
,
184 .GPIO_Speed
= GPIO_Speed_50MHz
,
185 .GPIO_Mode
= GPIO_Mode_OUT
,
186 .GPIO_OType
= GPIO_OType_PP
,
187 .GPIO_PuPd
= GPIO_PuPd_UP
191 #endif /* ifdef PIOS_RFM22B_DEBUG_ON_TELEM */
194 static const struct pios_gpio_cfg pios_led_v2_cfg
= {
195 .gpios
= pios_leds_v2
,
196 .num_gpios
= NELEMENTS(pios_leds_v2
),
199 const struct pios_gpio_cfg
*PIOS_BOARD_HW_DEFS_GetLedCfg(uint32_t board_revision
)
201 switch (board_revision
) {
203 return &pios_led_cfg
;
207 return &pios_led_v2_cfg
;
211 PIOS_DEBUG_Assert(0);
216 #endif /* PIOS_INCLUDE_LED */
218 #if defined(PIOS_INCLUDE_SPI)
219 #include <pios_spi_priv.h>
221 #if defined(PIOS_OVERO_SPI)
223 * - Used for Flexi/IO/Overo communications
224 3: PB12 = SPI2 NSS, CAN2 RX
225 4: PB13 = SPI2 SCK, CAN2 TX, USART3 CTS
226 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
227 6: PB15 = SPI2 MOSI, TIM12 CH2
229 #include <pios_overo_priv.h>
230 void PIOS_OVERO_irq_handler(void);
231 void DMA1_Stream7_IRQHandler(void) __attribute__((alias("PIOS_OVERO_irq_handler")));
232 static const struct pios_overo_cfg pios_overo_cfg
= {
234 .remap
= GPIO_AF_SPI2
,
236 .SPI_Mode
= SPI_Mode_Slave
,
237 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
238 .SPI_DataSize
= SPI_DataSize_8b
,
239 .SPI_NSS
= SPI_NSS_Hard
,
240 .SPI_FirstBit
= SPI_FirstBit_MSB
,
241 .SPI_CRCPolynomial
= 7,
242 .SPI_CPOL
= SPI_CPOL_High
,
243 .SPI_CPHA
= SPI_CPHA_2Edge
,
244 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_2
,
249 // Note this is the stream ID that triggers interrupts (in this case TX)
250 .flags
= (DMA_IT_TCIF7
),
252 .NVIC_IRQChannel
= DMA1_Stream7_IRQn
,
253 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
254 .NVIC_IRQChannelSubPriority
= 0,
255 .NVIC_IRQChannelCmd
= ENABLE
,
260 .channel
= DMA1_Stream0
,
262 .DMA_Channel
= DMA_Channel_0
,
263 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI2
->DR
),
264 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
265 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
266 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
267 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
268 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
269 .DMA_Mode
= DMA_Mode_Circular
,
270 .DMA_Priority
= DMA_Priority_Medium
,
272 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
273 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
274 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
275 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
279 .channel
= DMA1_Stream7
,
281 .DMA_Channel
= DMA_Channel_0
,
282 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI2
->DR
),
283 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
284 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
285 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
286 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
287 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
288 .DMA_Mode
= DMA_Mode_Circular
,
289 .DMA_Priority
= DMA_Priority_Medium
,
290 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
291 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
292 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
293 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
300 .GPIO_Pin
= GPIO_Pin_13
,
301 .GPIO_Speed
= GPIO_Speed_100MHz
,
302 .GPIO_Mode
= GPIO_Mode_AF
,
303 .GPIO_OType
= GPIO_OType_PP
,
304 .GPIO_PuPd
= GPIO_PuPd_NOPULL
310 .GPIO_Pin
= GPIO_Pin_14
,
311 .GPIO_Speed
= GPIO_Speed_50MHz
,
312 .GPIO_Mode
= GPIO_Mode_AF
,
313 .GPIO_OType
= GPIO_OType_PP
,
314 .GPIO_PuPd
= GPIO_PuPd_NOPULL
320 .GPIO_Pin
= GPIO_Pin_15
,
321 .GPIO_Speed
= GPIO_Speed_50MHz
,
322 .GPIO_Mode
= GPIO_Mode_AF
,
323 .GPIO_OType
= GPIO_OType_PP
,
324 .GPIO_PuPd
= GPIO_PuPd_NOPULL
332 .GPIO_Pin
= GPIO_Pin_12
,
333 .GPIO_Speed
= GPIO_Speed_50MHz
,
334 .GPIO_Mode
= GPIO_Mode_OUT
,
335 .GPIO_OType
= GPIO_OType_PP
,
336 .GPIO_PuPd
= GPIO_PuPd_UP
341 uint32_t pios_overo_id
= 0;
342 void PIOS_OVERO_irq_handler(void)
344 /* Call into the generic code to handle the IRQ for this specific device */
345 PIOS_OVERO_DMA_irq_handler(pios_overo_id
);
348 #endif /* PIOS_OVERO_SPI */
352 * Used for MPU6000 gyro and accelerometer
354 void PIOS_SPI_gyro_irq_handler(void);
355 void DMA2_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
356 void DMA2_Stream3_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
357 static const struct pios_spi_cfg pios_spi_gyro_cfg
= {
359 .remap
= GPIO_AF_SPI1
,
361 .SPI_Mode
= SPI_Mode_Master
,
362 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
363 .SPI_DataSize
= SPI_DataSize_8b
,
364 .SPI_NSS
= SPI_NSS_Soft
,
365 .SPI_FirstBit
= SPI_FirstBit_MSB
,
366 .SPI_CRCPolynomial
= 7,
367 .SPI_CPOL
= SPI_CPOL_High
,
368 .SPI_CPHA
= SPI_CPHA_2Edge
,
369 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_16
,
374 .flags
= (DMA_IT_TCIF0
| DMA_IT_TEIF0
| DMA_IT_HTIF0
),
376 .NVIC_IRQChannel
= DMA2_Stream0_IRQn
,
377 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
378 .NVIC_IRQChannelSubPriority
= 0,
379 .NVIC_IRQChannelCmd
= ENABLE
,
384 .channel
= DMA2_Stream0
,
386 .DMA_Channel
= DMA_Channel_3
,
387 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI1
->DR
),
388 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
389 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
390 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
391 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
392 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
393 .DMA_Mode
= DMA_Mode_Normal
,
394 .DMA_Priority
= DMA_Priority_Medium
,
395 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
396 /* .DMA_FIFOThreshold */
397 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
398 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
402 .channel
= DMA2_Stream3
,
404 .DMA_Channel
= DMA_Channel_3
,
405 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI1
->DR
),
406 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
407 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
408 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
409 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
410 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
411 .DMA_Mode
= DMA_Mode_Normal
,
412 .DMA_Priority
= DMA_Priority_High
,
413 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
414 /* .DMA_FIFOThreshold */
415 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
416 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
423 .GPIO_Pin
= GPIO_Pin_5
,
424 .GPIO_Speed
= GPIO_Speed_100MHz
,
425 .GPIO_Mode
= GPIO_Mode_AF
,
426 .GPIO_OType
= GPIO_OType_PP
,
427 .GPIO_PuPd
= GPIO_PuPd_UP
433 .GPIO_Pin
= GPIO_Pin_6
,
434 .GPIO_Speed
= GPIO_Speed_50MHz
,
435 .GPIO_Mode
= GPIO_Mode_AF
,
436 .GPIO_OType
= GPIO_OType_PP
,
437 .GPIO_PuPd
= GPIO_PuPd_UP
443 .GPIO_Pin
= GPIO_Pin_7
,
444 .GPIO_Speed
= GPIO_Speed_50MHz
,
445 .GPIO_Mode
= GPIO_Mode_AF
,
446 .GPIO_OType
= GPIO_OType_PP
,
447 .GPIO_PuPd
= GPIO_PuPd_UP
455 .GPIO_Pin
= GPIO_Pin_4
,
456 .GPIO_Speed
= GPIO_Speed_50MHz
,
457 .GPIO_Mode
= GPIO_Mode_OUT
,
458 .GPIO_OType
= GPIO_OType_PP
,
459 .GPIO_PuPd
= GPIO_PuPd_UP
465 static uint32_t pios_spi_gyro_id
;
466 void PIOS_SPI_gyro_irq_handler(void)
468 /* Call into the generic code to handle the IRQ for this specific device */
469 PIOS_SPI_IRQ_Handler(pios_spi_gyro_id
);
475 * Used for Flash and the RFM22B
477 void PIOS_SPI_telem_flash_irq_handler(void);
478 void DMA1_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
479 void DMA1_Stream5_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
480 static const struct pios_spi_cfg pios_spi_telem_flash_cfg
= {
482 .remap
= GPIO_AF_SPI3
,
484 .SPI_Mode
= SPI_Mode_Master
,
485 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
486 .SPI_DataSize
= SPI_DataSize_8b
,
487 .SPI_NSS
= SPI_NSS_Soft
,
488 .SPI_FirstBit
= SPI_FirstBit_MSB
,
489 .SPI_CRCPolynomial
= 7,
490 .SPI_CPOL
= SPI_CPOL_Low
,
491 .SPI_CPHA
= SPI_CPHA_1Edge
,
492 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_8
,
497 // Note this is the stream ID that triggers interrupts (in this case RX)
498 .flags
= (DMA_IT_TCIF0
| DMA_IT_TEIF0
| DMA_IT_HTIF0
),
500 .NVIC_IRQChannel
= DMA1_Stream0_IRQn
,
501 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
502 .NVIC_IRQChannelSubPriority
= 0,
503 .NVIC_IRQChannelCmd
= ENABLE
,
508 .channel
= DMA1_Stream0
,
510 .DMA_Channel
= DMA_Channel_0
,
511 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI3
->DR
),
512 .DMA_DIR
= DMA_DIR_PeripheralToMemory
,
513 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
514 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
515 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
516 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
517 .DMA_Mode
= DMA_Mode_Normal
,
518 .DMA_Priority
= DMA_Priority_Medium
,
520 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
521 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
522 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
523 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
527 .channel
= DMA1_Stream5
,
529 .DMA_Channel
= DMA_Channel_0
,
530 .DMA_PeripheralBaseAddr
= (uint32_t)&(SPI3
->DR
),
531 .DMA_DIR
= DMA_DIR_MemoryToPeripheral
,
532 .DMA_PeripheralInc
= DMA_PeripheralInc_Disable
,
533 .DMA_MemoryInc
= DMA_MemoryInc_Enable
,
534 .DMA_PeripheralDataSize
= DMA_PeripheralDataSize_Byte
,
535 .DMA_MemoryDataSize
= DMA_MemoryDataSize_Byte
,
536 .DMA_Mode
= DMA_Mode_Normal
,
537 .DMA_Priority
= DMA_Priority_Medium
,
538 .DMA_FIFOMode
= DMA_FIFOMode_Disable
,
539 .DMA_FIFOThreshold
= DMA_FIFOThreshold_Full
,
540 .DMA_MemoryBurst
= DMA_MemoryBurst_Single
,
541 .DMA_PeripheralBurst
= DMA_PeripheralBurst_Single
,
548 .GPIO_Pin
= GPIO_Pin_10
,
549 .GPIO_Speed
= GPIO_Speed_100MHz
,
550 .GPIO_Mode
= GPIO_Mode_AF
,
551 .GPIO_OType
= GPIO_OType_PP
,
552 .GPIO_PuPd
= GPIO_PuPd_NOPULL
558 .GPIO_Pin
= GPIO_Pin_11
,
559 .GPIO_Speed
= GPIO_Speed_50MHz
,
560 .GPIO_Mode
= GPIO_Mode_AF
,
561 .GPIO_OType
= GPIO_OType_PP
,
562 .GPIO_PuPd
= GPIO_PuPd_NOPULL
568 .GPIO_Pin
= GPIO_Pin_12
,
569 .GPIO_Speed
= GPIO_Speed_50MHz
,
570 .GPIO_Mode
= GPIO_Mode_AF
,
571 .GPIO_OType
= GPIO_OType_PP
,
572 .GPIO_PuPd
= GPIO_PuPd_NOPULL
580 .GPIO_Pin
= GPIO_Pin_15
,
581 .GPIO_Speed
= GPIO_Speed_50MHz
,
582 .GPIO_Mode
= GPIO_Mode_OUT
,
583 .GPIO_OType
= GPIO_OType_PP
,
584 .GPIO_PuPd
= GPIO_PuPd_UP
590 .GPIO_Pin
= GPIO_Pin_3
,
591 .GPIO_Speed
= GPIO_Speed_50MHz
,
592 .GPIO_Mode
= GPIO_Mode_OUT
,
593 .GPIO_OType
= GPIO_OType_PP
,
594 .GPIO_PuPd
= GPIO_PuPd_UP
600 uint32_t pios_spi_telem_flash_id
;
601 void PIOS_SPI_telem_flash_irq_handler(void)
603 /* Call into the generic code to handle the IRQ for this specific device */
604 PIOS_SPI_IRQ_Handler(pios_spi_telem_flash_id
);
608 #if defined(PIOS_INCLUDE_RFM22B)
609 #include <pios_rfm22b_priv.h>
611 static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config
= {
612 .vector
= PIOS_RFM22_EXT_Int
,
617 .GPIO_Pin
= GPIO_Pin_2
,
618 .GPIO_Speed
= GPIO_Speed_100MHz
,
619 .GPIO_Mode
= GPIO_Mode_IN
,
620 .GPIO_OType
= GPIO_OType_OD
,
621 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
626 .NVIC_IRQChannel
= EXTI2_IRQn
,
627 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_LOW
,
628 .NVIC_IRQChannelSubPriority
= 0,
629 .NVIC_IRQChannelCmd
= ENABLE
,
634 .EXTI_Line
= EXTI_Line2
, // matches above GPIO pin
635 .EXTI_Mode
= EXTI_Mode_Interrupt
,
636 .EXTI_Trigger
= EXTI_Trigger_Falling
,
637 .EXTI_LineCmd
= ENABLE
,
642 const struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg
= {
643 .spi_cfg
= &pios_spi_telem_flash_cfg
,
644 .exti_cfg
= &pios_exti_rfm22b_cfg
,
647 .gpio_direction
= GPIO0_RX_GPIO1_TX
,
650 const struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg
= {
651 .spi_cfg
= &pios_spi_telem_flash_cfg
,
652 .exti_cfg
= &pios_exti_rfm22b_cfg
,
655 .gpio_direction
= GPIO0_TX_GPIO1_RX
,
658 const struct pios_rfm22b_cfg
*PIOS_BOARD_HW_DEFS_GetRfm22Cfg(uint32_t board_revision
)
660 switch (board_revision
) {
662 return &pios_rfm22b_rm1_cfg
;
666 return &pios_rfm22b_rm2_cfg
;
670 PIOS_DEBUG_Assert(0);
675 #endif /* PIOS_INCLUDE_RFM22B */
677 #endif /* PIOS_INCLUDE_SPI */
679 #if defined(PIOS_INCLUDE_FLASH)
680 #include "pios_flashfs_logfs_priv.h"
681 #include "pios_flash_jedec_priv.h"
682 #include "pios_flash_internal_priv.h"
684 static const struct flashfs_logfs_cfg flashfs_external_user_cfg
= {
685 .fs_magic
= 0x99abceff,
686 .total_fs_size
= 0x001C0000, /* 2M bytes (32 sectors = entire chip) */
687 .arena_size
= 0x000E0000, /* biggest possible arena size fssize/2 */
688 .slot_size
= 0x00000100, /* 256 bytes */
690 .start_offset
= 0x00040000, /* start offset */
691 .sector_size
= 0x00010000, /* 64K bytes */
692 .page_size
= 0x00000100, /* 256 bytes */
695 static const struct flashfs_logfs_cfg flashfs_external_system_cfg
= {
696 .fs_magic
= 0x99bbcdef,
697 .total_fs_size
= 0x00040000, /* 2M bytes (32 sectors = entire chip) */
698 .arena_size
= 0x00010000, /* 256 * slot size */
699 .slot_size
= 0x00000100, /* 256 bytes */
701 .start_offset
= 0, /* start at the beginning of the chip */
702 .sector_size
= 0x00010000, /* 64K bytes */
703 .page_size
= 0x00000100, /* 256 bytes */
707 static const struct pios_flash_internal_cfg flash_internal_cfg
= {};
709 static const struct flashfs_logfs_cfg flashfs_internal_cfg
= {
710 .fs_magic
= 0x99abcfef,
711 .total_fs_size
= EE_BANK_SIZE
, /* 32K bytes (2x16KB sectors) */
712 .arena_size
= 0x00004000, /* 64 * slot size = 16K bytes = 1 sector */
713 .slot_size
= 0x00000100, /* 256 bytes */
715 .start_offset
= EE_BANK_BASE
, /* start after the bootloader */
716 .sector_size
= 0x00004000, /* 16K bytes */
717 .page_size
= 0x00004000, /* 16K bytes */
720 #endif /* PIOS_INCLUDE_FLASH */
722 #include <pios_usart_priv.h>
724 #ifdef PIOS_INCLUDE_COM_TELEM
729 static const struct pios_usart_cfg pios_usart_main_cfg
= {
731 .remap
= GPIO_AF_USART1
,
733 .USART_BaudRate
= 57600,
734 .USART_WordLength
= USART_WordLength_8b
,
735 .USART_Parity
= USART_Parity_No
,
736 .USART_StopBits
= USART_StopBits_1
,
737 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
738 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
742 .NVIC_IRQChannel
= USART1_IRQn
,
743 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
744 .NVIC_IRQChannelSubPriority
= 0,
745 .NVIC_IRQChannelCmd
= ENABLE
,
751 .GPIO_Pin
= GPIO_Pin_10
,
752 .GPIO_Speed
= GPIO_Speed_2MHz
,
753 .GPIO_Mode
= GPIO_Mode_AF
,
754 .GPIO_OType
= GPIO_OType_PP
,
755 .GPIO_PuPd
= GPIO_PuPd_UP
761 .GPIO_Pin
= GPIO_Pin_9
,
762 .GPIO_Speed
= GPIO_Speed_2MHz
,
763 .GPIO_Mode
= GPIO_Mode_AF
,
764 .GPIO_OType
= GPIO_OType_PP
,
765 .GPIO_PuPd
= GPIO_PuPd_UP
769 #endif /* PIOS_INCLUDE_COM_TELEM */
771 #ifdef PIOS_INCLUDE_DSM
773 #include "pios_dsm_priv.h"
774 static const struct pios_usart_cfg pios_usart_dsm_main_cfg
= {
776 .remap
= GPIO_AF_USART1
,
778 .USART_BaudRate
= 115200,
779 .USART_WordLength
= USART_WordLength_8b
,
780 .USART_Parity
= USART_Parity_No
,
781 .USART_StopBits
= USART_StopBits_1
,
782 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
783 .USART_Mode
= USART_Mode_Rx
,
787 .NVIC_IRQChannel
= USART1_IRQn
,
788 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
789 .NVIC_IRQChannelSubPriority
= 0,
790 .NVIC_IRQChannelCmd
= ENABLE
,
796 .GPIO_Pin
= GPIO_Pin_10
,
797 .GPIO_Speed
= GPIO_Speed_2MHz
,
798 .GPIO_Mode
= GPIO_Mode_AF
,
799 .GPIO_OType
= GPIO_OType_PP
,
800 .GPIO_PuPd
= GPIO_PuPd_UP
806 .GPIO_Pin
= GPIO_Pin_9
,
807 .GPIO_Speed
= GPIO_Speed_2MHz
,
808 .GPIO_Mode
= GPIO_Mode_AF
,
809 .GPIO_OType
= GPIO_OType_PP
,
810 .GPIO_PuPd
= GPIO_PuPd_UP
815 // Because of the inverter on the main port this will not
816 // work. Notice the mode is set to IN to maintain API
817 // compatibility but protect the pins
818 static const struct pios_dsm_cfg pios_dsm_main_cfg
= {
822 .GPIO_Pin
= GPIO_Pin_10
,
823 .GPIO_Speed
= GPIO_Speed_2MHz
,
824 .GPIO_Mode
= GPIO_Mode_IN
,
825 .GPIO_OType
= GPIO_OType_PP
,
826 .GPIO_PuPd
= GPIO_PuPd_NOPULL
831 #endif /* PIOS_INCLUDE_DSM */
833 #include <pios_sbus_priv.h>
834 #if defined(PIOS_INCLUDE_SBUS)
838 #include <pios_sbus_priv.h>
840 static const struct pios_usart_cfg pios_usart_sbus_main_cfg
= {
842 .remap
= GPIO_AF_USART1
,
844 .USART_BaudRate
= 100000,
845 .USART_WordLength
= USART_WordLength_8b
,
846 .USART_Parity
= USART_Parity_Even
,
847 .USART_StopBits
= USART_StopBits_2
,
848 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
849 .USART_Mode
= USART_Mode_Rx
,
853 .NVIC_IRQChannel
= USART1_IRQn
,
854 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
855 .NVIC_IRQChannelSubPriority
= 0,
856 .NVIC_IRQChannelCmd
= ENABLE
,
862 .GPIO_Pin
= GPIO_Pin_10
,
863 .GPIO_Speed
= GPIO_Speed_2MHz
,
864 .GPIO_Mode
= GPIO_Mode_AF
,
865 .GPIO_OType
= GPIO_OType_PP
,
866 .GPIO_PuPd
= GPIO_PuPd_UP
872 .GPIO_Pin
= GPIO_Pin_9
,
873 .GPIO_Speed
= GPIO_Speed_2MHz
,
874 .GPIO_Mode
= GPIO_Mode_OUT
,
875 .GPIO_OType
= GPIO_OType_PP
,
876 .GPIO_PuPd
= GPIO_PuPd_NOPULL
881 #endif /* PIOS_INCLUDE_SBUS */
883 // Need this defined regardless to be able to turn it off
884 static const struct pios_sbus_cfg pios_sbus_cfg
= {
885 /* Inverter configuration */
889 .GPIO_Pin
= GPIO_Pin_0
,
890 .GPIO_Speed
= GPIO_Speed_2MHz
,
891 .GPIO_Mode
= GPIO_Mode_OUT
,
892 .GPIO_OType
= GPIO_OType_PP
,
893 .GPIO_PuPd
= GPIO_PuPd_UP
896 .gpio_inv_enable
= Bit_SET
,
897 .gpio_inv_disable
= Bit_RESET
,
898 .gpio_clk_func
= RCC_AHB1PeriphClockCmd
,
899 .gpio_clk_periph
= RCC_AHB1Periph_GPIOC
,
902 #ifdef PIOS_INCLUDE_COM_FLEXI
906 static const struct pios_usart_cfg pios_usart_flexi_cfg
= {
908 .remap
= GPIO_AF_USART3
,
910 .USART_BaudRate
= 57600,
911 .USART_WordLength
= USART_WordLength_8b
,
912 .USART_Parity
= USART_Parity_No
,
913 .USART_StopBits
= USART_StopBits_1
,
914 .USART_HardwareFlowControl
=
915 USART_HardwareFlowControl_None
,
916 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
920 .NVIC_IRQChannel
= USART3_IRQn
,
921 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
922 .NVIC_IRQChannelSubPriority
= 0,
923 .NVIC_IRQChannelCmd
= ENABLE
,
929 .GPIO_Pin
= GPIO_Pin_11
,
930 .GPIO_Speed
= GPIO_Speed_2MHz
,
931 .GPIO_Mode
= GPIO_Mode_AF
,
932 .GPIO_OType
= GPIO_OType_PP
,
933 .GPIO_PuPd
= GPIO_PuPd_UP
939 .GPIO_Pin
= GPIO_Pin_10
,
940 .GPIO_Speed
= GPIO_Speed_2MHz
,
941 .GPIO_Mode
= GPIO_Mode_AF
,
942 .GPIO_OType
= GPIO_OType_PP
,
943 .GPIO_PuPd
= GPIO_PuPd_UP
948 #endif /* PIOS_INCLUDE_COM_FLEXI */
950 #ifdef PIOS_INCLUDE_DSM
952 #include "pios_dsm_priv.h"
953 static const struct pios_usart_cfg pios_usart_dsm_flexi_cfg
= {
955 .remap
= GPIO_AF_USART3
,
957 .USART_BaudRate
= 115200,
958 .USART_WordLength
= USART_WordLength_8b
,
959 .USART_Parity
= USART_Parity_No
,
960 .USART_StopBits
= USART_StopBits_1
,
961 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
962 .USART_Mode
= USART_Mode_Rx
,
966 .NVIC_IRQChannel
= USART3_IRQn
,
967 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
968 .NVIC_IRQChannelSubPriority
= 0,
969 .NVIC_IRQChannelCmd
= ENABLE
,
975 .GPIO_Pin
= GPIO_Pin_11
,
976 .GPIO_Speed
= GPIO_Speed_2MHz
,
977 .GPIO_Mode
= GPIO_Mode_AF
,
978 .GPIO_OType
= GPIO_OType_PP
,
979 .GPIO_PuPd
= GPIO_PuPd_UP
985 .GPIO_Pin
= GPIO_Pin_10
,
986 .GPIO_Speed
= GPIO_Speed_2MHz
,
987 .GPIO_Mode
= GPIO_Mode_AF
,
988 .GPIO_OType
= GPIO_OType_PP
,
989 .GPIO_PuPd
= GPIO_PuPd_UP
994 static const struct pios_dsm_cfg pios_dsm_flexi_cfg
= {
998 .GPIO_Pin
= GPIO_Pin_11
,
999 .GPIO_Speed
= GPIO_Speed_2MHz
,
1000 .GPIO_Mode
= GPIO_Mode_OUT
,
1001 .GPIO_OType
= GPIO_OType_PP
,
1002 .GPIO_PuPd
= GPIO_PuPd_NOPULL
1007 #endif /* PIOS_INCLUDE_DSM */
1009 #if defined(PIOS_INCLUDE_SRXL)
1013 #include <pios_srxl_priv.h>
1015 static const struct pios_usart_cfg pios_usart_srxl_flexi_cfg
= {
1017 .remap
= GPIO_AF_USART3
,
1019 .USART_BaudRate
= 115200,
1020 .USART_WordLength
= USART_WordLength_8b
,
1021 .USART_Parity
= USART_Parity_No
,
1022 .USART_StopBits
= USART_StopBits_1
,
1023 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1024 .USART_Mode
= USART_Mode_Rx
,
1028 .NVIC_IRQChannel
= USART3_IRQn
,
1029 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1030 .NVIC_IRQChannelSubPriority
= 0,
1031 .NVIC_IRQChannelCmd
= ENABLE
,
1037 .GPIO_Pin
= GPIO_Pin_11
,
1038 .GPIO_Speed
= GPIO_Speed_2MHz
,
1039 .GPIO_Mode
= GPIO_Mode_AF
,
1040 .GPIO_OType
= GPIO_OType_PP
,
1041 .GPIO_PuPd
= GPIO_PuPd_UP
1047 .GPIO_Pin
= GPIO_Pin_10
,
1048 .GPIO_Speed
= GPIO_Speed_2MHz
,
1049 .GPIO_Mode
= GPIO_Mode_OUT
,
1050 .GPIO_OType
= GPIO_OType_PP
,
1051 .GPIO_PuPd
= GPIO_PuPd_UP
1056 #endif /* PIOS_INCLUDE_SRXL */
1060 static const struct pios_usart_cfg pios_usart_hkosd_main_cfg
= {
1062 .remap
= GPIO_AF_USART1
,
1064 .USART_BaudRate
= 57600,
1065 .USART_WordLength
= USART_WordLength_8b
,
1066 .USART_Parity
= USART_Parity_No
,
1067 .USART_StopBits
= USART_StopBits_1
,
1068 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1069 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
1073 .NVIC_IRQChannel
= USART1_IRQn
,
1074 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1075 .NVIC_IRQChannelSubPriority
= 0,
1076 .NVIC_IRQChannelCmd
= ENABLE
,
1082 .GPIO_Pin
= GPIO_Pin_10
,
1083 .GPIO_Speed
= GPIO_Speed_2MHz
,
1084 .GPIO_Mode
= GPIO_Mode_AF
,
1085 .GPIO_OType
= GPIO_OType_PP
,
1086 .GPIO_PuPd
= GPIO_PuPd_UP
1092 .GPIO_Pin
= GPIO_Pin_9
,
1093 .GPIO_Speed
= GPIO_Speed_2MHz
,
1094 .GPIO_Mode
= GPIO_Mode_AF
,
1095 .GPIO_OType
= GPIO_OType_PP
,
1096 .GPIO_PuPd
= GPIO_PuPd_UP
1101 static const struct pios_usart_cfg pios_usart_hkosd_flexi_cfg
= {
1103 .remap
= GPIO_AF_USART3
,
1105 .USART_BaudRate
= 57600,
1106 .USART_WordLength
= USART_WordLength_8b
,
1107 .USART_Parity
= USART_Parity_No
,
1108 .USART_StopBits
= USART_StopBits_1
,
1109 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1110 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
1114 .NVIC_IRQChannel
= USART3_IRQn
,
1115 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1116 .NVIC_IRQChannelSubPriority
= 0,
1117 .NVIC_IRQChannelCmd
= ENABLE
,
1123 .GPIO_Pin
= GPIO_Pin_11
,
1124 .GPIO_Speed
= GPIO_Speed_2MHz
,
1125 .GPIO_Mode
= GPIO_Mode_AF
,
1126 .GPIO_OType
= GPIO_OType_PP
,
1127 .GPIO_PuPd
= GPIO_PuPd_UP
1133 .GPIO_Pin
= GPIO_Pin_10
,
1134 .GPIO_Speed
= GPIO_Speed_2MHz
,
1135 .GPIO_Mode
= GPIO_Mode_AF
,
1136 .GPIO_OType
= GPIO_OType_PP
,
1137 .GPIO_PuPd
= GPIO_PuPd_UP
1142 static const struct pios_usart_cfg pios_usart_rcvrport_cfg
= {
1144 .remap
= GPIO_AF_USART6
,
1146 .USART_BaudRate
= 57600,
1147 .USART_WordLength
= USART_WordLength_8b
,
1148 .USART_Parity
= USART_Parity_No
,
1149 .USART_StopBits
= USART_StopBits_1
,
1150 .USART_HardwareFlowControl
= USART_HardwareFlowControl_None
,
1151 .USART_Mode
= USART_Mode_Rx
| USART_Mode_Tx
,
1155 .NVIC_IRQChannel
= USART6_IRQn
,
1156 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1157 .NVIC_IRQChannelSubPriority
= 0,
1158 .NVIC_IRQChannelCmd
= ENABLE
,
1166 .GPIO_Pin
= GPIO_Pin_8
,
1167 .GPIO_Speed
= GPIO_Speed_25MHz
,
1168 .GPIO_Mode
= GPIO_Mode_OUT
,
1169 .GPIO_OType
= GPIO_OType_PP
,
1174 // * 7: PC6 = TIM8 CH1, USART6 TX
1177 .GPIO_Pin
= GPIO_Pin_6
,
1178 .GPIO_Speed
= GPIO_Speed_2MHz
,
1179 .GPIO_Mode
= GPIO_Mode_AF
,
1180 .GPIO_OType
= GPIO_OType_PP
,
1181 .GPIO_PuPd
= GPIO_PuPd_UP
1183 .pin_source
= GPIO_PinSource6
,
1187 // * 8: PC7 = TIM8 CH2, USART6 RX
1190 .GPIO_Pin
= GPIO_Pin_7
,
1191 .GPIO_Speed
= GPIO_Speed_2MHz
,
1192 .GPIO_Mode
= GPIO_Mode_AF
,
1193 .GPIO_OType
= GPIO_OType_PP
,
1194 .GPIO_PuPd
= GPIO_PuPd_UP
1196 .pin_source
= GPIO_PinSource7
,
1200 #if defined(PIOS_INCLUDE_COM)
1202 #include <pios_com_priv.h>
1204 #endif /* PIOS_INCLUDE_COM */
1206 #if defined(PIOS_INCLUDE_I2C)
1208 #include <pios_i2c_priv.h>
1213 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void);
1214 void PIOS_I2C_mag_pressureadapter_er_irq_handler(void);
1215 void I2C1_EV_IRQHandler()
1216 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_ev_irq_handler")));
1217 void I2C1_ER_IRQHandler()
1218 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler")));
1220 static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg
= {
1222 .remapSCL
= GPIO_AF_I2C1
,
1223 .remapSDA
= GPIO_AF_I2C1
,
1225 .I2C_Mode
= I2C_Mode_I2C
,
1226 .I2C_OwnAddress1
= 0,
1227 .I2C_Ack
= I2C_Ack_Enable
,
1228 .I2C_AcknowledgedAddress
= I2C_AcknowledgedAddress_7bit
,
1229 .I2C_DutyCycle
= I2C_DutyCycle_2
,
1230 .I2C_ClockSpeed
= 400000, /* bits/s */
1232 .transfer_timeout_ms
= 50,
1236 .GPIO_Pin
= GPIO_Pin_8
,
1237 .GPIO_Mode
= GPIO_Mode_AF
,
1238 .GPIO_Speed
= GPIO_Speed_50MHz
,
1239 .GPIO_OType
= GPIO_OType_OD
,
1240 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
1246 .GPIO_Pin
= GPIO_Pin_9
,
1247 .GPIO_Mode
= GPIO_Mode_AF
,
1248 .GPIO_Speed
= GPIO_Speed_50MHz
,
1249 .GPIO_OType
= GPIO_OType_OD
,
1250 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
1254 .flags
= 0, /* FIXME: check this */
1256 .NVIC_IRQChannel
= I2C1_EV_IRQn
,
1257 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1258 .NVIC_IRQChannelSubPriority
= 0,
1259 .NVIC_IRQChannelCmd
= ENABLE
,
1263 .flags
= 0, /* FIXME: check this */
1265 .NVIC_IRQChannel
= I2C1_ER_IRQn
,
1266 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1267 .NVIC_IRQChannelSubPriority
= 0,
1268 .NVIC_IRQChannelCmd
= ENABLE
,
1273 uint32_t pios_i2c_mag_pressure_adapter_id
;
1274 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void)
1276 /* Call into the generic code to handle the IRQ for this specific device */
1277 PIOS_I2C_EV_IRQ_Handler(pios_i2c_mag_pressure_adapter_id
);
1280 void PIOS_I2C_mag_pressure_adapter_er_irq_handler(void)
1282 /* Call into the generic code to handle the IRQ for this specific device */
1283 PIOS_I2C_ER_IRQ_Handler(pios_i2c_mag_pressure_adapter_id
);
1287 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void);
1288 void PIOS_I2C_flexiport_adapter_er_irq_handler(void);
1289 void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_irq_handler")));
1290 void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler")));
1292 static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg
= {
1294 .remapSCL
= GPIO_AF_I2C2
,
1295 .remapSDA
= GPIO_AF_I2C2
,
1297 .I2C_Mode
= I2C_Mode_I2C
,
1298 .I2C_OwnAddress1
= 0,
1299 .I2C_Ack
= I2C_Ack_Enable
,
1300 .I2C_AcknowledgedAddress
= I2C_AcknowledgedAddress_7bit
,
1301 .I2C_DutyCycle
= I2C_DutyCycle_2
,
1302 .I2C_ClockSpeed
= 400000, /* bits/s */
1304 .transfer_timeout_ms
= 50,
1308 .GPIO_Pin
= GPIO_Pin_10
,
1309 .GPIO_Mode
= GPIO_Mode_AF
,
1310 .GPIO_Speed
= GPIO_Speed_50MHz
,
1311 .GPIO_OType
= GPIO_OType_OD
,
1312 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
1318 .GPIO_Pin
= GPIO_Pin_11
,
1319 .GPIO_Mode
= GPIO_Mode_AF
,
1320 .GPIO_Speed
= GPIO_Speed_50MHz
,
1321 .GPIO_OType
= GPIO_OType_OD
,
1322 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
1326 .flags
= 0, /* FIXME: check this */
1328 .NVIC_IRQChannel
= I2C2_EV_IRQn
,
1329 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1330 .NVIC_IRQChannelSubPriority
= 0,
1331 .NVIC_IRQChannelCmd
= ENABLE
,
1335 .flags
= 0, /* FIXME: check this */
1337 .NVIC_IRQChannel
= I2C2_ER_IRQn
,
1338 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
1339 .NVIC_IRQChannelSubPriority
= 0,
1340 .NVIC_IRQChannelCmd
= ENABLE
,
1345 uint32_t pios_i2c_flexiport_adapter_id
;
1346 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void)
1348 /* Call into the generic code to handle the IRQ for this specific device */
1349 PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexiport_adapter_id
);
1352 void PIOS_I2C_flexiport_adapter_er_irq_handler(void)
1354 /* Call into the generic code to handle the IRQ for this specific device */
1355 PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexiport_adapter_id
);
1359 void PIOS_I2C_pressure_adapter_ev_irq_handler(void);
1360 void PIOS_I2C_pressure_adapter_er_irq_handler(void);
1362 #endif /* PIOS_INCLUDE_I2C */
1364 #if defined(PIOS_INCLUDE_RTC)
1366 * Realtime Clock (RTC)
1368 #include <pios_rtc_priv.h>
1370 void PIOS_RTC_IRQ_Handler(void);
1371 void RTC_WKUP_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
1372 static const struct pios_rtc_cfg pios_rtc_main_cfg
= {
1373 .clksrc
= RCC_RTCCLKSource_HSE_Div8
, // Divide 8 Mhz crystal down to 1
1374 // For some reason it's acting like crystal is 16 Mhz. This clock is then divided
1375 // by another 16 to give a nominal 62.5 khz clock
1376 .prescaler
= 100, // Every 100 cycles gives 625 Hz
1379 .NVIC_IRQChannel
= RTC_WKUP_IRQn
,
1380 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1381 .NVIC_IRQChannelSubPriority
= 0,
1382 .NVIC_IRQChannelCmd
= ENABLE
,
1387 void PIOS_RTC_IRQ_Handler(void)
1389 PIOS_RTC_irq_handler();
1392 #endif /* if defined(PIOS_INCLUDE_RTC) */
1394 #include "pios_tim_priv.h"
1396 static const TIM_TimeBaseInitTypeDef tim_3_5_time_base
= {
1397 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB1_CLOCK
/ 1000000) - 1,
1398 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1399 .TIM_CounterMode
= TIM_CounterMode_Up
,
1400 .TIM_Period
= ((1000000 / PIOS_SERVO_UPDATE_HZ
) - 1),
1401 .TIM_RepetitionCounter
= 0x0000,
1403 static const TIM_TimeBaseInitTypeDef tim_9_10_11_time_base
= {
1404 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB2_CLOCK
/ 1000000) - 1,
1405 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1406 .TIM_CounterMode
= TIM_CounterMode_Up
,
1407 .TIM_Period
= ((1000000 / PIOS_SERVO_UPDATE_HZ
) - 1),
1408 .TIM_RepetitionCounter
= 0x0000,
1411 static const struct pios_tim_clock_cfg tim_3_cfg
= {
1413 .time_base_init
= &tim_3_5_time_base
,
1416 .NVIC_IRQChannel
= TIM3_IRQn
,
1417 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1418 .NVIC_IRQChannelSubPriority
= 0,
1419 .NVIC_IRQChannelCmd
= ENABLE
,
1424 static const struct pios_tim_clock_cfg tim_5_cfg
= {
1426 .time_base_init
= &tim_3_5_time_base
,
1429 .NVIC_IRQChannel
= TIM5_IRQn
,
1430 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1431 .NVIC_IRQChannelSubPriority
= 0,
1432 .NVIC_IRQChannelCmd
= ENABLE
,
1437 static const struct pios_tim_clock_cfg tim_9_cfg
= {
1439 .time_base_init
= &tim_9_10_11_time_base
,
1442 .NVIC_IRQChannel
= TIM1_BRK_TIM9_IRQn
,
1443 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1444 .NVIC_IRQChannelSubPriority
= 0,
1445 .NVIC_IRQChannelCmd
= ENABLE
,
1450 static const struct pios_tim_clock_cfg tim_10_cfg
= {
1452 .time_base_init
= &tim_9_10_11_time_base
,
1455 .NVIC_IRQChannel
= TIM1_UP_TIM10_IRQn
,
1456 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1457 .NVIC_IRQChannelSubPriority
= 0,
1458 .NVIC_IRQChannelCmd
= ENABLE
,
1463 static const struct pios_tim_clock_cfg tim_11_cfg
= {
1465 .time_base_init
= &tim_9_10_11_time_base
,
1468 .NVIC_IRQChannel
= TIM1_TRG_COM_TIM11_IRQn
,
1469 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1470 .NVIC_IRQChannelSubPriority
= 0,
1471 .NVIC_IRQChannelCmd
= ENABLE
,
1476 // Set up timers that only have inputs on APB1
1477 // TIM2,3,4,5,6,7,12,13,14
1478 static const TIM_TimeBaseInitTypeDef tim_apb1_time_base
= {
1479 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB1_CLOCK
/ 1000000) - 1,
1480 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1481 .TIM_CounterMode
= TIM_CounterMode_Up
,
1482 .TIM_Period
= 0xFFFF,
1483 .TIM_RepetitionCounter
= 0x0000,
1487 // Set up timers that only have inputs on APB2
1489 static const TIM_TimeBaseInitTypeDef tim_apb2_time_base
= {
1490 .TIM_Prescaler
= (PIOS_PERIPHERAL_APB2_CLOCK
/ 1000000) - 1,
1491 .TIM_ClockDivision
= TIM_CKD_DIV1
,
1492 .TIM_CounterMode
= TIM_CounterMode_Up
,
1493 .TIM_Period
= 0xFFFF,
1494 .TIM_RepetitionCounter
= 0x0000,
1497 static const struct pios_tim_clock_cfg tim_1_cfg
= {
1499 .time_base_init
= &tim_apb2_time_base
,
1502 .NVIC_IRQChannel
= TIM1_CC_IRQn
,
1503 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1504 .NVIC_IRQChannelSubPriority
= 0,
1505 .NVIC_IRQChannelCmd
= ENABLE
,
1510 static const struct pios_tim_clock_cfg tim_4_cfg
= {
1512 .time_base_init
= &tim_apb1_time_base
,
1515 .NVIC_IRQChannel
= TIM4_IRQn
,
1516 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1517 .NVIC_IRQChannelSubPriority
= 0,
1518 .NVIC_IRQChannelCmd
= ENABLE
,
1522 static const struct pios_tim_clock_cfg tim_8_cfg
= {
1524 .time_base_init
= &tim_apb2_time_base
,
1527 .NVIC_IRQChannel
= TIM8_CC_IRQn
,
1528 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1529 .NVIC_IRQChannelSubPriority
= 0,
1530 .NVIC_IRQChannelCmd
= ENABLE
,
1535 static const struct pios_tim_clock_cfg tim_12_cfg
= {
1537 .time_base_init
= &tim_apb1_time_base
,
1540 .NVIC_IRQChannel
= TIM8_BRK_TIM12_IRQn
,
1541 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
1542 .NVIC_IRQChannelSubPriority
= 0,
1543 .NVIC_IRQChannelCmd
= ENABLE
,
1550 * Pios servo configuration structures
1551 * Using TIM3, TIM9, TIM2, TIM5
1553 #include <pios_servo_priv.h>
1554 static const struct pios_tim_channel pios_tim_servoport_all_pins
[] = {
1557 .timer_chan
= TIM_Channel_3
,
1561 .GPIO_Pin
= GPIO_Pin_0
,
1562 .GPIO_Speed
= GPIO_Speed_2MHz
,
1563 .GPIO_Mode
= GPIO_Mode_AF
,
1564 .GPIO_OType
= GPIO_OType_PP
,
1565 .GPIO_PuPd
= GPIO_PuPd_UP
1567 .pin_source
= GPIO_PinSource0
,
1569 .remap
= GPIO_AF_TIM3
,
1573 .timer_chan
= TIM_Channel_4
,
1577 .GPIO_Pin
= GPIO_Pin_1
,
1578 .GPIO_Speed
= GPIO_Speed_2MHz
,
1579 .GPIO_Mode
= GPIO_Mode_AF
,
1580 .GPIO_OType
= GPIO_OType_PP
,
1581 .GPIO_PuPd
= GPIO_PuPd_UP
1583 .pin_source
= GPIO_PinSource1
,
1585 .remap
= GPIO_AF_TIM3
,
1589 .timer_chan
= TIM_Channel_2
,
1593 .GPIO_Pin
= GPIO_Pin_3
,
1594 .GPIO_Speed
= GPIO_Speed_2MHz
,
1595 .GPIO_Mode
= GPIO_Mode_AF
,
1596 .GPIO_OType
= GPIO_OType_PP
,
1597 .GPIO_PuPd
= GPIO_PuPd_UP
1599 .pin_source
= GPIO_PinSource3
,
1601 .remap
= GPIO_AF_TIM9
,
1605 .timer_chan
= TIM_Channel_3
,
1609 .GPIO_Pin
= GPIO_Pin_2
,
1610 .GPIO_Speed
= GPIO_Speed_2MHz
,
1611 .GPIO_Mode
= GPIO_Mode_AF
,
1612 .GPIO_OType
= GPIO_OType_PP
,
1613 .GPIO_PuPd
= GPIO_PuPd_UP
1615 .pin_source
= GPIO_PinSource2
,
1617 .remap
= GPIO_AF_TIM2
,
1621 .timer_chan
= TIM_Channel_2
,
1625 .GPIO_Pin
= GPIO_Pin_1
,
1626 .GPIO_Speed
= GPIO_Speed_2MHz
,
1627 .GPIO_Mode
= GPIO_Mode_AF
,
1628 .GPIO_OType
= GPIO_OType_PP
,
1629 .GPIO_PuPd
= GPIO_PuPd_UP
1631 .pin_source
= GPIO_PinSource1
,
1633 .remap
= GPIO_AF_TIM5
,
1637 .timer_chan
= TIM_Channel_1
,
1641 .GPIO_Pin
= GPIO_Pin_0
,
1642 .GPIO_Speed
= GPIO_Speed_2MHz
,
1643 .GPIO_Mode
= GPIO_Mode_AF
,
1644 .GPIO_OType
= GPIO_OType_PP
,
1645 .GPIO_PuPd
= GPIO_PuPd_UP
1647 .pin_source
= GPIO_PinSource0
,
1649 .remap
= GPIO_AF_TIM5
,
1651 // PWM pins on FlexiIO(receiver) port
1653 // * 6: PB15 = SPI2 MOSI, TIM12 CH2
1656 .timer_chan
= TIM_Channel_2
,
1660 .GPIO_Pin
= GPIO_Pin_15
,
1661 .GPIO_Speed
= GPIO_Speed_2MHz
,
1662 .GPIO_Mode
= GPIO_Mode_AF
,
1663 .GPIO_OType
= GPIO_OType_PP
,
1664 .GPIO_PuPd
= GPIO_PuPd_UP
1666 .pin_source
= GPIO_PinSource15
,
1668 .remap
= GPIO_AF_TIM12
,
1671 // * 7: PC6 = TIM8 CH1, USART6 TX
1673 .timer_chan
= TIM_Channel_1
,
1677 .GPIO_Pin
= GPIO_Pin_6
,
1678 .GPIO_Speed
= GPIO_Speed_2MHz
,
1679 .GPIO_Mode
= GPIO_Mode_AF
,
1680 .GPIO_OType
= GPIO_OType_PP
,
1681 .GPIO_PuPd
= GPIO_PuPd_UP
1683 .pin_source
= GPIO_PinSource6
,
1685 .remap
= GPIO_AF_TIM8
,
1689 // * 8: PC7 = TIM8 CH2, USART6 RX
1691 .timer_chan
= TIM_Channel_2
,
1695 .GPIO_Pin
= GPIO_Pin_7
,
1696 .GPIO_Speed
= GPIO_Speed_2MHz
,
1697 .GPIO_Mode
= GPIO_Mode_AF
,
1698 .GPIO_OType
= GPIO_OType_PP
,
1699 .GPIO_PuPd
= GPIO_PuPd_UP
1701 .pin_source
= GPIO_PinSource7
,
1703 .remap
= GPIO_AF_TIM8
,
1707 // * 9: PC8 = TIM8 CH3
1709 .timer_chan
= TIM_Channel_3
,
1713 .GPIO_Pin
= GPIO_Pin_8
,
1714 .GPIO_Speed
= GPIO_Speed_2MHz
,
1715 .GPIO_Mode
= GPIO_Mode_AF
,
1716 .GPIO_OType
= GPIO_OType_PP
,
1717 .GPIO_PuPd
= GPIO_PuPd_UP
1719 .pin_source
= GPIO_PinSource8
,
1721 .remap
= GPIO_AF_TIM8
,
1725 // * 10: PC9 = TIM8 CH4
1727 .timer_chan
= TIM_Channel_4
,
1731 .GPIO_Pin
= GPIO_Pin_9
,
1732 .GPIO_Speed
= GPIO_Speed_2MHz
,
1733 .GPIO_Mode
= GPIO_Mode_AF
,
1734 .GPIO_OType
= GPIO_OType_PP
,
1735 .GPIO_PuPd
= GPIO_PuPd_UP
1737 .pin_source
= GPIO_PinSource9
,
1739 .remap
= GPIO_AF_TIM8
,
1743 // * 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
1745 .timer_chan
= TIM_Channel_1
,
1749 .GPIO_Pin
= GPIO_Pin_14
,
1750 .GPIO_Speed
= GPIO_Speed_2MHz
,
1751 .GPIO_Mode
= GPIO_Mode_AF
,
1752 .GPIO_OType
= GPIO_OType_PP
,
1753 .GPIO_PuPd
= GPIO_PuPd_UP
1755 .pin_source
= GPIO_PinSource14
,
1757 .remap
= GPIO_AF_TIM12
,
1760 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT 6
1761 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM 11
1762 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN 12
1764 const struct pios_servo_cfg pios_servo_cfg_out
= {
1766 .TIM_OCMode
= TIM_OCMode_PWM1
,
1767 .TIM_OutputState
= TIM_OutputState_Enable
,
1768 .TIM_OutputNState
= TIM_OutputNState_Disable
,
1769 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
1770 .TIM_OCPolarity
= TIM_OCPolarity_High
,
1771 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
1772 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
1773 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
1775 .channels
= pios_tim_servoport_all_pins
,
1776 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT
,
1778 // All servo outputs, servo input ch1 ppm, ch2-6 outputs
1779 const struct pios_servo_cfg pios_servo_cfg_out_in_ppm
= {
1781 .TIM_OCMode
= TIM_OCMode_PWM1
,
1782 .TIM_OutputState
= TIM_OutputState_Enable
,
1783 .TIM_OutputNState
= TIM_OutputNState_Disable
,
1784 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
1785 .TIM_OCPolarity
= TIM_OCPolarity_High
,
1786 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
1787 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
1788 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
1790 .channels
= pios_tim_servoport_all_pins
,
1791 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM
,
1793 // All servo outputs, servo inputs ch1-6 Outputs
1794 const struct pios_servo_cfg pios_servo_cfg_out_in
= {
1796 .TIM_OCMode
= TIM_OCMode_PWM1
,
1797 .TIM_OutputState
= TIM_OutputState_Enable
,
1798 .TIM_OutputNState
= TIM_OutputNState_Disable
,
1799 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
1800 .TIM_OCPolarity
= TIM_OCPolarity_High
,
1801 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
1802 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
1803 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
1805 .channels
= pios_tim_servoport_all_pins
,
1806 .num_channels
= PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN
,
1814 #if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM)
1815 #include <pios_pwm_priv.h>
1816 static const struct pios_tim_channel pios_tim_rcvrport_all_channels
[] = {
1819 .timer_chan
= TIM_Channel_1
,
1823 .GPIO_Pin
= GPIO_Pin_14
,
1824 .GPIO_Speed
= GPIO_Speed_2MHz
,
1825 .GPIO_Mode
= GPIO_Mode_AF
,
1826 .GPIO_OType
= GPIO_OType_PP
,
1827 .GPIO_PuPd
= GPIO_PuPd_UP
1829 .pin_source
= GPIO_PinSource14
,
1831 .remap
= GPIO_AF_TIM12
,
1835 .timer_chan
= TIM_Channel_2
,
1839 .GPIO_Pin
= GPIO_Pin_15
,
1840 .GPIO_Speed
= GPIO_Speed_2MHz
,
1841 .GPIO_Mode
= GPIO_Mode_AF
,
1842 .GPIO_OType
= GPIO_OType_PP
,
1843 .GPIO_PuPd
= GPIO_PuPd_UP
1845 .pin_source
= GPIO_PinSource15
,
1847 .remap
= GPIO_AF_TIM12
,
1851 .timer_chan
= TIM_Channel_1
,
1855 .GPIO_Pin
= GPIO_Pin_6
,
1856 .GPIO_Speed
= GPIO_Speed_2MHz
,
1857 .GPIO_Mode
= GPIO_Mode_AF
,
1858 .GPIO_OType
= GPIO_OType_PP
,
1859 .GPIO_PuPd
= GPIO_PuPd_UP
1861 .pin_source
= GPIO_PinSource6
,
1863 .remap
= GPIO_AF_TIM8
,
1867 .timer_chan
= TIM_Channel_2
,
1871 .GPIO_Pin
= GPIO_Pin_7
,
1872 .GPIO_Speed
= GPIO_Speed_2MHz
,
1873 .GPIO_Mode
= GPIO_Mode_AF
,
1874 .GPIO_OType
= GPIO_OType_PP
,
1875 .GPIO_PuPd
= GPIO_PuPd_UP
1877 .pin_source
= GPIO_PinSource7
,
1879 .remap
= GPIO_AF_TIM8
,
1883 .timer_chan
= TIM_Channel_3
,
1887 .GPIO_Pin
= GPIO_Pin_8
,
1888 .GPIO_Speed
= GPIO_Speed_2MHz
,
1889 .GPIO_Mode
= GPIO_Mode_AF
,
1890 .GPIO_OType
= GPIO_OType_PP
,
1891 .GPIO_PuPd
= GPIO_PuPd_UP
1893 .pin_source
= GPIO_PinSource8
,
1895 .remap
= GPIO_AF_TIM8
,
1899 .timer_chan
= TIM_Channel_4
,
1903 .GPIO_Pin
= GPIO_Pin_9
,
1904 .GPIO_Speed
= GPIO_Speed_2MHz
,
1905 .GPIO_Mode
= GPIO_Mode_AF
,
1906 .GPIO_OType
= GPIO_OType_PP
,
1907 .GPIO_PuPd
= GPIO_PuPd_UP
1909 .pin_source
= GPIO_PinSource9
,
1911 .remap
= GPIO_AF_TIM8
,
1915 const struct pios_pwm_cfg pios_pwm_cfg
= {
1917 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
1918 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
1919 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
1920 .TIM_ICFilter
= 0x0,
1922 .channels
= pios_tim_rcvrport_all_channels
,
1923 .num_channels
= NELEMENTS(pios_tim_rcvrport_all_channels
),
1925 // this configures outputs 2-6 as pwm inputs
1926 const struct pios_pwm_cfg pios_pwm_ppm_cfg
= {
1928 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
1929 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
1930 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
1931 .TIM_ICFilter
= 0x0,
1933 .channels
= &pios_tim_rcvrport_all_channels
[1],
1934 .num_channels
= NELEMENTS(pios_tim_rcvrport_all_channels
) - 1,
1937 #endif /* if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM) */
1942 #if defined(PIOS_INCLUDE_PPM)
1943 #include <pios_ppm_priv.h>
1944 static const struct pios_ppm_cfg pios_ppm_cfg
= {
1946 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
1947 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
1948 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
1949 .TIM_ICFilter
= 0x0,
1950 .TIM_Channel
= TIM_Channel_1
,
1952 /* Use only the first channel for ppm */
1953 .channels
= &pios_tim_rcvrport_all_channels
[0],
1959 #if defined(PIOS_INCLUDE_GCSRCVR)
1960 #include "pios_gcsrcvr_priv.h"
1961 #endif /* PIOS_INCLUDE_GCSRCVR */
1963 #if defined(PIOS_INCLUDE_RCVR)
1964 #include "pios_rcvr_priv.h"
1965 #endif /* PIOS_INCLUDE_RCVR */
1967 #if defined(PIOS_INCLUDE_USB)
1968 #include "pios_usb_priv.h"
1970 static const struct pios_usb_cfg pios_usb_main_rm1_cfg
= {
1973 .NVIC_IRQChannel
= OTG_FS_IRQn
,
1974 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1975 .NVIC_IRQChannelSubPriority
= 0, // PriorityGroup=4
1976 .NVIC_IRQChannelCmd
= ENABLE
,
1982 .GPIO_Pin
= GPIO_Pin_13
,
1983 .GPIO_Speed
= GPIO_Speed_25MHz
,
1984 .GPIO_Mode
= GPIO_Mode_IN
,
1985 .GPIO_OType
= GPIO_OType_OD
,
1988 .vsense_active_low
= false
1991 static const struct pios_usb_cfg pios_usb_main_rm2_cfg
= {
1994 .NVIC_IRQChannel
= OTG_FS_IRQn
,
1995 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
1996 .NVIC_IRQChannelSubPriority
= 0, // PriorityGroup=4
1997 .NVIC_IRQChannelCmd
= ENABLE
,
2003 .GPIO_Pin
= GPIO_Pin_5
,
2004 .GPIO_Speed
= GPIO_Speed_25MHz
,
2005 .GPIO_Mode
= GPIO_Mode_IN
,
2006 .GPIO_OType
= GPIO_OType_OD
,
2009 .vsense_active_low
= false
2012 const struct pios_usb_cfg
*PIOS_BOARD_HW_DEFS_GetUsbCfg(uint32_t board_revision
)
2014 switch (board_revision
) {
2016 return &pios_usb_main_rm1_cfg
;
2020 return &pios_usb_main_rm2_cfg
;
2024 PIOS_DEBUG_Assert(0);
2029 #include "pios_usb_board_data_priv.h"
2030 #include "pios_usb_desc_hid_cdc_priv.h"
2031 #include "pios_usb_desc_hid_only_priv.h"
2032 #include "pios_usbhook.h"
2034 #endif /* PIOS_INCLUDE_USB */
2036 #if defined(PIOS_INCLUDE_COM_MSG)
2038 #include <pios_com_msg_priv.h>
2040 #endif /* PIOS_INCLUDE_COM_MSG */
2042 #if defined(PIOS_INCLUDE_USB_HID) && !defined(PIOS_INCLUDE_USB_CDC)
2043 #include <pios_usb_hid_priv.h>
2045 const struct pios_usb_hid_cfg pios_usb_hid_cfg
= {
2050 #endif /* PIOS_INCLUDE_USB_HID && !PIOS_INCLUDE_USB_CDC */
2052 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_USB_CDC)
2053 #include <pios_usb_cdc_priv.h>
2055 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg
= {
2064 #include <pios_usb_hid_priv.h>
2066 const struct pios_usb_hid_cfg pios_usb_hid_cfg
= {
2071 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
2073 #ifdef PIOS_INCLUDE_WS2811
2074 #include <pios_ws2811_cfg.h>
2075 #include <hwsettings.h>
2076 #define PIOS_WS2811_TIM_DIVIDER (PIOS_PERIPHERAL_APB2_CLOCK / (800000 * PIOS_WS2811_TIM_PERIOD))
2078 void DMA2_Stream1_IRQHandler(void) __attribute__((alias("PIOS_WS2811_irq_handler")));
2079 // list of pin configurable as ws281x outputs.
2080 // this will not clash with PWM in or servo output as
2081 // pins will be reconfigured as _OUT so the alternate function is disabled.
2082 const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg
[] = {
2083 [HWSETTINGS_WS2811LED_OUT_SERVOOUT1
] = {
2086 .GPIO_Pin
= GPIO_Pin_0
,
2087 .GPIO_Speed
= GPIO_Speed_25MHz
,
2088 .GPIO_Mode
= GPIO_Mode_OUT
,
2089 .GPIO_OType
= GPIO_OType_PP
,
2092 [HWSETTINGS_WS2811LED_OUT_SERVOOUT2
] = {
2095 .GPIO_Pin
= GPIO_Pin_1
,
2096 .GPIO_Speed
= GPIO_Speed_25MHz
,
2097 .GPIO_Mode
= GPIO_Mode_OUT
,
2098 .GPIO_OType
= GPIO_OType_PP
,
2101 [HWSETTINGS_WS2811LED_OUT_SERVOOUT3
] = {
2104 .GPIO_Pin
= GPIO_Pin_3
,
2105 .GPIO_Speed
= GPIO_Speed_25MHz
,
2106 .GPIO_Mode
= GPIO_Mode_OUT
,
2107 .GPIO_OType
= GPIO_OType_PP
,
2110 [HWSETTINGS_WS2811LED_OUT_SERVOOUT4
] = {
2113 .GPIO_Pin
= GPIO_Pin_2
,
2114 .GPIO_Speed
= GPIO_Speed_25MHz
,
2115 .GPIO_Mode
= GPIO_Mode_OUT
,
2116 .GPIO_OType
= GPIO_OType_PP
,
2119 [HWSETTINGS_WS2811LED_OUT_SERVOOUT5
] = {
2122 .GPIO_Pin
= GPIO_Pin_1
,
2123 .GPIO_Speed
= GPIO_Speed_25MHz
,
2124 .GPIO_Mode
= GPIO_Mode_OUT
,
2125 .GPIO_OType
= GPIO_OType_PP
,
2128 [HWSETTINGS_WS2811LED_OUT_SERVOOUT6
] = {
2131 .GPIO_Pin
= GPIO_Pin_0
,
2132 .GPIO_Speed
= GPIO_Speed_25MHz
,
2133 .GPIO_Mode
= GPIO_Mode_OUT
,
2134 .GPIO_OType
= GPIO_OType_PP
,
2137 [HWSETTINGS_WS2811LED_OUT_FLEXIIOPIN3
] = {
2140 .GPIO_Pin
= GPIO_Pin_12
,
2141 .GPIO_Speed
= GPIO_Speed_25MHz
,
2142 .GPIO_Mode
= GPIO_Mode_OUT
,
2143 .GPIO_OType
= GPIO_OType_PP
,
2146 [HWSETTINGS_WS2811LED_OUT_FLEXIIOPIN4
] = {
2149 .GPIO_Pin
= GPIO_Pin_13
,
2150 .GPIO_Speed
= GPIO_Speed_25MHz
,
2151 .GPIO_Mode
= GPIO_Mode_OUT
,
2152 .GPIO_OType
= GPIO_OType_PP
,
2157 const struct pios_ws2811_cfg pios_ws2811_cfg
= {
2160 .TIM_Prescaler
= PIOS_WS2811_TIM_DIVIDER
- 1,
2161 .TIM_ClockDivision
= TIM_CKD_DIV1
,
2162 .TIM_CounterMode
= TIM_CounterMode_Up
,
2163 // period (1.25 uS per period
2164 .TIM_Period
= PIOS_WS2811_TIM_PERIOD
,
2165 .TIM_RepetitionCounter
= 0x0000,
2169 .streamCh1
= DMA2_Stream1
,
2171 .streamCh2
= DMA2_Stream6
,
2172 .streamUpdate
= DMA2_Stream5
,
2174 // DMA streamCh1, triggered by timerCh1 pwm signal.
2175 // if FrameBuffer indicates, reset output value early to indicate "0" bit to ws2812
2176 .dmaInitCh1
= PIOS_WS2811_DMA_CH1_CONFIG(DMA_Channel_6
),
2177 .dmaItCh1
= DMA_IT_TEIF1
| DMA_IT_TCIF1
,
2179 // DMA streamCh2, triggered by timerCh2 pwm signal.
2180 // Reset output value late to indicate "1" bit to ws2812.
2181 .dmaInitCh2
= PIOS_WS2811_DMA_CH2_CONFIG(DMA_Channel_6
),
2182 .dmaItCh2
= DMA_IT_TEIF6
| DMA_IT_TCIF6
,
2184 // DMA streamUpdate Triggered by timer update event
2185 // Outputs a high logic level at beginning of a cycle
2186 .dmaInitUpdate
= PIOS_WS2811_DMA_UPDATE_CONFIG(DMA_Channel_6
),
2187 .dmaItUpdate
= DMA_IT_TEIF5
| DMA_IT_TCIF5
,
2188 .dmaSource
= TIM_DMA_CC1
| TIM_DMA_CC3
| TIM_DMA_Update
,
2190 // DMAInitCh1 interrupt vector, used to block timer at end of framebuffer transfer
2192 .flags
= (DMA_IT_TCIF1
),
2194 .NVIC_IRQChannel
= DMA2_Stream1_IRQn
,
2195 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGHEST
,
2196 .NVIC_IRQChannelSubPriority
= 0,
2197 .NVIC_IRQChannelCmd
= ENABLE
,
2202 void PIOS_WS2811_irq_handler(void)
2204 PIOS_WS2811_DMA_irq_handler();
2206 #endif // PIOS_INCLUDE_WS2811