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  * Additional note on redistribution: The copyright and license notices above
32  * must be maintained in each individual source file that is a derivative work
33  * of this source file; otherwise redistribution is prohibited.
34  */
35 
36 #include <pios_config.h>
37 #include <pios_board_info.h>
38 
39 #if defined(PIOS_INCLUDE_ANNUNC)
40 
41 #include <pios_annunc_priv.h>
42 static const struct pios_annunc pios_annuncs[] = {
43  [PIOS_LED_HEARTBEAT] = {
44  .pin = {
45  .gpio = GPIOA,
46  .init = {
47  .GPIO_Pin = GPIO_Pin_13,
48  .GPIO_Speed = GPIO_Speed_50MHz,
49  .GPIO_Mode = GPIO_Mode_OUT,
50  .GPIO_OType = GPIO_OType_PP,
51  .GPIO_PuPd = GPIO_PuPd_NOPULL
52  },
53  },
54  .active_high = false,
55  },
56  [PIOS_LED_ALARM] = {
57  .pin = {
58  .gpio = GPIOA,
59  .init = {
60  .GPIO_Pin = GPIO_Pin_14,
61  .GPIO_Speed = GPIO_Speed_50MHz,
62  .GPIO_Mode = GPIO_Mode_OUT,
63  .GPIO_OType = GPIO_OType_PP,
64  .GPIO_PuPd = GPIO_PuPd_NOPULL
65  },
66  },
67  .active_high = false,
68  },
69  [PIOS_LED_USB] = {
70  .pin = {
71  .gpio = GPIOA,
72  .init = {
73  .GPIO_Pin = GPIO_Pin_15,
74  .GPIO_Speed = GPIO_Speed_50MHz,
75  .GPIO_Mode = GPIO_Mode_OUT,
76  .GPIO_OType = GPIO_OType_PP,
77  .GPIO_PuPd = GPIO_PuPd_NOPULL
78  },
79  },
80  .active_high = false,
81  },
83  // Bipolar NPN low side, 100R base; 26mA flows, kinda naughty
84  .pin = {
85  .gpio = GPIOB,
86  .init = {
87  .GPIO_Pin = GPIO_Pin_2,
88  .GPIO_Speed = GPIO_Speed_50MHz,
89  .GPIO_Mode = GPIO_Mode_OUT,
90  .GPIO_OType = GPIO_OType_PP,
91  .GPIO_PuPd = GPIO_PuPd_NOPULL
92  },
93  },
94  .active_high = true,
95  },
96 };
97 
98 static const struct pios_annunc_cfg pios_annunc_cfg = {
99  .annunciators = pios_annuncs,
100  .num_annunciators = NELEMENTS(pios_annuncs),
101 };
102 
103 const struct pios_annunc_cfg * PIOS_BOARD_HW_DEFS_GetLedCfg (uint32_t board_revision)
104 {
105  return &pios_annunc_cfg;
106 }
107 
108 #endif /* PIOS_INCLUDE_ANNUNC */
109 
110 #if defined(PIOS_INCLUDE_SPI)
111 #include <pios_spi_priv.h>
112 /*
113  * SPI1 Interface
114  * Used for ICM20608G gyro and accelerometer
115  */
116 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
117  .regs = SPI1,
118  .remap = GPIO_AF_5,
119  .init = {
120  .SPI_Mode = SPI_Mode_Master,
121  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
122  .SPI_DataSize = SPI_DataSize_8b,
123  .SPI_NSS = SPI_NSS_Soft,
124  .SPI_FirstBit = SPI_FirstBit_MSB,
125  .SPI_CRCPolynomial = 7,
126  .SPI_CPOL = SPI_CPOL_Low,
127  .SPI_CPHA = SPI_CPHA_1Edge,
128  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
129  },
130  .sclk = {
131  .gpio = GPIOB,
132  .init = {
133  .GPIO_Pin = GPIO_Pin_3,
134  .GPIO_Speed = GPIO_Speed_50MHz,
135  .GPIO_Mode = GPIO_Mode_AF,
136  .GPIO_OType = GPIO_OType_PP,
137  .GPIO_PuPd = GPIO_PuPd_NOPULL
138  },
139  .pin_source = GPIO_PinSource3,
140  },
141  .miso = {
142  .gpio = GPIOB,
143  .init = {
144  .GPIO_Pin = GPIO_Pin_4,
145  .GPIO_Speed = GPIO_Speed_50MHz,
146  .GPIO_Mode = GPIO_Mode_AF,
147  .GPIO_OType = GPIO_OType_PP,
148  .GPIO_PuPd = GPIO_PuPd_NOPULL
149  },
150  .pin_source = GPIO_PinSource4,
151  },
152  .mosi = {
153  .gpio = GPIOB,
154  .init = {
155  .GPIO_Pin = GPIO_Pin_5,
156  .GPIO_Speed = GPIO_Speed_50MHz,
157  .GPIO_Mode = GPIO_Mode_AF,
158  .GPIO_OType = GPIO_OType_PP,
159  .GPIO_PuPd = GPIO_PuPd_NOPULL
160  },
161  .pin_source = GPIO_PinSource5,
162  },
163  .slave_count = 1,
164  .ssel = { {
165  .gpio = GPIOC,
166  .init = {
167  .GPIO_Pin = GPIO_Pin_14,
168  .GPIO_Speed = GPIO_Speed_50MHz,
169  .GPIO_Mode = GPIO_Mode_OUT,
170  .GPIO_OType = GPIO_OType_PP,
171  .GPIO_PuPd = GPIO_PuPd_UP
172  },
173  } },
174 };
175 #endif
176 
177 #if defined(PIOS_INCLUDE_FLASH)
178 #include "pios_flashfs_logfs_priv.h"
179 
180 static const struct flashfs_logfs_cfg flashfs_internal_settings_cfg = {
181  .fs_magic = 0x9ae1ee11,
182  .arena_size = 0x00002000, /* 32 * slot size = 8K bytes = 4 sectors */
183  .slot_size = 0x00000100, /* 256 bytes */
184 };
185 
187 
188 static const struct pios_flash_internal_cfg flash_internal_cfg = {
189 };
190 
191 #include "pios_flash_priv.h"
192 
193 static const struct pios_flash_sector_range stm32f3_sectors[] = {
194  {
195  .base_sector = 0,
196  .last_sector = 127,
197  .sector_size = FLASH_SECTOR_2KB,
198  },
199 };
200 
201 uintptr_t pios_internal_flash_id;
202 static const struct pios_flash_chip pios_flash_chip_internal = {
204  .chip_id = &pios_internal_flash_id,
205  .page_size = 16, /* 128-bit rows */
206  .sector_blocks = stm32f3_sectors,
207  .num_blocks = NELEMENTS(stm32f3_sectors),
208 };
209 
210 static const struct pios_flash_partition pios_flash_partition_table[] = {
211  {
213  .chip_desc = &pios_flash_chip_internal,
214  .first_sector = 0,
215  .last_sector = 7,
216  .chip_offset = 0,
217  .size = (7 - 0 + 1) * FLASH_SECTOR_2KB,
218  },
219 
220  {
222  .chip_desc = &pios_flash_chip_internal,
223  .first_sector = 8,
224  .last_sector = 15,
225  .chip_offset = (8 * FLASH_SECTOR_2KB),
226  .size = (15 - 8 + 1) * FLASH_SECTOR_2KB,
227  },
228 
229  {
231  .chip_desc = &pios_flash_chip_internal,
232  .first_sector = 16,
233  .last_sector = 23,
234  .chip_offset = (16 * FLASH_SECTOR_2KB),
235  .size = (23 - 16 + 1) * FLASH_SECTOR_2KB,
236  },
237 
238  {
239  .label = FLASH_PARTITION_LABEL_FW,
240  .chip_desc = &pios_flash_chip_internal,
241  .first_sector = 24,
242  .last_sector = 127,
243  .chip_offset = (24 * FLASH_SECTOR_2KB),
244  .size = (127 - 24 + 1) * FLASH_SECTOR_2KB,
245  },
246 };
247 
248 const struct pios_flash_partition * PIOS_BOARD_HW_DEFS_GetPartitionTable (uint32_t board_revision, uint32_t * num_partitions)
249 {
250  PIOS_Assert(num_partitions);
251 
252  *num_partitions = NELEMENTS(pios_flash_partition_table);
254 }
255 
256 #endif /* PIOS_INCLUDE_FLASH */
257 
258 
259 
260 #if defined(PIOS_INCLUDE_USART)
261 
262 #include "pios_usart_priv.h"
263 
264 #if defined(PIOS_INCLUDE_DSM)
265 /*
266  * Spektrum/JR DSM USART
267  */
268 #include <pios_dsm_priv.h>
269 
270 static const struct pios_dsm_cfg pios_uart1_dsm_cfg = {
271  .bind = {
272  .gpio = GPIOB,
273  .init = {
274  .GPIO_Pin = GPIO_Pin_7,
275  .GPIO_Speed = GPIO_Speed_2MHz,
276  .GPIO_Mode = GPIO_Mode_OUT,
277  .GPIO_OType = GPIO_OType_PP,
278  .GPIO_PuPd = GPIO_PuPd_NOPULL
279  },
280  },
281 };
282 
283 static const struct pios_dsm_cfg pios_uart2_dsm_cfg = {
284  .bind = {
285  .gpio = GPIOA,
286  .init = {
287  .GPIO_Pin = GPIO_Pin_3,
288  .GPIO_Speed = GPIO_Speed_2MHz,
289  .GPIO_Mode = GPIO_Mode_OUT,
290  .GPIO_OType = GPIO_OType_PP,
291  .GPIO_PuPd = GPIO_PuPd_NOPULL
292  },
293  },
294 };
295 
296 static const struct pios_dsm_cfg pios_uart3_dsm_cfg = {
297  .bind = {
298  .gpio = GPIOB,
299  .init = {
300  .GPIO_Pin = GPIO_Pin_11,
301  .GPIO_Speed = GPIO_Speed_2MHz,
302  .GPIO_Mode = GPIO_Mode_OUT,
303  .GPIO_OType = GPIO_OType_PP,
304  .GPIO_PuPd = GPIO_PuPd_NOPULL
305  },
306  },
307 };
308 
309 #endif /* PIOS_INCLUDE_DSM */
310 
311 static const struct pios_usart_cfg pios_uart1_usart_cfg = {
312  .regs = USART1,
313  .remap = GPIO_AF_7,
314  .irq = {
315  .init = {
316  .NVIC_IRQChannel = USART1_IRQn,
317  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
318  .NVIC_IRQChannelSubPriority = 0,
319  .NVIC_IRQChannelCmd = ENABLE,
320  },
321  },
322  .rx = {
323  .gpio = GPIOB,
324  .init = {
325  .GPIO_Pin = GPIO_Pin_7,
326  .GPIO_Speed = GPIO_Speed_2MHz,
327  .GPIO_Mode = GPIO_Mode_AF,
328  .GPIO_OType = GPIO_OType_PP,
329  .GPIO_PuPd = GPIO_PuPd_UP
330  },
331  .pin_source = GPIO_PinSource7,
332  },
333  .tx = {
334  .gpio = GPIOB,
335  .init = {
336  .GPIO_Pin = GPIO_Pin_6,
337  .GPIO_Speed = GPIO_Speed_2MHz,
338  .GPIO_Mode = GPIO_Mode_AF,
339  .GPIO_OType = GPIO_OType_PP,
340  .GPIO_PuPd = GPIO_PuPd_DOWN
341  },
342  .pin_source = GPIO_PinSource6,
343  },
344 };
345 
346 static const struct pios_usart_cfg pios_uart2_usart_cfg = {
347  .regs = USART2,
348  .remap = GPIO_AF_7,
349  .irq = {
350  .init = {
351  .NVIC_IRQChannel = USART2_IRQn,
352  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
353  .NVIC_IRQChannelSubPriority = 0,
354  .NVIC_IRQChannelCmd = ENABLE,
355  },
356  },
357  .rx = {
358  .gpio = GPIOA,
359  .init = {
360  .GPIO_Pin = GPIO_Pin_3,
361  .GPIO_Speed = GPIO_Speed_2MHz,
362  .GPIO_Mode = GPIO_Mode_AF,
363  .GPIO_OType = GPIO_OType_PP,
364  .GPIO_PuPd = GPIO_PuPd_UP
365  },
366  .pin_source = GPIO_PinSource3,
367  },
368  .tx = {
369  .gpio = GPIOA,
370  .init = {
371  .GPIO_Pin = GPIO_Pin_2,
372  .GPIO_Speed = GPIO_Speed_2MHz,
373  .GPIO_Mode = GPIO_Mode_AF,
374  .GPIO_OType = GPIO_OType_PP,
375  .GPIO_PuPd = GPIO_PuPd_DOWN
376  },
377  .pin_source = GPIO_PinSource2,
378  },
379 };
380 
381 static const struct pios_usart_cfg pios_uart3_usart_cfg = {
382  .regs = USART3,
383  .remap = GPIO_AF_7,
384  .irq = {
385  .init = {
386  .NVIC_IRQChannel = USART3_IRQn,
387  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
388  .NVIC_IRQChannelSubPriority = 0,
389  .NVIC_IRQChannelCmd = ENABLE,
390  },
391  },
392  .rx = {
393  .gpio = GPIOB,
394  .init = {
395  .GPIO_Pin = GPIO_Pin_11,
396  .GPIO_Speed = GPIO_Speed_2MHz,
397  .GPIO_Mode = GPIO_Mode_AF,
398  .GPIO_OType = GPIO_OType_PP,
399  .GPIO_PuPd = GPIO_PuPd_UP
400  },
401  .pin_source = GPIO_PinSource11,
402  },
403  .tx = {
404  .gpio = GPIOB,
405  .init = {
406  .GPIO_Pin = GPIO_Pin_10,
407  .GPIO_Speed = GPIO_Speed_2MHz,
408  .GPIO_Mode = GPIO_Mode_AF,
409  .GPIO_OType = GPIO_OType_PP,
410  .GPIO_PuPd = GPIO_PuPd_DOWN
411  },
412  .pin_source = GPIO_PinSource10,
413  },
414 };
415 #endif /* PIOS_INCLUDE_USART */
416 
417 #if defined(PIOS_INCLUDE_COM)
418 
419 #include "pios_com_priv.h"
420 
421 #endif /* PIOS_INCLUDE_COM */
422 
423 #if defined(PIOS_INCLUDE_RTC)
424 /*
425  * Realtime Clock (RTC)
426  */
427 #include <pios_rtc_priv.h>
428 
429 void PIOS_RTC_IRQ_Handler (void);
430 void RTC_WKUP_IRQHandler() __attribute__ ((alias ("PIOS_RTC_IRQ_Handler")));
431 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
432  .clksrc = RCC_RTCCLKSource_HSE_Div32,
433  .prescaler = 25 - 1, // 8MHz / 32 / 16 / 25 == 625Hz
434  .irq = {
435  .init = {
436  .NVIC_IRQChannel = RTC_WKUP_IRQn,
437  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
438  .NVIC_IRQChannelSubPriority = 0,
439  .NVIC_IRQChannelCmd = ENABLE,
440  },
441  },
442 };
443 
444 void PIOS_RTC_IRQ_Handler (void)
445 {
447 }
448 
449 #endif
450 
451 
452 #include "pios_tim_priv.h"
453 
454 static const TIM_TimeBaseInitTypeDef tim_1_15_16_17_time_base = {
455  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
456  .TIM_ClockDivision = TIM_CKD_DIV1,
457  .TIM_CounterMode = TIM_CounterMode_Up,
458  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
459  .TIM_RepetitionCounter = 0x0000,
460 };
461 
462 static const TIM_TimeBaseInitTypeDef tim_2_3_time_base = {
463  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000 * 2) - 1,
464  .TIM_ClockDivision = TIM_CKD_DIV1,
465  .TIM_CounterMode = TIM_CounterMode_Up,
466  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
467  .TIM_RepetitionCounter = 0x0000,
468 };
469 
470 static const struct pios_tim_clock_cfg tim_2_cfg = {
471  .timer = TIM2,
472  .time_base_init = &tim_2_3_time_base,
473  .irq = {
474  .init = {
475  .NVIC_IRQChannel = TIM2_IRQn,
476  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
477  .NVIC_IRQChannelSubPriority = 0,
478  .NVIC_IRQChannelCmd = ENABLE,
479  },
480  },
481 };
482 
483 static const struct pios_tim_clock_cfg tim_1_cfg = {
484  .timer = TIM1,
485  .time_base_init = &tim_1_15_16_17_time_base,
486  .irq = {
487  .init = {
488  .NVIC_IRQChannel = TIM1_CC_IRQn,
489  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
490  .NVIC_IRQChannelSubPriority = 0,
491  .NVIC_IRQChannelCmd = ENABLE,
492  },
493  },
494 };
495 static const struct pios_tim_clock_cfg tim_15_cfg = {
496  .timer = TIM15,
497  .time_base_init = &tim_1_15_16_17_time_base,
498  .irq = {
499  .init = {
500  .NVIC_IRQChannel = TIM1_BRK_TIM15_IRQn,
501  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
502  .NVIC_IRQChannelSubPriority = 0,
503  .NVIC_IRQChannelCmd = ENABLE,
504  },
505  },
506 };
507 
508 static const struct pios_tim_clock_cfg tim_16_cfg = {
509  .timer = TIM16,
510  .time_base_init = &tim_1_15_16_17_time_base,
511  .irq = {
512  .init = {
513  .NVIC_IRQChannel = TIM1_UP_TIM16_IRQn,
514  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
515  .NVIC_IRQChannelSubPriority = 0,
516  .NVIC_IRQChannelCmd = ENABLE,
517  },
518  },
519 };
520 static const struct pios_tim_clock_cfg tim_17_cfg = {
521  .timer = TIM17,
522  .time_base_init = &tim_1_15_16_17_time_base,
523  .irq = {
524  .init = {
525  .NVIC_IRQChannel = TIM1_TRG_COM_TIM17_IRQn,
526  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
527  .NVIC_IRQChannelSubPriority = 0,
528  .NVIC_IRQChannelCmd = ENABLE,
529  },
530  },
531 };
532 
536 /*
537  * OUTPUTS
538  1: TIM4_CH3 (PB8)
539  2: TIM4_CH4 (PB9)
540  3: TIM2_CH4 (PA10)
541  4: TIM2_CH3 (PA9)
542  5: TIM2_CH1 (PA0)
543  6: TIM2_CH2 (PA1)
544  7: TIM3_CH3 (PB0)
545  8: TIM3_CH4 (PB1)
546  */
547 static const struct pios_tim_channel pios_tim_servoport_pins[] = {
548  { // Ch1
549  .timer = TIM4,
550  .timer_chan = TIM_Channel_3,
551  .remap = GPIO_AF_2,
552  .pin = {
553  .gpio = GPIOB,
554  .init = {
555  .GPIO_Pin = GPIO_Pin_8,
556  .GPIO_Speed = GPIO_Speed_2MHz,
557  .GPIO_Mode = GPIO_Mode_AF,
558  .GPIO_OType = GPIO_OType_PP,
559  .GPIO_PuPd = GPIO_PuPd_UP
560  },
561  .pin_source = GPIO_PinSource8,
562  },
563  },
564  { // Ch2
565  .timer = TIM4,
566  .timer_chan = TIM_Channel_4,
567  .remap = GPIO_AF_2,
568  .pin = {
569  .gpio = GPIOB,
570  .init = {
571  .GPIO_Pin = GPIO_Pin_9,
572  .GPIO_Speed = GPIO_Speed_2MHz,
573  .GPIO_Mode = GPIO_Mode_AF,
574  .GPIO_OType = GPIO_OType_PP,
575  .GPIO_PuPd = GPIO_PuPd_UP
576  },
577  .pin_source = GPIO_PinSource9,
578  },
579  },
580  { // Ch3
581  .timer = TIM2,
582  .timer_chan = TIM_Channel_4,
583  .remap = GPIO_AF_10,
584  .pin = {
585  .gpio = GPIOA,
586  .init = {
587  .GPIO_Pin = GPIO_Pin_10,
588  .GPIO_Speed = GPIO_Speed_2MHz,
589  .GPIO_Mode = GPIO_Mode_AF,
590  .GPIO_OType = GPIO_OType_PP,
591  .GPIO_PuPd = GPIO_PuPd_UP
592  },
593  .pin_source = GPIO_PinSource10,
594  },
595  },
596  { // Ch4
597  .timer = TIM2,
598  .timer_chan = TIM_Channel_3,
599  .remap = GPIO_AF_10,
600  .pin = {
601  .gpio = GPIOA,
602  .init = {
603  .GPIO_Pin = GPIO_Pin_9,
604  .GPIO_Speed = GPIO_Speed_2MHz,
605  .GPIO_Mode = GPIO_Mode_AF,
606  .GPIO_OType = GPIO_OType_PP,
607  .GPIO_PuPd = GPIO_PuPd_UP
608  },
609  .pin_source = GPIO_PinSource9,
610  },
611  },
612  { // Ch5
613  .timer = TIM2,
614  .timer_chan = TIM_Channel_1,
615  .remap = GPIO_AF_1,
616  .pin = {
617  .gpio = GPIOA,
618  .init = {
619  .GPIO_Pin = GPIO_Pin_0,
620  .GPIO_Speed = GPIO_Speed_2MHz,
621  .GPIO_Mode = GPIO_Mode_AF,
622  .GPIO_OType = GPIO_OType_PP,
623  .GPIO_PuPd = GPIO_PuPd_UP
624  },
625  .pin_source = GPIO_PinSource0,
626  },
627  },
628  { // Ch6
629  .timer = TIM2,
630  .timer_chan = TIM_Channel_2,
631  .remap = GPIO_AF_1,
632  .pin = {
633  .gpio = GPIOA,
634  .init = {
635  .GPIO_Pin = GPIO_Pin_1,
636  .GPIO_Speed = GPIO_Speed_2MHz,
637  .GPIO_Mode = GPIO_Mode_AF,
638  .GPIO_OType = GPIO_OType_PP,
639  .GPIO_PuPd = GPIO_PuPd_UP
640  },
641  .pin_source = GPIO_PinSource1,
642  },
643  },
644 };
645 
646 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
647 /*
648  * Servo outputs
649  */
650 #include <pios_servo_priv.h>
651 
652 static const struct pios_servo_cfg pios_servo_cfg = {
653  .tim_oc_init = {
654  .TIM_OCMode = TIM_OCMode_PWM1,
655  .TIM_OutputState = TIM_OutputState_Enable,
656  .TIM_OutputNState = TIM_OutputNState_Disable,
657  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
658  .TIM_OCPolarity = TIM_OCPolarity_High,
659  .TIM_OCNPolarity = TIM_OCPolarity_High,
660  .TIM_OCIdleState = TIM_OCIdleState_Reset,
661  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
662  },
663  .channels = pios_tim_servoport_pins,
664  .num_channels = NELEMENTS(pios_tim_servoport_pins),
665 };
666 
667 #endif /* PIOS_INCLUDE_SERVO && PIOS_INCLUDE_TIM */
668 
669 
670 
671 /*
672  * PWM Inputs
673  */
674 #if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM)
675 #include <pios_pwm_priv.h>
676 
677 /*
678  * INPUTS
679  1: TIM1_CH1 (PA8)
680  */
681 static const struct pios_tim_channel pios_tim_rcvrport_ppm[] = {
682  {
683  .timer = TIM1,
684  .timer_chan = TIM_Channel_1,
685  .remap = GPIO_AF_6,
686  .pin = {
687  .gpio = GPIOA,
688  .init = {
689  .GPIO_Pin = GPIO_Pin_8,
690  .GPIO_Speed = GPIO_Speed_2MHz,
691  .GPIO_Mode = GPIO_Mode_AF,
692  .GPIO_OType = GPIO_OType_PP,
693  .GPIO_PuPd = GPIO_PuPd_UP
694  },
695  .pin_source = GPIO_PinSource8,
696  },
697  },
698 };
699 
700 static const struct pios_tim_channel pios_tim_rcvrport_pwm[] = {
701  {
702  .timer = TIM1,
703  .timer_chan = TIM_Channel_1,
704  .remap = GPIO_AF_6,
705  .pin = {
706  .gpio = GPIOA,
707  .init = {
708  .GPIO_Pin = GPIO_Pin_8,
709  .GPIO_Speed = GPIO_Speed_2MHz,
710  .GPIO_Mode = GPIO_Mode_AF,
711  .GPIO_OType = GPIO_OType_PP,
712  .GPIO_PuPd = GPIO_PuPd_UP
713  },
714  .pin_source = GPIO_PinSource8,
715  },
716  },
717 };
718 
719 #endif
720 
721 /*
722  * PPM Input
723  */
724 #if defined(PIOS_INCLUDE_PPM)
725 #include <pios_ppm_priv.h>
726 static const struct pios_ppm_cfg pios_ppm_cfg = {
727  .tim_ic_init = {
728  .TIM_ICPolarity = TIM_ICPolarity_Rising,
729  .TIM_ICSelection = TIM_ICSelection_DirectTI,
730  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
731  .TIM_ICFilter = 0x0,
732  .TIM_Channel = TIM_Channel_1,
733  },
734  /* Use only the first channel for ppm */
735  .channels = pios_tim_rcvrport_ppm,
736  .num_channels = 1,
737 };
738 
739 #endif //PPM
740 
741 #if defined(PIOS_INCLUDE_ADC)
742 #include "pios_adc_priv.h"
743 #include "pios_internal_adc_priv.h"
744 
745 #define DTFC_VOLTAGE_CALIBRATION_VALUE 90.9091f // mV/V
746 #define DTFC_CURRENT_CALIBRATION_VALUE 24.95f // mV/A
747 
748 uintptr_t pios_internal_adc_id;
749 
750 void DMA2_Channel1_IRQHandler(void) __attribute__((alias("PIOS_ADC_DMA_irq_handler")));
751 
752 void PIOS_ADC_DMA_irq_handler(void)
753 {
754  /* Call into the generic code to handle the IRQ for this specific device */
755  PIOS_INTERNAL_ADC_DMA_Handler(pios_internal_adc_id);
756 }
757 
758 static const struct pios_internal_adc_cfg internal_adc_cfg = {
759  .dma = {
760  .irq = {
761  .flags = (DMA2_FLAG_TC1 | DMA2_FLAG_TE1 | DMA2_FLAG_HT1 | DMA2_FLAG_GL1),
762  .init = {
763  .NVIC_IRQChannel = DMA2_Channel1_IRQn,
764  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
765  .NVIC_IRQChannelSubPriority = 0,
766  .NVIC_IRQChannelCmd = ENABLE,
767  },
768  },
769  .rx = {
770  .channel = DMA2_Channel1,
771  .init = {
772  .DMA_Priority = DMA_Priority_High,
773  },
774  }
775  },
776  .half_flag = DMA2_IT_HT1,
777  .full_flag = DMA2_IT_TC1,
778  .oversampling = 32,
779  .adc_pin_count = 2,
780  .adc_pins = {
781  {GPIOA,GPIO_Pin_5,ADC_Channel_2,true}, // Current
782  {GPIOA,GPIO_Pin_4,ADC_Channel_1,true}, // Voltage
783  },
784  .adc_dev_master = ADC2,
785 };
786 
787 #endif /* PIOS_INCLUDE_ADC */
788 
789 #if defined(PIOS_INCLUDE_RCVR)
790 #include "pios_rcvr_priv.h"
791 #endif /* PIOS_INCLUDE_RCVR */
792 
793 #if defined(PIOS_INCLUDE_USB)
794 #include "pios_usb_priv.h"
795 
796 static const struct pios_usb_cfg pios_usb_main_cfg = {
797  .irq = {
798  .init = {
799  .NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
800  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
801  .NVIC_IRQChannelSubPriority = 0,
802  .NVIC_IRQChannelCmd = ENABLE,
803  },
804  },
805  .vsense = {
806  .gpio = GPIOA,
807  .init = {
808  .GPIO_Pin = GPIO_Pin_7,
809  .GPIO_Speed = GPIO_Speed_2MHz,
810  .GPIO_Mode = GPIO_Mode_IN,
811  .GPIO_OType = GPIO_OType_OD,
812  .GPIO_PuPd = GPIO_PuPd_NOPULL,
813  },
814  }
815 };
816 
817 const struct pios_usb_cfg * PIOS_BOARD_HW_DEFS_GetUsbCfg (uint32_t board_revision)
818 {
819  return &pios_usb_main_cfg;
820 }
821 
825 #include "pios_usbhook.h"
826 
827 #endif /* PIOS_INCLUDE_USB */
828 
829 #if defined(PIOS_INCLUDE_COM_MSG)
830 
831 #include <pios_com_msg_priv.h>
832 
833 #endif /* PIOS_INCLUDE_COM_MSG */
834 
835 #if defined(PIOS_INCLUDE_USB_HID)
836 #include <pios_usb_hid_priv.h>
837 
838 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
839  .data_if = 0,
840  .data_rx_ep = 1,
841  .data_tx_ep = 1,
842 };
843 #endif /* PIOS_INCLUDE_USB_HID */
844 
845 #if defined(PIOS_INCLUDE_USB_CDC)
846 #include <pios_usb_cdc_priv.h>
847 
848 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
849  .ctrl_if = 1,
850  .ctrl_tx_ep = 2,
851 
852  .data_if = 2,
853  .data_rx_ep = 3,
854  .data_tx_ep = 3,
855 };
856 #endif /* PIOS_INCLUDE_USB_CDC */
857 
861 #if defined(PIOS_INCLUDE_MPU)
862 #include "pios_mpu.h"
863 static const struct pios_exti_cfg pios_exti_mpu_cfg __exti_config = {
864  .vector = PIOS_MPU_IRQHandler,
865  .line = EXTI_Line13,
866  .pin = {
867  .gpio = GPIOC,
868  .init = {
869  .GPIO_Pin = GPIO_Pin_13,
870  .GPIO_Speed = GPIO_Speed_50MHz,
871  .GPIO_Mode = GPIO_Mode_IN,
872  .GPIO_OType = GPIO_OType_OD,
873  .GPIO_PuPd = GPIO_PuPd_NOPULL,
874  },
875  },
876  .irq = {
877  .init = {
878  .NVIC_IRQChannel = EXTI15_10_IRQn,
879  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
880  .NVIC_IRQChannelSubPriority = 0,
881  .NVIC_IRQChannelCmd = ENABLE,
882  },
883  },
884  .exti = {
885  .init = {
886  .EXTI_Line = EXTI_Line13, // matches above GPIO pin
887  .EXTI_Mode = EXTI_Mode_Interrupt,
888  .EXTI_Trigger = EXTI_Trigger_Rising,
889  .EXTI_LineCmd = ENABLE,
890  },
891  },
892 };
893 
894 static struct pios_mpu_cfg pios_mpu_cfg = {
895  .exti_cfg = &pios_exti_mpu_cfg,
896  .default_samplerate = 1000,
897  .orientation = PIOS_MPU_TOP_180DEG
898 };
899 #endif /* PIOS_INCLUDE_MPU */
900 
struct stm32_gpio pin
static const TIM_TimeBaseInitTypeDef tim_2_3_time_base
SPI private definitions.
#define NELEMENTS(x)
Definition: pios.h:192
struct stm32_gpio bind
#define FLASH_SECTOR_2KB
#define DMA2_Channel1_IRQHandler
COM private definitions.
COM MSG private definitions.
APIs for PIOS_USBHOOK layer.
GPIO_TypeDef * gpio
Definition: pios_stm32.h:60
ADC private definitions.
#define PIOS_LED_USB
Definition: pios_board.h:99
static const struct pios_tim_channel pios_tim_servoport_pins[]
#define PIOS_IRQ_PRIO_HIGHEST
Definition: pios_board.h:172
#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 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.
const struct pios_exti_cfg * exti_cfg
Definition: pios_mpu.h:140
#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
uintptr_t pios_internal_adc_id
Definition: pios_board.c:51
static const struct pios_tim_channel pios_tim_rcvrport_ppm[]
#define PIOS_PERIPHERAL_APB1_CLOCK
Definition: pios_board.h:154
static const struct pios_tim_clock_cfg tim_2_cfg
static const struct pios_tim_clock_cfg tim_15_cfg
const struct pios_annunc * annunciators
ppm private structures.
NVIC_InitTypeDef init
Definition: pios_stm32.h:36
static const struct pios_tim_clock_cfg tim_1_cfg
USART_TypeDef * regs
USB private definitions.
TIM_OCInitTypeDef tim_oc_init
USB COM HID private definitions.
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
static const TIM_TimeBaseInitTypeDef tim_1_15_16_17_time_base
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
static const struct pios_tim_clock_cfg tim_17_cfg
#define PIOS_IRQ_PRIO_HIGH
Definition: pios_board.h:171
static const struct pios_tim_clock_cfg tim_16_cfg
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
#define PIOS_Assert(test)
Definition: pios_debug.h:52
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.