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 * @brief Defines board specific static initializers for hardware for the PikoBLX board.
9 *****************************************************************************/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #if defined(PIOS_INCLUDE_LED)
28 #include <pios_led_priv.h>
29 static const struct pios_gpio pios_leds
[] = {
30 [PIOS_LED_HEARTBEAT
] = {
34 .GPIO_Pin
= GPIO_Pin_9
,
35 .GPIO_Mode
= GPIO_Mode_OUT
,
36 .GPIO_OType
= GPIO_OType_PP
,
37 .GPIO_Speed
= GPIO_Speed_50MHz
,
38 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
47 .GPIO_Pin
= GPIO_Pin_5
,
48 .GPIO_Mode
= GPIO_Mode_OUT
,
49 .GPIO_OType
= GPIO_OType_PP
,
50 .GPIO_Speed
= GPIO_Speed_50MHz
,
51 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
56 [PIOS_BUZZER_ALARM
] = {
60 .GPIO_Pin
= GPIO_Pin_0
,
61 .GPIO_Mode
= GPIO_Mode_OUT
,
62 .GPIO_OType
= GPIO_OType_PP
,
63 .GPIO_Speed
= GPIO_Speed_50MHz
,
64 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
71 static const struct pios_gpio_cfg pios_led_cfg
= {
73 .num_gpios
= NELEMENTS(pios_leds
),
76 const struct pios_gpio_cfg
*PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused
)) uint32_t board_revision
)
81 #endif /* PIOS_INCLUDE_LED */
83 #if defined(PIOS_INCLUDE_SPI)
85 #include <pios_spi_priv.h>
89 static const struct pios_spi_cfg pios_spi_mpu6000_cfg
= {
92 .SPI_Mode
= SPI_Mode_Master
,
93 .SPI_Direction
= SPI_Direction_2Lines_FullDuplex
,
94 .SPI_DataSize
= SPI_DataSize_8b
,
95 .SPI_NSS
= SPI_NSS_Soft
,
96 .SPI_FirstBit
= SPI_FirstBit_MSB
,
97 .SPI_CRCPolynomial
= 7,
98 .SPI_CPOL
= SPI_CPOL_High
,
99 .SPI_CPHA
= SPI_CPHA_2Edge
,
100 .SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_16
, /* 10 Mhz */
107 .GPIO_Pin
= GPIO_Pin_13
,
108 .GPIO_Speed
= GPIO_Speed_50MHz
,
109 .GPIO_Mode
= GPIO_Mode_AF
,
110 .GPIO_OType
= GPIO_OType_PP
,
111 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
117 .GPIO_Pin
= GPIO_Pin_14
,
118 .GPIO_Speed
= GPIO_Speed_50MHz
,
119 .GPIO_Mode
= GPIO_Mode_AF
,
120 .GPIO_OType
= GPIO_OType_PP
,
121 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
127 .GPIO_Pin
= GPIO_Pin_15
,
128 .GPIO_Speed
= GPIO_Speed_50MHz
,
129 .GPIO_Mode
= GPIO_Mode_AF
,
130 .GPIO_OType
= GPIO_OType_PP
,
131 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
139 .GPIO_Pin
= GPIO_Pin_12
,
140 .GPIO_Speed
= GPIO_Speed_50MHz
,
141 .GPIO_Mode
= GPIO_Mode_OUT
,
142 .GPIO_OType
= GPIO_OType_PP
,
143 .GPIO_PuPd
= GPIO_PuPd_UP
149 uint32_t pios_spi_mpu6000_id
;
151 #endif /* PIOS_INCLUDE_SPI */
153 #if defined(PIOS_INCLUDE_FLASH)
154 #include "pios_flashfs_logfs_priv.h"
155 #include "pios_flash_jedec_priv.h"
156 #include "pios_flash_internal_priv.h"
158 static const struct pios_flash_internal_cfg flash_internal_system_cfg
= {};
160 static const struct flashfs_logfs_cfg flashfs_internal_cfg
= {
161 .fs_magic
= 0x99abcfef,
162 .total_fs_size
= EE_BANK_SIZE
, /* 32K bytes (16x2KB sectors) */
163 .arena_size
= 0x00004000, /* 64 * slot size = 16K bytes = 8 sectors */
164 .slot_size
= 0x00000100, /* 256 bytes */
166 .start_offset
= EE_BANK_BASE
, /* start after the bootloader */
167 .sector_size
= 0x00000800, /* 2K bytes */
168 .page_size
= 0x00000800, /* 2K bytes */
171 #endif /* PIOS_INCLUDE_FLASH */
173 #include "pios_tim_priv.h"
175 static const TIM_TimeBaseInitTypeDef tim_time_base
= {
176 .TIM_Prescaler
= (PIOS_MASTER_CLOCK
/ 1000000) - 1,
177 .TIM_ClockDivision
= TIM_CKD_DIV1
,
178 .TIM_CounterMode
= TIM_CounterMode_Up
,
179 .TIM_Period
= ((1000000 / PIOS_SERVO_UPDATE_HZ
) - 1),
180 .TIM_RepetitionCounter
= 0x0000,
183 static const struct pios_tim_clock_cfg tim_1_cfg
= {
185 .time_base_init
= &tim_time_base
,
188 .NVIC_IRQChannel
= TIM1_CC_IRQn
,
189 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
190 .NVIC_IRQChannelSubPriority
= 0,
191 .NVIC_IRQChannelCmd
= ENABLE
,
196 static const struct pios_tim_clock_cfg tim_2_cfg
= {
198 .time_base_init
= &tim_time_base
,
201 .NVIC_IRQChannel
= TIM2_IRQn
,
202 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
203 .NVIC_IRQChannelSubPriority
= 0,
204 .NVIC_IRQChannelCmd
= ENABLE
,
209 static const struct pios_tim_clock_cfg tim_3_cfg
= {
211 .time_base_init
= &tim_time_base
,
214 .NVIC_IRQChannel
= TIM3_IRQn
,
215 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
216 .NVIC_IRQChannelSubPriority
= 0,
217 .NVIC_IRQChannelCmd
= ENABLE
,
222 static const struct pios_tim_clock_cfg tim_4_cfg
= {
224 .time_base_init
= &tim_time_base
,
227 .NVIC_IRQChannel
= TIM4_IRQn
,
228 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
229 .NVIC_IRQChannelSubPriority
= 0,
230 .NVIC_IRQChannelCmd
= ENABLE
,
235 static const struct pios_tim_clock_cfg tim_8_cfg
= {
237 .time_base_init
= &tim_time_base
,
240 .NVIC_IRQChannel
= TIM8_CC_IRQn
,
241 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
242 .NVIC_IRQChannelSubPriority
= 0,
243 .NVIC_IRQChannelCmd
= ENABLE
,
248 static const struct pios_tim_clock_cfg tim_15_cfg
= {
250 .time_base_init
= &tim_time_base
,
253 .NVIC_IRQChannel
= TIM1_BRK_TIM15_IRQn
,
254 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
255 .NVIC_IRQChannelSubPriority
= 0,
256 .NVIC_IRQChannelCmd
= ENABLE
,
261 static const struct pios_tim_clock_cfg tim_16_cfg
= {
263 .time_base_init
= &tim_time_base
,
266 .NVIC_IRQChannel
= TIM1_UP_TIM16_IRQn
,
267 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
268 .NVIC_IRQChannelSubPriority
= 0,
269 .NVIC_IRQChannelCmd
= ENABLE
,
274 static const struct pios_tim_clock_cfg tim_17_cfg
= {
276 .time_base_init
= &tim_time_base
,
279 .NVIC_IRQChannel
= TIM1_TRG_COM_TIM17_IRQn
,
280 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
281 .NVIC_IRQChannelSubPriority
= 0,
282 .NVIC_IRQChannelCmd
= ENABLE
,
287 #include <pios_servo_config.h>
289 #define GPIO_AF_PA1_TIM2 GPIO_AF_1
290 #define GPIO_AF_PA0_TIM2 GPIO_AF_1
291 #define GPIO_AF_PA8_TIM1 GPIO_AF_6
292 #define GPIO_AF_PA2_TIM2 GPIO_AF_1
293 #define GPIO_AF_PB6_TIM4 GPIO_AF_2
294 #define GPIO_AF_PB5_TIM3 GPIO_AF_2
295 #define GPIO_AF_PB0_TIM3 GPIO_AF_2
296 #define GPIO_AF_PB1_TIM3 GPIO_AF_2
297 #define GPIO_AF_PB9_TIM4 GPIO_AF_2
298 #define GPIO_AF_PB8_TIM4 GPIO_AF_2
299 #define GPIO_AF_PB7_TIM4 GPIO_AF_2
300 #define GPIO_AF_PB4_TIM3 GPIO_AF_2
301 #define GPIO_AF_PB11_TIM2 GPIO_AF_1
302 #define GPIO_AF_PA15_TIM8 GPIO_AF_2
303 #define GPIO_AF_PA3_TIM15 GPIO_AF_9
304 #define GPIO_AF_PA6_TIM3 GPIO_AF_2
305 #define GPIO_AF_PA7_TIM3 GPIO_AF_2
306 #define GPIO_AF_PA10_TIM2 GPIO_AF_10
308 #define GPIO_AF_PA4_TIM3 GPIO_AF_2
309 #define GPIO_AF_PA7_TIM17 GPIO_AF_1
310 #define GPIO_AF_PB8_TIM16 GPIO_AF_1
312 #define TIM1_CH1_DMA_INSTANCE 1
313 #define TIM1_CH1_DMA_CHANNEL 2
315 #define TIM16_CH1_DMA_INSTANCE 2
316 #define TIM16_CH1_DMA_CHANNEL 3
318 static const struct pios_tim_channel pios_tim_servoport_pins
[] = {
319 TIM_SERVO_CHANNEL_CONFIG(TIM3
, 2, A
, 4), // bank 1
320 TIM_SERVO_CHANNEL_CONFIG(TIM3
, 1, A
, 6), // bank 1
321 TIM_SERVO_CHANNEL_CONFIG(TIM3
, 3, B
, 0), // bank 1
322 TIM_SERVO_CHANNEL_CONFIG(TIM3
, 4, B
, 1), // bank 1
323 TIM_SERVO_CHANNEL_CONFIG(TIM2
, 2, A
, 1), // bank 2
324 TIM_SERVO_CHANNEL_CONFIG(TIM2
, 3, A
, 2), // bank 2
325 TIM_SERVO_CHANNEL_CONFIG(TIM15
, 2, A
, 3), // bank 3
326 TIM_SERVO_CHANNEL_CONFIG(TIM1
, 1, A
, 8), // transponder (bank 4)
329 #if defined(PIOS_INCLUDE_USART)
331 #define GPIO_AF_USART1 GPIO_AF_7
332 #define GPIO_AF_USART2 GPIO_AF_7
333 #define GPIO_AF_USART3 GPIO_AF_7
336 #include "pios_usart_priv.h"
337 #include "pios_usart_config.h"
339 static const struct pios_usart_cfg pios_usart_cfg
[] = {
340 USART_CONFIG(USART1
, B
, 7, B
, 6),
341 USART_CONFIG(USART2
, B
, 4, B
, 3),
342 USART_CONFIG(USART3
, B
, 11, B
, 10),
346 #endif /* PIOS_INCLUDE_USART */
348 #if defined(PIOS_INCLUDE_COM)
350 #include "pios_com_priv.h"
352 #endif /* PIOS_INCLUDE_COM */
354 #if defined(PIOS_INCLUDE_RTC)
356 * Realtime Clock (RTC)
358 #include <pios_rtc_priv.h>
360 void PIOS_RTC_IRQ_Handler(void);
361 void RTC_WKUP_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
362 static const struct pios_rtc_cfg pios_rtc_main_cfg
= {
363 .clksrc
= RCC_RTCCLKSource_HSE_Div32
,
364 .prescaler
= 25 - 1, // 8Mhz / 32 / 16 / 25 => 625Hz
367 .NVIC_IRQChannel
= RTC_WKUP_IRQn
,
368 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_MID
,
369 .NVIC_IRQChannelSubPriority
= 0,
370 .NVIC_IRQChannelCmd
= ENABLE
,
375 void PIOS_RTC_IRQ_Handler(void)
377 PIOS_RTC_irq_handler();
380 #endif /* if defined(PIOS_INCLUDE_RTC) */
382 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
386 #include <pios_servo_priv.h>
388 const struct pios_servo_cfg pios_servo_cfg
= {
390 .TIM_OCMode
= TIM_OCMode_PWM1
,
391 .TIM_OutputState
= TIM_OutputState_Enable
,
392 .TIM_OutputNState
= TIM_OutputNState_Disable
,
393 .TIM_Pulse
= PIOS_SERVOS_INITIAL_POSITION
,
394 .TIM_OCPolarity
= TIM_OCPolarity_High
,
395 .TIM_OCNPolarity
= TIM_OCPolarity_High
,
396 .TIM_OCIdleState
= TIM_OCIdleState_Reset
,
397 .TIM_OCNIdleState
= TIM_OCNIdleState_Reset
,
399 .channels
= pios_tim_servoport_pins
,
400 .num_channels
= NELEMENTS(pios_tim_servoport_pins
),
403 #endif /* PIOS_INCLUDE_SERVO && PIOS_INCLUDE_TIM */
408 #if defined(PIOS_INCLUDE_PPM)
409 #include <pios_ppm_priv.h>
411 static const struct pios_tim_channel pios_tim_ppm
= TIM_SERVO_CHANNEL_CONFIG(TIM17
, 1, A
, 7);
413 const struct pios_ppm_cfg pios_ppm_cfg
= {
415 .TIM_ICPolarity
= TIM_ICPolarity_Rising
,
416 .TIM_ICSelection
= TIM_ICSelection_DirectTI
,
417 .TIM_ICPrescaler
= TIM_ICPSC_DIV1
,
420 .channels
= &pios_tim_ppm
,
423 #endif /* PIOS_INCLUDE_PPM */
426 #if defined(PIOS_INCLUDE_RCVR)
427 #include "pios_rcvr_priv.h"
429 #endif /* PIOS_INCLUDE_RCVR */
431 #if defined(PIOS_INCLUDE_USB)
432 #include "pios_usb_priv.h"
434 static const struct pios_usb_cfg pios_usb_main_cfg
= {
437 .NVIC_IRQChannel
= USB_LP_CAN1_RX0_IRQn
,
438 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_LOW
,
439 .NVIC_IRQChannelSubPriority
= 0,
440 .NVIC_IRQChannelCmd
= ENABLE
,
445 const struct pios_usb_cfg
*PIOS_BOARD_HW_DEFS_GetUsbCfg(__attribute__((unused
)) uint32_t board_revision
)
447 return &pios_usb_main_cfg
;
449 #endif /* PIOS_INCLUDE_USB */
451 #if defined(PIOS_INCLUDE_WS2811)
452 #include "pios_ws2811_cfg.h"
454 static const struct pios_ws2811_cfg pios_ws2811_cfg
= PIOS_WS2811_CONFIG(TIM16
, 1, B
, 8);
456 void DMA1_Channel2_IRQHandler()
458 PIOS_WS2811_DMA_irq_handler();
461 #endif /* PIOS_INCLUDE_WS2811 */
463 #if defined(PIOS_INCLUDE_ADC)
464 #include "pios_adc_priv.h"
465 void PIOS_ADC_DMC_irq_handler(void);
466 void DMA2_Channel1_IRQHandler(void) __attribute__((alias("PIOS_ADC_DMC_irq_handler")));
468 struct pios_adc_cfg pios_adc_cfg
= {
472 .flags
= (DMA2_FLAG_TC1
| DMA2_FLAG_TE1
| DMA2_FLAG_HT1
),
474 .NVIC_IRQChannel
= DMA2_Channel1_IRQn
,
475 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_LOW
,
476 .NVIC_IRQChannelSubPriority
= 0,
477 .NVIC_IRQChannelCmd
= ENABLE
,
481 .channel
= DMA2_Channel1
,
484 .half_flag
= DMA2_FLAG_HT1
,
485 .full_flag
= DMA2_FLAG_TC1
,
488 void PIOS_ADC_DMC_irq_handler(void)
490 /* Call into the generic code to handle the IRQ for this specific device */
491 PIOS_ADC_DMA_Handler();
493 const struct pios_adc_cfg
*PIOS_BOARD_HW_DEFS_GetAdcCfg(__attribute__((unused
)) uint32_t board_revision
)
495 return &pios_adc_cfg
;
497 #endif /* if defined(PIOS_INCLUDE_ADC) */
500 * Configuration for MPU6000 chip
502 #if defined(PIOS_INCLUDE_MPU6000)
503 #include "pios_mpu6000.h"
504 static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config
= {
505 .vector
= PIOS_MPU6000_IRQHandler
,
510 .GPIO_Pin
= GPIO_Pin_15
,
511 .GPIO_Speed
= GPIO_Speed_10MHz
,
512 .GPIO_Mode
= GPIO_Mode_IN
,
513 .GPIO_OType
= GPIO_OType_OD
,
514 .GPIO_PuPd
= GPIO_PuPd_NOPULL
,
519 .NVIC_IRQChannel
= EXTI15_10_IRQn
,
520 .NVIC_IRQChannelPreemptionPriority
= PIOS_IRQ_PRIO_HIGH
,
521 .NVIC_IRQChannelSubPriority
= 0,
522 .NVIC_IRQChannelCmd
= ENABLE
,
527 .EXTI_Line
= EXTI_Line15
, // matches above GPIO pin
528 .EXTI_Mode
= EXTI_Mode_Interrupt
,
529 .EXTI_Trigger
= EXTI_Trigger_Rising
,
530 .EXTI_LineCmd
= ENABLE
,
535 static const struct pios_mpu6000_cfg pios_mpu6000_cfg
= {
536 .exti_cfg
= &pios_exti_mpu6000_cfg
,
537 .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
,
538 // Clock at 8 khz, downsampled by 8 for 1000 Hz
539 .Smpl_rate_div_no_dlp
= 7,
540 // Clock at 1 khz, downsampled by 1 for 1000 Hz
541 .Smpl_rate_div_dlp
= 0,
542 .interrupt_cfg
= PIOS_MPU6000_INT_CLR_ANYRD
,
543 .interrupt_en
= PIOS_MPU6000_INTEN_DATA_RDY
,
544 .User_ctl
= PIOS_MPU6000_USERCTL_DIS_I2C
,
545 .Pwr_mgmt_clk
= PIOS_MPU6000_PWRMGMT_PLL_X_CLK
,
546 .accel_range
= PIOS_MPU6000_ACCEL_8G
,
547 .gyro_range
= PIOS_MPU6000_SCALE_2000_DEG
,
548 .filter
= PIOS_MPU6000_LOWPASS_256_HZ
,
549 .orientation
= PIOS_MPU6000_TOP_270DEG
,
550 #ifdef PIOS_INCLUDE_SPI
551 .fast_prescaler
= PIOS_SPI_PRESCALER_4
,
552 .std_prescaler
= PIOS_SPI_PRESCALER_64
,
553 #endif /* PIOS_INCLUDE_SPI */
557 const struct pios_mpu6000_cfg
*PIOS_BOARD_HW_DEFS_GetMPU6000Cfg(__attribute__((unused
)) uint32_t board_revision
)
559 return &pios_mpu6000_cfg
;
561 #endif /* PIOS_INCLUDE_MPU6000 */