dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
board_hw_defs.c
Go to the documentation of this file.
1 
17 /*
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful, but
24  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26  * for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with this program; if not, see <http://www.gnu.org/licenses/>
30  *
31  * Additional note on redistribution: The copyright and license notices above
32  * must be maintained in each individual source file that is a derivative work
33  * of this source file; otherwise redistribution is prohibited.
34  */
35 #include <pios_config.h>
36 #include <pios_board_info.h>
37 
38 #if defined(PIOS_INCLUDE_ANNUNC)
39 
40 #include <pios_annunc_priv.h>
41 static const struct pios_annunc pios_annuncs[] = {
42  [PIOS_LED_HEARTBEAT] = {
43  .pin = {
44  .gpio = GPIOB,
45  .init = {
46  .GPIO_Pin = GPIO_Pin_12,
47  .GPIO_Speed = GPIO_Speed_50MHz,
48  .GPIO_Mode = GPIO_Mode_OUT,
49  .GPIO_OType = GPIO_OType_PP,
50  .GPIO_PuPd = GPIO_PuPd_UP
51  },
52  },
53  },
54 };
55 
56 static const struct pios_annunc_cfg pios_annunc_cfg = {
57  .annunciators = pios_annuncs,
58  .num_annunciators = NELEMENTS(pios_annuncs),
59 };
60 
61 static const struct pios_annunc pios_annuncs_v2[] = {
62  [PIOS_LED_HEARTBEAT] = {
63  .pin = {
64  .gpio = GPIOB,
65  .init = {
66  .GPIO_Pin = GPIO_Pin_5,
67  .GPIO_Speed = GPIO_Speed_50MHz,
68  .GPIO_Mode = GPIO_Mode_OUT,
69  .GPIO_OType = GPIO_OType_PP,
70  .GPIO_PuPd = GPIO_PuPd_UP
71  },
72  },
73  },
74  [PIOS_LED_ALARM] = {
75  .pin = {
76  .gpio = GPIOB,
77  .init = {
78  .GPIO_Pin = GPIO_Pin_4,
79  .GPIO_Speed = GPIO_Speed_50MHz,
80  .GPIO_Mode = GPIO_Mode_OUT,
81  .GPIO_OType = GPIO_OType_PP,
82  .GPIO_PuPd = GPIO_PuPd_UP
83  },
84  },
85  },
86 };
87 
88 static const struct pios_annunc_cfg pios_annunc_v2_cfg = {
89  .annunciators = pios_annuncs_v2,
90  .num_annunciators = NELEMENTS(pios_annuncs_v2),
91 };
92 
93 static const struct pios_annunc pios_annuncs_omnibus[] = {
94  [PIOS_LED_HEARTBEAT] = {
95  .pin = {
96  .gpio = GPIOB,
97  .init = {
98  .GPIO_Pin = GPIO_Pin_5,
99  .GPIO_Speed = GPIO_Speed_50MHz,
100  .GPIO_Mode = GPIO_Mode_OUT,
101  .GPIO_OType = GPIO_OType_PP,
102  .GPIO_PuPd = GPIO_PuPd_UP
103  },
104  },
105  },
107  .pin = {
108  .gpio = GPIOB,
109  .init = {
110  .GPIO_Pin = GPIO_Pin_4,
111  .GPIO_Speed = GPIO_Speed_50MHz,
112  .GPIO_Mode = GPIO_Mode_OUT,
113  .GPIO_OType = GPIO_OType_PP,
114  .GPIO_PuPd = GPIO_PuPd_UP
115  },
116  },
117  .active_high = true,
118  },
119 };
120 
121 static const struct pios_annunc_cfg pios_annunc_omnibus_cfg = {
122  .annunciators = pios_annuncs_omnibus,
123  .num_annunciators = NELEMENTS(pios_annuncs_omnibus),
124 };
125 
126 const struct pios_annunc_cfg * PIOS_BOARD_HW_DEFS_GetLedCfg (uint32_t board_revision)
127 {
128  switch(board_revision) {
129  case 2:
130  return &pios_annunc_cfg;
131  break;
132  case 3:
133  return &pios_annunc_v2_cfg;
134  break;
135  default:
137  }
138  return NULL;
139 }
140 
141 #endif /* PIOS_INCLUDE_ANNUNC */
142 
143 #if defined(PIOS_INCLUDE_SPI)
144 #include <pios_spi_priv.h>
145 
146 /*
147  * SPI1 Interface
148  * Used for MPU6000 gyro and accelerometer
149  */
150 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
151  .regs = SPI1,
152  .remap = GPIO_AF_SPI1,
153  .init = {
154  .SPI_Mode = SPI_Mode_Master,
155  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
156  .SPI_DataSize = SPI_DataSize_8b,
157  .SPI_NSS = SPI_NSS_Soft,
158  .SPI_FirstBit = SPI_FirstBit_MSB,
159  .SPI_CRCPolynomial = 7,
160  .SPI_CPOL = SPI_CPOL_High,
161  .SPI_CPHA = SPI_CPHA_2Edge,
162  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16,
163  },
164  .sclk = {
165  .gpio = GPIOA,
166  .init = {
167  .GPIO_Pin = GPIO_Pin_5,
168  .GPIO_Speed = GPIO_Speed_100MHz,
169  .GPIO_Mode = GPIO_Mode_AF,
170  .GPIO_OType = GPIO_OType_PP,
171  .GPIO_PuPd = GPIO_PuPd_UP
172  },
173  },
174  .miso = {
175  .gpio = GPIOA,
176  .init = {
177  .GPIO_Pin = GPIO_Pin_6,
178  .GPIO_Speed = GPIO_Speed_50MHz,
179  .GPIO_Mode = GPIO_Mode_AF,
180  .GPIO_OType = GPIO_OType_PP,
181  .GPIO_PuPd = GPIO_PuPd_UP
182  },
183  },
184  .mosi = {
185  .gpio = GPIOA,
186  .init = {
187  .GPIO_Pin = GPIO_Pin_7,
188  .GPIO_Speed = GPIO_Speed_50MHz,
189  .GPIO_Mode = GPIO_Mode_AF,
190  .GPIO_OType = GPIO_OType_PP,
191  .GPIO_PuPd = GPIO_PuPd_UP
192  },
193  },
194  .slave_count = 1,
195  .ssel = { {
196  .gpio = GPIOA,
197  .init = {
198  .GPIO_Pin = GPIO_Pin_4,
199  .GPIO_Speed = GPIO_Speed_50MHz,
200  .GPIO_Mode = GPIO_Mode_OUT,
201  .GPIO_OType = GPIO_OType_PP,
202  .GPIO_PuPd = GPIO_PuPd_UP
203  } }
204  }
205 };
206 
207 /*
208  * SPI3 Interface
209  * Used for Flash and the RFM22B
210  */
211 static const struct pios_spi_cfg pios_spi_telem_flash_cfg = {
212  .regs = SPI3,
213  .remap = GPIO_AF_SPI3,
214  .init = {
215  .SPI_Mode = SPI_Mode_Master,
216  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
217  .SPI_DataSize = SPI_DataSize_8b,
218  .SPI_NSS = SPI_NSS_Soft,
219  .SPI_FirstBit = SPI_FirstBit_MSB,
220  .SPI_CRCPolynomial = 7,
221  .SPI_CPOL = SPI_CPOL_Low,
222  .SPI_CPHA = SPI_CPHA_1Edge,
223  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
224  },
225  .sclk = {
226  .gpio = GPIOC,
227  .init = {
228  .GPIO_Pin = GPIO_Pin_10,
229  .GPIO_Speed = GPIO_Speed_100MHz,
230  .GPIO_Mode = GPIO_Mode_AF,
231  .GPIO_OType = GPIO_OType_PP,
232  .GPIO_PuPd = GPIO_PuPd_NOPULL
233  },
234  },
235  .miso = {
236  .gpio = GPIOC,
237  .init = {
238  .GPIO_Pin = GPIO_Pin_11,
239  .GPIO_Speed = GPIO_Speed_50MHz,
240  .GPIO_Mode = GPIO_Mode_AF,
241  .GPIO_OType = GPIO_OType_PP,
242  .GPIO_PuPd = GPIO_PuPd_NOPULL
243  },
244  },
245  .mosi = {
246  .gpio = GPIOC,
247  .init = {
248  .GPIO_Pin = GPIO_Pin_12,
249  .GPIO_Speed = GPIO_Speed_50MHz,
250  .GPIO_Mode = GPIO_Mode_AF,
251  .GPIO_OType = GPIO_OType_PP,
252  .GPIO_PuPd = GPIO_PuPd_NOPULL
253  },
254  },
255  .slave_count = 2,
256  .ssel = {
257  { // RFM22b
258  .gpio = GPIOA,
259  .init = {
260  .GPIO_Pin = GPIO_Pin_15,
261  .GPIO_Speed = GPIO_Speed_50MHz,
262  .GPIO_Mode = GPIO_Mode_OUT,
263  .GPIO_OType = GPIO_OType_PP,
264  .GPIO_PuPd = GPIO_PuPd_UP
265  } },
266  { // Flash
267  .gpio = GPIOB,
268  .init = {
269  .GPIO_Pin = GPIO_Pin_3,
270  .GPIO_Speed = GPIO_Speed_50MHz,
271  .GPIO_Mode = GPIO_Mode_OUT,
272  .GPIO_OType = GPIO_OType_PP,
273  .GPIO_PuPd = GPIO_PuPd_UP
274  } },
275  },
276 };
277 
278 #ifdef PIOS_INCLUDE_BMP280_SPI
279 #include "pios_bmp280_priv.h"
280 
281 static const struct pios_bmp280_cfg pios_bmp280_cfg = {
283 };
284 #endif
285 
286 pios_spi_t pios_spi_telem_flash_id;
287 
288 #if defined(PIOS_INCLUDE_OPENLRS)
289 
290 #include <pios_openlrs_priv.h>
291 
292 pios_openlrs_t openlrs_handle;
293 
294 static bool openlrs_int(void) {
295  return PIOS_OpenLRS_EXT_Int(openlrs_handle);
296 }
297 
298 static const struct pios_exti_cfg pios_exti_openlrs_cfg __exti_config = {
299  .vector = openlrs_int,
300  .line = EXTI_Line2,
301  .pin = {
302  .gpio = GPIOD,
303  .init = {
304  .GPIO_Pin = GPIO_Pin_2,
305  .GPIO_Speed = GPIO_Speed_100MHz,
306  .GPIO_Mode = GPIO_Mode_IN,
307  .GPIO_OType = GPIO_OType_OD,
308  .GPIO_PuPd = GPIO_PuPd_NOPULL,
309  },
310  },
311  .irq = {
312  .init = {
313  .NVIC_IRQChannel = EXTI2_IRQn,
314  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
315  .NVIC_IRQChannelSubPriority = 0,
316  .NVIC_IRQChannelCmd = ENABLE,
317  },
318  },
319  .exti = {
320  .init = {
321  .EXTI_Line = EXTI_Line2, // matches above GPIO pin
322  .EXTI_Mode = EXTI_Mode_Interrupt,
323  .EXTI_Trigger = EXTI_Trigger_Falling,
324  .EXTI_LineCmd = ENABLE,
325  },
326  },
327 };
328 
329 const struct pios_openlrs_cfg pios_openlrs_rm1_cfg = {
330  .spi_cfg = &pios_spi_telem_flash_cfg,
331  .exti_cfg = &pios_exti_openlrs_cfg,
332  .gpio_direction = GPIO0_RX_GPIO1_TX,
333 };
334 
335 const struct pios_openlrs_cfg pios_openlrs_rm2_cfg = {
336  .spi_cfg = &pios_spi_telem_flash_cfg,
337  .exti_cfg = &pios_exti_openlrs_cfg,
338  .gpio_direction = GPIO0_TX_GPIO1_RX,
339 };
340 
341 const struct pios_openlrs_cfg * PIOS_BOARD_HW_DEFS_GetOpenLRSCfg (uint32_t board_revision)
342 {
343  switch(board_revision) {
344  case 2:
345  return &pios_openlrs_rm1_cfg;
346  break;
347  case 3:
348  return &pios_openlrs_rm2_cfg;
349  break;
350  default:
352  }
353  return NULL;
354 }
355 
356 #endif /* PIOS_INCLUDE_OPENLRS */
357 
358 #endif /* PIOS_INCLUDE_SPI */
359 
360 #if defined(PIOS_INCLUDE_FLASH)
361 #include "pios_flashfs_logfs_priv.h"
362 
363 static const struct flashfs_logfs_cfg flashfs_settings_cfg = {
364  .fs_magic = 0x99abcedf,
365  /* This was increased from 0x10000 in order to accomodate the
366  * 0x20000 settings sector size on F4 internal flash. It's a win
367  * for external flash, though, as it allows more settings to be
368  * stored. The upgrader will fix this automatically.
369  */
370  .arena_size = 0x00020000, /* 256 * slot size */
371  .slot_size = 0x00000100, /* 256 bytes */
372 };
373 
374 #if defined(PIOS_INCLUDE_FLASH_JEDEC)
375 #include "pios_flash_jedec_priv.h"
376 
377 static const struct pios_flash_jedec_cfg flash_chip_cfgs[] = {
378  {
379  /* M25P 2MByte chip used in original revo design */
381  .expect_memorytype = 0x20,
382  .expect_capacity = 0x15,
383  .sector_erase = 0xD8,
384  },
385  {
386  /* Larger NOR flash has been shipping on some clone Revolution boards
387  * without full sensor suite. Tolerate any 128mbit NOR flash, and assume
388  * it has 64k blocks with an erase command of 0xD8.
389  */
390  .expect_manufacturer = JEDEC_MANUFACTURER_ANY,
391  .expect_memorytype = JEDEC_MEMORYTYPE_ANY,
392  .expect_capacity = 0x18,
393  .sector_erase = 0xD8,
394  },
395  {
396  /* And some with 8MByte chips too */
397  .expect_manufacturer = JEDEC_MANUFACTURER_ANY,
398  .expect_memorytype = JEDEC_MEMORYTYPE_ANY,
399  .expect_capacity = 0x17,
400  .sector_erase = 0xD8,
401  },
402 };
403 #endif /* PIOS_INCLUDE_FLASH_JEDEC */
404 
405 #if defined(PIOS_INCLUDE_FLASH_INTERNAL)
407 
408 static const struct pios_flash_internal_cfg flash_internal_cfg = {
409 };
410 #endif /* PIOS_INCLUDE_FLASH_INTERNAL */
411 
412 #include "pios_flash_priv.h"
413 
414 #if defined(PIOS_INCLUDE_FLASH_INTERNAL)
415 static const struct pios_flash_sector_range stm32f4_sectors[] = {
416  {
417  .base_sector = 0,
418  .last_sector = 3,
419  .sector_size = FLASH_SECTOR_16KB,
420  },
421  {
422  .base_sector = 4,
423  .last_sector = 4,
424  .sector_size = FLASH_SECTOR_64KB,
425  },
426  {
427  .base_sector = 5,
428  .last_sector = 11,
429  .sector_size = FLASH_SECTOR_128KB,
430  },
431 
432 };
433 
434 uintptr_t pios_internal_flash_id;
435 static const struct pios_flash_chip pios_flash_chip_internal = {
437  .chip_id = &pios_internal_flash_id,
438  .page_size = 16, /* 128-bit rows */
439  .sector_blocks = stm32f4_sectors,
440  .num_blocks = NELEMENTS(stm32f4_sectors),
441 };
442 #endif /* PIOS_INCLUDE_FLASH_INTERNAL */
443 
444 #if defined(PIOS_INCLUDE_FLASH_JEDEC)
445 static struct pios_flash_sector_range m25p16_sectors[] = {
446  {
447  .base_sector = 0,
448  .last_sector = 31,
449  .sector_size = FLASH_SECTOR_64KB,
450  },
451 };
452 
453 uintptr_t pios_external_flash_id;
454 static const struct pios_flash_chip pios_flash_chip_external = {
456  .chip_id = &pios_external_flash_id,
457  .page_size = 256,
458  .sector_blocks = m25p16_sectors,
459  .num_blocks = NELEMENTS(m25p16_sectors),
460 };
461 #endif /* PIOS_INCLUDE_FLASH_JEDEC */
462 
463 static const struct pios_flash_partition pios_flash_partition_table_nojedec[] = {
464 #if defined(PIOS_INCLUDE_FLASH_INTERNAL)
465  {
467  .chip_desc = &pios_flash_chip_internal,
468  .first_sector = 0,
469  .last_sector = 1,
470  .chip_offset = 0,
471  .size = (1 - 0 + 1) * FLASH_SECTOR_16KB,
472  },
473  {
475  .chip_desc = &pios_flash_chip_internal,
476  .first_sector = 2,
477  .last_sector = 3,
478  .chip_offset = (2 * FLASH_SECTOR_16KB),
479  .size = (3 - 2 + 1) * FLASH_SECTOR_16KB,
480  },
481  /* NOTE: sectors 4 of the internal flash is unallocated */
482  {
483  .label = FLASH_PARTITION_LABEL_FW,
484  .chip_desc = &pios_flash_chip_internal,
485  .first_sector = 5,
486  .last_sector = 7,
487  .chip_offset = (4 * FLASH_SECTOR_16KB) + (1 * FLASH_SECTOR_64KB),
488  .size = (7 - 5 + 1) * FLASH_SECTOR_128KB,
489  },
490  {
492  .chip_desc = &pios_flash_chip_internal,
493  .first_sector = 8,
494  .last_sector = 9,
495  .chip_offset = (4 * FLASH_SECTOR_16KB) + (1 * FLASH_SECTOR_64KB) + (3 * FLASH_SECTOR_128KB),
496  .size = (9 - 8 + 1) * FLASH_SECTOR_128KB,
497  },
498  {
500  .chip_desc = &pios_flash_chip_internal,
501  .first_sector = 10,
502  .last_sector = 10,
503  .chip_offset = (4 * FLASH_SECTOR_16KB) + (1 * FLASH_SECTOR_64KB) + (5 * FLASH_SECTOR_128KB),
504  .size = (10 - 10 + 1) * FLASH_SECTOR_128KB,
505  },
506  /* NOTE: sector 11 of the internal flash are currently unallocated */
507 #endif /* PIOS_INCLUDE_FLASH_INTERNAL */
508 };
509 
510 #if defined(PIOS_INCLUDE_FLASH_JEDEC)
512 #if defined(PIOS_INCLUDE_FLASH_INTERNAL)
513  {
515  .chip_desc = &pios_flash_chip_internal,
516  .first_sector = 0,
517  .last_sector = 1,
518  .chip_offset = 0,
519  .size = (1 - 0 + 1) * FLASH_SECTOR_16KB,
520  },
521 
522  /* NOTE: sectors 2-4 of the internal flash are currently unallocated */
523 
524  {
525  .label = FLASH_PARTITION_LABEL_FW,
526  .chip_desc = &pios_flash_chip_internal,
527  .first_sector = 5,
528  .last_sector = 7,
529  .chip_offset = (4 * FLASH_SECTOR_16KB) + (1 * FLASH_SECTOR_64KB),
530  .size = (7 - 5 + 1) * FLASH_SECTOR_128KB,
531  },
532 
533  {
535  .chip_desc = &pios_flash_chip_internal,
536  .first_sector = 10,
537  .last_sector = 10,
538  .chip_offset = (4 * FLASH_SECTOR_16KB) + (1 * FLASH_SECTOR_64KB) + (5 * FLASH_SECTOR_128KB),
539  .size = (10 - 10 + 1) * FLASH_SECTOR_128KB,
540  },
541 
542  /* NOTE: sectors 8-9, 11 of the internal flash are currently unallocated */
543 
544 #endif /* PIOS_INCLUDE_FLASH_INTERNAL */
545 
546  {
548  .chip_desc = &pios_flash_chip_external,
549  .first_sector = 0,
550  .last_sector = 5,
551  .chip_offset = 0,
552  .size = (5 - 0 + 1) * FLASH_SECTOR_64KB,
553  },
554 
555  {
557  .chip_desc = &pios_flash_chip_external,
558  .first_sector = 6,
559  .last_sector = 10,
560  .chip_offset = (6 * FLASH_SECTOR_64KB),
561  .size = (10 - 6 + 1) * FLASH_SECTOR_64KB,
562  },
563 
564  {
565  .label = FLASH_PARTITION_LABEL_LOG,
566  .chip_desc = &pios_flash_chip_external,
567  .first_sector = 16,
568  .last_sector = 31,
569  .chip_offset = (16 * FLASH_SECTOR_64KB),
570  .size = (31 - 16 + 1) * FLASH_SECTOR_64KB,
571  },
572 };
573 #endif /* PIOS_INCLUDE_FLASH_JEDEC */
574 
575 const struct pios_flash_partition * PIOS_BOARD_HW_DEFS_GetPartitionTable (uint32_t board_revision, uint32_t * num_partitions)
576 {
577  PIOS_Assert(num_partitions);
578 
579 #ifdef PIOS_INCLUDE_FLASH_JEDEC
580  if (pios_external_flash_id) {
581  *num_partitions = NELEMENTS(pios_flash_partition_table);
582 
583  uint32_t capacity = PIOS_Flash_Jedec_GetCapacity(pios_external_flash_id);
584 
585  PIOS_FLASH_fixup_partitions_for_capacity(pios_flash_partition_table,
586  NELEMENTS(pios_flash_partition_table),
587  &pios_flash_chip_external,
588  m25p16_sectors,
589  capacity);
590 
592  }
593 #endif
594 
595  *num_partitions = NELEMENTS(pios_flash_partition_table_nojedec);
596  /* Fall back to the no-SPI-FLASH partition table */
597  return pios_flash_partition_table_nojedec;
598 }
599 #endif /* PIOS_INCLUDE_FLASH */
600 
601 #ifdef PIOS_INCLUDE_USART
602 
603 #include <pios_usart_priv.h>
604 /*
605  * MAIN USART
606  */
607 static const struct pios_usart_cfg pios_usart_main_cfg = {
608  .regs = USART1,
609  .remap = GPIO_AF_USART1,
610  .irq = {
611  .init = {
612  .NVIC_IRQChannel = USART1_IRQn,
613  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
614  .NVIC_IRQChannelSubPriority = 0,
615  .NVIC_IRQChannelCmd = ENABLE,
616  },
617  },
618  .rx = {
619  .gpio = GPIOA,
620  .init = {
621  .GPIO_Pin = GPIO_Pin_10,
622  .GPIO_Speed = GPIO_Speed_2MHz,
623  .GPIO_Mode = GPIO_Mode_AF,
624  .GPIO_OType = GPIO_OType_PP,
625  .GPIO_PuPd = GPIO_PuPd_UP
626  },
627  .pin_source = GPIO_PinSource10,
628  },
629  .tx = {
630  .gpio = GPIOA,
631  .init = {
632  .GPIO_Pin = GPIO_Pin_9,
633  .GPIO_Speed = GPIO_Speed_2MHz,
634  .GPIO_Mode = GPIO_Mode_AF,
635  .GPIO_OType = GPIO_OType_PP,
636  .GPIO_PuPd = GPIO_PuPd_UP
637  },
638  .pin_source = GPIO_PinSource9,
639  },
640 };
641 
642 #include <pios_sbus_priv.h>
643 
644 // Need this defined regardless to be able to hardware sbus inverter off
645 static const struct pios_sbus_cfg pios_sbus_cfg = {
646  /* Inverter configuration */
647  .inv = {
648  .gpio = GPIOC,
649  .init = {
650  .GPIO_Pin = GPIO_Pin_0,
651  .GPIO_Speed = GPIO_Speed_2MHz,
652  .GPIO_Mode = GPIO_Mode_OUT,
653  .GPIO_OType = GPIO_OType_PP,
654  .GPIO_PuPd = GPIO_PuPd_UP
655  },
656  },
657  .gpio_inv_enable = Bit_SET,
658  .gpio_inv_disable = Bit_RESET,
659  .gpio_clk_func = RCC_AHB1PeriphClockCmd,
660  .gpio_clk_periph = RCC_AHB1Periph_GPIOC,
661 };
662 
663 /*
664  * FLEXI PORT
665  */
666 static const struct pios_usart_cfg pios_usart_flexi_cfg = {
667  .regs = USART3,
668  .remap = GPIO_AF_USART3,
669  .irq = {
670  .init = {
671  .NVIC_IRQChannel = USART3_IRQn,
672  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
673  .NVIC_IRQChannelSubPriority = 0,
674  .NVIC_IRQChannelCmd = ENABLE,
675  },
676  },
677  .rx = {
678  .gpio = GPIOB,
679  .init = {
680  .GPIO_Pin = GPIO_Pin_11,
681  .GPIO_Speed = GPIO_Speed_2MHz,
682  .GPIO_Mode = GPIO_Mode_AF,
683  .GPIO_OType = GPIO_OType_PP,
684  .GPIO_PuPd = GPIO_PuPd_UP
685  },
686  .pin_source = GPIO_PinSource11,
687  },
688  .tx = {
689  .gpio = GPIOB,
690  .init = {
691  .GPIO_Pin = GPIO_Pin_10,
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_PinSource10,
698  },
699 };
700 
701 /*
702  * FLEXI-IO PORT
703  */
704 static const struct pios_usart_cfg pios_rxportusart_cfg = {
705  .regs = USART6,
706  .remap = GPIO_AF_USART6,
707  .irq = {
708  .init = {
709  .NVIC_IRQChannel = USART6_IRQn,
710  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
711  .NVIC_IRQChannelSubPriority = 0,
712  .NVIC_IRQChannelCmd = ENABLE,
713  },
714  },
715  .rx = {
716  .gpio = GPIOC,
717  .init = {
718  .GPIO_Pin = GPIO_Pin_7,
719  .GPIO_Speed = GPIO_Speed_2MHz,
720  .GPIO_Mode = GPIO_Mode_AF,
721  .GPIO_OType = GPIO_OType_PP,
722  .GPIO_PuPd = GPIO_PuPd_UP
723  },
724  .pin_source = GPIO_PinSource7,
725  },
726  .tx = {
727  .gpio = GPIOC,
728  .init = {
729  .GPIO_Pin = GPIO_Pin_6,
730  .GPIO_Speed = GPIO_Speed_2MHz,
731  .GPIO_Mode = GPIO_Mode_AF,
732  .GPIO_OType = GPIO_OType_PP,
733  .GPIO_PuPd = GPIO_PuPd_UP
734  },
735  .pin_source = GPIO_PinSource6,
736  },
737 };
738 
739 #if defined(PIOS_INCLUDE_DSM)
740 
741 /*
742  * Spektrum/JR DSM USART
743  */
744 #include <pios_dsm_priv.h>
745 
746 // Because of the inverter on the main port this will not
747 // work. Notice the mode is set to IN to maintain API
748 // compatibility but protect the pins
749 static const struct pios_dsm_cfg pios_dsm_main_cfg = {
750  .bind = {
751  .gpio = GPIOA,
752  .init = {
753  .GPIO_Pin = GPIO_Pin_10,
754  .GPIO_Speed = GPIO_Speed_2MHz,
755  .GPIO_Mode = GPIO_Mode_IN,
756  .GPIO_OType = GPIO_OType_PP,
757  .GPIO_PuPd = GPIO_PuPd_NOPULL
758  },
759  },
760 };
761 
762 static const struct pios_dsm_cfg pios_dsm_flexi_cfg = {
763  .bind = {
764  .gpio = GPIOB,
765  .init = {
766  .GPIO_Pin = GPIO_Pin_11,
767  .GPIO_Speed = GPIO_Speed_2MHz,
768  .GPIO_Mode = GPIO_Mode_OUT,
769  .GPIO_OType = GPIO_OType_PP,
770  .GPIO_PuPd = GPIO_PuPd_NOPULL
771  },
772  },
773 };
774 
775 static const struct pios_dsm_cfg pios_rxportusart_dsm_aux_cfg = {
776  .bind = {
777  .gpio = GPIOC,
778  .init = {
779  .GPIO_Pin = GPIO_Pin_7,
780  .GPIO_Speed = GPIO_Speed_2MHz,
781  .GPIO_Mode = GPIO_Mode_OUT,
782  .GPIO_OType = GPIO_OType_PP,
783  .GPIO_PuPd = GPIO_PuPd_NOPULL
784  },
785  },
786 };
787 
788 #endif /* PIOS_INCLUDE_DSM */
789 
790 #endif /* PIOS_INCLUDE_USART */
791 
792 
793 
794 #if defined(PIOS_INCLUDE_COM)
795 
796 #include <pios_com_priv.h>
797 
798 #endif /* PIOS_INCLUDE_COM */
799 
800 #if defined(PIOS_INCLUDE_I2C)
801 
802 #include <pios_i2c_priv.h>
803 
804 /*
805  * I2C Adapters
806  */
807 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void);
808 void PIOS_I2C_mag_pressureadapter_er_irq_handler(void);
809 void I2C1_EV_IRQHandler()
810  __attribute__ ((alias("PIOS_I2C_mag_pressure_adapter_ev_irq_handler")));
811 void I2C1_ER_IRQHandler()
812  __attribute__ ((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler")));
813 
814 static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg = {
815  .regs = I2C1,
816  .remap = GPIO_AF_I2C1,
817  .init = {
818  .I2C_Mode = I2C_Mode_I2C,
819  .I2C_OwnAddress1 = 0,
820  .I2C_Ack = I2C_Ack_Enable,
821  .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
822  .I2C_DutyCycle = I2C_DutyCycle_2,
823  .I2C_ClockSpeed = 400000, /* bits/s */
824  },
825  .transfer_timeout_ms = 50,
826  .scl = {
827  .gpio = GPIOB,
828  .init = {
829  .GPIO_Pin = GPIO_Pin_8,
830  .GPIO_Mode = GPIO_Mode_AF,
831  .GPIO_Speed = GPIO_Speed_50MHz,
832  .GPIO_OType = GPIO_OType_OD,
833  .GPIO_PuPd = GPIO_PuPd_UP,
834  },
835  },
836  .sda = {
837  .gpio = GPIOB,
838  .init = {
839  .GPIO_Pin = GPIO_Pin_9,
840  .GPIO_Mode = GPIO_Mode_AF,
841  .GPIO_Speed = GPIO_Speed_50MHz,
842  .GPIO_OType = GPIO_OType_OD,
843  .GPIO_PuPd = GPIO_PuPd_UP,
844  },
845  },
846  .event = {
847  .flags = 0, /* FIXME: check this */
848  .init = {
849  .NVIC_IRQChannel = I2C1_EV_IRQn,
850  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
851  .NVIC_IRQChannelSubPriority = 0,
852  .NVIC_IRQChannelCmd = ENABLE,
853  },
854  },
855  .error = {
856  .flags = 0, /* FIXME: check this */
857  .init = {
858  .NVIC_IRQChannel = I2C1_ER_IRQn,
859  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
860  .NVIC_IRQChannelSubPriority = 0,
861  .NVIC_IRQChannelCmd = ENABLE,
862  },
863  },
864 };
865 
866 pios_i2c_t pios_i2c_mag_pressure_adapter_id;
867 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void)
868 {
869  /* Call into the generic code to handle the IRQ for this specific device */
870  PIOS_I2C_EV_IRQ_Handler(pios_i2c_mag_pressure_adapter_id);
871 }
872 
873 void PIOS_I2C_mag_pressure_adapter_er_irq_handler(void)
874 {
875  /* Call into the generic code to handle the IRQ for this specific device */
876  PIOS_I2C_ER_IRQ_Handler(pios_i2c_mag_pressure_adapter_id);
877 }
878 
879 
880 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void);
881 void PIOS_I2C_flexiport_adapter_er_irq_handler(void);
882 void I2C2_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_flexiport_adapter_ev_irq_handler")));
883 void I2C2_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_flexiport_adapter_er_irq_handler")));
884 
885 static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = {
886  .regs = I2C2,
887  .remap = GPIO_AF_I2C2,
888  .init = {
889  .I2C_Mode = I2C_Mode_I2C,
890  .I2C_OwnAddress1 = 0,
891  .I2C_Ack = I2C_Ack_Enable,
892  .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
893  .I2C_DutyCycle = I2C_DutyCycle_2,
894  .I2C_ClockSpeed = 400000, /* bits/s */
895  },
896  .transfer_timeout_ms = 50,
897  .scl = {
898  .gpio = GPIOB,
899  .init = {
900  .GPIO_Pin = GPIO_Pin_10,
901  .GPIO_Mode = GPIO_Mode_AF,
902  .GPIO_Speed = GPIO_Speed_50MHz,
903  .GPIO_OType = GPIO_OType_OD,
904  .GPIO_PuPd = GPIO_PuPd_UP,
905  },
906  },
907  .sda = {
908  .gpio = GPIOB,
909  .init = {
910  .GPIO_Pin = GPIO_Pin_11,
911  .GPIO_Mode = GPIO_Mode_AF,
912  .GPIO_Speed = GPIO_Speed_50MHz,
913  .GPIO_OType = GPIO_OType_OD,
914  .GPIO_PuPd = GPIO_PuPd_UP,
915  },
916  },
917  .event = {
918  .flags = 0, /* FIXME: check this */
919  .init = {
920  .NVIC_IRQChannel = I2C2_EV_IRQn,
921  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
922  .NVIC_IRQChannelSubPriority = 0,
923  .NVIC_IRQChannelCmd = ENABLE,
924  },
925  },
926  .error = {
927  .flags = 0, /* FIXME: check this */
928  .init = {
929  .NVIC_IRQChannel = I2C2_ER_IRQn,
930  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
931  .NVIC_IRQChannelSubPriority = 0,
932  .NVIC_IRQChannelCmd = ENABLE,
933  },
934  },
935 };
936 
937 pios_i2c_t pios_i2c_flexiport_adapter_id;
938 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void)
939 {
940  /* Call into the generic code to handle the IRQ for this specific device */
941  PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexiport_adapter_id);
942 }
943 
944 void PIOS_I2C_flexiport_adapter_er_irq_handler(void)
945 {
946  /* Call into the generic code to handle the IRQ for this specific device */
947  PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexiport_adapter_id);
948 }
949 
950 
951 void PIOS_I2C_pressure_adapter_ev_irq_handler(void);
952 void PIOS_I2C_pressure_adapter_er_irq_handler(void);
953 
954 #endif /* PIOS_INCLUDE_I2C */
955 
956 #if defined(PIOS_INCLUDE_RTC)
957 /*
958  * Realtime Clock (RTC)
959  */
960 #include <pios_rtc_priv.h>
961 
962 void PIOS_RTC_IRQ_Handler (void);
963 void RTC_WKUP_IRQHandler() __attribute__ ((alias ("PIOS_RTC_IRQ_Handler")));
964 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
965  .clksrc = RCC_RTCCLKSource_HSE_Div8, // Divide 8 Mhz crystal down to 1
966  .prescaler = 100, // Every 100 cycles gives 625 Hz
967  .irq = {
968  .init = {
969  .NVIC_IRQChannel = RTC_WKUP_IRQn,
970  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
971  .NVIC_IRQChannelSubPriority = 0,
972  .NVIC_IRQChannelCmd = ENABLE,
973  },
974  },
975 };
976 
977 void PIOS_RTC_IRQ_Handler (void)
978 {
980 }
981 
982 #endif
983 
984 #include "pios_tim_priv.h"
985 
986 static const TIM_TimeBaseInitTypeDef tim_3_5_time_base = {
987  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_COUNTER_CLOCK / 1000000) - 1,
988  .TIM_ClockDivision = TIM_CKD_DIV1,
989  .TIM_CounterMode = TIM_CounterMode_Up,
990  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
991  .TIM_RepetitionCounter = 0x0000,
992 };
993 static const TIM_TimeBaseInitTypeDef tim_9_10_11_time_base = {
994  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 1000000) - 1,
995  .TIM_ClockDivision = TIM_CKD_DIV1,
996  .TIM_CounterMode = TIM_CounterMode_Up,
997  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
998  .TIM_RepetitionCounter = 0x0000,
999 };
1000 
1001 static const struct pios_tim_clock_cfg tim_3_cfg = {
1002  .timer = TIM3,
1003  .time_base_init = &tim_3_5_time_base,
1004  .irq = {
1005  .init = {
1006  .NVIC_IRQChannel = TIM3_IRQn,
1007  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1008  .NVIC_IRQChannelSubPriority = 0,
1009  .NVIC_IRQChannelCmd = ENABLE,
1010  },
1011  },
1012 };
1013 
1014 static const struct pios_tim_clock_cfg tim_5_cfg = {
1015  .timer = TIM5,
1016  .time_base_init = &tim_3_5_time_base,
1017  .irq = {
1018  .init = {
1019  .NVIC_IRQChannel = TIM5_IRQn,
1020  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1021  .NVIC_IRQChannelSubPriority = 0,
1022  .NVIC_IRQChannelCmd = ENABLE,
1023  },
1024  },
1025 };
1026 
1027 static const struct pios_tim_clock_cfg tim_9_cfg = {
1028  .timer = TIM9,
1029  .time_base_init = &tim_9_10_11_time_base,
1030  .irq = {
1031  .init = {
1032  .NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn,
1033  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1034  .NVIC_IRQChannelSubPriority = 0,
1035  .NVIC_IRQChannelCmd = ENABLE,
1036  },
1037  },
1038 };
1039 
1040 static const struct pios_tim_clock_cfg tim_10_cfg = {
1041  .timer = TIM10,
1042  .time_base_init = &tim_9_10_11_time_base,
1043  .irq = {
1044  .init = {
1045  .NVIC_IRQChannel = TIM1_UP_TIM10_IRQn,
1046  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1047  .NVIC_IRQChannelSubPriority = 0,
1048  .NVIC_IRQChannelCmd = ENABLE,
1049  },
1050  },
1051 };
1052 
1053 static const struct pios_tim_clock_cfg tim_11_cfg = {
1054  .timer = TIM11,
1055  .time_base_init = &tim_9_10_11_time_base,
1056  .irq = {
1057  .init = {
1058  .NVIC_IRQChannel = TIM1_TRG_COM_TIM11_IRQn,
1059  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1060  .NVIC_IRQChannelSubPriority = 0,
1061  .NVIC_IRQChannelCmd = ENABLE,
1062  },
1063  },
1064 };
1065 
1066 // Set up timers that only have inputs on APB1
1067 // TIM2,3,4,5,6,7,12,13,14
1068 static const TIM_TimeBaseInitTypeDef tim_apb1_time_base = {
1069  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_COUNTER_CLOCK / 1000000) - 1,
1070  .TIM_ClockDivision = TIM_CKD_DIV1,
1071  .TIM_CounterMode = TIM_CounterMode_Up,
1072  .TIM_Period = 0xFFFF,
1073  .TIM_RepetitionCounter = 0x0000,
1074 };
1075 
1076 
1077 // Set up timers that only have inputs on APB2
1078 // TIM1,8,9,10,11
1079 static const TIM_TimeBaseInitTypeDef tim_apb2_time_base = {
1080  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 1000000) - 1,
1081  .TIM_ClockDivision = TIM_CKD_DIV1,
1082  .TIM_CounterMode = TIM_CounterMode_Up,
1083  .TIM_Period = 0xFFFF,
1084  .TIM_RepetitionCounter = 0x0000,
1085 };
1086 
1087 static const struct pios_tim_clock_cfg tim_1_cfg = {
1088  .timer = TIM1,
1089  .time_base_init = &tim_apb2_time_base,
1090  .irq = {
1091  .init = {
1092  .NVIC_IRQChannel = TIM1_CC_IRQn,
1093  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1094  .NVIC_IRQChannelSubPriority = 0,
1095  .NVIC_IRQChannelCmd = ENABLE,
1096  },
1097  },
1098 };
1099 
1100 static const struct pios_tim_clock_cfg tim_4_cfg = {
1101  .timer = TIM4,
1102  .time_base_init = &tim_apb1_time_base,
1103  .irq = {
1104  .init = {
1105  .NVIC_IRQChannel = TIM4_IRQn,
1106  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1107  .NVIC_IRQChannelSubPriority = 0,
1108  .NVIC_IRQChannelCmd = ENABLE,
1109  },
1110  },
1111 };
1112 static const struct pios_tim_clock_cfg tim_8_cfg = {
1113  .timer = TIM8,
1114  .time_base_init = &tim_apb2_time_base,
1115  .irq = {
1116  .init = {
1117  .NVIC_IRQChannel = TIM8_CC_IRQn,
1118  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1119  .NVIC_IRQChannelSubPriority = 0,
1120  .NVIC_IRQChannelCmd = ENABLE,
1121  },
1122  },
1123 };
1124 
1125 static const struct pios_tim_clock_cfg tim_12_cfg = {
1126  .timer = TIM12,
1127  .time_base_init = &tim_apb1_time_base,
1128  .irq = {
1129  .init = {
1130  .NVIC_IRQChannel = TIM8_BRK_TIM12_IRQn,
1131  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1132  .NVIC_IRQChannelSubPriority = 0,
1133  .NVIC_IRQChannelCmd = ENABLE,
1134  },
1135  },
1136 };
1137 
1138 
1139 /*
1140  * Pios servo configuration structures
1141  * Outputs
1142  * 1: TIM3_CH3 (PB0)
1143  * 2: TIM3_CH4 (PB1)
1144  * 3: TIM9_CH2 (PA3)
1145  * 4: TIM2_CH3 (PA2)
1146  * 5: TIM5_CH2 (PA1)
1147  * 6: TIM5_CH1 (PA0)
1148  */
1149 
1150 #include <pios_servo_priv.h>
1151 
1153  {
1154  .timer = TIM3,
1155  .timer_chan = TIM_Channel_3,
1156  .pin = {
1157  .gpio = GPIOB,
1158  .init = {
1159  .GPIO_Pin = GPIO_Pin_0,
1160  .GPIO_Speed = GPIO_Speed_2MHz,
1161  .GPIO_Mode = GPIO_Mode_AF,
1162  .GPIO_OType = GPIO_OType_PP,
1163  .GPIO_PuPd = GPIO_PuPd_UP
1164  },
1165  .pin_source = GPIO_PinSource0,
1166  },
1167  .remap = GPIO_AF_TIM3,
1168  },
1169  {
1170  .timer = TIM3,
1171  .timer_chan = TIM_Channel_4,
1172  .pin = {
1173  .gpio = GPIOB,
1174  .init = {
1175  .GPIO_Pin = GPIO_Pin_1,
1176  .GPIO_Speed = GPIO_Speed_2MHz,
1177  .GPIO_Mode = GPIO_Mode_AF,
1178  .GPIO_OType = GPIO_OType_PP,
1179  .GPIO_PuPd = GPIO_PuPd_UP
1180  },
1181  .pin_source = GPIO_PinSource1,
1182  },
1183  .remap = GPIO_AF_TIM3,
1184  },
1185  {
1186  .timer = TIM9,
1187  .timer_chan = TIM_Channel_2,
1188  .pin = {
1189  .gpio = GPIOA,
1190  .init = {
1191  .GPIO_Pin = GPIO_Pin_3,
1192  .GPIO_Speed = GPIO_Speed_2MHz,
1193  .GPIO_Mode = GPIO_Mode_AF,
1194  .GPIO_OType = GPIO_OType_PP,
1195  .GPIO_PuPd = GPIO_PuPd_UP
1196  },
1197  .pin_source = GPIO_PinSource3,
1198  },
1199  .remap = GPIO_AF_TIM9,
1200  },
1201  {
1202  .timer = TIM2,
1203  .timer_chan = TIM_Channel_3,
1204  .pin = {
1205  .gpio = GPIOA,
1206  .init = {
1207  .GPIO_Pin = GPIO_Pin_2,
1208  .GPIO_Speed = GPIO_Speed_2MHz,
1209  .GPIO_Mode = GPIO_Mode_AF,
1210  .GPIO_OType = GPIO_OType_PP,
1211  .GPIO_PuPd = GPIO_PuPd_UP
1212  },
1213  .pin_source = GPIO_PinSource2,
1214  },
1215  .remap = GPIO_AF_TIM2,
1216  },
1217  {
1218  .timer = TIM5,
1219  .timer_chan = TIM_Channel_2,
1220  .pin = {
1221  .gpio = GPIOA,
1222  .init = {
1223  .GPIO_Pin = GPIO_Pin_1,
1224  .GPIO_Speed = GPIO_Speed_2MHz,
1225  .GPIO_Mode = GPIO_Mode_AF,
1226  .GPIO_OType = GPIO_OType_PP,
1227  .GPIO_PuPd = GPIO_PuPd_UP
1228  },
1229  .pin_source = GPIO_PinSource1,
1230  },
1231  .remap = GPIO_AF_TIM5,
1232  },
1233  {
1234  .timer = TIM5,
1235  .timer_chan = TIM_Channel_1,
1236  .pin = {
1237  .gpio = GPIOA,
1238  .init = {
1239  .GPIO_Pin = GPIO_Pin_0,
1240  .GPIO_Speed = GPIO_Speed_2MHz,
1241  .GPIO_Mode = GPIO_Mode_AF,
1242  .GPIO_OType = GPIO_OType_PP,
1243  .GPIO_PuPd = GPIO_PuPd_UP
1244  },
1245  .pin_source = GPIO_PinSource0,
1246  },
1247  .remap = GPIO_AF_TIM5,
1248  }
1249 };
1250 
1251 /*
1252  * OUTPUTS with extra outputs on recieverport
1253  1: TIM3_CH3 (PB0)
1254  2: TIM3_CH4 (PB1)
1255  3: TIM9_CH2 (PA3)
1256  4: TIM2_CH3 (PA2)
1257  5: TIM5_CH2 (PA1)
1258  6: TIM5_CH1 (PA0)
1259  7: TIM12_CH2 (PB15)
1260  8: TIM8_CH1 (PC6) UART
1261  9: TIM8_CH2 (PC7) UART
1262  10: TIM8_CH3 (PC8)
1263  11: TIM8_CH4 (PC9)
1264  12: TIM12_CH1 (PB14) PPM
1265  */
1266 
1268  { // output 1
1269  .timer = TIM3,
1270  .timer_chan = TIM_Channel_3,
1271  .pin = {
1272  .gpio = GPIOB,
1273  .init = {
1274  .GPIO_Pin = GPIO_Pin_0,
1275  .GPIO_Speed = GPIO_Speed_2MHz,
1276  .GPIO_Mode = GPIO_Mode_AF,
1277  .GPIO_OType = GPIO_OType_PP,
1278  .GPIO_PuPd = GPIO_PuPd_UP
1279  },
1280  .pin_source = GPIO_PinSource0,
1281  },
1282  .remap = GPIO_AF_TIM3,
1283  },
1284  { // output 2
1285  .timer = TIM3,
1286  .timer_chan = TIM_Channel_4,
1287  .pin = {
1288  .gpio = GPIOB,
1289  .init = {
1290  .GPIO_Pin = GPIO_Pin_1,
1291  .GPIO_Speed = GPIO_Speed_2MHz,
1292  .GPIO_Mode = GPIO_Mode_AF,
1293  .GPIO_OType = GPIO_OType_PP,
1294  .GPIO_PuPd = GPIO_PuPd_UP
1295  },
1296  .pin_source = GPIO_PinSource1,
1297  },
1298  .remap = GPIO_AF_TIM3,
1299  },
1300  { // output 3
1301  .timer = TIM9,
1302  .timer_chan = TIM_Channel_2,
1303  .pin = {
1304  .gpio = GPIOA,
1305  .init = {
1306  .GPIO_Pin = GPIO_Pin_3,
1307  .GPIO_Speed = GPIO_Speed_2MHz,
1308  .GPIO_Mode = GPIO_Mode_AF,
1309  .GPIO_OType = GPIO_OType_PP,
1310  .GPIO_PuPd = GPIO_PuPd_UP
1311  },
1312  .pin_source = GPIO_PinSource3,
1313  },
1314  .remap = GPIO_AF_TIM9,
1315  },
1316  { // output 4
1317  .timer = TIM2,
1318  .timer_chan = TIM_Channel_3,
1319  .pin = {
1320  .gpio = GPIOA,
1321  .init = {
1322  .GPIO_Pin = GPIO_Pin_2,
1323  .GPIO_Speed = GPIO_Speed_2MHz,
1324  .GPIO_Mode = GPIO_Mode_AF,
1325  .GPIO_OType = GPIO_OType_PP,
1326  .GPIO_PuPd = GPIO_PuPd_UP
1327  },
1328  .pin_source = GPIO_PinSource2,
1329  },
1330  .remap = GPIO_AF_TIM2,
1331  },
1332  { // output 5
1333  .timer = TIM5,
1334  .timer_chan = TIM_Channel_2,
1335  .pin = {
1336  .gpio = GPIOA,
1337  .init = {
1338  .GPIO_Pin = GPIO_Pin_1,
1339  .GPIO_Speed = GPIO_Speed_2MHz,
1340  .GPIO_Mode = GPIO_Mode_AF,
1341  .GPIO_OType = GPIO_OType_PP,
1342  .GPIO_PuPd = GPIO_PuPd_UP
1343  },
1344  .pin_source = GPIO_PinSource1,
1345  },
1346  .remap = GPIO_AF_TIM5,
1347  },
1348  { // output 6
1349  .timer = TIM5,
1350  .timer_chan = TIM_Channel_1,
1351  .pin = {
1352  .gpio = GPIOA,
1353  .init = {
1354  .GPIO_Pin = GPIO_Pin_0,
1355  .GPIO_Speed = GPIO_Speed_2MHz,
1356  .GPIO_Mode = GPIO_Mode_AF,
1357  .GPIO_OType = GPIO_OType_PP,
1358  .GPIO_PuPd = GPIO_PuPd_UP
1359  },
1360  .pin_source = GPIO_PinSource0,
1361  },
1362  .remap = GPIO_AF_TIM5,
1363  },
1364  { // output 7
1365  .timer = TIM12,
1366  .timer_chan = TIM_Channel_2,
1367  .remap = GPIO_AF_TIM12,
1368  .pin = {
1369  .gpio = GPIOB,
1370  .init = {
1371  .GPIO_Pin = GPIO_Pin_15,
1372  .GPIO_Speed = GPIO_Speed_2MHz,
1373  .GPIO_Mode = GPIO_Mode_AF,
1374  .GPIO_OType = GPIO_OType_PP,
1375  .GPIO_PuPd = GPIO_PuPd_UP
1376  },
1377  .pin_source = GPIO_PinSource15,
1378  },
1379  },
1380  { // output 8
1381  .timer = TIM8,
1382  .timer_chan = TIM_Channel_1,
1383  .remap = GPIO_AF_TIM8,
1384  .pin = {
1385  .gpio = GPIOC,
1386  .init = {
1387  .GPIO_Pin = GPIO_Pin_6,
1388  .GPIO_Speed = GPIO_Speed_2MHz,
1389  .GPIO_Mode = GPIO_Mode_AF,
1390  .GPIO_OType = GPIO_OType_PP,
1391  .GPIO_PuPd = GPIO_PuPd_UP
1392  },
1393  .pin_source = GPIO_PinSource6,
1394  },
1395  },
1396  { // output 9
1397  .timer = TIM8,
1398  .timer_chan = TIM_Channel_2,
1399  .remap = GPIO_AF_TIM8,
1400  .pin = {
1401  .gpio = GPIOC,
1402  .init = {
1403  .GPIO_Pin = GPIO_Pin_7,
1404  .GPIO_Speed = GPIO_Speed_2MHz,
1405  .GPIO_Mode = GPIO_Mode_AF,
1406  .GPIO_OType = GPIO_OType_PP,
1407  .GPIO_PuPd = GPIO_PuPd_UP
1408  },
1409  .pin_source = GPIO_PinSource7,
1410  },
1411  },
1412  { // output 10
1413  .timer = TIM8,
1414  .timer_chan = TIM_Channel_3,
1415  .remap = GPIO_AF_TIM8,
1416  .pin = {
1417  .gpio = GPIOC,
1418  .init = {
1419  .GPIO_Pin = GPIO_Pin_8,
1420  .GPIO_Speed = GPIO_Speed_2MHz,
1421  .GPIO_Mode = GPIO_Mode_AF,
1422  .GPIO_OType = GPIO_OType_PP,
1423  .GPIO_PuPd = GPIO_PuPd_UP
1424  },
1425  .pin_source = GPIO_PinSource8,
1426  },
1427  },
1428  { // output 11
1429  .timer = TIM8,
1430  .timer_chan = TIM_Channel_4,
1431  .remap = GPIO_AF_TIM8,
1432  .pin = {
1433  .gpio = GPIOC,
1434  .init = {
1435  .GPIO_Pin = GPIO_Pin_9,
1436  .GPIO_Speed = GPIO_Speed_2MHz,
1437  .GPIO_Mode = GPIO_Mode_AF,
1438  .GPIO_OType = GPIO_OType_PP,
1439  .GPIO_PuPd = GPIO_PuPd_UP
1440  },
1441  .pin_source = GPIO_PinSource9,
1442  },
1443  },
1444  { // output 12
1445  .timer = TIM12,
1446  .timer_chan = TIM_Channel_1,
1447  .remap = GPIO_AF_TIM12,
1448  .pin = {
1449  .gpio = GPIOB,
1450  .init = {
1451  .GPIO_Pin = GPIO_Pin_14,
1452  .GPIO_Speed = GPIO_Speed_2MHz,
1453  .GPIO_Mode = GPIO_Mode_AF,
1454  .GPIO_OType = GPIO_OType_PP,
1455  .GPIO_PuPd = GPIO_PuPd_UP
1456  },
1457  .pin_source = GPIO_PinSource14,
1458  },
1459  },
1460 };
1461 
1462 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
1463 /*
1464  * Servo outputs
1465  */
1466 
1467 const struct pios_servo_cfg pios_servo_cfg = {
1468  .tim_oc_init = {
1469  .TIM_OCMode = TIM_OCMode_PWM1,
1470  .TIM_OutputState = TIM_OutputState_Enable,
1471  .TIM_OutputNState = TIM_OutputNState_Disable,
1472  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1473  .TIM_OCPolarity = TIM_OCPolarity_High,
1474  .TIM_OCNPolarity = TIM_OCPolarity_High,
1475  .TIM_OCIdleState = TIM_OCIdleState_Reset,
1476  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1477  },
1478  .channels = pios_tim_servoport_all_pins,
1479  .num_channels = NELEMENTS(pios_tim_servoport_all_pins),
1480 };
1481 
1482 const struct pios_servo_cfg pios_servo_rcvr_ppm_cfg = {
1483  .tim_oc_init = {
1484  .TIM_OCMode = TIM_OCMode_PWM1,
1485  .TIM_OutputState = TIM_OutputState_Enable,
1486  .TIM_OutputNState = TIM_OutputNState_Disable,
1487  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1488  .TIM_OCPolarity = TIM_OCPolarity_High,
1489  .TIM_OCNPolarity = TIM_OCPolarity_High,
1490  .TIM_OCIdleState = TIM_OCIdleState_Reset,
1491  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1492  },
1494  .num_channels = NELEMENTS(pios_tim_servoport_rcvrport_pins) - 1,
1495 };
1496 
1497 const struct pios_servo_cfg pios_servo_rcvr_all_cfg = {
1498  .tim_oc_init = {
1499  .TIM_OCMode = TIM_OCMode_PWM1,
1500  .TIM_OutputState = TIM_OutputState_Enable,
1501  .TIM_OutputNState = TIM_OutputNState_Disable,
1502  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1503  .TIM_OCPolarity = TIM_OCPolarity_High,
1504  .TIM_OCNPolarity = TIM_OCPolarity_High,
1505  .TIM_OCIdleState = TIM_OCIdleState_Reset,
1506  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1507  },
1509  .num_channels = NELEMENTS(pios_tim_servoport_rcvrport_pins),
1510 };
1511 
1512 #endif /* PIOS_INCLUDE_SERVO && PIOS_INCLUDE_TIM */
1513 
1514 
1515 /*
1516  * INPUTS
1517  1: TIM12_CH1 (PB14)
1518  2: TIM12_CH2 (PB15)
1519  3: TIM8_CH1 (PC6)
1520  4: TIM8_CH2 (PC7)
1521  5: TIM8_CH3 (PC8)
1522  6: TIM8_CH4 (PC9)
1523  */
1524 #if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM)
1525 #include <pios_pwm_priv.h>
1526 static const struct pios_tim_channel pios_tim_rcvrport_all_channels[] = {
1527  {
1528  .timer = TIM12,
1529  .timer_chan = TIM_Channel_1,
1530  .pin = {
1531  .gpio = GPIOB,
1532  .init = {
1533  .GPIO_Pin = GPIO_Pin_14,
1534  .GPIO_Speed = GPIO_Speed_2MHz,
1535  .GPIO_Mode = GPIO_Mode_AF,
1536  .GPIO_OType = GPIO_OType_PP,
1537  .GPIO_PuPd = GPIO_PuPd_UP
1538  },
1539  .pin_source = GPIO_PinSource14,
1540  },
1541  .remap = GPIO_AF_TIM12,
1542  },
1543  {
1544  .timer = TIM12,
1545  .timer_chan = TIM_Channel_2,
1546  .pin = {
1547  .gpio = GPIOB,
1548  .init = {
1549  .GPIO_Pin = GPIO_Pin_15,
1550  .GPIO_Speed = GPIO_Speed_2MHz,
1551  .GPIO_Mode = GPIO_Mode_AF,
1552  .GPIO_OType = GPIO_OType_PP,
1553  .GPIO_PuPd = GPIO_PuPd_UP
1554  },
1555  .pin_source = GPIO_PinSource15,
1556  },
1557  .remap = GPIO_AF_TIM12,
1558  },
1559  {
1560  .timer = TIM8,
1561  .timer_chan = TIM_Channel_1,
1562  .pin = {
1563  .gpio = GPIOC,
1564  .init = {
1565  .GPIO_Pin = GPIO_Pin_6,
1566  .GPIO_Speed = GPIO_Speed_2MHz,
1567  .GPIO_Mode = GPIO_Mode_AF,
1568  .GPIO_OType = GPIO_OType_PP,
1569  .GPIO_PuPd = GPIO_PuPd_UP
1570  },
1571  .pin_source = GPIO_PinSource6,
1572  },
1573  .remap = GPIO_AF_TIM8,
1574  },
1575  {
1576  .timer = TIM8,
1577  .timer_chan = TIM_Channel_2,
1578  .pin = {
1579  .gpio = GPIOC,
1580  .init = {
1581  .GPIO_Pin = GPIO_Pin_7,
1582  .GPIO_Speed = GPIO_Speed_2MHz,
1583  .GPIO_Mode = GPIO_Mode_AF,
1584  .GPIO_OType = GPIO_OType_PP,
1585  .GPIO_PuPd = GPIO_PuPd_UP
1586  },
1587  .pin_source = GPIO_PinSource7,
1588  },
1589  .remap = GPIO_AF_TIM8,
1590  },
1591  {
1592  .timer = TIM8,
1593  .timer_chan = TIM_Channel_3,
1594  .pin = {
1595  .gpio = GPIOC,
1596  .init = {
1597  .GPIO_Pin = GPIO_Pin_8,
1598  .GPIO_Speed = GPIO_Speed_2MHz,
1599  .GPIO_Mode = GPIO_Mode_AF,
1600  .GPIO_OType = GPIO_OType_PP,
1601  .GPIO_PuPd = GPIO_PuPd_UP
1602  },
1603  .pin_source = GPIO_PinSource8,
1604  },
1605  .remap = GPIO_AF_TIM8,
1606  },
1607  {
1608  .timer = TIM8,
1609  .timer_chan = TIM_Channel_4,
1610  .pin = {
1611  .gpio = GPIOC,
1612  .init = {
1613  .GPIO_Pin = GPIO_Pin_9,
1614  .GPIO_Speed = GPIO_Speed_2MHz,
1615  .GPIO_Mode = GPIO_Mode_AF,
1616  .GPIO_OType = GPIO_OType_PP,
1617  .GPIO_PuPd = GPIO_PuPd_UP
1618  },
1619  .pin_source = GPIO_PinSource9,
1620  },
1621  .remap = GPIO_AF_TIM8,
1622  },
1623 };
1624 
1625 const struct pios_pwm_cfg pios_pwm_cfg = {
1626  .tim_ic_init = {
1627  .TIM_ICPolarity = TIM_ICPolarity_Rising,
1628  .TIM_ICSelection = TIM_ICSelection_DirectTI,
1629  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1630  .TIM_ICFilter = 0x0,
1631  },
1632  .channels = pios_tim_rcvrport_all_channels,
1633  .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels),
1634 };
1635 
1636 const struct pios_pwm_cfg pios_pwm_with_ppm_cfg = {
1637  .tim_ic_init = {
1638  .TIM_ICPolarity = TIM_ICPolarity_Rising,
1639  .TIM_ICSelection = TIM_ICSelection_DirectTI,
1640  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1641  .TIM_ICFilter = 0x0,
1642  },
1643  /* Leave the first channel for PPM use and use the rest for PWM */
1644  .channels = &pios_tim_rcvrport_all_channels[1],
1645  .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels) - 1,
1646 };
1647 
1648 #endif
1649 
1650 /*
1651  * PPM Input
1652  */
1653 #if defined(PIOS_INCLUDE_PPM)
1654 #include <pios_ppm_priv.h>
1655 static const struct pios_ppm_cfg pios_ppm_cfg = {
1656  .tim_ic_init = {
1657  .TIM_ICPolarity = TIM_ICPolarity_Rising,
1658  .TIM_ICSelection = TIM_ICSelection_DirectTI,
1659  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1660  .TIM_ICFilter = 0x0,
1661  .TIM_Channel = TIM_Channel_2, //FIXME Why is this Channel 2 and Brain 3 ?
1662  },
1663  /* Use only the first channel for ppm */
1664  .channels = &pios_tim_rcvrport_all_channels[0],
1665  .num_channels = 1,
1666 };
1667 
1668 #endif //PPM
1669 
1670 #if defined(PIOS_INCLUDE_RCVR)
1671 #include "pios_rcvr_priv.h"
1672 #endif /* PIOS_INCLUDE_RCVR */
1673 
1674 #if defined(PIOS_INCLUDE_USB)
1675 #include "pios_usb_priv.h"
1676 
1677 static const struct pios_usb_cfg pios_usb_main_rm1_cfg = {
1678  .irq = {
1679  .init = {
1680  .NVIC_IRQChannel = OTG_FS_IRQn,
1681  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1682  .NVIC_IRQChannelSubPriority = 3,
1683  .NVIC_IRQChannelCmd = ENABLE,
1684  },
1685  },
1686  .vsense = {
1687  .gpio = GPIOB,
1688  .init = {
1689  .GPIO_Pin = GPIO_Pin_13,
1690  .GPIO_Speed = GPIO_Speed_25MHz,
1691  .GPIO_Mode = GPIO_Mode_IN,
1692  .GPIO_OType = GPIO_OType_OD,
1693  },
1694  }
1695 };
1696 
1697 static const struct pios_usb_cfg pios_usb_main_rm2_cfg = {
1698  .irq = {
1699  .init = {
1700  .NVIC_IRQChannel = OTG_FS_IRQn,
1701  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1702  .NVIC_IRQChannelSubPriority = 3,
1703  .NVIC_IRQChannelCmd = ENABLE,
1704  },
1705  },
1706  .vsense = {
1707  .gpio = GPIOC,
1708  .init = {
1709  .GPIO_Pin = GPIO_Pin_5,
1710  .GPIO_Speed = GPIO_Speed_25MHz,
1711  .GPIO_Mode = GPIO_Mode_IN,
1712  .GPIO_OType = GPIO_OType_OD,
1713  },
1714  }
1715 };
1716 
1717 static const struct pios_usb_cfg pios_usb_main_novsense_cfg = {
1718  .irq = {
1719  .init = {
1720  .NVIC_IRQChannel = OTG_FS_IRQn,
1721  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1722  .NVIC_IRQChannelSubPriority = 3,
1723  .NVIC_IRQChannelCmd = ENABLE,
1724  },
1725  },
1726 };
1727 
1728 const struct pios_usb_cfg * PIOS_BOARD_HW_DEFS_GetUsbCfg (uint32_t board_revision)
1729 {
1730  /* Crummy revolution -- omnibus variants -- with no flash often have no
1731  * vsense line connected.
1732  */
1733  if (!pios_external_flash_id) {
1734  return &pios_usb_main_novsense_cfg;
1735  }
1736 
1737  switch(board_revision) {
1738  case 2:
1739  return &pios_usb_main_rm1_cfg;
1740  break;
1741  case 3:
1742  return &pios_usb_main_rm2_cfg;
1743  break;
1744  default:
1745  PIOS_DEBUG_Assert(0);
1746  }
1747  return NULL;
1748 }
1749 
1750 #include "pios_usb_board_data_priv.h"
1753 #include "pios_usbhook.h"
1754 
1755 #endif /* PIOS_INCLUDE_USB */
1756 
1757 #if defined(PIOS_INCLUDE_COM_MSG)
1758 
1759 #include <pios_com_msg_priv.h>
1760 
1761 #endif /* PIOS_INCLUDE_COM_MSG */
1762 
1763 #if defined(PIOS_INCLUDE_USB_HID) && !defined(PIOS_INCLUDE_USB_CDC)
1764 #include <pios_usb_hid_priv.h>
1765 
1766 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
1767  .data_if = 0,
1768  .data_rx_ep = 1,
1769  .data_tx_ep = 1,
1770 };
1771 #endif /* PIOS_INCLUDE_USB_HID && !PIOS_INCLUDE_USB_CDC */
1772 
1773 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_USB_CDC)
1774 #include <pios_usb_cdc_priv.h>
1775 
1776 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
1777  .ctrl_if = 0,
1778  .ctrl_tx_ep = 2,
1779 
1780  .data_if = 1,
1781  .data_rx_ep = 3,
1782  .data_tx_ep = 3,
1783 };
1784 
1785 #include <pios_usb_hid_priv.h>
1786 
1787 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
1788  .data_if = 2,
1789  .data_rx_ep = 1,
1790  .data_tx_ep = 1,
1791 };
1792 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
1793 
1794 #if defined(PIOS_INCLUDE_ADC)
1795 #include "pios_adc_priv.h"
1796 #include "pios_internal_adc_priv.h"
1797 
1798 static void PIOS_ADC_DMA_irq_handler(void);
1799 void DMA2_Stream0_IRQHandler(void) __attribute__((alias("PIOS_ADC_DMA_irq_handler")));
1800 struct pios_internal_adc_cfg pios_adc_cfg = {
1801  .adc_dev_master = ADC1,
1802  .dma = {
1803  .irq = {
1804  .flags = (DMA_FLAG_TCIF0 | DMA_FLAG_TEIF0 | DMA_FLAG_HTIF0),
1805  .init = {
1806  .NVIC_IRQChannel = DMA2_Stream0_IRQn,
1807  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1808  .NVIC_IRQChannelSubPriority = 0,
1809  .NVIC_IRQChannelCmd = ENABLE,
1810  },
1811  },
1812  .rx = {
1813  .channel = DMA2_Stream0,
1814  .init = {
1815  .DMA_Channel = DMA_Channel_0,
1816  .DMA_PeripheralBaseAddr = (uint32_t) & ADC1->DR
1817  },
1818  }
1819  },
1820  .half_flag = DMA_IT_HTIF0,
1821  .full_flag = DMA_IT_TCIF0,
1822  .adc_pins = { \
1823  {GPIOC, GPIO_Pin_1, ADC_Channel_11}, \
1824  {GPIOC, GPIO_Pin_2, ADC_Channel_12}, \
1825  {NULL, 0, ADC_Channel_Vrefint}, /* Voltage reference */ \
1826  {NULL, 0, ADC_Channel_TempSensor}, /* Temperature sensor */ \
1827  },
1828  .adc_pin_count = 4,
1829 };
1830 
1831 struct stm32_gpio pios_current_sonar_pin = {
1832  .gpio = GPIOA,
1833  .init = {
1834  .GPIO_Pin = GPIO_Pin_8,
1835  .GPIO_Speed = GPIO_Speed_2MHz,
1836  .GPIO_Mode = GPIO_Mode_IN,
1837  .GPIO_OType = GPIO_OType_OD,
1838  .GPIO_PuPd = GPIO_PuPd_NOPULL
1839  },
1840  .pin_source = GPIO_PinSource8,
1841 };
1842 
1843 static void PIOS_ADC_DMA_irq_handler(void)
1844 {
1845  /* Call into the generic code to handle the IRQ for this specific device */
1847 }
1848 
1849 #endif /* PIOS_INCLUDE_ADC */
1850 
1856 #if defined(PIOS_INCLUDE_WS2811)
1857 #include "pios_ws2811.h"
1858 
1860 
1861 void DMA2_Stream6_IRQHandler() {
1862  PIOS_WS2811_dma_interrupt_handler(pios_ws2811);
1863 }
1864 
1865 static const struct pios_ws2811_cfg pios_ws2811_cfg_pb12 = {
1866  .timer = TIM1,
1867  .clock_cfg = {
1868  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 12000000) - 1,
1869  .TIM_ClockDivision = TIM_CKD_DIV1,
1870  .TIM_CounterMode = TIM_CounterMode_Up,
1871  .TIM_Period = 25, /* 2.083us/bit */
1872  },
1873  .interrupt = {
1874  .NVIC_IRQChannel = DMA2_Stream6_IRQn,
1875  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1876  .NVIC_IRQChannelSubPriority = 0,
1877  .NVIC_IRQChannelCmd = ENABLE,
1878  },
1879  .bit_clear_dma_tcif = DMA_IT_TCIF6,
1880  .fall_time_l = 5, /* 333ns */
1881  .fall_time_h = 11, /* 833ns */
1882  .led_gpio = GPIOB,
1883  .gpio_pin = GPIO_Pin_12,
1884  .bit_set_dma_stream = DMA2_Stream4,
1885  .bit_set_dma_channel = DMA_Channel_6, /* 2/S4/C6: TIM1 CH4|TRIG|COM */
1886  .bit_clear_dma_stream = DMA2_Stream6,
1887  .bit_clear_dma_channel = DMA_Channel_0, /* 0/S6/C0: TIM1 CH1|CH2|CH3 */
1888 };
1889 
1890 static const struct pios_ws2811_cfg pios_ws2811_cfg_pd2 = {
1891  .timer = TIM1,
1892  .clock_cfg = {
1893  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 12000000) - 1,
1894  .TIM_ClockDivision = TIM_CKD_DIV1,
1895  .TIM_CounterMode = TIM_CounterMode_Up,
1896  .TIM_Period = 25, /* 2.083us/bit */
1897  },
1898  .interrupt = {
1899  .NVIC_IRQChannel = DMA2_Stream6_IRQn,
1900  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1901  .NVIC_IRQChannelSubPriority = 0,
1902  .NVIC_IRQChannelCmd = ENABLE,
1903  },
1904  .bit_clear_dma_tcif = DMA_IT_TCIF6,
1905  .fall_time_l = 5, /* 333ns */
1906  .fall_time_h = 11, /* 833ns */
1907  .led_gpio = GPIOD,
1908  .gpio_pin = GPIO_Pin_2,
1909  .bit_set_dma_stream = DMA2_Stream4,
1910  .bit_set_dma_channel = DMA_Channel_6, /* 2/S4/C6: TIM1 CH4|TRIG|COM */
1911  .bit_clear_dma_stream = DMA2_Stream6,
1912  .bit_clear_dma_channel = DMA_Channel_0, /* 0/S6/C0: TIM1 CH1|CH2|CH3 */
1913 };
1914 
1915 static const struct pios_ws2811_cfg pios_ws2811_cfg_pa0 = {
1916  .timer = TIM1,
1917  .clock_cfg = {
1918  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 12000000) - 1,
1919  .TIM_ClockDivision = TIM_CKD_DIV1,
1920  .TIM_CounterMode = TIM_CounterMode_Up,
1921  .TIM_Period = 25, /* 2.083us/bit */
1922  },
1923  .interrupt = {
1924  .NVIC_IRQChannel = DMA2_Stream6_IRQn,
1925  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1926  .NVIC_IRQChannelSubPriority = 0,
1927  .NVIC_IRQChannelCmd = ENABLE,
1928  },
1929  .bit_clear_dma_tcif = DMA_IT_TCIF6,
1930  .fall_time_l = 5, /* 333ns */
1931  .fall_time_h = 11, /* 833ns */
1932  .led_gpio = GPIOA,
1933  .gpio_pin = GPIO_Pin_0,
1934  .bit_set_dma_stream = DMA2_Stream4,
1935  .bit_set_dma_channel = DMA_Channel_6, /* 2/S4/C6: TIM1 CH4|TRIG|COM */
1936  .bit_clear_dma_stream = DMA2_Stream6,
1937  .bit_clear_dma_channel = DMA_Channel_0, /* 0/S6/C0: TIM1 CH1|CH2|CH3 */
1938 };
1939 
1940 static const struct pios_ws2811_cfg pios_ws2811_cfg_pb6 = {
1941  .timer = TIM1,
1942  .clock_cfg = {
1943  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 12000000) - 1,
1944  .TIM_ClockDivision = TIM_CKD_DIV1,
1945  .TIM_CounterMode = TIM_CounterMode_Up,
1946  .TIM_Period = 25, /* 2.083us/bit */
1947  },
1948  .interrupt = {
1949  .NVIC_IRQChannel = DMA2_Stream6_IRQn,
1950  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1951  .NVIC_IRQChannelSubPriority = 0,
1952  .NVIC_IRQChannelCmd = ENABLE,
1953  },
1954  .bit_clear_dma_tcif = DMA_IT_TCIF6,
1955  .fall_time_l = 5, /* 333ns */
1956  .fall_time_h = 11, /* 833ns */
1957  .led_gpio = GPIOB,
1958  .gpio_pin = GPIO_Pin_6,
1959  .bit_set_dma_stream = DMA2_Stream4,
1960  .bit_set_dma_channel = DMA_Channel_6, /* 2/S4/C6: TIM1 CH4|TRIG|COM */
1961  .bit_clear_dma_stream = DMA2_Stream6,
1962  .bit_clear_dma_channel = DMA_Channel_0, /* 0/S6/C0: TIM1 CH1|CH2|CH3 */
1963 };
1964 #endif
1965 
1969 #if defined(PIOS_INCLUDE_MPU)
1970 #include "pios_mpu.h"
1971 static const struct pios_exti_cfg pios_exti_mpu_cfg __exti_config = {
1973  .line = EXTI_Line4,
1974  .pin = {
1975  .gpio = GPIOC,
1976  .init = {
1977  .GPIO_Pin = GPIO_Pin_4,
1978  .GPIO_Speed = GPIO_Speed_100MHz,
1979  .GPIO_Mode = GPIO_Mode_IN,
1980  .GPIO_OType = GPIO_OType_OD,
1981  .GPIO_PuPd = GPIO_PuPd_NOPULL,
1982  },
1983  },
1984  .irq = {
1985  .init = {
1986  .NVIC_IRQChannel = EXTI4_IRQn,
1987  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
1988  .NVIC_IRQChannelSubPriority = 0,
1989  .NVIC_IRQChannelCmd = ENABLE,
1990  },
1991  },
1992  .exti = {
1993  .init = {
1994  .EXTI_Line = EXTI_Line4, // matches above GPIO pin
1995  .EXTI_Mode = EXTI_Mode_Interrupt,
1996  .EXTI_Trigger = EXTI_Trigger_Rising,
1997  .EXTI_LineCmd = ENABLE,
1998  },
1999  },
2000 };
2001 
2002 static const struct pios_mpu_cfg pios_mpu_cfg = {
2003  .exti_cfg = &pios_exti_mpu_cfg,
2004  .default_samplerate = 1000,
2005  .orientation = PIOS_MPU_TOP_180DEG,
2006 };
2007 #endif /* PIOS_INCLUDE_MPU */
2008 
2009 #if defined(PIOS_INCLUDE_HMC5883)
2010 #include "pios_hmc5883_priv.h"
2011 static const struct pios_exti_cfg pios_exti_hmc5883_cfg __exti_config = {
2013  .line = EXTI_Line7,
2014  .pin = {
2015  .gpio = GPIOB,
2016  .init = {
2017  .GPIO_Pin = GPIO_Pin_7,
2018  .GPIO_Speed = GPIO_Speed_100MHz,
2019  .GPIO_Mode = GPIO_Mode_IN,
2020  .GPIO_OType = GPIO_OType_OD,
2021  .GPIO_PuPd = GPIO_PuPd_NOPULL,
2022  },
2023  },
2024  .irq = {
2025  .init = {
2026  .NVIC_IRQChannel = EXTI9_5_IRQn,
2027  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
2028  .NVIC_IRQChannelSubPriority = 0,
2029  .NVIC_IRQChannelCmd = ENABLE,
2030  },
2031  },
2032  .exti = {
2033  .init = {
2034  .EXTI_Line = EXTI_Line7, // matches above GPIO pin
2035  .EXTI_Mode = EXTI_Mode_Interrupt,
2036  .EXTI_Trigger = EXTI_Trigger_Rising,
2037  .EXTI_LineCmd = ENABLE,
2038  },
2039  },
2040 };
2041 
2042 static const struct pios_hmc5883_cfg pios_hmc5883_cfg = {
2043  .exti_cfg = &pios_exti_hmc5883_cfg,
2044  .M_ODR = PIOS_HMC5883_ODR_75,
2045  .Meas_Conf = PIOS_HMC5883_MEASCONF_NORMAL,
2046  .Gain = PIOS_HMC5883_GAIN_1_9,
2048  .Default_Orientation = PIOS_HMC5883_TOP_270DEG,
2049 };
2050 #endif /* PIOS_INCLUDE_HMC5883 */
2051 
2055 #if defined(PIOS_INCLUDE_MS5611)
2056 #include "pios_ms5611_priv.h"
2057 static const struct pios_ms5611_cfg pios_ms5611_cfg = {
2059  .temperature_interleaving = 1,
2060 };
2061 #endif /* PIOS_INCLUDE_MS5611 */
2062 
struct stm32_gpio pin
uint8_t capacity[3]
const struct pios_exti_cfg * exti_cfg
MS5611 functions header.
#define PIOS_HMC5883_ODR_75
static const struct pios_tim_clock_cfg tim_3_cfg
const struct pios_flash_driver pios_jedec_flash_driver
SPI private definitions.
#define NELEMENTS(x)
Definition: pios.h:192
#define I2C2_EV_IRQHandler
struct stm32_gpio bind
COM private definitions.
COM MSG private definitions.
APIs for PIOS_USBHOOK layer.
TIM_ICInitTypeDef tim_ic_init
Definition: pios_pwm_priv.h:39
GPIO_TypeDef * gpio
Definition: pios_stm32.h:60
#define PIOS_DEBUG_Assert(test)
Definition: pios_debug.h:51
static const struct pios_tim_clock_cfg tim_11_cfg
#define PIOS_HMC5883_MODE_CONTINUOUS
I2C_TypeDef * regs
Definition: pios_i2c_priv.h:37
ADC private definitions.
static const struct pios_usart_cfg pios_usart_main_cfg
bool PIOS_HMC5883_IRQHandler()
#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
bool(* vector)(void)
Definition: pios_exti.h:38
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_5_cfg
static const struct pios_tim_clock_cfg tim_4_cfg
#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
static const struct pios_tim_clock_cfg tim_12_cfg
Spektrum/JR DSMx satellite receiver private structures.
enum pios_ms5611_osr oversampling
#define JEDEC_MEMORYTYPE_ANY
#define I2C2_ER_IRQHandler
static const TIM_TimeBaseInitTypeDef tim_9_10_11_time_base
#define FLASH_SECTOR_64KB
const struct pios_exti_cfg * exti_cfg
Definition: pios_mpu.h:140
Driver for talking to most JEDEC flash chips.
#define PIOS_SERVO_UPDATE_HZ
Definition: pios_board.h:209
TIM_TypeDef * timer
Definition: pios_tim_priv.h:7
SPI_TypeDef * regs
Definition: pios_spi_priv.h:44
static const struct pios_tim_channel pios_tim_rcvrport_all_channels[]
static const TIM_TimeBaseInitTypeDef tim_3_5_time_base
struct pios_i2c_adapter * pios_i2c_t
Definition: pios_i2c.h:48
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)
static const TIM_TimeBaseInitTypeDef tim_apb2_time_base
#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
static const struct pios_usart_cfg pios_usart_flexi_cfg
void PIOS_FLASH_fixup_partitions_for_capacity(struct pios_flash_partition *partition_table, uint8_t partition_table_len, const struct pios_flash_chip *descriptor, struct pios_flash_sector_range *sectors, uint32_t num_bytes)
static const struct pios_tim_clock_cfg tim_9_cfg
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
Defines the API to set up the HID-only USB descriptor config.
static const struct pios_tim_channel pios_tim_servoport_rcvrport_pins[]
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.
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_servoport_all_pins[]
static const struct pios_tim_clock_cfg tim_10_cfg
const struct pios_flash_partition pios_flash_partition_table[]
Definition: unittest_init.c:50
static const struct pios_tim_clock_cfg tim_1_cfg
#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
static const struct pios_tim_clock_cfg tim_8_cfg
uint32_t PIOS_Flash_Jedec_GetCapacity(uintptr_t chip_id)
LED private definitions.
#define BMP280_HIGH_RESOLUTION
#define JEDEC_MANUFACTURER_ANY
#define PIOS_ANNUNCIATOR_BUZZER
Definition: pios_board.h:87
struct stm32_irq irq
Definition: pios_usb_priv.h:37
#define FLASH_SECTOR_128KB
static const TIM_TimeBaseInitTypeDef tim_apb1_time_base
Implements an OpenLRS driver for the RFM22B.
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.