Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / targets / boards / ccf3d / board_hw_defs.c
blob4061f9cdd1511036128bbe0737a85e94985fb2f6
1 /**
2 ******************************************************************************
3 * @file board_hw_defs.c
4 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
5 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012
8 * @addtogroup OpenPilotSystem OpenPilot System
9 * @{
10 * @addtogroup OpenPilotCore OpenPilot Core
11 * @{
12 * @brief Defines board specific static initializers for hardware for the CCF3D board.
13 *****************************************************************************/
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #if defined(PIOS_INCLUDE_LED)
32 #include <pios_led_priv.h>
34 static const struct pios_gpio pios_leds_cc3d[] = {
35 [PIOS_LED_HEARTBEAT] = {
36 .pin = {
37 .gpio = GPIOB,
38 .init = {
39 .GPIO_Pin = GPIO_Pin_3,
40 .GPIO_Mode = GPIO_Mode_OUT,
41 .GPIO_OType = GPIO_OType_PP,
42 .GPIO_Speed = GPIO_Speed_50MHz,
43 .GPIO_PuPd = GPIO_PuPd_NOPULL,
46 // .remap = GPIO_Remap_SWJ_JTAGDisable,
47 .active_low = true
51 static const struct pios_gpio_cfg pios_led_cfg_cc3d = {
52 .gpios = pios_leds_cc3d,
53 .num_gpios = NELEMENTS(pios_leds_cc3d),
56 const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision)
58 return &pios_led_cfg_cc3d;
61 #endif /* PIOS_INCLUDE_LED */
63 #if defined(PIOS_INCLUDE_SPI)
65 #include <pios_spi_priv.h>
67 /* Gyro interface */
68 void PIOS_SPI_gyro_irq_handler(void);
69 void DMA1_Channel2_IRQHandler() __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
70 void DMA1_Channel3_IRQHandler() __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
71 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
72 .regs = SPI1,
73 .init = {
74 .SPI_Mode = SPI_Mode_Master,
75 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
76 .SPI_DataSize = SPI_DataSize_8b,
77 .SPI_NSS = SPI_NSS_Soft,
78 .SPI_FirstBit = SPI_FirstBit_MSB,
79 .SPI_CRCPolynomial = 7,
80 .SPI_CPOL = SPI_CPOL_High,
81 .SPI_CPHA = SPI_CPHA_2Edge,
82 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16, /* 10 Mhz */
84 .use_crc = false,
85 .dma = {
86 .ahb_clk = RCC_AHBPeriph_DMA1,
88 .irq = {
89 .flags = (DMA1_FLAG_TC2 | DMA1_FLAG_TE2 | DMA1_FLAG_HT2 | DMA1_FLAG_GL2),
90 .init = {
91 .NVIC_IRQChannel = DMA1_Channel2_IRQn,
92 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
93 .NVIC_IRQChannelSubPriority = 0,
94 .NVIC_IRQChannelCmd = ENABLE,
98 .rx = {
99 .channel = DMA1_Channel2,
100 .init = {
101 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
102 .DMA_DIR = DMA_DIR_PeripheralSRC,
103 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
104 .DMA_MemoryInc = DMA_MemoryInc_Enable,
105 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
106 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
107 .DMA_Mode = DMA_Mode_Normal,
108 .DMA_Priority = DMA_Priority_Medium,
109 .DMA_M2M = DMA_M2M_Disable,
112 .tx = {
113 .channel = DMA1_Channel3,
114 .init = {
115 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
116 .DMA_DIR = DMA_DIR_PeripheralDST,
117 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
118 .DMA_MemoryInc = DMA_MemoryInc_Enable,
119 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
120 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
121 .DMA_Mode = DMA_Mode_Normal,
122 .DMA_Priority = DMA_Priority_Medium,
123 .DMA_M2M = DMA_M2M_Disable,
127 .remap = GPIO_AF_5,
128 .sclk = {
129 .gpio = GPIOA,
130 .init = {
131 .GPIO_Pin = GPIO_Pin_5,
132 .GPIO_Speed = GPIO_Speed_50MHz,
133 .GPIO_Mode = GPIO_Mode_AF,
134 .GPIO_OType = GPIO_OType_PP,
135 .GPIO_PuPd = GPIO_PuPd_NOPULL,
138 .miso = {
139 .gpio = GPIOA,
140 .init = {
141 .GPIO_Pin = GPIO_Pin_6,
142 .GPIO_Speed = GPIO_Speed_50MHz,
143 .GPIO_Mode = GPIO_Mode_AF,
144 .GPIO_OType = GPIO_OType_PP,
145 .GPIO_PuPd = GPIO_PuPd_NOPULL,
148 .mosi = {
149 .gpio = GPIOA,
150 .init = {
151 .GPIO_Pin = GPIO_Pin_7,
152 .GPIO_Speed = GPIO_Speed_50MHz,
153 .GPIO_Mode = GPIO_Mode_AF,
154 .GPIO_OType = GPIO_OType_PP,
155 .GPIO_PuPd = GPIO_PuPd_NOPULL,
158 .slave_count = 1,
159 .ssel = {
161 .gpio = GPIOA,
162 .init = {
163 .GPIO_Pin = GPIO_Pin_4,
164 .GPIO_Speed = GPIO_Speed_50MHz,
165 .GPIO_Mode = GPIO_Mode_OUT,
166 .GPIO_OType = GPIO_OType_PP,
167 .GPIO_PuPd = GPIO_PuPd_UP
173 uint32_t pios_spi_gyro_id;
174 void PIOS_SPI_gyro_irq_handler(void)
176 /* Call into the generic code to handle the IRQ for this specific device */
177 PIOS_SPI_IRQ_Handler(pios_spi_gyro_id);
181 /* Flash/Accel Interface
183 * NOTE: Leave this declared as const data so that it ends up in the
184 * .rodata section (ie. Flash) rather than in the .bss section (RAM).
186 void PIOS_SPI_flash_accel_irq_handler(void);
187 void DMA1_Channel4_IRQHandler() __attribute__((alias("PIOS_SPI_flash_accel_irq_handler")));
188 void DMA1_Channel5_IRQHandler() __attribute__((alias("PIOS_SPI_flash_accel_irq_handler")));
189 static const struct pios_spi_cfg pios_spi_flash_accel_cfg_cc3d = {
190 .regs = SPI2,
191 .init = {
192 .SPI_Mode = SPI_Mode_Master,
193 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
194 .SPI_DataSize = SPI_DataSize_8b,
195 .SPI_NSS = SPI_NSS_Soft,
196 .SPI_FirstBit = SPI_FirstBit_MSB,
197 .SPI_CRCPolynomial = 7,
198 .SPI_CPOL = SPI_CPOL_High,
199 .SPI_CPHA = SPI_CPHA_2Edge,
200 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
202 .use_crc = false,
203 .dma = {
204 .ahb_clk = RCC_AHBPeriph_DMA1,
206 .irq = {
207 .flags = (DMA1_FLAG_TC4 | DMA1_FLAG_TE4 | DMA1_FLAG_HT4 | DMA1_FLAG_GL4),
208 .init = {
209 .NVIC_IRQChannel = DMA1_Channel4_IRQn,
210 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
211 .NVIC_IRQChannelSubPriority = 0,
212 .NVIC_IRQChannelCmd = ENABLE,
216 .rx = {
217 .channel = DMA1_Channel4,
218 .init = {
219 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
220 .DMA_DIR = DMA_DIR_PeripheralSRC,
221 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
222 .DMA_MemoryInc = DMA_MemoryInc_Enable,
223 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
224 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
225 .DMA_Mode = DMA_Mode_Normal,
226 .DMA_Priority = DMA_Priority_High,
227 .DMA_M2M = DMA_M2M_Disable,
230 .tx = {
231 .channel = DMA1_Channel5,
232 .init = {
233 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
234 .DMA_DIR = DMA_DIR_PeripheralDST,
235 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
236 .DMA_MemoryInc = DMA_MemoryInc_Enable,
237 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
238 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
239 .DMA_Mode = DMA_Mode_Normal,
240 .DMA_Priority = DMA_Priority_High,
241 .DMA_M2M = DMA_M2M_Disable,
245 .remap = GPIO_AF_5,
246 .sclk = {
247 .gpio = GPIOB,
248 .init = {
249 .GPIO_Pin = GPIO_Pin_13,
250 .GPIO_Speed = GPIO_Speed_50MHz,
251 .GPIO_Mode = GPIO_Mode_AF,
252 .GPIO_OType = GPIO_OType_PP,
253 .GPIO_PuPd = GPIO_PuPd_NOPULL,
256 .miso = {
257 .gpio = GPIOB,
258 .init = {
259 .GPIO_Pin = GPIO_Pin_14,
260 .GPIO_Speed = GPIO_Speed_50MHz,
261 .GPIO_Mode = GPIO_Mode_AF, /* NOTE: was GPIO_Mode_IN_FLOATING */
262 .GPIO_OType = GPIO_OType_PP,
263 .GPIO_PuPd = GPIO_PuPd_NOPULL,
266 .mosi = {
267 .gpio = GPIOB,
268 .init = {
269 .GPIO_Pin = GPIO_Pin_15,
270 .GPIO_Speed = GPIO_Speed_50MHz,
271 .GPIO_Mode = GPIO_Mode_AF,
272 .GPIO_OType = GPIO_OType_PP,
273 .GPIO_PuPd = GPIO_PuPd_NOPULL,
276 .slave_count = 2,
277 .ssel = {
279 .gpio = GPIOB,
280 .init = {
281 .GPIO_Pin = GPIO_Pin_12,
282 .GPIO_Speed = GPIO_Speed_50MHz,
283 .GPIO_Mode = GPIO_Mode_OUT,
284 .GPIO_OType = GPIO_OType_PP,
285 .GPIO_PuPd = GPIO_PuPd_UP,
288 .gpio = GPIOC,
289 .init = {
290 .GPIO_Pin = GPIO_Pin_15,
291 .GPIO_Speed = GPIO_Speed_50MHz,
292 .GPIO_Mode = GPIO_Mode_OUT,
293 .GPIO_OType = GPIO_OType_PP,
294 .GPIO_PuPd = GPIO_PuPd_UP,
300 static uint32_t pios_spi_flash_accel_id;
301 void PIOS_SPI_flash_accel_irq_handler(void)
303 /* Call into the generic code to handle the IRQ for this specific device */
304 PIOS_SPI_IRQ_Handler(pios_spi_flash_accel_id);
307 #endif /* PIOS_INCLUDE_SPI */
309 #if defined(PIOS_INCLUDE_FLASH)
310 #include "pios_flashfs_logfs_priv.h"
311 #include "pios_flash_jedec_priv.h"
313 static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
314 .fs_magic = 0x99abceef,
315 .total_fs_size = 0x00200000, /* 2M bytes (32 sectors = entire chip) */
316 .arena_size = 0x00010000, /* 256 * slot size */
317 .slot_size = 0x00000100, /* 256 bytes */
319 .start_offset = 0, /* start at the beginning of the chip */
320 .sector_size = 0x00010000, /* 64K bytes */
321 .page_size = 0x00000100, /* 256 bytes */
324 #include "pios_flash.h"
326 #endif /* PIOS_INCLUDE_FLASH */
329 * ADC system
331 #if defined(PIOS_INCLUDE_ADC)
332 #include "pios_adc_priv.h"
333 extern void PIOS_ADC_handler(void);
334 void DMA1_Channel1_IRQHandler() __attribute__((alias("PIOS_ADC_handler")));
335 // Remap the ADC DMA handler to this one
336 static const struct pios_adc_cfg pios_adc_cfg = {
337 .dma = {
338 .ahb_clk = RCC_AHBPeriph_DMA1,
339 .irq = {
340 .flags = (DMA1_FLAG_TC1 | DMA1_FLAG_TE1 | DMA1_FLAG_HT1 | DMA1_FLAG_GL1),
341 .init = {
342 .NVIC_IRQChannel = DMA1_Channel1_IRQn,
343 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
344 .NVIC_IRQChannelSubPriority = 0,
345 .NVIC_IRQChannelCmd = ENABLE,
348 .rx = {
349 .channel = DMA1_Channel1,
350 .init = {
351 .DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR,
352 .DMA_DIR = DMA_DIR_PeripheralSRC,
353 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
354 .DMA_MemoryInc = DMA_MemoryInc_Enable,
355 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word,
356 .DMA_MemoryDataSize = DMA_MemoryDataSize_Word,
357 .DMA_Mode = DMA_Mode_Circular,
358 .DMA_Priority = DMA_Priority_High,
359 .DMA_M2M = DMA_M2M_Disable,
363 .half_flag = DMA1_IT_HT1,
364 .full_flag = DMA1_IT_TC1,
367 void PIOS_ADC_handler()
369 PIOS_ADC_DMA_Handler();
371 #endif /* if defined(PIOS_INCLUDE_ADC) */
373 #include "pios_tim_priv.h"
375 static const TIM_TimeBaseInitTypeDef tim_1_2_3_4_time_base = {
376 .TIM_Prescaler = (PIOS_MASTER_CLOCK / 1000000) - 1,
377 .TIM_ClockDivision = TIM_CKD_DIV1,
378 .TIM_CounterMode = TIM_CounterMode_Up,
379 .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
380 .TIM_RepetitionCounter = 0x0000,
383 static const struct pios_tim_clock_cfg tim_1_cfg = {
384 .timer = TIM1,
385 .time_base_init = &tim_1_2_3_4_time_base,
386 .irq = {
387 .init = {
388 .NVIC_IRQChannel = TIM1_CC_IRQn,
389 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
390 .NVIC_IRQChannelSubPriority = 0,
391 .NVIC_IRQChannelCmd = ENABLE,
396 static const struct pios_tim_clock_cfg tim_2_cfg = {
397 .timer = TIM2,
398 .time_base_init = &tim_1_2_3_4_time_base,
399 .irq = {
400 .init = {
401 .NVIC_IRQChannel = TIM2_IRQn,
402 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
403 .NVIC_IRQChannelSubPriority = 0,
404 .NVIC_IRQChannelCmd = ENABLE,
409 static const struct pios_tim_clock_cfg tim_3_cfg = {
410 .timer = TIM3,
411 .time_base_init = &tim_1_2_3_4_time_base,
412 .irq = {
413 .init = {
414 .NVIC_IRQChannel = TIM3_IRQn,
415 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
416 .NVIC_IRQChannelSubPriority = 0,
417 .NVIC_IRQChannelCmd = ENABLE,
422 static const struct pios_tim_clock_cfg tim_4_cfg = {
423 .timer = TIM4,
424 .time_base_init = &tim_1_2_3_4_time_base,
425 .irq = {
426 .init = {
427 .NVIC_IRQChannel = TIM4_IRQn,
428 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
429 .NVIC_IRQChannelSubPriority = 0,
430 .NVIC_IRQChannelCmd = ENABLE,
435 #include <pios_servo_config.h>
437 #define GPIO_AF_PA1_TIM2 GPIO_AF_1
438 #define GPIO_AF_PA0_TIM2 GPIO_AF_1
439 #define GPIO_AF_PA8_TIM1 GPIO_AF_6
440 #define GPIO_AF_PA2_TIM2 GPIO_AF_1
441 #define GPIO_AF_PB6_TIM4 GPIO_AF_2
442 #define GPIO_AF_PB5_TIM3 GPIO_AF_2
443 #define GPIO_AF_PB0_TIM3 GPIO_AF_2
444 #define GPIO_AF_PB1_TIM3 GPIO_AF_2
445 #define GPIO_AF_PB9_TIM4 GPIO_AF_2
446 #define GPIO_AF_PB8_TIM4 GPIO_AF_2
447 #define GPIO_AF_PB7_TIM4 GPIO_AF_2
448 #define GPIO_AF_PB4_TIM3 GPIO_AF_2
449 #define GPIO_AF_PB11_TIM2 GPIO_AF_1
451 static const struct pios_tim_channel pios_tim_rcvrport_all_channels[] = {
452 TIM_SERVO_CHANNEL_CONFIG(TIM4, 1, B, 6),
453 TIM_SERVO_CHANNEL_CONFIG(TIM3, 2, B, 5),
454 TIM_SERVO_CHANNEL_CONFIG(TIM3, 3, B, 0),
455 TIM_SERVO_CHANNEL_CONFIG(TIM3, 4, B, 1),
456 TIM_SERVO_CHANNEL_CONFIG(TIM2, 1, A, 0),
457 TIM_SERVO_CHANNEL_CONFIG(TIM2, 2, A, 1),
460 static const struct pios_tim_channel pios_tim_servoport_rcvrport_pins[] = {
461 TIM_SERVO_CHANNEL_CONFIG(TIM4, 4, B, 9),
462 TIM_SERVO_CHANNEL_CONFIG(TIM4, 3, B, 8),
463 TIM_SERVO_CHANNEL_CONFIG(TIM4, 2, B, 7),
464 TIM_SERVO_CHANNEL_CONFIG(TIM1, 1, A, 8),
465 TIM_SERVO_CHANNEL_CONFIG(TIM3, 1, B, 4),
466 TIM_SERVO_CHANNEL_CONFIG(TIM2, 3, A, 2),
468 // Receiver port pins
469 // S3-S6 inputs are used as outputs in this case
471 TIM_SERVO_CHANNEL_CONFIG(TIM3, 3, B, 0),
472 TIM_SERVO_CHANNEL_CONFIG(TIM3, 4, B, 1),
473 TIM_SERVO_CHANNEL_CONFIG(TIM2, 1, A, 0),
474 TIM_SERVO_CHANNEL_CONFIG(TIM2, 2, A, 1),
477 static const struct pios_tim_channel pios_tim_ppm_flexi_port = TIM_SERVO_CHANNEL_CONFIG(TIM2, 4, B, 11);
480 #if defined(PIOS_INCLUDE_USART)
482 #define GPIO_AF_USART1 GPIO_AF_7
483 #define GPIO_AF_USART3 GPIO_AF_7
486 #include "pios_usart_priv.h"
487 #include "pios_usart_config.h"
489 static const struct pios_usart_cfg pios_usart_main_cfg = USART_CONFIG(USART1, A, 10, A, 9);
490 static const struct pios_usart_cfg pios_usart_flexi_cfg = USART_CONFIG(USART3, B, 11, B, 10);
491 #endif /* PIOS_INCLUDE_USART */
493 #if defined(PIOS_INCLUDE_RTC)
495 * Realtime Clock (RTC)
497 #include <pios_rtc_priv.h>
499 void PIOS_RTC_IRQ_Handler(void);
500 void RTC_WKUP_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
501 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
502 .clksrc = RCC_RTCCLKSource_HSE_Div32,
503 .prescaler = 25 - 1, // 8Mhz / 32 / 16 / 25 => 625Hz
504 .irq = {
505 .init = {
506 .NVIC_IRQChannel = RTC_WKUP_IRQn,
507 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
508 .NVIC_IRQChannelSubPriority = 0,
509 .NVIC_IRQChannelCmd = ENABLE,
514 void PIOS_RTC_IRQ_Handler(void)
516 PIOS_RTC_irq_handler();
519 #endif /* if defined(PIOS_INCLUDE_RTC) */
521 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
523 * Servo outputs
525 #include <pios_servo_priv.h>
527 const struct pios_servo_cfg pios_servo_cfg = {
528 .tim_oc_init = {
529 .TIM_OCMode = TIM_OCMode_PWM1,
530 .TIM_OutputState = TIM_OutputState_Enable,
531 .TIM_OutputNState = TIM_OutputNState_Disable,
532 .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
533 .TIM_OCPolarity = TIM_OCPolarity_High,
534 .TIM_OCNPolarity = TIM_OCPolarity_High,
535 .TIM_OCIdleState = TIM_OCIdleState_Reset,
536 .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
538 .channels = pios_tim_servoport_rcvrport_pins,
539 .num_channels = 6,
542 const struct pios_servo_cfg pios_servo_rcvr_cfg = {
543 .tim_oc_init = {
544 .TIM_OCMode = TIM_OCMode_PWM1,
545 .TIM_OutputState = TIM_OutputState_Enable,
546 .TIM_OutputNState = TIM_OutputNState_Disable,
547 .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
548 .TIM_OCPolarity = TIM_OCPolarity_High,
549 .TIM_OCNPolarity = TIM_OCPolarity_High,
550 .TIM_OCIdleState = TIM_OCIdleState_Reset,
551 .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
553 .channels = pios_tim_servoport_rcvrport_pins,
554 .num_channels = NELEMENTS(pios_tim_servoport_rcvrport_pins),
557 #endif /* PIOS_INCLUDE_SERVO && PIOS_INCLUDE_TIM */
560 * PPM Inputs
562 #if defined(PIOS_INCLUDE_PPM)
563 #include <pios_ppm_priv.h>
565 const struct pios_ppm_cfg pios_ppm_cfg = {
566 .tim_ic_init = {
567 .TIM_ICPolarity = TIM_ICPolarity_Rising,
568 .TIM_ICSelection = TIM_ICSelection_DirectTI,
569 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
570 .TIM_ICFilter = 0x0,
572 /* Use only the first channel for ppm */
573 .channels = &pios_tim_rcvrport_all_channels[0],
574 .num_channels = 1,
577 const struct pios_ppm_cfg pios_ppm_pin8_cfg = {
578 .tim_ic_init = {
579 .TIM_ICPolarity = TIM_ICPolarity_Rising,
580 .TIM_ICSelection = TIM_ICSelection_DirectTI,
581 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
582 .TIM_ICFilter = 0x0,
584 /* Use only the first channel for ppm */
585 .channels = &pios_tim_rcvrport_all_channels[5],
586 .num_channels = 1,
589 #endif /* PIOS_INCLUDE_PPM */
591 #if defined(PIOS_INCLUDE_PPM_FLEXI)
592 #include <pios_ppm_priv.h>
594 const struct pios_ppm_cfg pios_ppm_flexi_cfg = {
595 .tim_ic_init = {
596 .TIM_ICPolarity = TIM_ICPolarity_Rising,
597 .TIM_ICSelection = TIM_ICSelection_DirectTI,
598 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
599 .TIM_ICFilter = 0x0,
601 .channels = &pios_tim_ppm_flexi_port,
602 .num_channels = 1,
605 #endif /* PIOS_INCLUDE_PPM_FLEXI */
608 * PWM Inputs
610 #if defined(PIOS_INCLUDE_PWM)
611 #include <pios_pwm_priv.h>
613 const struct pios_pwm_cfg pios_pwm_cfg = {
614 .tim_ic_init = {
615 .TIM_ICPolarity = TIM_ICPolarity_Rising,
616 .TIM_ICSelection = TIM_ICSelection_DirectTI,
617 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
618 .TIM_ICFilter = 0x0,
620 .channels = pios_tim_rcvrport_all_channels,
621 .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels),
624 const struct pios_pwm_cfg pios_pwm_with_ppm_cfg = {
625 .tim_ic_init = {
626 .TIM_ICPolarity = TIM_ICPolarity_Rising,
627 .TIM_ICSelection = TIM_ICSelection_DirectTI,
628 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
629 .TIM_ICFilter = 0x0,
631 /* Leave the first channel for PPM use and use the rest for PWM */
632 .channels = &pios_tim_rcvrport_all_channels[1],
633 .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels) - 1,
636 #endif /* if defined(PIOS_INCLUDE_PWM) */
640 * SONAR Inputs
642 #if defined(PIOS_INCLUDE_HCSR04)
643 #include <pios_hcsr04_priv.h>
645 static const struct pios_tim_channel pios_tim_hcsr04_port_all_channels[] = {
647 .timer = TIM3,
648 .timer_chan = TIM_Channel_2,
649 .pin = {
650 .gpio = GPIOB,
651 .init = {
652 .GPIO_Pin = GPIO_Pin_5,
653 .GPIO_Mode = GPIO_Mode_IPD,
654 .GPIO_Speed = GPIO_Speed_2MHz,
657 .remap = GPIO_PartialRemap_TIM3,
661 const struct pios_hcsr04_cfg pios_hcsr04_cfg = {
662 .tim_ic_init = {
663 .TIM_ICPolarity = TIM_ICPolarity_Rising,
664 .TIM_ICSelection = TIM_ICSelection_DirectTI,
665 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
666 .TIM_ICFilter = 0x0,
668 .channels = pios_tim_hcsr04_port_all_channels,
669 .num_channels = NELEMENTS(pios_tim_hcsr04_port_all_channels),
670 .trigger = {
671 .gpio = GPIOB,
672 .init = {
673 .GPIO_Pin = GPIO_Pin_6,
674 .GPIO_Mode = GPIO_Mode_Out_PP,
675 .GPIO_Speed = GPIO_Speed_2MHz,
679 #endif /* if defined(PIOS_INCLUDE_HCSR04) */
681 #if defined(PIOS_INCLUDE_I2C)
683 #include <pios_i2c_priv.h>
686 * I2C Adapters
689 void PIOS_I2C_flexi_adapter_ev_irq_handler(void);
690 void PIOS_I2C_flexi_adapter_er_irq_handler(void);
691 void I2C2_EV_EXTI24_IRQHandler() __attribute__((alias("PIOS_I2C_flexi_adapter_ev_irq_handler")));
692 void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexi_adapter_er_irq_handler")));
694 static const struct pios_i2c_adapter_cfg pios_i2c_flexi_adapter_cfg = {
695 .regs = I2C2,
696 .init = {
697 .I2C_Mode = I2C_Mode_I2C,
698 .I2C_OwnAddress1 = 0,
699 .I2C_Ack = I2C_Ack_Enable,
700 .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
701 .I2C_DigitalFilter = 0x00,
702 .I2C_AnalogFilter = I2C_AnalogFilter_Enable,
703 .I2C_Timing = 0x70310309, // 50kHz I2C @ 8MHz input -> PRESC=0x7, SCLDEL=0x3, SDADEL=0x1, SCLH=0x03, SCLL=0x09
705 .remapSDA = GPIO_AF_4, /* I2C1, I2C2 */
706 .remapSCL = GPIO_AF_4, /* I2C1, I2C2 */
707 .transfer_timeout_ms = 50,
708 .scl = {
709 .gpio = GPIOB,
710 .init = {
711 .GPIO_Pin = GPIO_Pin_10,
712 .GPIO_Mode = GPIO_Mode_AF,
713 .GPIO_Speed = GPIO_Speed_50MHz,
714 .GPIO_OType = GPIO_OType_OD,
715 .GPIO_PuPd = GPIO_PuPd_UP,
718 .sda = {
719 .gpio = GPIOB,
720 .init = {
721 .GPIO_Pin = GPIO_Pin_11,
722 .GPIO_Mode = GPIO_Mode_AF,
723 .GPIO_Speed = GPIO_Speed_50MHz,
724 .GPIO_OType = GPIO_OType_OD,
725 .GPIO_PuPd = GPIO_PuPd_UP,
728 .event = {
729 .flags = 0, /* FIXME: check this */
730 .init = {
731 .NVIC_IRQChannel = I2C2_EV_IRQn,
732 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
733 .NVIC_IRQChannelSubPriority = 0,
734 .NVIC_IRQChannelCmd = ENABLE,
737 .error = {
738 .flags = 0, /* FIXME: check this */
739 .init = {
740 .NVIC_IRQChannel = I2C2_ER_IRQn,
741 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
742 .NVIC_IRQChannelSubPriority = 0,
743 .NVIC_IRQChannelCmd = ENABLE,
748 uint32_t pios_i2c_flexi_adapter_id;
749 void PIOS_I2C_flexi_adapter_ev_irq_handler(void)
751 /* Call into the generic code to handle the IRQ for this specific device */
752 PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexi_adapter_id);
755 void PIOS_I2C_flexi_adapter_er_irq_handler(void)
757 /* Call into the generic code to handle the IRQ for this specific device */
758 PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexi_adapter_id);
761 #endif /* PIOS_INCLUDE_I2C */
763 #if defined(PIOS_INCLUDE_RCVR)
764 #include "pios_rcvr_priv.h"
766 #endif /* PIOS_INCLUDE_RCVR */
768 #if defined(PIOS_INCLUDE_USB)
769 #include "pios_usb_priv.h"
771 static const struct pios_usb_cfg pios_usb_main_cfg_cc3d = {
772 .irq = {
773 .init = {
774 .NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
775 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
776 .NVIC_IRQChannelSubPriority = 0,
777 .NVIC_IRQChannelCmd = ENABLE,
780 .vsense = {
781 .gpio = GPIOC,
782 .init = {
783 .GPIO_Pin = GPIO_Pin_14,
784 .GPIO_Speed = GPIO_Speed_2MHz,
785 .GPIO_Mode = GPIO_Mode_IN,
786 .GPIO_OType = GPIO_OType_OD,
787 .GPIO_PuPd = GPIO_PuPd_DOWN,
790 .vsense_active_low = false
793 const struct pios_usb_cfg *PIOS_BOARD_HW_DEFS_GetUsbCfg(__attribute__((unused)) uint32_t board_revision)
795 return &pios_usb_main_cfg_cc3d;
798 #endif /* PIOS_INCLUDE_USB */
801 * Configuration for MPU6000 chip
803 #if defined(PIOS_INCLUDE_MPU6000)
804 #include "pios_mpu6000.h"
805 static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config = {
806 .vector = PIOS_MPU6000_IRQHandler,
807 .line = EXTI_Line3,
808 .pin = {
809 .gpio = GPIOA,
810 .init = {
811 .GPIO_Pin = GPIO_Pin_3,
812 .GPIO_Speed = GPIO_Speed_10MHz,
813 .GPIO_Mode = GPIO_Mode_IN,
814 .GPIO_OType = GPIO_OType_OD,
815 .GPIO_PuPd = GPIO_PuPd_NOPULL,
818 .irq = {
819 .init = {
820 .NVIC_IRQChannel = EXTI3_IRQn,
821 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
822 .NVIC_IRQChannelSubPriority = 0,
823 .NVIC_IRQChannelCmd = ENABLE,
826 .exti = {
827 .init = {
828 .EXTI_Line = EXTI_Line3, // matches above GPIO pin
829 .EXTI_Mode = EXTI_Mode_Interrupt,
830 .EXTI_Trigger = EXTI_Trigger_Rising,
831 .EXTI_LineCmd = ENABLE,
836 static const struct pios_mpu6000_cfg pios_mpu6000_cfg = {
837 .exti_cfg = &pios_exti_mpu6000_cfg,
838 .Fifo_store = PIOS_MPU6000_FIFO_TEMP_OUT | PIOS_MPU6000_FIFO_GYRO_X_OUT | PIOS_MPU6000_FIFO_GYRO_Y_OUT | PIOS_MPU6000_FIFO_GYRO_Z_OUT,
839 // Clock at 8 khz, downsampled by 8 for 1000 Hz
840 .Smpl_rate_div_no_dlp = 7,
841 // Clock at 1 khz, downsampled by 1 for 1000 Hz
842 .Smpl_rate_div_dlp = 0,
843 .interrupt_cfg = PIOS_MPU6000_INT_CLR_ANYRD,
844 .interrupt_en = PIOS_MPU6000_INTEN_DATA_RDY,
845 .User_ctl = PIOS_MPU6000_USERCTL_DIS_I2C,
846 .Pwr_mgmt_clk = PIOS_MPU6000_PWRMGMT_PLL_X_CLK,
847 .accel_range = PIOS_MPU6000_ACCEL_8G,
848 .gyro_range = PIOS_MPU6000_SCALE_2000_DEG,
849 .filter = PIOS_MPU6000_LOWPASS_256_HZ,
850 .orientation = PIOS_MPU6000_TOP_180DEG,
851 .fast_prescaler = PIOS_SPI_PRESCALER_4,
852 .std_prescaler = PIOS_SPI_PRESCALER_64,
853 .max_downsample = 2
856 const struct pios_mpu6000_cfg *PIOS_BOARD_HW_DEFS_GetMPU6000Cfg(__attribute__((unused)) uint32_t board_revision)
858 return &pios_mpu6000_cfg;
860 #endif /* PIOS_INCLUDE_MPU6000 */