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 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 #include <pios_config.h>
32 #include <pios_board_info.h>
33 
34 #if defined(PIOS_INCLUDE_ANNUNC)
35 
36 #include <pios_annunc_priv.h>
37 static const struct pios_annunc pios_annuncs[] = {
38  [PIOS_LED_HEARTBEAT] = {
39  .pin = {
40  .gpio = GPIOE,
41  .init = {
42  .GPIO_Pin = GPIO_Pin_5,
43  .GPIO_Speed = GPIO_Speed_2MHz,
44  .GPIO_Mode = GPIO_Mode_OUT,
45  .GPIO_OType = GPIO_OType_PP,
46  .GPIO_PuPd = GPIO_PuPd_NOPULL,
47  },
48  },
49  .remap = 0,
50  .active_high = true,
51  },
52  [PIOS_LED_ALARM] = {
53  .pin = {
54  .gpio = GPIOE,
55  .init = {
56  .GPIO_Pin = GPIO_Pin_6,
57  .GPIO_Speed = GPIO_Speed_2MHz,
58  .GPIO_Mode = GPIO_Mode_OUT,
59  .GPIO_OType = GPIO_OType_PP,
60  .GPIO_PuPd = GPIO_PuPd_NOPULL,
61  },
62  },
63  .remap = 0,
64  .active_high = true,
65  },
67  .pin = {
68  .gpio = GPIOD,
69  .init = {
70  .GPIO_Pin = GPIO_Pin_7,
71  .GPIO_Speed = GPIO_Speed_50MHz,
72  .GPIO_Mode = GPIO_Mode_OUT,
73  .GPIO_OType = GPIO_OType_PP,
74  .GPIO_PuPd = GPIO_PuPd_NOPULL
75  },
76  },
77  .active_high = true,
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 micro sd card communications
98  */
99 
100 static const struct pios_spi_cfg pios_spi_sdCard_cfg = {
101  .regs = SPI1,
102  .remap = GPIO_AF_SPI1,
103  .init = {
104  .SPI_Mode = SPI_Mode_Master,
105  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
106  .SPI_DataSize = SPI_DataSize_8b,
107  .SPI_NSS = SPI_NSS_Soft,
108  .SPI_FirstBit = SPI_FirstBit_MSB,
109  .SPI_CRCPolynomial = 7,
110  .SPI_CPOL = SPI_CPOL_High,
111  .SPI_CPHA = SPI_CPHA_2Edge,
112  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32,
113  },
114  .sclk = {
115  .gpio = GPIOA,
116  .init = {
117  .GPIO_Pin = GPIO_Pin_5,
118  .GPIO_Speed = GPIO_Speed_100MHz,
119  .GPIO_Mode = GPIO_Mode_AF,
120  .GPIO_OType = GPIO_OType_PP,
121  .GPIO_PuPd = GPIO_PuPd_NOPULL
122  },
123  .pin_source = GPIO_PinSource5,
124  },
125  .miso = {
126  .gpio = GPIOA,
127  .init = {
128  .GPIO_Pin = GPIO_Pin_6,
129  .GPIO_Speed = GPIO_Speed_100MHz,
130  .GPIO_Mode = GPIO_Mode_AF,
131  .GPIO_OType = GPIO_OType_PP,
132  .GPIO_PuPd = GPIO_PuPd_NOPULL
133  },
134  .pin_source = GPIO_PinSource6,
135  },
136  .mosi = {
137  .gpio = GPIOA,
138  .init = {
139  .GPIO_Pin = GPIO_Pin_7,
140  .GPIO_Speed = GPIO_Speed_100MHz,
141  .GPIO_Mode = GPIO_Mode_AF,
142  .GPIO_OType = GPIO_OType_PP,
143  .GPIO_PuPd = GPIO_PuPd_NOPULL
144  },
145  .pin_source = GPIO_PinSource7,
146  },
147  .slave_count = 1,
148  .ssel = { {
149  .gpio = GPIOE,
150  .init = {
151  .GPIO_Pin = GPIO_Pin_10,
152  .GPIO_Speed = GPIO_Speed_100MHz,
153  .GPIO_Mode = GPIO_Mode_OUT,
154  .GPIO_OType = GPIO_OType_PP,
155  .GPIO_PuPd = GPIO_PuPd_NOPULL
156  },
157  } },
158 };
159 
160 pios_spi_t pios_spi_sdCard_id;
161 
162 /* SPI2 Interface
163  * - Used for external communications
164  */
165 
166 static const struct pios_spi_cfg pios_spi_external_cfg = {
167  .regs = SPI2,
168  .remap = GPIO_AF_SPI2,
169  .init = {
170  .SPI_Mode = SPI_Mode_Master,
171  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
172  .SPI_DataSize = SPI_DataSize_8b,
173  .SPI_NSS = SPI_NSS_Soft,
174  .SPI_FirstBit = SPI_FirstBit_MSB,
175  .SPI_CRCPolynomial = 7,
176  .SPI_CPOL = SPI_CPOL_Low,
177  .SPI_CPHA = SPI_CPHA_1Edge,
178  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
179  },
180  .sclk = {
181  .gpio = GPIOB,
182  .init = {
183  .GPIO_Pin = GPIO_Pin_13,
184  .GPIO_Speed = GPIO_Speed_100MHz,
185  .GPIO_Mode = GPIO_Mode_AF,
186  .GPIO_OType = GPIO_OType_PP,
187  .GPIO_PuPd = GPIO_PuPd_NOPULL
188  },
189  .pin_source = GPIO_PinSource13,
190  },
191  .miso = {
192  .gpio = GPIOB,
193  .init = {
194  .GPIO_Pin = GPIO_Pin_14,
195  .GPIO_Speed = GPIO_Speed_100MHz,
196  .GPIO_Mode = GPIO_Mode_AF,
197  .GPIO_OType = GPIO_OType_PP,
198  .GPIO_PuPd = GPIO_PuPd_NOPULL
199  },
200  .pin_source = GPIO_PinSource14,
201  },
202  .mosi = {
203  .gpio = GPIOB,
204  .init = {
205  .GPIO_Pin = GPIO_Pin_15,
206  .GPIO_Speed = GPIO_Speed_100MHz,
207  .GPIO_Mode = GPIO_Mode_AF,
208  .GPIO_OType = GPIO_OType_PP,
209  .GPIO_PuPd = GPIO_PuPd_NOPULL
210  },
211  .pin_source = GPIO_PinSource15,
212  },
213  .slave_count = 1,
214  .ssel = { {
215  .gpio = GPIOA,
216  .init = {
217  .GPIO_Pin = GPIO_Pin_3,
218  .GPIO_Speed = GPIO_Speed_100MHz,
219  .GPIO_Mode = GPIO_Mode_OUT,
220  .GPIO_OType = GPIO_OType_PP,
221  .GPIO_PuPd = GPIO_PuPd_NOPULL
222  },
223  } },
224 };
225 
226 pios_spi_t pios_spi_external_id;
227 
228 /* SPI3 Interface
229  * - Used for gyro communications
230  */
231 
232 static const struct pios_spi_cfg pios_spi_internal_cfg = {
233  .regs = SPI3,
234  .remap = GPIO_AF_SPI3,
235  .init = {
236  .SPI_Mode = SPI_Mode_Master,
237  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
238  .SPI_DataSize = SPI_DataSize_8b,
239  .SPI_NSS = SPI_NSS_Soft,
240  .SPI_FirstBit = SPI_FirstBit_MSB,
241  .SPI_CRCPolynomial = 7,
242  .SPI_CPOL = SPI_CPOL_High,
243  .SPI_CPHA = SPI_CPHA_2Edge,
244  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32, //@ APB2 PCLK1 82MHz / 32 == 2.6MHz
245  },
246  .sclk = {
247  .gpio = GPIOC,
248  .init = {
249  .GPIO_Pin = GPIO_Pin_10,
250  .GPIO_Speed = GPIO_Speed_100MHz,
251  .GPIO_Mode = GPIO_Mode_AF,
252  .GPIO_OType = GPIO_OType_PP,
253  .GPIO_PuPd = GPIO_PuPd_NOPULL
254  },
255  .pin_source = GPIO_PinSource10,
256  },
257  .miso = {
258  .gpio = GPIOC,
259  .init = {
260  .GPIO_Pin = GPIO_Pin_11,
261  .GPIO_Speed = GPIO_Speed_100MHz,
262  .GPIO_Mode = GPIO_Mode_AF,
263  .GPIO_OType = GPIO_OType_PP,
264  .GPIO_PuPd = GPIO_PuPd_NOPULL
265  },
266  .pin_source = GPIO_PinSource11,
267  },
268  .mosi = {
269  .gpio = GPIOC,
270  .init = {
271  .GPIO_Pin = GPIO_Pin_12,
272  .GPIO_Speed = GPIO_Speed_100MHz,
273  .GPIO_Mode = GPIO_Mode_AF,
274  .GPIO_OType = GPIO_OType_PP,
275  .GPIO_PuPd = GPIO_PuPd_NOPULL
276  },
277  .pin_source = GPIO_PinSource12,
278  },
279  .slave_count = 1,
280  .ssel = { {
281  .gpio = GPIOB,
282  .init = {
283  .GPIO_Pin = GPIO_Pin_8,
284  .GPIO_Speed = GPIO_Speed_100MHz,
285  .GPIO_Mode = GPIO_Mode_OUT,
286  .GPIO_OType = GPIO_OType_PP,
287  .GPIO_PuPd = GPIO_PuPd_NOPULL
288  },
289  } },
290 };
291 
292 pios_spi_t pios_spi_internal_id;
293 
294 #endif /* PIOS_INCLUDE_SPI */
295 
296 #if defined(PIOS_INCLUDE_I2C)
297 
298 #include <pios_i2c_priv.h>
299 
300 void PIOS_I2C_internal_ev_irq_handler(void);
301 void PIOS_I2C_internal_er_irq_handler(void);
302 
303 void I2C1_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_internal_ev_irq_handler")));
304 void I2C1_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_internal_er_irq_handler")));
305 
306 static const struct pios_i2c_adapter_cfg pios_i2c_internal_cfg = {
307  .regs = I2C1,
308  .remap = GPIO_AF_I2C1,
309  .init = {
310  .I2C_Mode = I2C_Mode_I2C,
311  .I2C_OwnAddress1 = 0,
312  .I2C_Ack = I2C_Ack_Enable,
313  .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
314  .I2C_DutyCycle = I2C_DutyCycle_2,
315  .I2C_ClockSpeed = 400000, /* bits/s */
316  },
317  .transfer_timeout_ms = 50,
318  .scl = {
319  .gpio = GPIOB,
320  .init = {
321  .GPIO_Pin = GPIO_Pin_6,
322  .GPIO_Mode = GPIO_Mode_AF,
323  .GPIO_Speed = GPIO_Speed_50MHz,
324  .GPIO_OType = GPIO_OType_OD,
325  .GPIO_PuPd = GPIO_PuPd_UP,
326  },
327  .pin_source = GPIO_PinSource6,
328  },
329  .sda = {
330  .gpio = GPIOB,
331  .init = {
332  .GPIO_Pin = GPIO_Pin_7,
333  .GPIO_Mode = GPIO_Mode_AF,
334  .GPIO_Speed = GPIO_Speed_50MHz,
335  .GPIO_OType = GPIO_OType_OD,
336  .GPIO_PuPd = GPIO_PuPd_UP,
337  },
338  .pin_source = GPIO_PinSource7,
339  },
340  .event = {
341  .flags = 0, /* FIXME: check this */
342  .init = {
343  .NVIC_IRQChannel = I2C1_EV_IRQn,
344  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
345  .NVIC_IRQChannelSubPriority = 0,
346  .NVIC_IRQChannelCmd = ENABLE,
347  },
348  },
349  .error = {
350  .flags = 0, /* FIXME: check this */
351  .init = {
352  .NVIC_IRQChannel = I2C1_ER_IRQn,
353  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
354  .NVIC_IRQChannelSubPriority = 0,
355  .NVIC_IRQChannelCmd = ENABLE,
356  },
357  },
358 };
359 
360 pios_i2c_t pios_i2c_internal_id;
361 void PIOS_I2C_internal_ev_irq_handler(void)
362 {
363  /* Call into the generic code to handle the IRQ for this specific device */
364  PIOS_I2C_EV_IRQ_Handler(pios_i2c_internal_id);
365 }
366 
367 void PIOS_I2C_internal_er_irq_handler(void)
368 {
369  /* Call into the generic code to handle the IRQ for this specific device */
370  PIOS_I2C_ER_IRQ_Handler(pios_i2c_internal_id);
371 }
372 
373 void PIOS_I2C_external_ev_irq_handler(void);
374 void PIOS_I2C_external_er_irq_handler(void);
375 
376 void I2C2_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_external_ev_irq_handler")));
377 void I2C2_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_external_er_irq_handler")));
378 
379 static const struct pios_i2c_adapter_cfg pios_i2c_external_cfg = {
380  .regs = I2C2,
381  .remap = GPIO_AF_I2C2,
382  .init = {
383  .I2C_Mode = I2C_Mode_I2C,
384  .I2C_OwnAddress1 = 0,
385  .I2C_Ack = I2C_Ack_Enable,
386  .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
387  .I2C_DutyCycle = I2C_DutyCycle_2,
388  .I2C_ClockSpeed = 400000, /* bits/s */
389  },
390  .transfer_timeout_ms = 50,
391  .scl = {
392  .gpio = GPIOB,
393  .init = {
394  .GPIO_Pin = GPIO_Pin_10,
395  .GPIO_Mode = GPIO_Mode_AF,
396  .GPIO_Speed = GPIO_Speed_50MHz,
397  .GPIO_OType = GPIO_OType_OD,
398  .GPIO_PuPd = GPIO_PuPd_UP,
399  },
400  .pin_source = GPIO_PinSource10,
401  },
402  .sda = {
403  .gpio = GPIOB,
404  .init = {
405  .GPIO_Pin = GPIO_Pin_11,
406  .GPIO_Mode = GPIO_Mode_AF,
407  .GPIO_Speed = GPIO_Speed_50MHz,
408  .GPIO_OType = GPIO_OType_OD,
409  .GPIO_PuPd = GPIO_PuPd_UP,
410  },
411  .pin_source = GPIO_PinSource11,
412  },
413  .event = {
414  .flags = 0, /* FIXME: check this */
415  . init = {
416  .NVIC_IRQChannel = I2C2_EV_IRQn,
417  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
418  .NVIC_IRQChannelSubPriority = 0,
419  .NVIC_IRQChannelCmd = ENABLE,
420  },
421  },
422  .error = {
423  .flags = 0, /* FIXME: check this */
424  .init = {
425  .NVIC_IRQChannel = I2C2_ER_IRQn,
426  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
427  .NVIC_IRQChannelSubPriority = 0,
428  .NVIC_IRQChannelCmd = ENABLE,
429  },
430  },
431 };
432 
433 pios_i2c_t pios_i2c_external_id;
434 void PIOS_I2C_external_ev_irq_handler(void)
435 {
436 /* Call into the generic code to handle the IRQ for this specific device */
437 PIOS_I2C_EV_IRQ_Handler(pios_i2c_external_id);
438 }
439 
440 void PIOS_I2C_external_er_irq_handler(void)
441 {
442  /* Call into the generic code to handle the IRQ for this specific device */
443  PIOS_I2C_ER_IRQ_Handler(pios_i2c_external_id);
444 }
445 
446 #endif /* PIOS_INCLUDE_I2C */
447 
448 #if defined(PIOS_INCLUDE_FLASH)
449 #include "pios_flashfs_logfs_priv.h"
450 
451 static const struct flashfs_logfs_cfg flashfs_settings_cfg = {
452  .fs_magic = 0x3b1b14cf,
453  .arena_size = 0x00004000, /* 64 * slot size = 16K bytes = 1 sector */
454  .slot_size = 0x00000100, /* 256 bytes */
455 };
456 
458 
459 static const struct pios_flash_internal_cfg flash_internal_cfg = {
460 };
461 
462 #include "pios_flash_priv.h"
463 
464 static const struct pios_flash_sector_range stm32f4_sectors[] = {
465  {
466  .base_sector = 0,
467  .last_sector = 3,
468  .sector_size = FLASH_SECTOR_16KB,
469  },
470  {
471  .base_sector = 4,
472  .last_sector = 4,
473  .sector_size = FLASH_SECTOR_64KB,
474  },
475  {
476  .base_sector = 5,
477  .last_sector = 11,
478  .sector_size = FLASH_SECTOR_128KB,
479  },
480 
481 };
482 
483 uintptr_t pios_internal_flash_id;
484 static const struct pios_flash_chip pios_flash_chip_internal = {
486  .chip_id = &pios_internal_flash_id,
487  .page_size = 16, /* 128-bit rows */
488  .sector_blocks = stm32f4_sectors,
489  .num_blocks = NELEMENTS(stm32f4_sectors),
490 };
491 
492 static const struct pios_flash_partition pios_flash_partition_table[] = {
493  {
495  .chip_desc = &pios_flash_chip_internal,
496  .first_sector = 0,
497  .last_sector = 1,
498  .chip_offset = 0, // 0x0800 0000
499  .size = (1 - 0 + 1) * FLASH_SECTOR_16KB, // 32KB
500  },
501 
502  {
504  .chip_desc = &pios_flash_chip_internal,
505  .first_sector = 2,
506  .last_sector = 3,
507  .chip_offset = (2 * FLASH_SECTOR_16KB), // 0x0800 8000
508  .size = (3 - 2 + 1) * FLASH_SECTOR_16KB, // 32KB
509  },
510 
511  /* NOTE: sector 4 of internal flash is currently unallocated */
512 
513  {
514  .label = FLASH_PARTITION_LABEL_FW,
515  .chip_desc = &pios_flash_chip_internal,
516  .first_sector = 5,
517  .last_sector = 7,
518  .chip_offset = (4 * FLASH_SECTOR_16KB) + (1 * FLASH_SECTOR_64KB), // 0x0802 0000
519  .size = (7 - 5 + 1) * FLASH_SECTOR_128KB, // 384KB
520  },
521 
522  /* NOTE: sectors 8-9 of the internal flash are currently unallocated */
523 
524  {
526  .chip_desc = &pios_flash_chip_internal,
527  .first_sector = 10,
528  .last_sector = 10,
529  .chip_offset = (4 * FLASH_SECTOR_16KB) + (1 * FLASH_SECTOR_64KB) + (5 * FLASH_SECTOR_128KB), // 0x080C 0000
530  .size = (10 - 10 + 1) * FLASH_SECTOR_128KB, // 128KB
531  },
532 
533  /* Sector 11 is unallocated, but in old bootloaders was allocated to
534  * waypoints/autotune.
535  */
536 };
537 
538 const struct pios_flash_partition * PIOS_BOARD_HW_DEFS_GetPartitionTable (uint32_t board_revision, uint32_t * num_partitions)
539 {
540  PIOS_Assert(num_partitions);
541 
542  *num_partitions = NELEMENTS(pios_flash_partition_table);
544 }
545 
546 #endif /* PIOS_INCLUDE_FLASH */
547 
548 #if defined(PIOS_INCLUDE_USART)
549 
550 #include "pios_usart_priv.h"
551 
552 #if defined(PIOS_INCLUDE_DSM)
553 /*
554  * Spektrum/JR DSM USART
555  */
556 #include <pios_dsm_priv.h>
557 
558 static const struct pios_dsm_cfg pios_usart4_dsm_aux_cfg = {
559  .bind = {
560  .gpio = GPIOA,
561  .init = {
562  .GPIO_Pin = GPIO_Pin_1,
563  .GPIO_Speed = GPIO_Speed_2MHz,
564  .GPIO_Mode = GPIO_Mode_OUT,
565  .GPIO_OType = GPIO_OType_PP,
566  .GPIO_PuPd = GPIO_PuPd_NOPULL
567  },
568  },
569 };
570 
571 static const struct pios_dsm_cfg pios_usart6_dsm_aux_cfg = {
572  .bind = {
573  .gpio = GPIOC,
574  .init = {
575  .GPIO_Pin = GPIO_Pin_7,
576  .GPIO_Speed = GPIO_Speed_2MHz,
577  .GPIO_Mode = GPIO_Mode_OUT,
578  .GPIO_OType = GPIO_OType_PP,
579  .GPIO_PuPd = GPIO_PuPd_NOPULL
580  },
581  },
582 };
583 
584 #endif /* PIOS_INCLUDE_DSM */
585 
586 #if defined(PIOS_INCLUDE_SBUS)
587 
588 #include <pios_sbus_priv.h>
589 
590 static const struct pios_sbus_cfg pios_usart3_sbus_aux_cfg = {
591  /* Inverter configuration */
592  .inv = {
593  .gpio = GPIOB,
594  .init = {
595  .GPIO_Pin = GPIO_Pin_12,
596  .GPIO_Speed = GPIO_Speed_2MHz,
597  .GPIO_Mode = GPIO_Mode_OUT,
598  .GPIO_OType = GPIO_OType_PP,
599  .GPIO_PuPd = GPIO_PuPd_NOPULL
600  },
601  },
602  .gpio_inv_enable = Bit_SET,
603  .gpio_inv_disable = Bit_RESET,
604 };
605 
606 #endif /* PIOS_INCLUDE_SBUS */
607 
608 static const struct pios_usart_cfg pios_usart1_cfg = {
609  .regs = USART1,
610  .remap = GPIO_AF_USART1,
611  .irq = {
612  .init = {
613  .NVIC_IRQChannel = USART1_IRQn,
614  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
615  .NVIC_IRQChannelSubPriority = 0,
616  .NVIC_IRQChannelCmd = ENABLE,
617  },
618  },
619  .rx = {
620  .gpio = GPIOA,
621  .init = {
622  .GPIO_Pin = GPIO_Pin_10,
623  .GPIO_Speed = GPIO_Speed_2MHz,
624  .GPIO_Mode = GPIO_Mode_AF,
625  .GPIO_OType = GPIO_OType_PP,
626  .GPIO_PuPd = GPIO_PuPd_UP
627  },
628  .pin_source = GPIO_PinSource10,
629  },
630  .tx = {
631  .gpio = GPIOA,
632  .init = {
633  .GPIO_Pin = GPIO_Pin_9,
634  .GPIO_Speed = GPIO_Speed_2MHz,
635  .GPIO_Mode = GPIO_Mode_AF,
636  .GPIO_OType = GPIO_OType_PP,
637  .GPIO_PuPd = GPIO_PuPd_UP
638  },
639  .pin_source = GPIO_PinSource9,
640  },
641 };
642 
643 static const struct pios_usart_cfg pios_usart2_cfg = {
644  .regs = USART2,
645  .remap = GPIO_AF_USART2,
646  .irq = {
647  .init = {
648  .NVIC_IRQChannel = USART2_IRQn,
649  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
650  .NVIC_IRQChannelSubPriority = 0,
651  .NVIC_IRQChannelCmd = ENABLE,
652  },
653  },
654  .rx = {
655  .gpio = GPIOD,
656  .init = {
657  .GPIO_Pin = GPIO_Pin_6,
658  .GPIO_Speed = GPIO_Speed_2MHz,
659  .GPIO_Mode = GPIO_Mode_AF,
660  .GPIO_OType = GPIO_OType_PP,
661  .GPIO_PuPd = GPIO_PuPd_UP
662  },
663  .pin_source = GPIO_PinSource6,
664  },
665  .tx = {
666  .gpio = GPIOD,
667  .init = {
668  .GPIO_Pin = GPIO_Pin_5,
669  .GPIO_Speed = GPIO_Speed_2MHz,
670  .GPIO_Mode = GPIO_Mode_AF,
671  .GPIO_OType = GPIO_OType_PP,
672  .GPIO_PuPd = GPIO_PuPd_UP
673  },
674  .pin_source = GPIO_PinSource5,
675  },
676 };
677 
678 static const struct pios_usart_cfg pios_usart3_cfg = {
679  .regs = USART3,
680  .remap = GPIO_AF_USART3,
681  .irq = {
682  .init = {
683  .NVIC_IRQChannel = USART3_IRQn,
684  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
685  .NVIC_IRQChannelSubPriority = 0,
686  .NVIC_IRQChannelCmd = ENABLE,
687  },
688  },
689  .rx = {
690  .gpio = GPIOD,
691  .init = {
692  .GPIO_Pin = GPIO_Pin_9,
693  .GPIO_Speed = GPIO_Speed_2MHz,
694  .GPIO_Mode = GPIO_Mode_AF,
695  .GPIO_OType = GPIO_OType_PP,
696  .GPIO_PuPd = GPIO_PuPd_UP
697  },
698  .pin_source = GPIO_PinSource9,
699  },
700  .tx = {
701  .gpio = GPIOD,
702  .init = {
703  .GPIO_Pin = GPIO_Pin_8,
704  .GPIO_Speed = GPIO_Speed_2MHz,
705  .GPIO_Mode = GPIO_Mode_AF,
706  .GPIO_OType = GPIO_OType_PP,
707  .GPIO_PuPd = GPIO_PuPd_UP
708  },
709  .pin_source = GPIO_PinSource8,
710  },
711 };
712 
713 static const struct pios_usart_cfg pios_usart4_cfg = {
714  .regs = UART4,
715  .remap = GPIO_AF_UART4,
716  .irq = {
717  .init = {
718  .NVIC_IRQChannel = UART4_IRQn,
719  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
720  .NVIC_IRQChannelSubPriority = 0,
721  .NVIC_IRQChannelCmd = ENABLE,
722  },
723  },
724  .rx = {
725  .gpio = GPIOA,
726  .init = {
727  .GPIO_Pin = GPIO_Pin_1,
728  .GPIO_Speed = GPIO_Speed_2MHz,
729  .GPIO_Mode = GPIO_Mode_AF,
730  .GPIO_OType = GPIO_OType_PP,
731  .GPIO_PuPd = GPIO_PuPd_UP
732  },
733  .pin_source = GPIO_PinSource1,
734  },
735  .tx = {
736  .gpio = GPIOA,
737  .init = {
738  .GPIO_Pin = GPIO_Pin_0,
739  .GPIO_Speed = GPIO_Speed_2MHz,
740  .GPIO_Mode = GPIO_Mode_AF,
741  .GPIO_OType = GPIO_OType_PP,
742  .GPIO_PuPd = GPIO_PuPd_UP
743  },
744  .pin_source = GPIO_PinSource0,
745  },
746 };
747 
748 static const struct pios_usart_cfg pios_usart6_cfg = {
749  .regs = USART6,
750  .remap = GPIO_AF_USART6,
751  .irq = {
752  .init = {
753  .NVIC_IRQChannel = USART6_IRQn,
754  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
755  .NVIC_IRQChannelSubPriority = 0,
756  .NVIC_IRQChannelCmd = ENABLE,
757  },
758  },
759  .rx = {
760  .gpio = GPIOC,
761  .init = {
762  .GPIO_Pin = GPIO_Pin_7,
763  .GPIO_Speed = GPIO_Speed_2MHz,
764  .GPIO_Mode = GPIO_Mode_AF,
765  .GPIO_OType = GPIO_OType_PP,
766  .GPIO_PuPd = GPIO_PuPd_UP
767  },
768  .pin_source = GPIO_PinSource7,
769  },
770  .tx = {
771  .gpio = GPIOC,
772  .init = {
773  .GPIO_Pin = GPIO_Pin_6,
774  .GPIO_Speed = GPIO_Speed_2MHz,
775  .GPIO_Mode = GPIO_Mode_AF,
776  .GPIO_OType = GPIO_OType_PP,
777  .GPIO_PuPd = GPIO_PuPd_UP
778  },
779  .pin_source = GPIO_PinSource6,
780  },
781 };
782 
783 #endif /* PIOS_INCLUDE_USART */
784 
785 #if defined(PIOS_INCLUDE_COM)
786 
787 #include "pios_com_priv.h"
788 
789 #endif /* PIOS_INCLUDE_COM */
790 
791 #if defined(PIOS_INCLUDE_RTC)
792 /*
793  * Realtime Clock (RTC)
794  */
795 #include <pios_rtc_priv.h>
796 
797 void PIOS_RTC_IRQ_Handler (void);
798 void RTC_WKUP_IRQHandler() __attribute__ ((alias ("PIOS_RTC_IRQ_Handler")));
799 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
800  .clksrc = RCC_RTCCLKSource_HSE_Div8, // Divide 8 MHz HSE by 8 = 1 MHz
801  // 1 MHz resulting clock is then divided
802  // by another 16 to give a nominal 62.5 kHz clock
803  .prescaler = 100, // Every 100 cycles gives 625 Hz
804  .irq = {
805  .init = {
806  .NVIC_IRQChannel = RTC_WKUP_IRQn,
807  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
808  .NVIC_IRQChannelSubPriority = 0,
809  .NVIC_IRQChannelCmd = ENABLE,
810  },
811  },
812 };
813 
814 void PIOS_RTC_IRQ_Handler (void)
815 {
817 }
818 
819 #endif
820 
821 #include "pios_tim_priv.h"
822 
823 //Timers used for inputs (5)
824 
825 // Set up timers that only have outputs on APB1
826 static const TIM_TimeBaseInitTypeDef tim_5_time_base = {
827  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_COUNTER_CLOCK / 1000000) - 1,
828  .TIM_ClockDivision = TIM_CKD_DIV1,
829  .TIM_CounterMode = TIM_CounterMode_Up,
830  .TIM_Period = 0xFFFF,
831  .TIM_RepetitionCounter = 0x0000,
832 };
833 
834 static const struct pios_tim_clock_cfg tim_5_cfg = {
835  .timer = TIM5,
836  .time_base_init = &tim_5_time_base,
837  .irq = {
838  .init = {
839  .NVIC_IRQChannel = TIM5_IRQn,
840  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
841  .NVIC_IRQChannelSubPriority = 0,
842  .NVIC_IRQChannelCmd = ENABLE,
843  },
844  },
845 };
846 
847 // Timers used for outputs (1,2,3,4,8)
848 
849 // Set up timers that only have outputs on APB1
850 static const TIM_TimeBaseInitTypeDef tim_2_3_4_time_base = {
851  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_COUNTER_CLOCK / 1000000) - 1,
852  .TIM_ClockDivision = TIM_CKD_DIV1,
853  .TIM_CounterMode = TIM_CounterMode_Up,
854  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
855  .TIM_RepetitionCounter = 0x0000,
856 };
857 
858 // Set up timers that only have outputs on APB2
859 static const TIM_TimeBaseInitTypeDef tim_1_8_time_base = {
860  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 1000000) - 1,
861  .TIM_ClockDivision = TIM_CKD_DIV1,
862  .TIM_CounterMode = TIM_CounterMode_Up,
863  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
864  .TIM_RepetitionCounter = 0x0000,
865 };
866 
867 static const struct pios_tim_clock_cfg tim_2_cfg = {
868  .timer = TIM2,
869  .time_base_init = &tim_2_3_4_time_base,
870  .irq = {
871  .init = {
872  .NVIC_IRQChannel = TIM2_IRQn,
873  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
874  .NVIC_IRQChannelSubPriority = 0,
875  .NVIC_IRQChannelCmd = ENABLE,
876  },
877  },
878 };
879 
880 static const struct pios_tim_clock_cfg tim_3_cfg = {
881  .timer = TIM3,
882  .time_base_init = &tim_2_3_4_time_base,
883  .irq = {
884  .init = {
885  .NVIC_IRQChannel = TIM3_IRQn,
886  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
887  .NVIC_IRQChannelSubPriority = 0,
888  .NVIC_IRQChannelCmd = ENABLE,
889  },
890  },
891 };
892 
893 static const struct pios_tim_clock_cfg tim_4_cfg = {
894  .timer = TIM4,
895  .time_base_init = &tim_2_3_4_time_base,
896  .irq = {
897  .init = {
898  .NVIC_IRQChannel = TIM4_IRQn,
899  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
900  .NVIC_IRQChannelSubPriority = 0,
901  .NVIC_IRQChannelCmd = ENABLE,
902  },
903  },
904 };
905 
906 static const struct pios_tim_clock_cfg tim_8_cfg = {
907  .timer = TIM8,
908  .time_base_init = &tim_1_8_time_base,
909  .irq = {
910  .init = {
911  .NVIC_IRQChannel = TIM8_CC_IRQn,
912  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
913  .NVIC_IRQChannelSubPriority = 0,
914  .NVIC_IRQChannelCmd = ENABLE,
915  },
916  },
917 };
918 
923 /*
924  * Outputs
925  1: TIM8_CH4 (PC9) DMA2 Stream 1 Channel 7
926  2: TIM8_CH3 (PC8)
927  3: TIM2_CH1 (PA15) DMA1 Stream 7 Channel 3
928  4: TIM2_CH2 (PB3)
929  5: TIM3_CH1 (PB4) DMA1 Stream 2 Channel 5
930  6: TIM3_CH2 (PB5)
931  7: TIM4_CH1 (PD12) RX1 DMA1 Stream 6 Channel 2
932  8: TIM4_CH2 (PD13) RX2
933  9: TIM4_CH3 (PD14) RX3
934  10: TIM4_CH4 (PD15) RX4
935  */
936 static const struct pios_tim_channel pios_tim_outputs_pins[] = {
937  {
938  .timer = TIM8,
939  .timer_chan = TIM_Channel_4,
940  .remap = GPIO_AF_TIM8,
941  .pin = {
942  .gpio = GPIOC,
943  .init = {
944  .GPIO_Pin = GPIO_Pin_9,
945  .GPIO_Speed = GPIO_Speed_2MHz,
946  .GPIO_Mode = GPIO_Mode_AF,
947  .GPIO_OType = GPIO_OType_PP,
948  .GPIO_PuPd = GPIO_PuPd_NOPULL
949  },
950  .pin_source = GPIO_PinSource9,
951  },
952  },
953  {
954  .timer = TIM8,
955  .timer_chan = TIM_Channel_3,
956  .remap = GPIO_AF_TIM8,
957  .pin = {
958  .gpio = GPIOC,
959  .init = {
960  .GPIO_Pin = GPIO_Pin_8,
961  .GPIO_Speed = GPIO_Speed_2MHz,
962  .GPIO_Mode = GPIO_Mode_AF,
963  .GPIO_OType = GPIO_OType_PP,
964  .GPIO_PuPd = GPIO_PuPd_NOPULL
965  },
966  .pin_source = GPIO_PinSource8,
967  },
968  },
969  {
970  .timer = TIM2,
971  .timer_chan = TIM_Channel_1,
972  .remap = GPIO_AF_TIM2,
973  .pin = {
974  .gpio = GPIOA,
975  .init = {
976  .GPIO_Pin = GPIO_Pin_15,
977  .GPIO_Speed = GPIO_Speed_2MHz,
978  .GPIO_Mode = GPIO_Mode_AF,
979  .GPIO_OType = GPIO_OType_PP,
980  .GPIO_PuPd = GPIO_PuPd_NOPULL
981  },
982  .pin_source = GPIO_PinSource15,
983  },
984  },
985  {
986  .timer = TIM2,
987  .timer_chan = TIM_Channel_2,
988  .remap = GPIO_AF_TIM2,
989  .pin = {
990  .gpio = GPIOB,
991  .init = {
992  .GPIO_Pin = GPIO_Pin_3,
993  .GPIO_Speed = GPIO_Speed_2MHz,
994  .GPIO_Mode = GPIO_Mode_AF,
995  .GPIO_OType = GPIO_OType_PP,
996  .GPIO_PuPd = GPIO_PuPd_NOPULL
997  },
998  .pin_source = GPIO_PinSource3,
999  },
1000  },
1001  {
1002  .timer = TIM3,
1003  .timer_chan = TIM_Channel_1,
1004  .remap = GPIO_AF_TIM3,
1005  .pin = {
1006  .gpio = GPIOB,
1007  .init = {
1008  .GPIO_Pin = GPIO_Pin_4,
1009  .GPIO_Speed = GPIO_Speed_2MHz,
1010  .GPIO_Mode = GPIO_Mode_AF,
1011  .GPIO_OType = GPIO_OType_PP,
1012  .GPIO_PuPd = GPIO_PuPd_NOPULL
1013  },
1014  .pin_source = GPIO_PinSource4,
1015  },
1016  },
1017  {
1018  .timer = TIM3,
1019  .timer_chan = TIM_Channel_2,
1020  .remap = GPIO_AF_TIM3,
1021  .pin = {
1022  .gpio = GPIOB,
1023  .init = {
1024  .GPIO_Pin = GPIO_Pin_5,
1025  .GPIO_Speed = GPIO_Speed_2MHz,
1026  .GPIO_Mode = GPIO_Mode_AF,
1027  .GPIO_OType = GPIO_OType_PP,
1028  .GPIO_PuPd = GPIO_PuPd_NOPULL
1029  },
1030  .pin_source = GPIO_PinSource5,
1031  },
1032  },
1033  {
1034  .timer = TIM4,
1035  .timer_chan = TIM_Channel_1,
1036  .remap = GPIO_AF_TIM4,
1037  .pin = {
1038  .gpio = GPIOD,
1039  .init = {
1040  .GPIO_Pin = GPIO_Pin_12,
1041  .GPIO_Speed = GPIO_Speed_2MHz,
1042  .GPIO_Mode = GPIO_Mode_AF,
1043  .GPIO_OType = GPIO_OType_PP,
1044  .GPIO_PuPd = GPIO_PuPd_NOPULL
1045  },
1046  .pin_source = GPIO_PinSource12,
1047  },
1048  },
1049  {
1050  .timer = TIM4,
1051  .timer_chan = TIM_Channel_2,
1052  .remap = GPIO_AF_TIM4,
1053  .pin = {
1054  .gpio = GPIOD,
1055  .init = {
1056  .GPIO_Pin = GPIO_Pin_13,
1057  .GPIO_Speed = GPIO_Speed_2MHz,
1058  .GPIO_Mode = GPIO_Mode_AF,
1059  .GPIO_OType = GPIO_OType_PP,
1060  .GPIO_PuPd = GPIO_PuPd_NOPULL
1061  },
1062  .pin_source = GPIO_PinSource13,
1063  },
1064  },
1065  {
1066  .timer = TIM4,
1067  .timer_chan = TIM_Channel_3,
1068  .remap = GPIO_AF_TIM4,
1069  .pin = {
1070  .gpio = GPIOD,
1071  .init = {
1072  .GPIO_Pin = GPIO_Pin_14,
1073  .GPIO_Speed = GPIO_Speed_2MHz,
1074  .GPIO_Mode = GPIO_Mode_AF,
1075  .GPIO_OType = GPIO_OType_PP,
1076  .GPIO_PuPd = GPIO_PuPd_NOPULL
1077  },
1078  .pin_source = GPIO_PinSource14,
1079  },
1080  },
1081  {
1082  .timer = TIM4,
1083  .timer_chan = TIM_Channel_4,
1084  .remap = GPIO_AF_TIM4,
1085  .pin = {
1086  .gpio = GPIOD,
1087  .init = {
1088  .GPIO_Pin = GPIO_Pin_15,
1089  .GPIO_Speed = GPIO_Speed_2MHz,
1090  .GPIO_Mode = GPIO_Mode_AF,
1091  .GPIO_OType = GPIO_OType_PP,
1092  .GPIO_PuPd = GPIO_PuPd_NOPULL
1093  },
1094  .pin_source = GPIO_PinSource15,
1095  },
1096  },
1097 };
1098 
1099 #if defined(PIOS_INCLUDE_DMASHOT)
1100 
1101 #include <pios_dmashot.h>
1102 
1103 // Enable pins 1-10 for DMA1
1104 
1105 static const struct pios_dmashot_timer_cfg dmashot_tim_cfg[] = {
1106  {
1107  .timer = TIM8,
1108  .stream = DMA2_Stream1,
1109  .channel = DMA_Channel_7,
1110  .tcif = DMA_FLAG_TCIF1
1111  },
1112  {
1113  .timer = TIM2,
1114  .stream = DMA1_Stream7,
1115  .channel = DMA_Channel_3,
1116  .tcif = DMA_FLAG_TCIF7
1117  },
1118  {
1119  .timer = TIM3,
1120  .stream = DMA1_Stream2,
1121  .channel = DMA_Channel_5,
1122  .tcif = DMA_FLAG_TCIF2
1123  },
1124  {
1125  .timer = TIM4,
1126  .stream = DMA1_Stream6,
1127  .channel = DMA_Channel_2,
1128  .tcif = DMA_FLAG_TCIF6
1129  }
1130 };
1131 
1132 static const struct pios_dmashot_cfg dmashot_config = {
1133  .timer_cfg = &dmashot_tim_cfg[0],
1134  .num_timers = NELEMENTS(dmashot_tim_cfg)
1135 };
1136 
1137 #endif // defined(PIOS_INCLUDE_DMASHOT)
1138 
1139 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
1140 /*
1141  * Servo outputs
1142  */
1143 #include <pios_servo_priv.h>
1144 
1145 const struct pios_servo_cfg pios_servo_cfg = {
1146  .tim_oc_init = {
1147  .TIM_OCMode = TIM_OCMode_PWM1,
1148  .TIM_OutputState = TIM_OutputState_Enable,
1149  .TIM_OutputNState = TIM_OutputNState_Disable,
1150  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1151  .TIM_OCPolarity = TIM_OCPolarity_High,
1152  .TIM_OCNPolarity = TIM_OCPolarity_High,
1153  .TIM_OCIdleState = TIM_OCIdleState_Reset,
1154  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1155  },
1156  .channels = pios_tim_outputs_pins,
1157  .num_channels = NELEMENTS(pios_tim_outputs_pins),
1158 };
1159 
1160 #endif /* PIOS_INCLUDE_SERVO && PIOS_INCLUDE_TIM */
1161 
1162 /*
1163  * PPM INPUT
1164  1: TIM5_CH3 (PA2)
1165  */
1166 static const struct pios_tim_channel pios_tim_rcvrport_ppm[] = {
1167  {
1168  .timer = TIM5,
1169  .timer_chan = TIM_Channel_3,
1170  .remap = GPIO_AF_TIM5,
1171  .pin = {
1172  .gpio = GPIOA,
1173  .init = {
1174  .GPIO_Pin = GPIO_Pin_2,
1175  .GPIO_Speed = GPIO_Speed_2MHz,
1176  .GPIO_Mode = GPIO_Mode_AF,
1177  .GPIO_OType = GPIO_OType_PP,
1178  .GPIO_PuPd = GPIO_PuPd_UP
1179  },
1180  .pin_source = GPIO_PinSource2,
1181  },
1182  },
1183 };
1184 
1185 /*
1186  * PPM Input
1187  */
1188 #if defined(PIOS_INCLUDE_PPM)
1189 #include <pios_ppm_priv.h>
1190 
1191 /*
1192  * PPM Input
1193  */
1194 const struct pios_ppm_cfg pios_ppm_cfg = {
1195  .tim_ic_init = {
1196  .TIM_ICPolarity = TIM_ICPolarity_Rising,
1197  .TIM_ICSelection = TIM_ICSelection_DirectTI,
1198  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1199  .TIM_ICFilter = 0x0,
1200  .TIM_Channel = TIM_Channel_3,
1201  },
1202  /* Servo Out 3 for PPM Input */
1203  .channels = &pios_tim_rcvrport_ppm[0],
1204  .num_channels = 1,
1205 };
1206 
1207 #endif
1208 
1209 #if defined(PIOS_INCLUDE_RCVR)
1210 #include "pios_rcvr_priv.h"
1211 #endif /* PIOS_INCLUDE_RCVR */
1212 
1213 #if defined(PIOS_INCLUDE_USB)
1214 #include "pios_usb_priv.h"
1215 
1216 static const struct pios_usb_cfg pios_usb_main_cfg = {
1217  .irq = {
1218  .init = {
1219  .NVIC_IRQChannel = OTG_FS_IRQn,
1220  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1221  .NVIC_IRQChannelSubPriority = 0,
1222  .NVIC_IRQChannelCmd = ENABLE,
1223  },
1224  },
1225  .vsense = {
1226  .gpio = NULL,
1227  },
1228  .disconnect = {
1229  .gpio = GPIOD,
1230  .init = {
1231  .GPIO_Pin = GPIO_Pin_11,
1232  .GPIO_Speed = GPIO_Speed_2MHz,
1233  .GPIO_Mode = GPIO_Mode_OUT,
1234  .GPIO_OType = GPIO_OType_OD,
1235  .GPIO_PuPd = GPIO_PuPd_NOPULL,
1236  },
1237  }
1238 };
1239 
1240 const struct pios_usb_cfg * PIOS_BOARD_HW_DEFS_GetUsbCfg (uint32_t board_revision)
1241 {
1242  return &pios_usb_main_cfg;
1243 }
1244 
1245 #include "pios_usb_board_data_priv.h"
1248 #include "pios_usbhook.h"
1249 
1250 #endif /* PIOS_INCLUDE_USB */
1251 
1252 #if defined(PIOS_INCLUDE_COM_MSG)
1253 
1254 #include <pios_com_msg_priv.h>
1255 
1256 #endif /* PIOS_INCLUDE_COM_MSG */
1257 
1258 #if defined(PIOS_INCLUDE_USB_HID) && !defined(PIOS_INCLUDE_USB_CDC)
1259 #include <pios_usb_hid_priv.h>
1260 
1261 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
1262  .data_if = 0,
1263  .data_rx_ep = 1,
1264  .data_tx_ep = 1,
1265 };
1266 #endif /* PIOS_INCLUDE_USB_HID && !PIOS_INCLUDE_USB_CDC */
1267 
1268 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_USB_CDC)
1269 #include <pios_usb_cdc_priv.h>
1270 
1271 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
1272  .ctrl_if = 0,
1273  .ctrl_tx_ep = 2,
1274 
1275  .data_if = 1,
1276  .data_rx_ep = 3,
1277  .data_tx_ep = 3,
1278 };
1279 
1280 #include <pios_usb_hid_priv.h>
1281 
1282 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
1283  .data_if = 2,
1284  .data_rx_ep = 1,
1285  .data_tx_ep = 1,
1286 };
1287 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
1288 
1289 #if defined(PIOS_INCLUDE_ADC)
1290 #include "pios_adc_priv.h"
1291 #include "pios_internal_adc_priv.h"
1292 
1293 void PIOS_ADC_DMA_irq_handler(void);
1294 void DMA2_Stream0_IRQHandler(void) __attribute__((alias("PIOS_ADC_DMA_irq_handler")));
1295 struct pios_internal_adc_cfg pios_adc_cfg = {
1296  .adc_dev_master = ADC1,
1297  .dma = {
1298  .irq = {
1299  .flags = (DMA_FLAG_TCIF0 | DMA_FLAG_TEIF0 | DMA_FLAG_HTIF0),
1300  .init = {
1301  .NVIC_IRQChannel = DMA2_Stream0_IRQn,
1302  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1303  .NVIC_IRQChannelSubPriority = 0,
1304  .NVIC_IRQChannelCmd = ENABLE,
1305  },
1306  },
1307  .rx = {
1308  .channel = DMA2_Stream0,
1309  .init = {
1310  .DMA_Channel = DMA_Channel_0,
1311  .DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR
1312  },
1313  }
1314  },
1315  .half_flag = DMA_IT_HTIF0,
1316  .full_flag = DMA_IT_TCIF0,
1317  .adc_pins = { \
1318  { GPIOC, GPIO_Pin_4, ADC_Channel_14 }, /* AI2 */ \
1319  { GPIOC, GPIO_Pin_0, ADC_Channel_10 }, /* Internal Voltage Monitor */ \
1320  { GPIOB, GPIO_Pin_1, ADC_Channel_9 }, /* AI3 */ \
1321  { GPIOC, GPIO_Pin_5, ADC_Channel_15 }, /* AI4 */ \
1322  { GPIOC, GPIO_Pin_2, ADC_Channel_12 }, /* AI5 */ \
1323  },
1324  .adc_pin_count = 5,
1325 };
1326 
1327 void PIOS_ADC_DMA_irq_handler(void)
1328 {
1329  /* Call into the generic code to handle the IRQ for this specific device */
1331 }
1332 
1333 #endif /* PIOS_INCLUDE_ADC */
1334 
1339 #if defined(PIOS_INCLUDE_WS2811)
1340 #include "pios_ws2811.h"
1341 
1343 
1344 void DMA2_Stream6_IRQHandler() {
1345  PIOS_WS2811_dma_interrupt_handler(pios_ws2811);
1346 }
1347 
1348 static const struct pios_ws2811_cfg pios_ws2811_cfg = {
1349  .timer = TIM1,
1350  .clock_cfg = {
1351  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 12000000) - 1,
1352  .TIM_ClockDivision = TIM_CKD_DIV1,
1353  .TIM_CounterMode = TIM_CounterMode_Up,
1354  .TIM_Period = 25, /* 2.083us/bit */
1355  },
1356  .interrupt = {
1357  .NVIC_IRQChannel = DMA2_Stream6_IRQn,
1358  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1359  .NVIC_IRQChannelSubPriority = 0,
1360  .NVIC_IRQChannelCmd = ENABLE,
1361  },
1362  .bit_clear_dma_tcif = DMA_IT_TCIF6,
1363  .fall_time_l = 5, /* 333ns */
1364  .fall_time_h = 11, /* 833ns */
1365  .led_gpio = GPIOB,
1366  .gpio_pin = GPIO_Pin_0, /* PB0 / RNG */
1367  .bit_set_dma_stream = DMA2_Stream4,
1368  .bit_set_dma_channel = DMA_Channel_6, /* 2/S4/C6: TIM1 CH4|TRIG|COM */
1369  .bit_clear_dma_stream = DMA2_Stream6,
1370  .bit_clear_dma_channel = DMA_Channel_0, /* 0/S6/C0: TIM1 CH1|CH2|CH3 */
1371 };
1372 #endif
1373 
1374 #if defined(PIOS_INCLUDE_DAC)
1375 #include "pios_dac.h"
1376 
1377 dac_dev_t pios_dac;
1378 
1379 /* DAC 1 is the DAC output on AQ32; DMA1 Stream 5 Ch7 */
1380 
1381 void DMA1_Stream5_IRQHandler() {
1383 }
1384 
1385 typedef struct dac_dev_s *dac_dev_t;
1386 
1387 struct pios_dac_cfg pios_dac_cfg = {
1388  .timer = TIM6,
1389  .clock_cfg = {
1390  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_COUNTER_CLOCK / 600000) - 1,
1391  .TIM_ClockDivision = TIM_CKD_DIV1,
1392  .TIM_CounterMode = TIM_CounterMode_Up,
1393  .TIM_Period = 25-1, /* 600000 / 25 = 24000 samples per sec */
1394  },
1395  .interrupt = {
1396  .NVIC_IRQChannel = DMA1_Stream5_IRQn,
1397  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1398  .NVIC_IRQChannelSubPriority = 0,
1399  .NVIC_IRQChannelCmd = ENABLE,
1400  },
1401  .gpio = GPIOA,
1402  .gpio_pin = GPIO_Pin_4,
1403  .dma_stream = DMA1_Stream5,
1404  .dma_channel = DMA_Channel_7,
1405  .dac_channel = DAC_Channel_1,
1406  .dac_trigger = DAC_Trigger_T6_TRGO,
1407  .dac_outreg = (uintptr_t) (&DAC->DHR12L1),
1408  .dma_tcif = DMA_IT_TCIF5,
1409 };
1410 
1411 #endif /* PIOS_INCLUDE_DAC */
1412 
1416 #if defined(PIOS_INCLUDE_MPU)
1417 #include "pios_mpu.h"
1418 static const struct pios_exti_cfg pios_exti_mpu_cfg __exti_config = {
1419  .vector = PIOS_MPU_IRQHandler,
1420  .line = EXTI_Line4,
1421  .pin = {
1422  .gpio = GPIOE,
1423  .init = {
1424  .GPIO_Pin = GPIO_Pin_4,
1425  .GPIO_Speed = GPIO_Speed_100MHz,
1426  .GPIO_Mode = GPIO_Mode_IN,
1427  .GPIO_OType = GPIO_OType_OD,
1428  .GPIO_PuPd = GPIO_PuPd_NOPULL,
1429  },
1430  },
1431  .irq = {
1432  .init = {
1433  .NVIC_IRQChannel = EXTI4_IRQn,
1434  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
1435  .NVIC_IRQChannelSubPriority = 0,
1436  .NVIC_IRQChannelCmd = ENABLE,
1437  },
1438  },
1439  .exti = {
1440  .init = {
1441  .EXTI_Line = EXTI_Line4, // matches above GPIO pin
1442  .EXTI_Mode = EXTI_Mode_Interrupt,
1443  .EXTI_Trigger = EXTI_Trigger_Rising,
1444  .EXTI_LineCmd = ENABLE,
1445  },
1446  },
1447 };
1448 
1449 static struct pios_mpu_cfg pios_mpu_cfg = {
1450  .exti_cfg = &pios_exti_mpu_cfg,
1451  .default_samplerate = 1000,
1452  .orientation = PIOS_MPU_TOP_270DEG
1453 };
1454 #endif /* PIOS_INCLUDE_MPU */
1455 
1456 
1460 #if defined(PIOS_INCLUDE_HMC5883)
1461 #include "pios_hmc5883_priv.h"
1462 static const struct pios_exti_cfg pios_exti_hmc5883_internal_cfg __exti_config = {
1464  .line = EXTI_Line2,
1465  .pin = {
1466  .gpio = GPIOE,
1467  .init = {
1468  .GPIO_Pin = GPIO_Pin_2,
1469  .GPIO_Speed = GPIO_Speed_100MHz,
1470  .GPIO_Mode = GPIO_Mode_IN,
1471  .GPIO_OType = GPIO_OType_OD,
1472  .GPIO_PuPd = GPIO_PuPd_NOPULL,
1473  },
1474  },
1475  .irq = {
1476  .init = {
1477  .NVIC_IRQChannel = EXTI2_IRQn,
1478  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1479  .NVIC_IRQChannelSubPriority = 0,
1480  .NVIC_IRQChannelCmd = ENABLE,
1481  },
1482  },
1483  .exti = {
1484  .init = {
1485  .EXTI_Line = EXTI_Line2, // matches above GPIO pin
1486  .EXTI_Mode = EXTI_Mode_Interrupt,
1487  .EXTI_Trigger = EXTI_Trigger_Rising,
1488  .EXTI_LineCmd = ENABLE,
1489  },
1490  },
1491 };
1492 
1493 static const struct pios_hmc5883_cfg pios_hmc5883_internal_cfg = {
1494  .exti_cfg = &pios_exti_hmc5883_internal_cfg,
1495  .M_ODR = PIOS_HMC5883_ODR_75,
1496  .Meas_Conf = PIOS_HMC5883_MEASCONF_NORMAL,
1497  .Gain = PIOS_HMC5883_GAIN_1_9,
1499  .Default_Orientation = PIOS_HMC5883_TOP_270DEG,
1500 };
1501 #endif /* PIOS_INCLUDE_HMC5883 */
1502 
1506 #if defined(PIOS_INCLUDE_MS5611)
1507 #include "pios_ms5611_priv.h"
1508 static const struct pios_ms5611_cfg pios_ms5611_cfg = {
1510  .temperature_interleaving = 1,
1511  .use_0x76_address = true,
1512 };
1513 #endif /* PIOS_INCLUDE_MS5611 */
1514 
1515 
struct stm32_gpio pin
const struct pios_exti_cfg * exti_cfg
MS5611 functions header.
const struct pios_dmashot_timer_cfg * timer_cfg
Definition: pios_dmashot.h:68
#define PIOS_HMC5883_ODR_75
#define DMA1_Stream5_IRQHandler
SPI private definitions.
#define NELEMENTS(x)
Definition: pios.h:192
TIM_TypeDef * timer
Definition: pios_dmashot.h:53
#define I2C2_EV_IRQHandler
struct stm32_gpio bind
static const TIM_TimeBaseInitTypeDef tim_5_time_base
COM private definitions.
COM MSG private definitions.
APIs for PIOS_USBHOOK layer.
GPIO_TypeDef * gpio
Definition: pios_stm32.h:60
static const TIM_TimeBaseInitTypeDef tim_1_8_time_base
#define PIOS_HMC5883_MODE_CONTINUOUS
I2C_TypeDef * regs
Definition: pios_i2c_priv.h:37
ADC private definitions.
bool PIOS_HMC5883_IRQHandler()
#define PIOS_IRQ_PRIO_HIGHEST
Definition: pios_board.h:172
#define PIOS_SERVOS_INITIAL_POSITION
Definition: pios_board.h:210
bool(* vector)(void)
Definition: pios_exti.h:38
static const struct pios_tim_clock_cfg tim_8_cfg
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
Configuration structure for the MS5611 driver.
USART private definitions.
#define DMA2_Stream0_IRQHandler
Spektrum/JR DSMx satellite receiver private structures.
enum pios_ms5611_osr oversampling
#define I2C2_ER_IRQHandler
static const struct pios_tim_clock_cfg tim_4_cfg
#define FLASH_SECTOR_64KB
const struct pios_exti_cfg * exti_cfg
Definition: pios_mpu.h:140
#define PIOS_SERVO_UPDATE_HZ
Definition: pios_board.h:209
static const struct pios_tim_clock_cfg tim_5_cfg
Configuration struct holding all timer configurations.
Definition: pios_dmashot.h:66
TIM_TypeDef * timer
Definition: pios_tim_priv.h:7
SPI_TypeDef * regs
Definition: pios_spi_priv.h:44
Configuration struct to assign a DMA channel and stream to a timer, and optionally specify a master t...
Definition: pios_dmashot.h:51
struct pios_i2c_adapter * pios_i2c_t
Definition: pios_i2c.h:48
static const struct pios_tim_channel pios_tim_rcvrport_ppm[]
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
TIM_TypeDef * timer
ppm private structures.
NVIC_InitTypeDef init
Definition: pios_stm32.h:36
#define I2C1_ER_IRQHandler
struct stm32_gpio inv
USART_TypeDef * regs
USB private definitions.
TIM_OCInitTypeDef tim_oc_init
USB COM HID private definitions.
#define I2C1_EV_IRQHandler
ADC private definitions.
Servo private structures.
#define FLASH_SECTOR_16KB
NVIC_InitTypeDef interrupt
Definition: pios_dac.h:46
void PIOS_I2C_ER_IRQ_Handler(pios_i2c_t i2c_id)
TIM_ICInitTypeDef tim_ic_init
Definition: pios_ppm_priv.h:37
#define DMA2_Stream6_IRQHandler
static const TIM_TimeBaseInitTypeDef tim_2_3_4_time_base
Defines the API to set up the HID-only USB descriptor config.
NVIC_InitTypeDef interrupt
#define PIOS_HMC5883_MEASCONF_NORMAL
void PIOS_RTC_irq_handler(void)
Futaba S.Bus Private structures.
void PIOS_WS2811_dma_interrupt_handler(ws2811_dev_t dev)
Handles a DMA completion interrupt on bit_clear_dma_stream.
struct dac_dev_s * dac_dev_t
Definition: pios_dac.h:40
bool PIOS_MPU_IRQHandler(void)
The IMU interrupt handler. Fetches new data from the IMU.
const struct pios_flash_driver * driver
static const struct pios_tim_channel pios_tim_outputs_pins[]
const struct pios_flash_partition pios_flash_partition_table[]
Definition: unittest_init.c:50
#define PIOS_IRQ_PRIO_HIGH
Definition: pios_board.h:171
static const struct pios_tim_clock_cfg tim_3_cfg
TIM_TypeDef * timer
Definition: pios_tim_priv.h:14
USB COM CDC private definitions.
uint32_t clksrc
Definition: pios_rtc_priv.h:37
SPI_InitTypeDef init
Definition: pios_spi_priv.h:46
enum pios_flash_partition_labels label
board_revision
Definition: board_hw_defs.c:35
TIM_TypeDef * timer
Definition: pios_dac.h:43
static const struct pios_tim_clock_cfg tim_2_cfg
#define PIOS_IRQ_PRIO_LOW
Definition: pios_board.h:169
#define PIOS_Assert(test)
Definition: pios_debug.h:52
LED private definitions.
void PIOS_DAC_dma_interrupt_handler(dac_dev_t dev)
Handles a DMA completion interrupt on dma_stream.
#define PIOS_ANNUNCIATOR_BUZZER
Definition: pios_board.h:87
struct stm32_irq irq
Definition: pios_usb_priv.h:37
#define FLASH_SECTOR_128KB
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.