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 = GPIOB,
43  .init = {
44  .GPIO_Pin = GPIO_Pin_8,
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  },
54  .pin = {
55  // Not sure. Using values from CleanFlight which seem
56  // to imply this is active low.
57  .gpio = GPIOC,
58  .init = {
59  .GPIO_Pin = GPIO_Pin_15,
60  .GPIO_Speed = GPIO_Speed_50MHz,
61  .GPIO_Mode = GPIO_Mode_OUT,
62  .GPIO_OType = GPIO_OType_PP,
63  .GPIO_PuPd = GPIO_PuPd_NOPULL
64  },
65  },
66  .active_high = true,
67  },
68 };
69 
70 static const struct pios_annunc_cfg pios_annunc_cfg = {
71  .annunciators = pios_annuncs,
72  .num_annunciators = NELEMENTS(pios_annuncs),
73 };
74 
75 const struct pios_annunc_cfg * PIOS_BOARD_HW_DEFS_GetLedCfg (uint32_t board_revision)
76 {
77  return &pios_annunc_cfg;
78 }
79 
80 #endif /* PIOS_INCLUDE_ANNUNC */
81 #if defined(PIOS_INCLUDE_I2C)
83 
84 #include <pios_i2c_priv.h>
85 
86 /*
87  * I2C Adapters
88  */
89 void PIOS_I2C_internal_ev_irq_handler(void);
90 void PIOS_I2C_internal_er_irq_handler(void);
91 void I2C1_EV_EXTI23_IRQHandler() __attribute__ ((alias ("PIOS_I2C_internal_ev_irq_handler")));
92 void I2C1_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_internal_er_irq_handler")));
93 
94 static const struct pios_i2c_adapter_cfg pios_i2c_internal_cfg = {
95  .regs = I2C1,
96  .remap = GPIO_AF_4,
97  .init = {
98  .I2C_Mode = I2C_Mode_I2C,
99  .I2C_OwnAddress1 = 0,
100  .I2C_Ack = I2C_Ack_Enable,
101  .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
102  .I2C_DigitalFilter = 0x00,
103  .I2C_AnalogFilter = I2C_AnalogFilter_Enable,
104  .I2C_Timing = 0x00310309, //400kHz I2C @ 8MHz input -> PRESC=0x0, SCLDEL=0x3, SDADEL=0x1, SCLH=0x03, SCLL=0x09
105  },
106  .transfer_timeout_ms = 50,
107  .scl = {
108  .gpio = GPIOB,
109  .init = {
110  .GPIO_Pin = GPIO_Pin_6,
111  .GPIO_Mode = GPIO_Mode_AF,
112  .GPIO_Speed = GPIO_Speed_50MHz,
113  .GPIO_OType = GPIO_OType_PP,
114  .GPIO_PuPd = GPIO_PuPd_NOPULL,
115  },
116  .pin_source = GPIO_PinSource6,
117  },
118  .sda = {
119  .gpio = GPIOB,
120  .init = {
121  .GPIO_Pin = GPIO_Pin_7,
122  .GPIO_Mode = GPIO_Mode_AF,
123  .GPIO_Speed = GPIO_Speed_50MHz,
124  .GPIO_OType = GPIO_OType_PP,
125  .GPIO_PuPd = GPIO_PuPd_NOPULL,
126  },
127  .pin_source = GPIO_PinSource7,
128  },
129  .event = {
130  .flags = 0, /* FIXME: check this */
131  .init = {
132  .NVIC_IRQChannel = I2C1_EV_IRQn,
133  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
134  .NVIC_IRQChannelSubPriority = 0,
135  .NVIC_IRQChannelCmd = ENABLE,
136  },
137  },
138  .error = {
139  .flags = 0, /* FIXME: check this */
140  .init = {
141  .NVIC_IRQChannel = I2C1_ER_IRQn,
142  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
143  .NVIC_IRQChannelSubPriority = 0,
144  .NVIC_IRQChannelCmd = ENABLE,
145  },
146  },
147 };
148 
149 pios_i2c_t pios_i2c_internal_id;
150 void PIOS_I2C_internal_ev_irq_handler(void)
151 {
152  /* Call into the generic code to handle the IRQ for this specific device */
153  PIOS_I2C_EV_IRQ_Handler(pios_i2c_internal_id);
154 }
155 
156 void PIOS_I2C_internal_er_irq_handler(void)
157 {
158  /* Call into the generic code to handle the IRQ for this specific device */
159  PIOS_I2C_ER_IRQ_Handler(pios_i2c_internal_id);
160 }
161 
162 #endif /* PIOS_INCLUDE_I2C */
163 
164 #ifdef PIOS_INCLUDE_BMP280
165 #include "pios_bmp280_priv.h"
166 
167 static const struct pios_bmp280_cfg pios_bmp280_cfg = {
169 };
170 #endif
171 
172 
173 #if defined(PIOS_INCLUDE_SPI)
174 #include <pios_spi_priv.h>
175 /*
176  * SPI1 Interface
177  * Used for MPU9250 gyro, accelerometer and mag
178  */
179 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
180  .regs = SPI1,
181  .remap = GPIO_AF_5,
182  .init = {
183  .SPI_Mode = SPI_Mode_Master,
184  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
185  .SPI_DataSize = SPI_DataSize_8b,
186  .SPI_NSS = SPI_NSS_Soft,
187  .SPI_FirstBit = SPI_FirstBit_MSB,
188  .SPI_CRCPolynomial = 7,
189  .SPI_CPOL = SPI_CPOL_Low,
190  .SPI_CPHA = SPI_CPHA_1Edge,
191  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
192  },
193  .sclk = {
194  .gpio = GPIOB,
195  .init = {
196  .GPIO_Pin = GPIO_Pin_3,
197  .GPIO_Speed = GPIO_Speed_50MHz,
198  .GPIO_Mode = GPIO_Mode_AF,
199  .GPIO_OType = GPIO_OType_PP,
200  .GPIO_PuPd = GPIO_PuPd_NOPULL
201  },
202  .pin_source = GPIO_PinSource3,
203  },
204  .miso = {
205  .gpio = GPIOB,
206  .init = {
207  .GPIO_Pin = GPIO_Pin_4,
208  .GPIO_Speed = GPIO_Speed_50MHz,
209  .GPIO_Mode = GPIO_Mode_AF,
210  .GPIO_OType = GPIO_OType_PP,
211  .GPIO_PuPd = GPIO_PuPd_NOPULL
212  },
213  .pin_source = GPIO_PinSource4,
214  },
215  .mosi = {
216  .gpio = GPIOB,
217  .init = {
218  .GPIO_Pin = GPIO_Pin_5,
219  .GPIO_Speed = GPIO_Speed_50MHz,
220  .GPIO_Mode = GPIO_Mode_AF,
221  .GPIO_OType = GPIO_OType_PP,
222  .GPIO_PuPd = GPIO_PuPd_NOPULL
223  },
224  .pin_source = GPIO_PinSource5,
225  },
226  .slave_count = 1,
227  .ssel = { {
228  .gpio = GPIOB,
229  .init = {
230  .GPIO_Pin = GPIO_Pin_9,
231  .GPIO_Speed = GPIO_Speed_50MHz,
232  .GPIO_Mode = GPIO_Mode_OUT,
233  .GPIO_OType = GPIO_OType_PP,
234  .GPIO_PuPd = GPIO_PuPd_UP
235  },
236  } },
237 };
238 #endif
239 
240 #if defined(PIOS_INCLUDE_FLASH)
241 #include "pios_flashfs_logfs_priv.h"
242 
243 static const struct flashfs_logfs_cfg flashfs_internal_settings_cfg = {
244  .fs_magic = 0x9ae1ee11,
245  .arena_size = 0x00002000, /* 32 * slot size = 8K bytes = 4 sectors */
246  .slot_size = 0x00000100, /* 256 bytes */
247 };
248 
250 
251 static const struct pios_flash_internal_cfg flash_internal_cfg = {
252 };
253 
254 #include "pios_flash_priv.h"
255 
256 static const struct pios_flash_sector_range stm32f3_sectors[] = {
257  {
258  .base_sector = 0,
259  .last_sector = 127,
260  .sector_size = FLASH_SECTOR_2KB,
261  },
262 };
263 
264 uintptr_t pios_internal_flash_id;
265 static const struct pios_flash_chip pios_flash_chip_internal = {
267  .chip_id = &pios_internal_flash_id,
268  .page_size = 16, /* 128-bit rows */
269  .sector_blocks = stm32f3_sectors,
270  .num_blocks = NELEMENTS(stm32f3_sectors),
271 };
272 
273 static const struct pios_flash_partition pios_flash_partition_table[] = {
274  {
276  .chip_desc = &pios_flash_chip_internal,
277  .first_sector = 0,
278  .last_sector = 7,
279  .chip_offset = 0,
280  .size = (7 - 0 + 1) * FLASH_SECTOR_2KB,
281  },
282 
283  {
285  .chip_desc = &pios_flash_chip_internal,
286  .first_sector = 8,
287  .last_sector = 15,
288  .chip_offset = (8 * FLASH_SECTOR_2KB),
289  .size = (15 - 8 + 1) * FLASH_SECTOR_2KB,
290  },
291 
292  {
294  .chip_desc = &pios_flash_chip_internal,
295  .first_sector = 16,
296  .last_sector = 23,
297  .chip_offset = (16 * FLASH_SECTOR_2KB),
298  .size = (23 - 16 + 1) * FLASH_SECTOR_2KB,
299  },
300 
301  {
302  .label = FLASH_PARTITION_LABEL_FW,
303  .chip_desc = &pios_flash_chip_internal,
304  .first_sector = 24,
305  .last_sector = 127,
306  .chip_offset = (24 * FLASH_SECTOR_2KB),
307  .size = (127 - 24 + 1) * FLASH_SECTOR_2KB,
308  },
309 };
310 
311 const struct pios_flash_partition * PIOS_BOARD_HW_DEFS_GetPartitionTable (uint32_t board_revision, uint32_t * num_partitions)
312 {
313  PIOS_Assert(num_partitions);
314 
315  *num_partitions = NELEMENTS(pios_flash_partition_table);
317 }
318 
319 #endif /* PIOS_INCLUDE_FLASH */
320 
321 
322 
323 #if defined(PIOS_INCLUDE_USART)
324 
325 #include "pios_usart_priv.h"
326 
327 #if defined(PIOS_INCLUDE_DSM)
328 /*
329  * Spektrum/JR DSM USART
330  */
331 #include <pios_dsm_priv.h>
332 
333 static const struct pios_dsm_cfg pios_uart1_dsm_aux_cfg = {
334  .bind = {
335  .gpio = GPIOA,
336  .init = {
337  .GPIO_Pin = GPIO_Pin_10,
338  .GPIO_Speed = GPIO_Speed_2MHz,
339  .GPIO_Mode = GPIO_Mode_OUT,
340  .GPIO_OType = GPIO_OType_PP,
341  .GPIO_PuPd = GPIO_PuPd_NOPULL
342  },
343  },
344 };
345 
346 static const struct pios_dsm_cfg pios_uart2_dsm_aux_cfg = {
347  .bind = {
348  .gpio = GPIOA,
349  .init = {
350  .GPIO_Pin = GPIO_Pin_15,
351  .GPIO_Speed = GPIO_Speed_2MHz,
352  .GPIO_Mode = GPIO_Mode_OUT,
353  .GPIO_OType = GPIO_OType_PP,
354  .GPIO_PuPd = GPIO_PuPd_NOPULL
355  },
356  },
357 };
358 
359 static const struct pios_dsm_cfg pios_uart3_dsm_aux_cfg = {
360  .bind = {
361  .gpio = GPIOB,
362  .init = {
363  .GPIO_Pin = GPIO_Pin_11,
364  .GPIO_Speed = GPIO_Speed_2MHz,
365  .GPIO_Mode = GPIO_Mode_OUT,
366  .GPIO_OType = GPIO_OType_PP,
367  .GPIO_PuPd = GPIO_PuPd_NOPULL
368  },
369  },
370 };
371 
372 #endif /* PIOS_INCLUDE_DSM */
373 
374 static const struct pios_usart_cfg pios_uart1_cfg = {
375  .regs = USART1,
376  .remap = GPIO_AF_7,
377  .irq = {
378  .init = {
379  .NVIC_IRQChannel = USART1_IRQn,
380  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
381  .NVIC_IRQChannelSubPriority = 0,
382  .NVIC_IRQChannelCmd = ENABLE,
383  },
384  },
385  .rx = {
386  .gpio = GPIOA,
387  .init = {
388  .GPIO_Pin = GPIO_Pin_10,
389  .GPIO_Speed = GPIO_Speed_2MHz,
390  .GPIO_Mode = GPIO_Mode_AF,
391  .GPIO_OType = GPIO_OType_PP,
392  .GPIO_PuPd = GPIO_PuPd_UP
393  },
394  .pin_source = GPIO_PinSource10,
395  },
396  .tx = {
397  .gpio = GPIOA,
398  .init = {
399  .GPIO_Pin = GPIO_Pin_9,
400  .GPIO_Speed = GPIO_Speed_2MHz,
401  .GPIO_Mode = GPIO_Mode_AF,
402  .GPIO_OType = GPIO_OType_PP,
403  .GPIO_PuPd = GPIO_PuPd_DOWN
404  },
405  .pin_source = GPIO_PinSource9,
406  },
407 };
408 
409 static const struct pios_usart_cfg pios_uart2_cfg = {
410  .regs = USART2,
411  .remap = GPIO_AF_7,
412  .irq = {
413  .init = {
414  .NVIC_IRQChannel = USART2_IRQn,
415  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
416  .NVIC_IRQChannelSubPriority = 0,
417  .NVIC_IRQChannelCmd = ENABLE,
418  },
419  },
420  .rx = {
421  .gpio = GPIOA,
422  .init = {
423  .GPIO_Pin = GPIO_Pin_15,
424  .GPIO_Speed = GPIO_Speed_2MHz,
425  .GPIO_Mode = GPIO_Mode_AF,
426  .GPIO_OType = GPIO_OType_PP,
427  .GPIO_PuPd = GPIO_PuPd_UP
428  },
429  .pin_source = GPIO_PinSource15,
430  },
431  .tx = {
432  .gpio = GPIOA,
433  .init = {
434  .GPIO_Pin = GPIO_Pin_14,
435  .GPIO_Speed = GPIO_Speed_2MHz,
436  .GPIO_Mode = GPIO_Mode_AF,
437  .GPIO_OType = GPIO_OType_PP,
438  .GPIO_PuPd = GPIO_PuPd_DOWN
439  },
440  .pin_source = GPIO_PinSource14,
441  },
442 };
443 
444 static const struct pios_usart_cfg pios_uart3_cfg = {
445  .regs = USART3,
446  .remap = GPIO_AF_7,
447  .irq = {
448  .init = {
449  .NVIC_IRQChannel = USART3_IRQn,
450  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
451  .NVIC_IRQChannelSubPriority = 0,
452  .NVIC_IRQChannelCmd = ENABLE,
453  },
454  },
455  .rx = {
456  .gpio = GPIOB,
457  .init = {
458  .GPIO_Pin = GPIO_Pin_11,
459  .GPIO_Speed = GPIO_Speed_2MHz,
460  .GPIO_Mode = GPIO_Mode_AF,
461  .GPIO_OType = GPIO_OType_PP,
462  .GPIO_PuPd = GPIO_PuPd_UP
463  },
464  .pin_source = GPIO_PinSource11,
465  },
466  .tx = {
467  .gpio = GPIOB,
468  .init = {
469  .GPIO_Pin = GPIO_Pin_10,
470  .GPIO_Speed = GPIO_Speed_2MHz,
471  .GPIO_Mode = GPIO_Mode_AF,
472  .GPIO_OType = GPIO_OType_PP,
473  .GPIO_PuPd = GPIO_PuPd_DOWN
474  },
475  .pin_source = GPIO_PinSource10,
476  },
477 };
478 
479 #endif /* PIOS_INCLUDE_USART */
480 
481 #if defined(PIOS_INCLUDE_COM)
482 
483 #include "pios_com_priv.h"
484 
485 #endif /* PIOS_INCLUDE_COM */
486 
487 #if defined(PIOS_INCLUDE_RTC)
488 /*
489  * Realtime Clock (RTC)
490  */
491 #include <pios_rtc_priv.h>
492 
493 void PIOS_RTC_IRQ_Handler (void);
494 void RTC_WKUP_IRQHandler() __attribute__ ((alias ("PIOS_RTC_IRQ_Handler")));
495 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
496  .clksrc = RCC_RTCCLKSource_HSE_Div32,
497  .prescaler = 25 - 1, // 8MHz / 32 / 16 / 25 == 625Hz
498  .irq = {
499  .init = {
500  .NVIC_IRQChannel = RTC_WKUP_IRQn,
501  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
502  .NVIC_IRQChannelSubPriority = 0,
503  .NVIC_IRQChannelCmd = ENABLE,
504  },
505  },
506 };
507 
508 void PIOS_RTC_IRQ_Handler (void)
509 {
511 }
512 
513 #endif
514 
515 #include "pios_tim_priv.h"
516 
517 static const TIM_TimeBaseInitTypeDef tim_1_8_15_16_17_time_base = {
518  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
519  .TIM_ClockDivision = TIM_CKD_DIV1,
520  .TIM_CounterMode = TIM_CounterMode_Up,
521  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
522  .TIM_RepetitionCounter = 0x0000,
523 };
524 
525 static const TIM_TimeBaseInitTypeDef tim_2_3_time_base = {
526  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000 * 2) - 1,
527  .TIM_ClockDivision = TIM_CKD_DIV1,
528  .TIM_CounterMode = TIM_CounterMode_Up,
529  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
530  .TIM_RepetitionCounter = 0x0000,
531 };
532 
533 static const struct pios_tim_clock_cfg tim_2_cfg = {
534  .timer = TIM2,
535  .time_base_init = &tim_2_3_time_base,
536  .irq = {
537  .init = {
538  .NVIC_IRQChannel = TIM2_IRQn,
539  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
540  .NVIC_IRQChannelSubPriority = 0,
541  .NVIC_IRQChannelCmd = ENABLE,
542  },
543  },
544 };
545 
546 static const struct pios_tim_clock_cfg tim_3_cfg = {
547  .timer = TIM3,
548  .time_base_init = &tim_2_3_time_base,
549  .irq = {
550  .init = {
551  .NVIC_IRQChannel = TIM3_IRQn,
552  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
553  .NVIC_IRQChannelSubPriority = 0,
554  .NVIC_IRQChannelCmd = ENABLE,
555  },
556  },
557 };
558 
559 static const struct pios_tim_clock_cfg tim_8_cfg = {
560  .timer = TIM8,
561  .time_base_init = &tim_1_8_15_16_17_time_base,
562  .irq = {
563  .init = {
564  .NVIC_IRQChannel = TIM8_CC_IRQn,
565  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
566  .NVIC_IRQChannelSubPriority = 0,
567  .NVIC_IRQChannelCmd = ENABLE,
568  },
569  },
570  .irq2 = {
571  .init = {
572  .NVIC_IRQChannel = TIM8_UP_IRQn,
573  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
574  .NVIC_IRQChannelSubPriority = 0,
575  .NVIC_IRQChannelCmd = ENABLE,
576  },
577  },
578 };
579 
580 static const struct pios_tim_clock_cfg tim_15_cfg = {
581  .timer = TIM15,
582  .time_base_init = &tim_1_8_15_16_17_time_base,
583  .irq = {
584  .init = {
585  .NVIC_IRQChannel = TIM1_BRK_TIM15_IRQn,
586  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
587  .NVIC_IRQChannelSubPriority = 0,
588  .NVIC_IRQChannelCmd = ENABLE,
589  },
590  },
591 };
592 
593 static const struct pios_tim_clock_cfg tim_16_cfg = {
594  .timer = TIM16,
595  .time_base_init = &tim_1_8_15_16_17_time_base,
596  .irq = {
597  .init = {
598  .NVIC_IRQChannel = TIM1_UP_TIM16_IRQn,
599  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
600  .NVIC_IRQChannelSubPriority = 0,
601  .NVIC_IRQChannelCmd = ENABLE,
602  },
603  },
604 };
605 
606 static const struct pios_tim_clock_cfg tim_17_cfg = {
607  .timer = TIM17,
608  .time_base_init = &tim_1_8_15_16_17_time_base,
609  .irq = {
610  .init = {
611  .NVIC_IRQChannel = TIM1_TRG_COM_TIM17_IRQn,
612  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
613  .NVIC_IRQChannelSubPriority = 0,
614  .NVIC_IRQChannelCmd = ENABLE,
615  },
616  },
617 };
618 
619 static const struct pios_tim_channel pios_tim_servoport_pins[] = {
620  { // Ch1 TIM2_CH1 (PA0)
621  .timer = TIM2,
622  .timer_chan = TIM_Channel_1,
623  .remap = GPIO_AF_1,
624  .pin = {
625  .gpio = GPIOA,
626  .init = {
627  .GPIO_Pin = GPIO_Pin_0,
628  .GPIO_Speed = GPIO_Speed_2MHz,
629  .GPIO_Mode = GPIO_Mode_AF,
630  .GPIO_OType = GPIO_OType_PP,
631  .GPIO_PuPd = GPIO_PuPd_UP
632  },
633  .pin_source = GPIO_PinSource0,
634  },
635  },
636  { // Ch2 TIM2_CH2 (PA1)
637  .timer = TIM2,
638  .timer_chan = TIM_Channel_2,
639  .remap = GPIO_AF_1,
640  .pin = {
641  .gpio = GPIOA,
642  .init = {
643  .GPIO_Pin = GPIO_Pin_1,
644  .GPIO_Speed = GPIO_Speed_2MHz,
645  .GPIO_Mode = GPIO_Mode_AF,
646  .GPIO_OType = GPIO_OType_PP,
647  .GPIO_PuPd = GPIO_PuPd_UP
648  },
649  .pin_source = GPIO_PinSource1,
650  },
651  },
652  { // Ch3 TIM15_CH1 (PA2)
653  .timer = TIM15,
654  .timer_chan = TIM_Channel_1,
655  .remap = GPIO_AF_9,
656  .pin = {
657  .gpio = GPIOA,
658  .init = {
659  .GPIO_Pin = GPIO_Pin_2,
660  .GPIO_Speed = GPIO_Speed_2MHz,
661  .GPIO_Mode = GPIO_Mode_AF,
662  .GPIO_OType = GPIO_OType_PP,
663  .GPIO_PuPd = GPIO_PuPd_UP
664  },
665  .pin_source = GPIO_PinSource2,
666  },
667  },
668  { // Ch4 TIM15_CH2 (PA3)
669  .timer = TIM15,
670  .timer_chan = TIM_Channel_2,
671  .remap = GPIO_AF_9,
672  .pin = {
673  .gpio = GPIOA,
674  .init = {
675  .GPIO_Pin = GPIO_Pin_3,
676  .GPIO_Speed = GPIO_Speed_2MHz,
677  .GPIO_Mode = GPIO_Mode_AF,
678  .GPIO_OType = GPIO_OType_PP,
679  .GPIO_PuPd = GPIO_PuPd_UP
680  },
681  .pin_source = GPIO_PinSource3,
682  },
683  },
684  { // Ch5 TIM3_CH1 (PA6)
685  .timer = TIM3,
686  .timer_chan = TIM_Channel_1,
687  .remap = GPIO_AF_2,
688  .pin = {
689  .gpio = GPIOA,
690  .init = {
691  .GPIO_Pin = GPIO_Pin_6,
692  .GPIO_Speed = GPIO_Speed_2MHz,
693  .GPIO_Mode = GPIO_Mode_AF,
694  .GPIO_OType = GPIO_OType_PP,
695  .GPIO_PuPd = GPIO_PuPd_UP
696  },
697  .pin_source = GPIO_PinSource6,
698  },
699  },
700  { // Ch6 TIM3_CH2 (PA7)
701  .timer = TIM3,
702  .timer_chan = TIM_Channel_2,
703  .remap = GPIO_AF_2,
704  .pin = {
705  .gpio = GPIOA,
706  .init = {
707  .GPIO_Pin = GPIO_Pin_7,
708  .GPIO_Speed = GPIO_Speed_2MHz,
709  .GPIO_Mode = GPIO_Mode_AF,
710  .GPIO_OType = GPIO_OType_PP,
711  .GPIO_PuPd = GPIO_PuPd_UP
712  },
713  .pin_source = GPIO_PinSource7,
714  },
715  },
716  { // Ch7 TIM3_CH3 (PB0)
717  .timer = TIM3,
718  .timer_chan = TIM_Channel_3,
719  .remap = GPIO_AF_2,
720  .pin = {
721  .gpio = GPIOB,
722  .init = {
723  .GPIO_Pin = GPIO_Pin_0,
724  .GPIO_Speed = GPIO_Speed_2MHz,
725  .GPIO_Mode = GPIO_Mode_AF,
726  .GPIO_OType = GPIO_OType_PP,
727  .GPIO_PuPd = GPIO_PuPd_UP
728  },
729  .pin_source = GPIO_PinSource0,
730  },
731  },
732  { // Ch8 TIM3_CH4 (PB1)
733  .timer = TIM3,
734  .timer_chan = TIM_Channel_4,
735  .remap = GPIO_AF_2,
736  .pin = {
737  .gpio = GPIOB,
738  .init = {
739  .GPIO_Pin = GPIO_Pin_1,
740  .GPIO_Speed = GPIO_Speed_2MHz,
741  .GPIO_Mode = GPIO_Mode_AF,
742  .GPIO_OType = GPIO_OType_PP,
743  .GPIO_PuPd = GPIO_PuPd_UP
744  },
745  .pin_source = GPIO_PinSource1,
746  },
747  },
748 };
749 
750 /*
751  * Servo outputs
752  */
753 #include <pios_servo_priv.h>
754 
755 static const struct pios_servo_cfg pios_servo_cfg = {
756  .tim_oc_init = {
757  .TIM_OCMode = TIM_OCMode_PWM1,
758  .TIM_OutputState = TIM_OutputState_Enable,
759  .TIM_OutputNState = TIM_OutputNState_Disable,
760  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
761  .TIM_OCPolarity = TIM_OCPolarity_High,
762  .TIM_OCNPolarity = TIM_OCPolarity_High,
763  .TIM_OCIdleState = TIM_OCIdleState_Reset,
764  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
765  },
766  .channels = pios_tim_servoport_pins,
767  .num_channels = NELEMENTS(pios_tim_servoport_pins),
768 };
769 
770 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
771 struct pios_servo_cfg pios_servo_slow_cfg = {
772  .tim_oc_init = {
773  .TIM_OCMode = TIM_OCMode_PWM1,
774  .TIM_OutputState = TIM_OutputState_Enable,
775  .TIM_OutputNState = TIM_OutputNState_Disable,
776  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
777  .TIM_OCPolarity = TIM_OCPolarity_High,
778  .TIM_OCNPolarity = TIM_OCPolarity_High,
779  .TIM_OCIdleState = TIM_OCIdleState_Reset,
780  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
781  },
782  .force_1MHz = true,
783  .channels = pios_tim_servoport_pins,
784  .num_channels = NELEMENTS(pios_tim_servoport_pins),
785 };
786 
787 #endif /* PIOS_INCLUDE_SERVO && PIOS_INCLUDE_TIM */
788 
789 
790 
791 /*
792  * PPM Input
793  */
794 #if defined(PIOS_INCLUDE_PPM)
795 #include <pios_pwm_priv.h>
796 
797 /*
798  * INPUTS
799  { TIM8, IO_TAG(PA15), TIM_Channel_1, TIM8_CC_IRQn, 0, IOCFG_AF_PP, GPIO_AF_2}, // PPM
800  */
801 static const struct pios_tim_channel pios_tim_rxport_ppm[] = {
802  {
803  .timer = TIM8,
804  .timer_chan = TIM_Channel_1,
805  .remap = GPIO_AF_2,
806  .pin = {
807  .gpio = GPIOA,
808  .init = {
809  .GPIO_Pin = GPIO_Pin_15,
810  .GPIO_Speed = GPIO_Speed_2MHz,
811  .GPIO_Mode = GPIO_Mode_AF,
812  .GPIO_OType = GPIO_OType_PP,
813  .GPIO_PuPd = GPIO_PuPd_UP
814  },
815  .pin_source = GPIO_PinSource15,
816  },
817  },
818 };
819 #endif
820 
821 /*
822  * PPM Input
823  */
824 #if defined(PIOS_INCLUDE_PPM)
825 #include <pios_ppm_priv.h>
826 static const struct pios_ppm_cfg pios_ppm_cfg = {
827  .tim_ic_init = {
828  .TIM_ICPolarity = TIM_ICPolarity_Rising,
829  .TIM_ICSelection = TIM_ICSelection_DirectTI,
830  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
831  .TIM_ICFilter = 0x0,
832  .TIM_Channel = TIM_Channel_1,
833  },
834  /* Use only the first channel for ppm */
835  .channels = pios_tim_rxport_ppm,
836  .num_channels = 1,
837 };
838 
839 #endif //PPM
840 
841 #if defined(PIOS_INCLUDE_ADC)
842 #include "pios_adc_priv.h"
843 #include "pios_internal_adc_priv.h"
844 
845 uintptr_t pios_internal_adc_id;
846 
847 void DMA2_Channel1_IRQHandler(void) __attribute__((alias("PIOS_ADC_DMA_irq_handler")));
848 void PIOS_ADC_DMA_irq_handler(void)
849 {
850  /* Call into the generic code to handle the IRQ for this specific device */
851  PIOS_INTERNAL_ADC_DMA_Handler(pios_internal_adc_id);
852 }
853 
854 //-------------------------
855 // ADC
856 // ADC0 : PA4 ADC2_IN1 VBat
857 // ADC1 : PA5 ADC2_IN2 Current
858 // ADC2 : PB2 ADC2_IN12 RSSI
859 //-------------------------
860 
861 static const struct pios_internal_adc_cfg internal_adc_cfg = {
862  .dma = {
863  .irq = {
864  .flags = (DMA2_FLAG_TC1 | DMA2_FLAG_TE1 | DMA2_FLAG_HT1 | DMA2_FLAG_GL1),
865  .init = {
866  .NVIC_IRQChannel = DMA2_Channel1_IRQn,
867  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
868  .NVIC_IRQChannelSubPriority = 0,
869  .NVIC_IRQChannelCmd = ENABLE,
870  },
871  },
872  .rx = {
873  .channel = DMA2_Channel1,
874  .init = {
875  .DMA_Priority = DMA_Priority_High,
876  },
877  }
878  },
879  .half_flag = DMA2_IT_HT1,
880  .full_flag = DMA2_IT_TC1,
881  .oversampling = 32,
882  .adc_pin_count = 3,
883  .adc_pins = {
884  {GPIOA, GPIO_Pin_4, ADC_Channel_1, true}, // Voltage
885  {GPIOA, GPIO_Pin_5, ADC_Channel_2, true}, // Current
886  {GPIOB, GPIO_Pin_2, ADC_Channel_12, true}, // RSSI
887  },
888  .adc_dev_master = ADC2,
889 };
890 
891 
892 #endif /* PIOS_INCLUDE_ADC */
893 
894 #if defined(PIOS_INCLUDE_RCVR)
895 #include "pios_rcvr_priv.h"
896 #endif /* PIOS_INCLUDE_RCVR */
897 
898 #if defined(PIOS_INCLUDE_USB)
899 #include "pios_usb_priv.h"
900 
901 static const struct pios_usb_cfg pios_usb_main_cfg = {
902  .irq = {
903  .init = {
904  .NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn,
905  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
906  .NVIC_IRQChannelSubPriority = 0,
907  .NVIC_IRQChannelCmd = ENABLE,
908  },
909  },
910  .vsense = {
911  .gpio = NULL
912  }
913 };
914 
915 const struct pios_usb_cfg * PIOS_BOARD_HW_DEFS_GetUsbCfg (uint32_t board_revision)
916 {
917  return &pios_usb_main_cfg;
918 }
919 
923 #include "pios_usbhook.h"
924 
925 #endif /* PIOS_INCLUDE_USB */
926 
927 #if defined(PIOS_INCLUDE_WS2811)
928 #include "pios_ws2811.h"
929 
931 
932 static const struct pios_ws2811_cfg pios_ws2811_cfg = {
933  .timer = TIM1,
934  .timer_chan = TIM_Channel_1,
935  .led_gpio = GPIOA,
936  .gpio_pin = GPIO_Pin_8,
937  .remap = GPIO_AF_6,
938  .timer_dma_source = TIM_DMA_Update,
939  .dma_chan = DMA1_Channel5,
940  .dma_tcif = DMA1_FLAG_TC5,
941  .dma_irqn = DMA1_Channel5_IRQn,
942 };
943 #endif /* PIOS_INCLUDE_WS2811 */
944 
945 #if defined(PIOS_INCLUDE_COM_MSG)
946 
947 #include <pios_com_msg_priv.h>
948 
949 #endif /* PIOS_INCLUDE_COM_MSG */
950 
951 #if defined(PIOS_INCLUDE_USB_HID)
952 #include <pios_usb_hid_priv.h>
953 
954 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
955  .data_if = 0,
956  .data_rx_ep = 1,
957  .data_tx_ep = 1,
958 };
959 #endif /* PIOS_INCLUDE_USB_HID */
960 
961 #if defined(PIOS_INCLUDE_USB_CDC)
962 #include <pios_usb_cdc_priv.h>
963 
964 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
965  .ctrl_if = 1,
966  .ctrl_tx_ep = 2,
967 
968  .data_if = 2,
969  .data_rx_ep = 3,
970  .data_tx_ep = 3,
971 };
972 #endif /* PIOS_INCLUDE_USB_CDC */
973 
977 #if defined(PIOS_INCLUDE_MPU)
978 #include "pios_mpu.h"
979 static const struct pios_exti_cfg pios_exti_mpu_cfg __exti_config = {
980  .vector = PIOS_MPU_IRQHandler,
981  .line = EXTI_Line13,
982  .pin = {
983  .gpio = GPIOC,
984  .init = {
985  .GPIO_Pin = GPIO_Pin_13,
986  .GPIO_Speed = GPIO_Speed_50MHz,
987  .GPIO_Mode = GPIO_Mode_IN,
988  .GPIO_OType = GPIO_OType_OD,
989  .GPIO_PuPd = GPIO_PuPd_NOPULL,
990  },
991  },
992  .irq = {
993  .init = {
994  .NVIC_IRQChannel = EXTI15_10_IRQn,
995  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
996  .NVIC_IRQChannelSubPriority = 0,
997  .NVIC_IRQChannelCmd = ENABLE,
998  },
999  },
1000  .exti = {
1001  .init = {
1002  .EXTI_Line = EXTI_Line13, // matches above GPIO pin
1003  .EXTI_Mode = EXTI_Mode_Interrupt,
1004  .EXTI_Trigger = EXTI_Trigger_Rising,
1005  .EXTI_LineCmd = ENABLE,
1006  },
1007  },
1008 };
1009 
1010 static struct pios_mpu_cfg pios_mpu_cfg = {
1011  .exti_cfg = &pios_exti_mpu_cfg,
1012  .default_samplerate = 1000,
1013  .orientation = PIOS_MPU_TOP_90DEG,
1014  .use_internal_mag = true,
1015 };
1016 
1017 #endif /* PIOS_INCLUDE_MPU */
1018 
1019 #ifdef PIOS_INCLUDE_HMC5883
1020 #include "pios_hmc5883_priv.h"
1021 static const struct pios_hmc5883_cfg pios_hmc5883_external_cfg = {
1022  .exti_cfg = NULL,
1023  .M_ODR = PIOS_HMC5883_ODR_75,
1024  .Meas_Conf = PIOS_HMC5883_MEASCONF_NORMAL,
1025  .Gain = PIOS_HMC5883_GAIN_1_9,
1027  .Default_Orientation = PIOS_HMC5883_TOP_0DEG,
1028 };
1029 #endif
1030 
1031 #ifdef PIOS_INCLUDE_HMC5983_I2C
1032 #include "pios_hmc5983.h"
1033 
1034 static const struct pios_hmc5983_cfg pios_hmc5983_external_cfg = {
1035  .exti_cfg = NULL,
1036  .M_ODR = PIOS_HMC5983_ODR_75,
1037  .Meas_Conf = PIOS_HMC5983_MEASCONF_NORMAL,
1038  .Gain = PIOS_HMC5983_GAIN_1_9,
1040  .Averaging = PIOS_HMC5983_AVERAGING_1,
1041  .Orientation = PIOS_HMC5983_TOP_0DEG,
1042 };
1043 #endif
1044 
struct stm32_gpio pin
const struct pios_exti_cfg * exti_cfg
#define PIOS_HMC5883_ODR_75
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
HMC5983 functions header.
#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
#define PIOS_HMC5883_MODE_CONTINUOUS
I2C_TypeDef * regs
Definition: pios_i2c_priv.h:37
ADC private definitions.
#define PIOS_IRQ_PRIO_HIGHEST
Definition: pios_board.h:172
Configuration structure for the BMP280 driver.
#define PIOS_SERVOS_INITIAL_POSITION
Definition: pios_board.h:210
static const struct pios_tim_clock_cfg tim_16_cfg
Defines the API to set up the HID + CDC USB descriptor config.
void PIOS_INTERNAL_ADC_DMA_Handler()
#define RTC_WKUP_IRQHandler
static const struct pios_tim_clock_cfg tim_15_cfg
#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
#define PIOS_HMC5983_MEASCONF_NORMAL
Definition: pios_hmc5983.h:67
TIM_TypeDef * timer
Definition: pios_tim_priv.h:7
SPI_TypeDef * regs
Definition: pios_spi_priv.h:44
const struct pios_exti_cfg * exti_cfg
Definition: pios_hmc5983.h:121
#define PIOS_HMC5983_MODE_CONTINUOUS
Definition: pios_hmc5983.h:82
uintptr_t pios_internal_adc_id
Definition: pios_board.c:51
struct pios_i2c_adapter * pios_i2c_t
Definition: pios_i2c.h:48
#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
void PIOS_I2C_EV_IRQ_Handler(pios_i2c_t i2c_id)
#define PIOS_HMC5883_GAIN_1_9
#define PIOS_HMC5983_ODR_75
Definition: pios_hmc5983.h:63
TIM_TypeDef * timer
ppm private structures.
NVIC_InitTypeDef init
Definition: pios_stm32.h:36
#define I2C1_ER_IRQHandler
USART_TypeDef * regs
USB private definitions.
TIM_OCInitTypeDef tim_oc_init
static const struct pios_tim_clock_cfg tim_17_cfg
USB COM HID private definitions.
ADC private definitions.
Servo private structures.
static const TIM_TimeBaseInitTypeDef tim_1_8_15_16_17_time_base
static const struct pios_tim_clock_cfg tim_8_cfg
#define PIOS_HMC5983_GAIN_1_9
Definition: pios_hmc5983.h:74
void PIOS_I2C_ER_IRQ_Handler(pios_i2c_t i2c_id)
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
#define PIOS_HMC5883_MEASCONF_NORMAL
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 I2C1_EV_EXTI23_IRQHandler
#define PIOS_IRQ_PRIO_HIGH
Definition: pios_board.h:171
static const struct pios_tim_clock_cfg tim_2_cfg
TIM_TypeDef * timer
Definition: pios_tim_priv.h:14
USB COM CDC private definitions.
uint32_t clksrc
Definition: pios_rtc_priv.h:37
static const TIM_TimeBaseInitTypeDef tim_2_3_time_base
enum pios_flash_partition_labels label
board_revision
Definition: board_hw_defs.c:35
static const struct pios_tim_channel pios_tim_servoport_pins[]
#define PIOS_IRQ_PRIO_LOW
Definition: pios_board.h:169
#define PIOS_Assert(test)
Definition: pios_debug.h:52
static const struct pios_tim_clock_cfg tim_3_cfg
LED private definitions.
#define BMP280_HIGH_RESOLUTION
#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
#define PIOS_HMC5983_AVERAGING_1
Definition: pios_hmc5983.h:97
Defines the API to the board-specific USB data setup code.