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