dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
board_hw_defs.c
Go to the documentation of this file.
1 
17 /*
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful, but
24  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26  * for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with this program; if not, see <http://www.gnu.org/licenses/>
30  */
31 
32 #include <pios.h>
33 #include <pios_config.h>
34 #include <pios_board_info.h>
35 
36 #if defined(PIOS_INCLUDE_ANNUNC)
37 
38 #include <pios_annunc_priv.h>
39 static const struct pios_annunc pios_annuncs[] = {
40  [PIOS_LED_HEARTBEAT] = {
41  .pin = {
42  .gpio = GPIOC,
43  .init = {
44  .GPIO_Pin = GPIO_Pin_15,
45  .GPIO_Speed = GPIO_Speed_50MHz,
46  .GPIO_Mode = GPIO_Mode_OUT,
47  .GPIO_OType = GPIO_OType_PP,
48  .GPIO_PuPd = GPIO_PuPd_NOPULL
49  },
50  },
51  .active_high = false,
52  },
53  [PIOS_LED_ALARM] = {
54  .pin = {
55  .gpio = GPIOC,
56  .init = {
57  .GPIO_Pin = GPIO_Pin_14,
58  .GPIO_Speed = GPIO_Speed_50MHz,
59  .GPIO_Mode = GPIO_Mode_OUT,
60  .GPIO_OType = GPIO_OType_PP,
61  .GPIO_PuPd = GPIO_PuPd_NOPULL
62  },
63  },
64  .active_high = false,
65  },
67  .pin = {
68  // Not sure. Using values from CleanFlight which seem
69  // to imply this is active low.
70  .gpio = GPIOB,
71  .init = {
72  .GPIO_Pin = GPIO_Pin_13,
73  .GPIO_Speed = GPIO_Speed_50MHz,
74  .GPIO_Mode = GPIO_Mode_OUT,
75  .GPIO_OType = GPIO_OType_PP,
76  .GPIO_PuPd = GPIO_PuPd_NOPULL
77  },
78  },
79  .active_high = true,
80  },
81 };
82 
83 static const struct pios_annunc_cfg pios_annunc_cfg = {
84  .annunciators = pios_annuncs,
85  .num_annunciators = NELEMENTS(pios_annuncs),
86 };
87 
88 const struct pios_annunc_cfg * PIOS_BOARD_HW_DEFS_GetLedCfg (uint32_t board_revision)
89 {
90  return &pios_annunc_cfg;
91 }
92 
93 #endif /* PIOS_INCLUDE_ANNUNC */
94 
95 #if defined(PIOS_INCLUDE_SPI)
96 #include <pios_spi_priv.h>
97 /*
98  * SPI1 Interface
99  * Used for MPU9250 gyro, accelerometer and mag
100  */
101 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
102  .regs = SPI1,
103  .remap = GPIO_AF_5,
104  .init = {
105  .SPI_Mode = SPI_Mode_Master,
106  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
107  .SPI_DataSize = SPI_DataSize_8b,
108  .SPI_NSS = SPI_NSS_Soft,
109  .SPI_FirstBit = SPI_FirstBit_MSB,
110  .SPI_CRCPolynomial = 7,
111  .SPI_CPOL = SPI_CPOL_Low,
112  .SPI_CPHA = SPI_CPHA_1Edge,
113  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
114  },
115  .sclk = {
116  .gpio = GPIOB,
117  .init = {
118  .GPIO_Pin = GPIO_Pin_3,
119  .GPIO_Speed = GPIO_Speed_50MHz,
120  .GPIO_Mode = GPIO_Mode_AF,
121  .GPIO_OType = GPIO_OType_PP,
122  .GPIO_PuPd = GPIO_PuPd_NOPULL
123  },
124  .pin_source = GPIO_PinSource3,
125  },
126  .miso = {
127  .gpio = GPIOB,
128  .init = {
129  .GPIO_Pin = GPIO_Pin_4,
130  .GPIO_Speed = GPIO_Speed_50MHz,
131  .GPIO_Mode = GPIO_Mode_AF,
132  .GPIO_OType = GPIO_OType_PP,
133  .GPIO_PuPd = GPIO_PuPd_NOPULL
134  },
135  .pin_source = GPIO_PinSource4,
136  },
137  .mosi = {
138  .gpio = GPIOB,
139  .init = {
140  .GPIO_Pin = GPIO_Pin_5,
141  .GPIO_Speed = GPIO_Speed_50MHz,
142  .GPIO_Mode = GPIO_Mode_AF,
143  .GPIO_OType = GPIO_OType_PP,
144  .GPIO_PuPd = GPIO_PuPd_NOPULL
145  },
146  .pin_source = GPIO_PinSource5,
147  },
148  .slave_count = 1,
149  .ssel = { {
150  .gpio = GPIOA,
151  .init = {
152  .GPIO_Pin = GPIO_Pin_4,
153  .GPIO_Speed = GPIO_Speed_50MHz,
154  .GPIO_Mode = GPIO_Mode_OUT,
155  .GPIO_OType = GPIO_OType_PP,
156  .GPIO_PuPd = GPIO_PuPd_UP
157  },
158  } },
159 };
160 #endif
161 
162 #if defined(PIOS_INCLUDE_FLASH)
163 #include "pios_flashfs_logfs_priv.h"
164 
165 static const struct flashfs_logfs_cfg flashfs_internal_settings_cfg = {
166  .fs_magic = 0x9ae1ee11,
167  .arena_size = 0x00002000, /* 32 * slot size = 8K bytes = 4 sectors */
168  .slot_size = 0x00000100, /* 256 bytes */
169 };
170 
172 
173 static const struct pios_flash_internal_cfg flash_internal_cfg = {
174 };
175 
176 #include "pios_flash_priv.h"
177 
178 static const struct pios_flash_sector_range stm32f3_sectors[] = {
179  {
180  .base_sector = 0,
181  .last_sector = 127,
182  .sector_size = FLASH_SECTOR_2KB,
183  },
184 };
185 
186 uintptr_t pios_internal_flash_id;
187 static const struct pios_flash_chip pios_flash_chip_internal = {
189  .chip_id = &pios_internal_flash_id,
190  .page_size = 16, /* 128-bit rows */
191  .sector_blocks = stm32f3_sectors,
192  .num_blocks = NELEMENTS(stm32f3_sectors),
193 };
194 
195 static const struct pios_flash_partition pios_flash_partition_table[] = {
196  {
198  .chip_desc = &pios_flash_chip_internal,
199  .first_sector = 0,
200  .last_sector = 7,
201  .chip_offset = 0,
202  .size = (7 - 0 + 1) * FLASH_SECTOR_2KB,
203  },
204 
205  {
207  .chip_desc = &pios_flash_chip_internal,
208  .first_sector = 8,
209  .last_sector = 15,
210  .chip_offset = (8 * FLASH_SECTOR_2KB),
211  .size = (15 - 8 + 1) * FLASH_SECTOR_2KB,
212  },
213 
214  {
216  .chip_desc = &pios_flash_chip_internal,
217  .first_sector = 16,
218  .last_sector = 23,
219  .chip_offset = (16 * FLASH_SECTOR_2KB),
220  .size = (23 - 16 + 1) * FLASH_SECTOR_2KB,
221  },
222 
223  {
224  .label = FLASH_PARTITION_LABEL_FW,
225  .chip_desc = &pios_flash_chip_internal,
226  .first_sector = 24,
227  .last_sector = 127,
228  .chip_offset = (24 * FLASH_SECTOR_2KB),
229  .size = (127 - 24 + 1) * FLASH_SECTOR_2KB,
230  },
231 };
232 
233 const struct pios_flash_partition * PIOS_BOARD_HW_DEFS_GetPartitionTable (uint32_t board_revision, uint32_t * num_partitions)
234 {
235  PIOS_Assert(num_partitions);
236 
237  *num_partitions = NELEMENTS(pios_flash_partition_table);
239 }
240 
241 #endif /* PIOS_INCLUDE_FLASH */
242 
243 
244 
245 #if defined(PIOS_INCLUDE_USART)
246 
247 #include "pios_usart_priv.h"
248 
249 #if defined(PIOS_INCLUDE_DSM)
250 /*
251  * Spektrum/JR DSM USART
252  */
253 #include <pios_dsm_priv.h>
254 
255 static const struct pios_dsm_cfg pios_rxport_dsm_aux_cfg = {
256  .bind = {
257  .gpio = GPIOC,
258  .init = {
259  .GPIO_Pin = GPIO_Pin_5,
260  .GPIO_Speed = GPIO_Speed_2MHz,
261  .GPIO_Mode = GPIO_Mode_OUT,
262  .GPIO_OType = GPIO_OType_PP,
263  .GPIO_PuPd = GPIO_PuPd_NOPULL
264  },
265  },
266 };
267 
268 static const struct pios_dsm_cfg pios_uart2_dsm_aux_cfg = {
269  .bind = {
270  .gpio = GPIOA,
271  .init = {
272  .GPIO_Pin = GPIO_Pin_15,
273  .GPIO_Speed = GPIO_Speed_2MHz,
274  .GPIO_Mode = GPIO_Mode_OUT,
275  .GPIO_OType = GPIO_OType_PP,
276  .GPIO_PuPd = GPIO_PuPd_NOPULL
277  },
278  },
279 };
280 
281 static const struct pios_dsm_cfg pios_uart3_dsm_aux_cfg = {
282  .bind = {
283  .gpio = GPIOB,
284  .init = {
285  .GPIO_Pin = GPIO_Pin_11,
286  .GPIO_Speed = GPIO_Speed_2MHz,
287  .GPIO_Mode = GPIO_Mode_OUT,
288  .GPIO_OType = GPIO_OType_PP,
289  .GPIO_PuPd = GPIO_PuPd_NOPULL
290  },
291  },
292 };
293 
294 #endif /* PIOS_INCLUDE_DSM */
295 
296 static const struct pios_usart_cfg pios_uart2_cfg = {
297  .regs = USART2,
298  .remap = GPIO_AF_7,
299  .irq = {
300  .init = {
301  .NVIC_IRQChannel = USART2_IRQn,
302  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
303  .NVIC_IRQChannelSubPriority = 0,
304  .NVIC_IRQChannelCmd = ENABLE,
305  },
306  },
307  .rx = {
308  .gpio = GPIOA,
309  .init = {
310  .GPIO_Pin = GPIO_Pin_15,
311  .GPIO_Speed = GPIO_Speed_2MHz,
312  .GPIO_Mode = GPIO_Mode_AF,
313  .GPIO_OType = GPIO_OType_PP,
314  .GPIO_PuPd = GPIO_PuPd_UP
315  },
316  .pin_source = GPIO_PinSource15,
317  },
318  .tx = {
319  .gpio = GPIOA,
320  .init = {
321  .GPIO_Pin = GPIO_Pin_14,
322  .GPIO_Speed = GPIO_Speed_2MHz,
323  .GPIO_Mode = GPIO_Mode_AF,
324  .GPIO_OType = GPIO_OType_PP,
325  .GPIO_PuPd = GPIO_PuPd_DOWN
326  },
327  .pin_source = GPIO_PinSource14,
328  },
329 };
330 
331 static const struct pios_usart_cfg pios_uart3_cfg = {
332  .regs = USART3,
333  .remap = GPIO_AF_7,
334  .irq = {
335  .init = {
336  .NVIC_IRQChannel = USART3_IRQn,
337  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
338  .NVIC_IRQChannelSubPriority = 0,
339  .NVIC_IRQChannelCmd = ENABLE,
340  },
341  },
342  .rx = {
343  .gpio = GPIOB,
344  .init = {
345  .GPIO_Pin = GPIO_Pin_11,
346  .GPIO_Speed = GPIO_Speed_2MHz,
347  .GPIO_Mode = GPIO_Mode_AF,
348  .GPIO_OType = GPIO_OType_PP,
349  .GPIO_PuPd = GPIO_PuPd_UP
350  },
351  .pin_source = GPIO_PinSource11,
352  },
353  .tx = {
354  .gpio = GPIOB,
355  .init = {
356  .GPIO_Pin = GPIO_Pin_10,
357  .GPIO_Speed = GPIO_Speed_2MHz,
358  .GPIO_Mode = GPIO_Mode_AF,
359  .GPIO_OType = GPIO_OType_PP,
360  .GPIO_PuPd = GPIO_PuPd_DOWN
361  },
362  .pin_source = GPIO_PinSource10,
363  },
364 };
365 
366 static const struct pios_usart_cfg pios_rxport_usart_cfg = {
367  .regs = USART1,
368  .remap = GPIO_AF_7,
369  .irq = {
370  .init = {
371  .NVIC_IRQChannel = USART1_IRQn,
372  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
373  .NVIC_IRQChannelSubPriority = 0,
374  .NVIC_IRQChannelCmd = ENABLE,
375  },
376  },
377  .rx = {
378  .gpio = GPIOC,
379  .init = {
380  .GPIO_Pin = GPIO_Pin_5,
381  .GPIO_Speed = GPIO_Speed_2MHz,
382  .GPIO_Mode = GPIO_Mode_AF,
383  .GPIO_OType = GPIO_OType_PP,
384  .GPIO_PuPd = GPIO_PuPd_UP
385  },
386  .pin_source = GPIO_PinSource5,
387  },
388  .tx = {
389  .gpio = GPIOC,
390  .init = {
391  .GPIO_Pin = GPIO_Pin_4,
392  .GPIO_Speed = GPIO_Speed_2MHz,
393  .GPIO_Mode = GPIO_Mode_AF,
394  .GPIO_OType = GPIO_OType_PP,
395  .GPIO_PuPd = GPIO_PuPd_DOWN
396  },
397  .pin_source = GPIO_PinSource4,
398  },
399 };
400 
401 #endif /* PIOS_INCLUDE_USART */
402 
403 #if defined(PIOS_INCLUDE_COM)
404 
405 #include "pios_com_priv.h"
406 
407 #endif /* PIOS_INCLUDE_COM */
408 
409 #if defined(PIOS_INCLUDE_RTC)
410 /*
411  * Realtime Clock (RTC)
412  */
413 #include <pios_rtc_priv.h>
414 
415 void PIOS_RTC_IRQ_Handler (void);
416 void RTC_WKUP_IRQHandler() __attribute__ ((alias ("PIOS_RTC_IRQ_Handler")));
417 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
418  .clksrc = RCC_RTCCLKSource_HSE_Div32,
419  .prescaler = 25 - 1, // 8MHz / 32 / 16 / 25 == 625Hz
420  .irq = {
421  .init = {
422  .NVIC_IRQChannel = RTC_WKUP_IRQn,
423  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
424  .NVIC_IRQChannelSubPriority = 0,
425  .NVIC_IRQChannelCmd = ENABLE,
426  },
427  },
428 };
429 
430 void PIOS_RTC_IRQ_Handler (void)
431 {
433 }
434 
435 #endif
436 
437 
438 #include "pios_tim_priv.h"
439 
440 static const TIM_TimeBaseInitTypeDef tim_1_15_16_17_time_base = {
441  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
442  .TIM_ClockDivision = TIM_CKD_DIV1,
443  .TIM_CounterMode = TIM_CounterMode_Up,
444  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
445  .TIM_RepetitionCounter = 0x0000,
446 };
447 
448 static const TIM_TimeBaseInitTypeDef tim_2_3_time_base = {
449  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000 * 2) - 1,
450  .TIM_ClockDivision = TIM_CKD_DIV1,
451  .TIM_CounterMode = TIM_CounterMode_Up,
452  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
453  .TIM_RepetitionCounter = 0x0000,
454 };
455 
456 static const struct pios_tim_clock_cfg tim_2_cfg = {
457  .timer = TIM2,
458  .time_base_init = &tim_2_3_time_base,
459  .irq = {
460  .init = {
461  .NVIC_IRQChannel = TIM2_IRQn,
462  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
463  .NVIC_IRQChannelSubPriority = 0,
464  .NVIC_IRQChannelCmd = ENABLE,
465  },
466  },
467 };
468 
469 static const struct pios_tim_clock_cfg tim_3_cfg = {
470  .timer = TIM3,
471  .time_base_init = &tim_2_3_time_base,
472  .irq = {
473  .init = {
474  .NVIC_IRQChannel = TIM3_IRQn,
475  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
476  .NVIC_IRQChannelSubPriority = 0,
477  .NVIC_IRQChannelCmd = ENABLE,
478  },
479  },
480 };
481 
482 static const struct pios_tim_clock_cfg tim_1_cfg = {
483  .timer = TIM1,
484  .time_base_init = &tim_1_15_16_17_time_base,
485  .irq = {
486  .init = {
487  .NVIC_IRQChannel = TIM1_CC_IRQn,
488  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
489  .NVIC_IRQChannelSubPriority = 0,
490  .NVIC_IRQChannelCmd = ENABLE,
491  },
492  },
493 };
494 static const struct pios_tim_clock_cfg tim_15_cfg = {
495  .timer = TIM15,
496  .time_base_init = &tim_1_15_16_17_time_base,
497  .irq = {
498  .init = {
499  .NVIC_IRQChannel = TIM1_BRK_TIM15_IRQn,
500  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
501  .NVIC_IRQChannelSubPriority = 0,
502  .NVIC_IRQChannelCmd = ENABLE,
503  },
504  },
505 };
506 
507 static const struct pios_tim_clock_cfg tim_16_cfg = {
508  .timer = TIM16,
509  .time_base_init = &tim_1_15_16_17_time_base,
510  .irq = {
511  .init = {
512  .NVIC_IRQChannel = TIM1_UP_TIM16_IRQn,
513  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
514  .NVIC_IRQChannelSubPriority = 0,
515  .NVIC_IRQChannelCmd = ENABLE,
516  },
517  },
518 };
519 static const struct pios_tim_clock_cfg tim_17_cfg = {
520  .timer = TIM17,
521  .time_base_init = &tim_1_15_16_17_time_base,
522  .irq = {
523  .init = {
524  .NVIC_IRQChannel = TIM1_TRG_COM_TIM17_IRQn,
525  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
526  .NVIC_IRQChannelSubPriority = 0,
527  .NVIC_IRQChannelCmd = ENABLE,
528  },
529  },
530 };
531 
535 /*
536  * OUTPUTS
537  1: TIM3_CH1 (PC6)
538  2: TIM3_CH2 (PC7)
539  3: TIM3_CH3 (PC8)
540  4: TIM3_CH4 (PC9)
541  */
543  { // Ch1
544  .timer = TIM3,
545  .timer_chan = TIM_Channel_1,
546  .remap = GPIO_AF_2,
547  .pin = {
548  .gpio = GPIOC,
549  .init = {
550  .GPIO_Pin = GPIO_Pin_6,
551  .GPIO_Speed = GPIO_Speed_2MHz,
552  .GPIO_Mode = GPIO_Mode_AF,
553  .GPIO_OType = GPIO_OType_PP,
554  .GPIO_PuPd = GPIO_PuPd_UP
555  },
556  .pin_source = GPIO_PinSource6,
557  },
558  },
559  { // Ch2
560  .timer = TIM3,
561  .timer_chan = TIM_Channel_2,
562  .remap = GPIO_AF_2,
563  .pin = {
564  .gpio = GPIOC,
565  .init = {
566  .GPIO_Pin = GPIO_Pin_7,
567  .GPIO_Speed = GPIO_Speed_2MHz,
568  .GPIO_Mode = GPIO_Mode_AF,
569  .GPIO_OType = GPIO_OType_PP,
570  .GPIO_PuPd = GPIO_PuPd_UP
571  },
572  .pin_source = GPIO_PinSource7,
573  },
574  },
575  { // Ch3
576  .timer = TIM3,
577  .timer_chan = TIM_Channel_3,
578  .remap = GPIO_AF_2,
579  .pin = {
580  .gpio = GPIOC,
581  .init = {
582  .GPIO_Pin = GPIO_Pin_8,
583  .GPIO_Speed = GPIO_Speed_2MHz,
584  .GPIO_Mode = GPIO_Mode_AF,
585  .GPIO_OType = GPIO_OType_PP,
586  .GPIO_PuPd = GPIO_PuPd_UP
587  },
588  .pin_source = GPIO_PinSource8,
589  },
590  },
591  { // Ch4
592  .timer = TIM3,
593  .timer_chan = TIM_Channel_4,
594  .remap = GPIO_AF_2,
595  .pin = {
596  .gpio = GPIOC,
597  .init = {
598  .GPIO_Pin = GPIO_Pin_9,
599  .GPIO_Speed = GPIO_Speed_2MHz,
600  .GPIO_Mode = GPIO_Mode_AF,
601  .GPIO_OType = GPIO_OType_PP,
602  .GPIO_PuPd = GPIO_PuPd_UP
603  },
604  .pin_source = GPIO_PinSource9,
605  },
606  },
607 };
608 
609  /* OUTPUTS
610  1: TIM3_CH1 (PC6)
611  2: TIM3_CH2 (PC7)
612  3: TIM3_CH3 (PC8)
613  4: TIM3_CH4 (PC9)
614  */
615 
617  { // Ch1 TIM3_CH1 (PC6)
618  .timer = TIM3,
619  .timer_chan = TIM_Channel_1,
620  .remap = GPIO_AF_2,
621  .pin = {
622  .gpio = GPIOC,
623  .init = {
624  .GPIO_Pin = GPIO_Pin_6,
625  .GPIO_Speed = GPIO_Speed_2MHz,
626  .GPIO_Mode = GPIO_Mode_AF,
627  .GPIO_OType = GPIO_OType_PP,
628  .GPIO_PuPd = GPIO_PuPd_UP
629  },
630  .pin_source = GPIO_PinSource6,
631  },
632  },
633  { // Ch2 TIM3_CH2 (PC7)
634  .timer = TIM3,
635  .timer_chan = TIM_Channel_2,
636  .remap = GPIO_AF_2,
637  .pin = {
638  .gpio = GPIOC,
639  .init = {
640  .GPIO_Pin = GPIO_Pin_7,
641  .GPIO_Speed = GPIO_Speed_2MHz,
642  .GPIO_Mode = GPIO_Mode_AF,
643  .GPIO_OType = GPIO_OType_PP,
644  .GPIO_PuPd = GPIO_PuPd_UP
645  },
646  .pin_source = GPIO_PinSource7,
647  },
648  },
649  { // Ch3 TIM3_CH3 (PC8)
650  .timer = TIM3,
651  .timer_chan = TIM_Channel_3,
652  .remap = GPIO_AF_2,
653  .pin = {
654  .gpio = GPIOC,
655  .init = {
656  .GPIO_Pin = GPIO_Pin_8,
657  .GPIO_Speed = GPIO_Speed_2MHz,
658  .GPIO_Mode = GPIO_Mode_AF,
659  .GPIO_OType = GPIO_OType_PP,
660  .GPIO_PuPd = GPIO_PuPd_UP
661  },
662  .pin_source = GPIO_PinSource8,
663  },
664  },
665  { // Ch4 TIM3_CH4 (PC9)
666  .timer = TIM3,
667  .timer_chan = TIM_Channel_4,
668  .remap = GPIO_AF_2,
669  .pin = {
670  .gpio = GPIOC,
671  .init = {
672  .GPIO_Pin = GPIO_Pin_9,
673  .GPIO_Speed = GPIO_Speed_2MHz,
674  .GPIO_Mode = GPIO_Mode_AF,
675  .GPIO_OType = GPIO_OType_PP,
676  .GPIO_PuPd = GPIO_PuPd_UP
677  },
678  .pin_source = GPIO_PinSource9,
679  },
680  },
681 };
682 
683 
684 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
685 /*
686  * Servo outputs
687  */
688 #include <pios_servo_priv.h>
689 
690 static const struct pios_servo_cfg pios_servo_cfg = {
691  .tim_oc_init = {
692  .TIM_OCMode = TIM_OCMode_PWM1,
693  .TIM_OutputState = TIM_OutputState_Enable,
694  .TIM_OutputNState = TIM_OutputNState_Disable,
695  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
696  .TIM_OCPolarity = TIM_OCPolarity_High,
697  .TIM_OCNPolarity = TIM_OCPolarity_High,
698  .TIM_OCIdleState = TIM_OCIdleState_Reset,
699  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
700  },
701  .channels = pios_tim_servoport_v02_pins,
702  .num_channels = NELEMENTS(pios_tim_servoport_v02_pins),
703 };
704 
705 #endif /* PIOS_INCLUDE_SERVO && PIOS_INCLUDE_TIM */
706 
707 
708 
709 /*
710  * PPM Input
711  */
712 #if defined(PIOS_INCLUDE_PPM)
713 #include <pios_pwm_priv.h>
714 
715 /*
716  * INPUTS
717  1: TIM1_CH1 (PA8)
718  */
719 static const struct pios_tim_channel pios_tim_rxport_ppm[] = {
720  {
721  .timer = TIM1,
722  .timer_chan = TIM_Channel_1,
723  .remap = GPIO_AF_6,
724  .pin = {
725  .gpio = GPIOA,
726  .init = {
727  .GPIO_Pin = GPIO_Pin_8,
728  .GPIO_Speed = GPIO_Speed_2MHz,
729  .GPIO_Mode = GPIO_Mode_AF,
730  .GPIO_OType = GPIO_OType_PP,
731  .GPIO_PuPd = GPIO_PuPd_UP
732  },
733  .pin_source = GPIO_PinSource8,
734  },
735  },
736 };
737 #endif
738 
739 /*
740  * PPM Input
741  */
742 #if defined(PIOS_INCLUDE_PPM)
743 #include <pios_ppm_priv.h>
744 static const struct pios_ppm_cfg pios_ppm_cfg = {
745  .tim_ic_init = {
746  .TIM_ICPolarity = TIM_ICPolarity_Rising,
747  .TIM_ICSelection = TIM_ICSelection_DirectTI,
748  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
749  .TIM_ICFilter = 0x0,
750  .TIM_Channel = TIM_Channel_1,
751  },
752  /* Use only the first channel for ppm */
753  .channels = pios_tim_rxport_ppm,
754  .num_channels = 1,
755 };
756 
757 #endif //PPM
758 
759 #if defined(PIOS_INCLUDE_ADC)
760 #include "pios_adc_priv.h"
761 #include "pios_internal_adc_priv.h"
762 
763 uintptr_t pios_internal_adc_id;
764 
765 void DMA1_Channel1_IRQHandler(void) __attribute__((alias("PIOS_ADC_DMA_irq_handler")));
766 
767 void PIOS_ADC_DMA_irq_handler(void)
768 {
769  /* Call into the generic code to handle the IRQ for this specific device */
770  PIOS_INTERNAL_ADC_DMA_Handler(pios_internal_adc_id);
771 }
772 
773 static const struct pios_internal_adc_cfg internal_adc_cfg = {
774  .dma = {
775  .irq = {
776  .flags = (DMA1_FLAG_TC1 | DMA1_FLAG_TE1 | DMA1_FLAG_HT1 | DMA1_FLAG_GL1),
777  .init = {
778  .NVIC_IRQChannel = DMA1_Channel1_IRQn,
779  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
780  .NVIC_IRQChannelSubPriority = 0,
781  .NVIC_IRQChannelCmd = ENABLE,
782  },
783  },
784  .rx = {
785  .channel = DMA1_Channel1,
786  .init = {
787  .DMA_Priority = DMA_Priority_High,
788  },
789  }
790  },
791  .half_flag = DMA1_IT_HT1,
792  .full_flag = DMA1_IT_TC1,
793  .oversampling = 32,
794  .adc_pin_count = 3,
795  .adc_pins = {
796  {GPIOC,GPIO_Pin_0,ADC_Channel_6,true},
797  {GPIOC,GPIO_Pin_1,ADC_Channel_7,false},
798  {GPIOC,GPIO_Pin_2,ADC_Channel_8,false},
799  },
800  .adc_dev_master = ADC1,
801  .adc_dev_slave = ADC2,
802 };
803 
804 #endif /* PIOS_INCLUDE_ADC */
805 
806 #if defined(PIOS_INCLUDE_RCVR)
807 #include "pios_rcvr_priv.h"
808 #endif /* PIOS_INCLUDE_RCVR */
809 
810 #if defined(PIOS_INCLUDE_USB)
811 #include "pios_usb_priv.h"
812 
813 static const struct pios_usb_cfg pios_usb_main_cfg = {
814  .irq = {
815  .init = {
816  .NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
817  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
818  .NVIC_IRQChannelSubPriority = 0,
819  .NVIC_IRQChannelCmd = ENABLE,
820  },
821  },
822  .vsense = {
823  .gpio = NULL
824  }
825 };
826 
827 const struct pios_usb_cfg * PIOS_BOARD_HW_DEFS_GetUsbCfg (uint32_t board_revision)
828 {
829  return &pios_usb_main_cfg;
830 }
831 
835 #include "pios_usbhook.h"
836 
837 #endif /* PIOS_INCLUDE_USB */
838 
839 #if defined(PIOS_INCLUDE_WS2811)
840 #include "pios_ws2811.h"
841 
843 
844 static const struct pios_ws2811_cfg pios_ws2811_cfg = {
845  .timer = TIM16,
846  .timer_chan = TIM_Channel_1,
847  .led_gpio = GPIOA,
848  .gpio_pin = GPIO_Pin_6,
849  .remap = GPIO_AF_1,
850  .timer_dma_source = TIM_DMA_Update,
851  .dma_chan = DMA1_Channel3,
852  .dma_tcif = DMA1_FLAG_TC3,
853  .dma_irqn = DMA1_Channel3_IRQn,
854 };
855 #endif /* PIOS_INCLUDE_WS2811 */
856 
857 #if defined(PIOS_INCLUDE_COM_MSG)
858 
859 #include <pios_com_msg_priv.h>
860 
861 #endif /* PIOS_INCLUDE_COM_MSG */
862 
863 #if defined(PIOS_INCLUDE_USB_HID)
864 #include <pios_usb_hid_priv.h>
865 
866 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
867  .data_if = 0,
868  .data_rx_ep = 1,
869  .data_tx_ep = 1,
870 };
871 #endif /* PIOS_INCLUDE_USB_HID */
872 
873 #if defined(PIOS_INCLUDE_USB_CDC)
874 #include <pios_usb_cdc_priv.h>
875 
876 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
877  .ctrl_if = 1,
878  .ctrl_tx_ep = 2,
879 
880  .data_if = 2,
881  .data_rx_ep = 3,
882  .data_tx_ep = 3,
883 };
884 #endif /* PIOS_INCLUDE_USB_CDC */
885 
886 
890 #if defined(PIOS_INCLUDE_MPU)
891 #include "pios_mpu.h"
892 static const struct pios_exti_cfg pios_exti_mpu_cfg __exti_config = {
893  .vector = PIOS_MPU_IRQHandler,
894  .line = EXTI_Line5,
895  .pin = {
896  .gpio = GPIOA,
897  .init = {
898  .GPIO_Pin = GPIO_Pin_5,
899  .GPIO_Speed = GPIO_Speed_50MHz,
900  .GPIO_Mode = GPIO_Mode_IN,
901  .GPIO_OType = GPIO_OType_OD,
902  .GPIO_PuPd = GPIO_PuPd_NOPULL,
903  },
904  },
905  .irq = {
906  .init = {
907  .NVIC_IRQChannel = EXTI9_5_IRQn,
908  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
909  .NVIC_IRQChannelSubPriority = 0,
910  .NVIC_IRQChannelCmd = ENABLE,
911  },
912  },
913  .exti = {
914  .init = {
915  .EXTI_Line = EXTI_Line5, // matches above GPIO pin
916  .EXTI_Mode = EXTI_Mode_Interrupt,
917  .EXTI_Trigger = EXTI_Trigger_Rising,
918  .EXTI_LineCmd = ENABLE,
919  },
920  },
921 };
922 
923 static struct pios_mpu_cfg pios_mpu_cfg = {
924  .exti_cfg = &pios_exti_mpu_cfg,
925  .default_samplerate = 1000,
926  .orientation = PIOS_MPU_TOP_180DEG,
927  //.use_internal_mag = false,
928 };
929 
930 #endif /* PIOS_INCLUDE_MPU */
931 
struct stm32_gpio pin
Main PiOS header to include all the compiled in PiOS options.
SPI private definitions.
#define NELEMENTS(x)
Definition: pios.h:192
struct stm32_gpio bind
#define FLASH_SECTOR_2KB
COM private definitions.
COM MSG private definitions.
APIs for PIOS_USBHOOK layer.
GPIO_TypeDef * gpio
Definition: pios_stm32.h:60
static const struct pios_tim_clock_cfg tim_1_cfg
ADC private definitions.
#define PIOS_IRQ_PRIO_HIGHEST
Definition: pios_board.h:172
static const struct pios_tim_clock_cfg tim_3_cfg
#define PIOS_SERVOS_INITIAL_POSITION
Definition: pios_board.h:210
Defines the API to set up the HID + CDC USB descriptor config.
void PIOS_INTERNAL_ADC_DMA_Handler()
#define RTC_WKUP_IRQHandler
#define DMA1_Channel1_IRQHandler
static const struct pios_tim_clock_cfg tim_16_cfg
#define PIOS_LED_ALARM
Definition: pios_board.h:86
#define PIOS_IRQ_PRIO_MID
Definition: pios_board.h:170
USART private definitions.
struct stm32_irq irq
Definition: pios_stm32.h:54
Spektrum/JR DSMx satellite receiver private structures.
static const TIM_TimeBaseInitTypeDef tim_2_3_time_base
const struct pios_exti_cfg * exti_cfg
Definition: pios_mpu.h:140
static const struct pios_tim_clock_cfg tim_15_cfg
#define PIOS_SERVO_UPDATE_HZ
Definition: pios_board.h:209
TIM_TypeDef * timer
Definition: pios_tim_priv.h:7
SPI_TypeDef * regs
Definition: pios_spi_priv.h:44
static const TIM_TimeBaseInitTypeDef tim_1_15_16_17_time_base
uintptr_t pios_internal_adc_id
Definition: pios_board.c:51
#define PIOS_PERIPHERAL_APB1_CLOCK
Definition: pios_board.h:154
ws2811_dev_t pios_ws2811
Definition: pios_board.c:66
const struct pios_annunc * annunciators
TIM_TypeDef * timer
ppm private structures.
NVIC_InitTypeDef init
Definition: pios_stm32.h:36
USART_TypeDef * regs
USB private definitions.
TIM_OCInitTypeDef tim_oc_init
USB COM HID private definitions.
static const struct pios_tim_channel pios_tim_servoport_v02_pins[]
ADC private definitions.
Servo private structures.
TIM_ICInitTypeDef tim_ic_init
Definition: pios_ppm_priv.h:37
Defines the API to set up the HID-only USB descriptor config.
uint32_t flags
Definition: pios_stm32.h:35
void PIOS_RTC_irq_handler(void)
#define PIOS_PERIPHERAL_APB2_CLOCK
Definition: pios_board.h:164
bool PIOS_MPU_IRQHandler(void)
The IMU interrupt handler. Fetches new data from the IMU.
const struct pios_flash_driver * driver
const struct pios_flash_partition pios_flash_partition_table[]
Definition: unittest_init.c:50
#define PIOS_IRQ_PRIO_HIGH
Definition: pios_board.h:171
TIM_TypeDef * timer
Definition: pios_tim_priv.h:14
USB COM CDC private definitions.
uint32_t clksrc
Definition: pios_rtc_priv.h:37
enum pios_flash_partition_labels label
board_revision
Definition: board_hw_defs.c:35
#define PIOS_IRQ_PRIO_LOW
Definition: pios_board.h:169
static const struct pios_tim_clock_cfg tim_17_cfg
#define PIOS_Assert(test)
Definition: pios_debug.h:52
static const struct pios_tim_channel pios_tim_servoport_v01_pins[]
static const struct pios_tim_clock_cfg tim_2_cfg
LED private definitions.
#define PIOS_ANNUNCIATOR_BUZZER
Definition: pios_board.h:87
struct stm32_irq irq
Definition: pios_usb_priv.h:37
const struct pios_flash_driver pios_internal_flash_driver
USART private definitions.
#define PIOS_LED_HEARTBEAT
Definition: pios_board.h:85
#define __exti_config
Definition: pios_exti.h:48
Defines the API to the board-specific USB data setup code.