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