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 
36 #include <pios.h>
37 #include <pios_config.h>
38 #include <pios_board_info.h>
39 
40 #include <fpga_drv.h>
41 
42 #if defined(PIOS_INCLUDE_ANNUNC)
43 
44 #include <pios_annunc_priv.h>
45 static const struct pios_annunc pios_annuncs[] = {
46  [PIOS_LED_HEARTBEAT] = {
47  .pin = {
48  .gpio = GPIOB,
49  .init = {
50  .GPIO_Pin = GPIO_Pin_13,
51  .GPIO_Speed = GPIO_Speed_50MHz,
52  .GPIO_Mode = GPIO_Mode_OUT,
53  .GPIO_OType = GPIO_OType_PP,
54  .GPIO_PuPd = GPIO_PuPd_DOWN
55  },
56  },
57  .remap = 0,
58  .active_high = true,
59  },
60  [PIOS_LED_ALARM] = {
61  .pin = {
62  .gpio = GPIOC,
63  .init = {
64  .GPIO_Pin = GPIO_Pin_8,
65  .GPIO_Speed = GPIO_Speed_50MHz,
66  .GPIO_Mode = GPIO_Mode_OUT,
67  .GPIO_OType = GPIO_OType_PP,
68  .GPIO_PuPd = GPIO_PuPd_DOWN
69  },
70  },
71  .remap = 0,
72  .active_high = true,
73  },
74 #if defined(PIOS_INCLUDE_RE1_FPGA)
76  .handler = PIOS_RE1FPGA_Buzzer
77  },
78 #endif
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 #endif /* PIOS_INCLUDE_ANNUNC */
91 
92 
93 #if defined(PIOS_INCLUDE_FLASH)
95 
96 static const struct flashfs_logfs_cfg flashfs_settings_cfg = {
97  .fs_magic = 0x3bb141cf,
98  .arena_size = 0x00010000, /* 256 * slot size */
99  .slot_size = 0x00000100, /* 256 bytes */
100 };
101 
102 #if defined(PIOS_INCLUDE_FLASH_JEDEC)
103 #include "pios_flash_jedec_priv.h"
104 
105 static const struct pios_flash_jedec_cfg flash_s25fl127_cfg = {
107  .expect_memorytype = 0x20,
108  .expect_capacity = 0x18,
109  .sector_erase = 0xd8,
110 };
111 #endif /* PIOS_INCLUDE_FLASH_JEDEC */
112 
113 #if defined(PIOS_INCLUDE_FLASH_INTERNAL)
115 
116 static const struct pios_flash_internal_cfg flash_internal_cfg = {
117 };
118 #endif /* PIOS_INCLUDE_FLASH_INTERNAL */
119 
120 #include "pios_flash_priv.h"
121 
122 #if defined(PIOS_INCLUDE_FLASH_INTERNAL)
123 static const struct pios_flash_sector_range stm32f4_sectors[] = {
124  {
125  .base_sector = 0,
126  .last_sector = 3,
127  .sector_size = FLASH_SECTOR_16KB,
128  },
129  {
130  .base_sector = 4,
131  .last_sector = 4,
132  .sector_size = FLASH_SECTOR_64KB,
133  },
134  {
135  .base_sector = 5,
136  .last_sector = 7,
137  .sector_size = FLASH_SECTOR_128KB,
138  },
139 
140 };
141 
142 uintptr_t pios_internal_flash_id;
143 static const struct pios_flash_chip pios_flash_chip_internal = {
145  .chip_id = &pios_internal_flash_id,
146  .page_size = 16, /* 128-bit rows */
147  .sector_blocks = stm32f4_sectors,
148  .num_blocks = NELEMENTS(stm32f4_sectors),
149 };
150 #endif /* PIOS_INCLUDE_FLASH_INTERNAL */
151 
152 #if defined(PIOS_INCLUDE_FLASH_JEDEC)
153 static const struct pios_flash_sector_range s25fl127_sectors[] = {
154  {
155  .base_sector = 0,
156  .last_sector = 15,
157  .sector_size = FLASH_SECTOR_4KB,
158  },
159  // NOTE: The 4kB sectors are currently unused, as they need a different erase command
160  {
161  .base_sector = 16,
162  .last_sector = 270,
163  .sector_size = FLASH_SECTOR_64KB,
164  }
165 };
166 
167 uintptr_t pios_external_flash_id;
168 static const struct pios_flash_chip pios_flash_chip_external = {
170  .chip_id = &pios_external_flash_id,
171  .page_size = 256,
172  .sector_blocks = s25fl127_sectors,
173  .num_blocks = NELEMENTS(s25fl127_sectors),
174 };
175 #endif /* PIOS_INCLUDE_FLASH_JEDEC */
176 
177 static const struct pios_flash_partition pios_flash_partition_table[] = {
178 #if defined(PIOS_INCLUDE_FLASH_INTERNAL)
179  {
181  .chip_desc = &pios_flash_chip_internal,
182  .first_sector = 0,
183  .last_sector = 1,
184  .chip_offset = 0,
185  .size = (1 - 0 + 1) * FLASH_SECTOR_16KB,
186  },
187 
188  /* NOTE: sectors 2-4 of the internal flash are currently unallocated */
189 
190  {
191  .label = FLASH_PARTITION_LABEL_FW,
192  .chip_desc = &pios_flash_chip_internal,
193  .first_sector = 5,
194  .last_sector = 7,
195  .chip_offset = (4 * FLASH_SECTOR_16KB) + (1 * FLASH_SECTOR_64KB),
196  .size = (7 - 5 + 1) * FLASH_SECTOR_128KB,
197  },
198 
199 #endif /* PIOS_INCLUDE_FLASH_INTERNAL */
200 
201 #if defined(PIOS_INCLUDE_FLASH_JEDEC)
202  {
204  .chip_desc = &pios_flash_chip_external,
205  .first_sector = 16,
206  .last_sector = 18,
207  .chip_offset = (16 * FLASH_SECTOR_4KB),
208  .size = (18 - 16 + 1) * FLASH_SECTOR_64KB,
209  },
210 
211  {
213  .chip_desc = &pios_flash_chip_external,
214  .first_sector = 19,
215  .last_sector = 20,
216  .chip_offset = (16 * FLASH_SECTOR_4KB) + (3 * FLASH_SECTOR_64KB),
217  .size = (20 - 19 + 1) * FLASH_SECTOR_64KB,
218  },
219 
220  {
221  .label = FLASH_PARTITION_LABEL_LOG,
222  .chip_desc = &pios_flash_chip_external,
223  .first_sector = 21,
224  .last_sector = 270,
225  .chip_offset = (16 * FLASH_SECTOR_4KB) + (5 * FLASH_SECTOR_64KB),
226  .size = (270 - 21 + 1) * FLASH_SECTOR_64KB,
227  },
228 #endif /* PIOS_INCLUDE_FLASH_JEDEC */
229 };
230 
231 const struct pios_flash_partition * PIOS_BOARD_HW_DEFS_GetPartitionTable (uint32_t board_revision, uint32_t * num_partitions)
232 {
233  PIOS_Assert(num_partitions);
234 
235  *num_partitions = NELEMENTS(pios_flash_partition_table);
237 }
238 
239 
240 #endif /* PIOS_INCLUDE_FLASH */
241 
242 
243 #if defined(PIOS_INCLUDE_SPI)
244 #include <pios_spi_priv.h>
245 
246 /*
247  * SPI1 Interface
248  * Used for BMI160 gyro / accelerometer
249  */
250 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
251  .regs = SPI1,
252  .remap = GPIO_AF_SPI1,
253  .init = {
254  .SPI_Mode = SPI_Mode_Master,
255  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
256  .SPI_DataSize = SPI_DataSize_8b,
257  .SPI_NSS = SPI_NSS_Soft,
258  .SPI_FirstBit = SPI_FirstBit_MSB,
259  .SPI_CRCPolynomial = 7,
260  .SPI_CPOL = SPI_CPOL_High,
261  .SPI_CPHA = SPI_CPHA_2Edge,
262  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16, // 90MHz / 16 = 5.6MHz
263  },
264  .sclk = {
265  .gpio = GPIOA,
266  .init = {
267  .GPIO_Pin = GPIO_Pin_5,
268  .GPIO_Speed = GPIO_Speed_100MHz,
269  .GPIO_Mode = GPIO_Mode_AF,
270  .GPIO_OType = GPIO_OType_PP,
271  .GPIO_PuPd = GPIO_PuPd_UP
272  },
273  },
274  .miso = {
275  .gpio = GPIOA,
276  .init = {
277  .GPIO_Pin = GPIO_Pin_6,
278  .GPIO_Speed = GPIO_Speed_50MHz,
279  .GPIO_Mode = GPIO_Mode_AF,
280  .GPIO_OType = GPIO_OType_PP,
281  .GPIO_PuPd = GPIO_PuPd_UP
282  },
283  },
284  .mosi = {
285  .gpio = GPIOA,
286  .init = {
287  .GPIO_Pin = GPIO_Pin_7,
288  .GPIO_Speed = GPIO_Speed_50MHz,
289  .GPIO_Mode = GPIO_Mode_AF,
290  .GPIO_OType = GPIO_OType_PP,
291  .GPIO_PuPd = GPIO_PuPd_UP
292  },
293  },
294  .slave_count = 1,
295  .ssel = { {
296  .gpio = GPIOC,
297  .init = {
298  .GPIO_Pin = GPIO_Pin_14,
299  .GPIO_Speed = GPIO_Speed_2MHz,
300  .GPIO_Mode = GPIO_Mode_OUT,
301  .GPIO_OType = GPIO_OType_PP,
302  .GPIO_PuPd = GPIO_PuPd_UP
303  } }
304  }
305 };
306 
307 /* SPI3 Interface
308  * - Used for flash and RE1 FPGA communication
309  */
310 static const struct pios_spi_cfg pios_spi_flash_cfg = {
311  .regs = SPI3,
312  .remap = GPIO_AF_SPI3,
313  .init = {
314  .SPI_Mode = SPI_Mode_Master,
315  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
316  .SPI_DataSize = SPI_DataSize_8b,
317  .SPI_NSS = SPI_NSS_Soft,
318  .SPI_FirstBit = SPI_FirstBit_MSB,
319  .SPI_CRCPolynomial = 7,
320  .SPI_CPOL = SPI_CPOL_High,
321  .SPI_CPHA = SPI_CPHA_2Edge,
322  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8, //@ APB1 PCLK1 45MHz / 8 == 5.6MHz
323  },
324  .sclk = {
325  .gpio = GPIOB,
326  .init = {
327  .GPIO_Pin = GPIO_Pin_3,
328  .GPIO_Speed = GPIO_Speed_100MHz,
329  .GPIO_Mode = GPIO_Mode_AF,
330  .GPIO_OType = GPIO_OType_PP,
331  .GPIO_PuPd = GPIO_PuPd_NOPULL
332  },
333  .pin_source = GPIO_PinSource3,
334  },
335  .miso = {
336  .gpio = GPIOC,
337  .init = {
338  .GPIO_Pin = GPIO_Pin_11,
339  .GPIO_Speed = GPIO_Speed_50MHz,
340  .GPIO_Mode = GPIO_Mode_AF,
341  .GPIO_OType = GPIO_OType_PP,
342  .GPIO_PuPd = GPIO_PuPd_NOPULL
343  },
344  .pin_source = GPIO_PinSource11,
345  },
346  .mosi = {
347  .gpio = GPIOC,
348  .init = {
349  .GPIO_Pin = GPIO_Pin_12,
350  .GPIO_Speed = GPIO_Speed_50MHz,
351  .GPIO_Mode = GPIO_Mode_AF,
352  .GPIO_OType = GPIO_OType_PP,
353  .GPIO_PuPd = GPIO_PuPd_NOPULL
354  },
355  .pin_source = GPIO_PinSource12,
356  },
357  .slave_count = 2,
358  .ssel = {
359  {
360  .gpio = GPIOB,
361  .init = {
362  .GPIO_Pin = GPIO_Pin_15,
363  .GPIO_Speed = GPIO_Speed_50MHz,
364  .GPIO_Mode = GPIO_Mode_OUT,
365  .GPIO_OType = GPIO_OType_PP,
366  .GPIO_PuPd = GPIO_PuPd_UP
367  },
368  .pin_source = GPIO_PinSource15,
369  },
370  {
371  .gpio = GPIOC,
372  .init = {
373  .GPIO_Pin = GPIO_Pin_15,
374  .GPIO_Speed = GPIO_Speed_2MHz,
375  .GPIO_Mode = GPIO_Mode_OUT,
376  .GPIO_OType = GPIO_OType_PP,
377  .GPIO_PuPd = GPIO_PuPd_UP
378  },
379  .pin_source = GPIO_PinSource15,
380  },
381  },
382 
383 };
384 
385 pios_spi_t pios_spi_flash_id;
386 
387 #endif /* PIOS_INCLUDE_SPI */
388 
389 #if defined(PIOS_INCLUDE_I2C)
390 #include <pios_i2c_priv.h>
391 
392 /*
393  * I2C Adapters
394  */
395 void PIOS_I2C_internal_ev_irq_handler(void);
396 void PIOS_I2C_internal_er_irq_handler(void);
397 void I2C1_EV_IRQHandler() __attribute__ ((alias ("PIOS_I2C_external_ev_irq_handler")));
398 void I2C1_ER_IRQHandler() __attribute__ ((alias ("PIOS_I2C_external_er_irq_handler")));
399 
400 static const struct pios_i2c_adapter_cfg pios_i2c_external_cfg = {
401  .regs = I2C1,
402  .remap = GPIO_AF_I2C1,
403  .init = {
404  .I2C_Mode = I2C_Mode_I2C,
405  .I2C_OwnAddress1 = 0,
406  .I2C_Ack = I2C_Ack_Enable,
407  .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
408  .I2C_DutyCycle = I2C_DutyCycle_2,
409  .I2C_ClockSpeed = 400000, /* bits/s */
410  },
411  .transfer_timeout_ms = 50,
412  .scl = {
413  .gpio = GPIOB,
414  .init = {
415  .GPIO_Pin = GPIO_Pin_8,
416  .GPIO_Mode = GPIO_Mode_AF,
417  .GPIO_Speed = GPIO_Speed_50MHz,
418  .GPIO_OType = GPIO_OType_OD,
419  .GPIO_PuPd = GPIO_PuPd_NOPULL,
420  },
421  .pin_source = GPIO_PinSource8,
422  },
423  .sda = {
424  .gpio = GPIOB,
425  .init = {
426  .GPIO_Pin = GPIO_Pin_9,
427  .GPIO_Mode = GPIO_Mode_AF,
428  .GPIO_Speed = GPIO_Speed_50MHz,
429  .GPIO_OType = GPIO_OType_OD,
430  .GPIO_PuPd = GPIO_PuPd_NOPULL,
431  },
432  .pin_source = GPIO_PinSource9,
433  },
434  .event = {
435  .flags = 0,
436  .init = {
437  .NVIC_IRQChannel = I2C1_EV_IRQn,
438  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
439  .NVIC_IRQChannelSubPriority = 0,
440  .NVIC_IRQChannelCmd = ENABLE,
441  },
442  },
443  .error = {
444  .flags = 0,
445  .init = {
446  .NVIC_IRQChannel = I2C1_ER_IRQn,
447  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
448  .NVIC_IRQChannelSubPriority = 0,
449  .NVIC_IRQChannelCmd = ENABLE,
450  },
451  },
452 };
453 
454 pios_i2c_t pios_i2c_external_id;
455 void PIOS_I2C_external_ev_irq_handler(void)
456 {
457  /* Call into the generic code to handle the IRQ for this specific device */
458  PIOS_I2C_EV_IRQ_Handler(pios_i2c_external_id);
459 }
460 
461 void PIOS_I2C_external_er_irq_handler(void)
462 {
463  /* Call into the generic code to handle the IRQ for this specific device */
464  PIOS_I2C_ER_IRQ_Handler(pios_i2c_external_id);
465 }
466 #endif /* PIOS_INCLUDE_I2C */
467 
468 #if defined(PIOS_INCLUDE_COM)
469 #include "pios_com_priv.h"
470 #endif /* PIOS_INCLUDE_COM */
471 
472 #if defined(PIOS_INCLUDE_RCVR)
473 #include "pios_rcvr_priv.h"
474 #endif /* PIOS_INCLUDE_RCVR */
475 
476 #if defined(PIOS_INCLUDE_USB)
477 #include "pios_usb_priv.h"
478 
479 static const struct pios_usb_cfg pios_usb_main_cfg = {
480  .irq = {
481  .init = {
482  .NVIC_IRQChannel = OTG_FS_IRQn,
483  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
484  .NVIC_IRQChannelSubPriority = 0,
485  .NVIC_IRQChannelCmd = ENABLE,
486  },
487  },
488  .vsense = {
489  .gpio = GPIOA,
490  .init = {
491  .GPIO_Pin = GPIO_Pin_9,
492  .GPIO_Speed = GPIO_Speed_25MHz,
493  .GPIO_Mode = GPIO_Mode_IN,
494  .GPIO_OType = GPIO_OType_OD,
495  .GPIO_PuPd = GPIO_PuPd_NOPULL,
496  },
497  }
498 };
499 
503 #include "pios_usbhook.h"
504 
505 #endif /* PIOS_INCLUDE_USB */
506 
507 #if defined(PIOS_INCLUDE_COM_MSG)
508 
509 #include <pios_com_msg_priv.h>
510 
511 #endif /* PIOS_INCLUDE_COM_MSG */
512 
513 #if defined(PIOS_INCLUDE_USB_HID) && !defined(PIOS_INCLUDE_USB_CDC)
514 #include <pios_usb_hid_priv.h>
515 
516 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
517  .data_if = 0,
518  .data_rx_ep = 1,
519  .data_tx_ep = 1,
520 };
521 #endif /* PIOS_INCLUDE_USB_HID && !PIOS_INCLUDE_USB_CDC */
522 
523 #if defined(PIOS_INCLUDE_USB_HID) && defined(PIOS_INCLUDE_USB_CDC)
524 #include <pios_usb_cdc_priv.h>
525 
526 const struct pios_usb_cdc_cfg pios_usb_cdc_cfg = {
527  .ctrl_if = 0,
528  .ctrl_tx_ep = 2,
529 
530  .data_if = 1,
531  .data_rx_ep = 3,
532  .data_tx_ep = 3,
533 };
534 
535 #include <pios_usb_hid_priv.h>
536 
537 const struct pios_usb_hid_cfg pios_usb_hid_cfg = {
538  .data_if = 2,
539  .data_rx_ep = 1,
540  .data_tx_ep = 1,
541 };
542 #endif /* PIOS_INCLUDE_USB_HID && PIOS_INCLUDE_USB_CDC */
543 
544 #if defined(PIOS_INCLUDE_ADC)
545 #include "pios_adc_priv.h"
546 #include "pios_internal_adc_priv.h"
547 
548 void PIOS_ADC_DMA_irq_handler(void);
549 void DMA2_Stream4_IRQHandler(void) __attribute__((alias("PIOS_ADC_DMA_irq_handler")));
550 struct pios_internal_adc_cfg pios_adc_cfg = {
551  .adc_dev_master = ADC1,
552  .dma = {
553  .irq = {
554  .flags = (DMA_FLAG_TCIF4 | DMA_FLAG_TEIF4 | DMA_FLAG_HTIF4),
555  .init = {
556  .NVIC_IRQChannel = DMA2_Stream4_IRQn,
557  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
558  .NVIC_IRQChannelSubPriority = 0,
559  .NVIC_IRQChannelCmd = ENABLE,
560  },
561  },
562  .rx = {
563  .channel = DMA2_Stream4,
564  .init = {
565  .DMA_Channel = DMA_Channel_0,
566  .DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR
567  },
568  }
569  },
570  .half_flag = DMA_IT_HTIF4,
571  .full_flag = DMA_IT_TCIF4,
572  .adc_pins = { \
573  { GPIOC, GPIO_Pin_1, ADC_Channel_11 }, \
574  { GPIOC, GPIO_Pin_0, ADC_Channel_10 }, \
575  { GPIOC, GPIO_Pin_3, ADC_Channel_13 } \
576  },
577  .adc_pin_count = 3
578 };
579 
580 void PIOS_ADC_DMA_irq_handler(void)
581 {
582  /* Call into the generic code to handle the IRQ for this specific device */
584 }
585 
586 #endif /* PIOS_INCLUDE_ADC */
587 
588 
589 #if defined(PIOS_INCLUDE_RTC)
590 /*
591  * Realtime Clock (RTC)
592  */
593 #include <pios_rtc_priv.h>
594 
595 void PIOS_RTC_IRQ_Handler (void);
596 void RTC_WKUP_IRQHandler() __attribute__ ((alias ("PIOS_RTC_IRQ_Handler")));
597 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
598  // FIXME for real board the clock is 16MHz
599  .clksrc = RCC_RTCCLKSource_HSE_Div16, // Divide 8 Mhz crystal down to 1
600  // For some reason it's acting like crystal is 16 Mhz. This clock is then divided
601  // by another 16 to give a nominal 62.5 khz clock
602  .prescaler = 100, // Every 100 cycles gives 625 Hz
603  .irq = {
604  .init = {
605  .NVIC_IRQChannel = RTC_WKUP_IRQn,
606  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
607  .NVIC_IRQChannelSubPriority = 0,
608  .NVIC_IRQChannelCmd = ENABLE,
609  },
610  },
611 };
612 
613 void PIOS_RTC_IRQ_Handler (void)
614 {
616 }
617 
618 #endif /* PIOS_INCLUDE_RTC */
619 
620 #if defined(PIOS_INCLUDE_USART)
621 
622 #include "pios_usart_priv.h"
623 
624 static const struct pios_usart_cfg pios_usart1_cfg = {
625  .regs = USART1,
626  .remap = GPIO_AF_USART1,
627  .irq = {
628  .init = {
629  .NVIC_IRQChannel = USART1_IRQn,
630  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
631  .NVIC_IRQChannelSubPriority = 0,
632  .NVIC_IRQChannelCmd = ENABLE,
633  },
634  },
635  .rx = {
636  .gpio = GPIOB,
637  .init = {
638  .GPIO_Pin = GPIO_Pin_7,
639  .GPIO_Speed = GPIO_Speed_25MHz,
640  .GPIO_Mode = GPIO_Mode_AF,
641  .GPIO_OType = GPIO_OType_PP,
642  .GPIO_PuPd = GPIO_PuPd_UP
643  },
644  .pin_source = GPIO_PinSource7,
645  },
646  .tx = {
647  .gpio = GPIOB,
648  .init = {
649  .GPIO_Pin = GPIO_Pin_6,
650  .GPIO_Speed = GPIO_Speed_25MHz,
651  .GPIO_Mode = GPIO_Mode_AF,
652  .GPIO_OType = GPIO_OType_PP,
653  .GPIO_PuPd = GPIO_PuPd_UP
654  },
655  .pin_source = GPIO_PinSource6,
656  },
657 };
658 
659 static const struct pios_usart_cfg pios_usart3_cfg = {
660  .regs = USART3,
661  .remap = GPIO_AF_USART3,
662  .irq = {
663  .init = {
664  .NVIC_IRQChannel = USART3_IRQn,
665  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
666  .NVIC_IRQChannelSubPriority = 0,
667  .NVIC_IRQChannelCmd = ENABLE,
668  },
669  },
670  .rx = {
671  .gpio = GPIOC,
672  .init = {
673  .GPIO_Pin = GPIO_Pin_5,
674  .GPIO_Speed = GPIO_Speed_2MHz,
675  .GPIO_Mode = GPIO_Mode_AF,
676  .GPIO_OType = GPIO_OType_PP,
677  .GPIO_PuPd = GPIO_PuPd_UP
678  },
679  .pin_source = GPIO_PinSource5,
680  }
681 };
682 
683 static const struct pios_usart_cfg pios_usart4_cfg = {
684  .regs = UART4,
685  .remap = GPIO_AF_UART4,
686  .irq = {
687  .init = {
688  .NVIC_IRQChannel = UART4_IRQn,
689  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
690  .NVIC_IRQChannelSubPriority = 0,
691  .NVIC_IRQChannelCmd = ENABLE,
692  },
693  },
694  .rx = {
695  .gpio = GPIOA,
696  .init = {
697  .GPIO_Pin = GPIO_Pin_1,
698  .GPIO_Speed = GPIO_Speed_25MHz,
699  .GPIO_Mode = GPIO_Mode_AF,
700  .GPIO_OType = GPIO_OType_PP,
701  .GPIO_PuPd = GPIO_PuPd_UP
702  },
703  .pin_source = GPIO_PinSource1,
704  },
705  .tx = {
706  .gpio = GPIOA,
707  .init = {
708  .GPIO_Pin = GPIO_Pin_0,
709  .GPIO_Speed = GPIO_Speed_25MHz,
710  .GPIO_Mode = GPIO_Mode_AF,
711  .GPIO_OType = GPIO_OType_PP,
712  .GPIO_PuPd = GPIO_PuPd_UP
713  },
714  .pin_source = GPIO_PinSource0,
715  },
716 };
717 
718 static const struct pios_usart_cfg pios_usart6_cfg = {
719  .regs = USART6,
720  .remap = GPIO_AF_USART6,
721  .irq = {
722  .init = {
723  .NVIC_IRQChannel = USART6_IRQn,
724  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
725  .NVIC_IRQChannelSubPriority = 0,
726  .NVIC_IRQChannelCmd = ENABLE,
727  },
728  },
729  .rx = {
730  .gpio = GPIOC,
731  .init = {
732  .GPIO_Pin = GPIO_Pin_7,
733  .GPIO_Speed = GPIO_Speed_25MHz,
734  .GPIO_Mode = GPIO_Mode_AF,
735  .GPIO_OType = GPIO_OType_PP,
736  .GPIO_PuPd = GPIO_PuPd_UP
737  },
738  .pin_source = GPIO_PinSource7,
739  },
740  .tx = {
741  .gpio = GPIOC,
742  .init = {
743  .GPIO_Pin = GPIO_Pin_6,
744  .GPIO_Speed = GPIO_Speed_25MHz,
745  .GPIO_Mode = GPIO_Mode_AF,
746  .GPIO_OType = GPIO_OType_PP,
747  .GPIO_PuPd = GPIO_PuPd_UP
748  },
749  .pin_source = GPIO_PinSource6,
750  },
751 };
752 
753 #endif /* defined(PIOS_INCLUDE_USART) */
754 
755 #if defined(PIOS_INCLUDE_PPM)
756 /*
757  * PPM Input
758  */
759 // Timer 12 used for PPM input
760 #include "pios_tim_priv.h"
761 #include <pios_ppm_priv.h>
762 
763 static const TIM_TimeBaseInitTypeDef tim_12_time_base = {
764  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_COUNTER_CLOCK / 1000000) - 1,
765  .TIM_ClockDivision = TIM_CKD_DIV1,
766  .TIM_CounterMode = TIM_CounterMode_Up,
767  .TIM_Period = 0xFFFF,
768  .TIM_RepetitionCounter = 0x0000,
769 };
770 
771 static const struct pios_tim_clock_cfg tim_12_cfg = {
772  .timer = TIM12,
773  .time_base_init = &tim_12_time_base,
774  .irq = {
775  .init = {
776  .NVIC_IRQChannel = TIM8_BRK_TIM12_IRQn,
777  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
778  .NVIC_IRQChannelSubPriority = 0,
779  .NVIC_IRQChannelCmd = ENABLE,
780  },
781  },
782 };
783 
784 static const struct pios_tim_channel pios_tim_ppm_channel[] = {
785  {
786  .timer = TIM12,
787  .timer_chan = TIM_Channel_1,
788  .remap = GPIO_AF_TIM12,
789  .pin = {
790  .gpio = GPIOB,
791  .init = {
792  .GPIO_Pin = GPIO_Pin_14,
793  .GPIO_Speed = GPIO_Speed_2MHz,
794  .GPIO_Mode = GPIO_Mode_AF,
795  .GPIO_OType = GPIO_OType_PP,
796  .GPIO_PuPd = GPIO_PuPd_UP
797  },
798  .pin_source = GPIO_PinSource14,
799  },
800  },
801 };
802 
803 #include <pios_ppm_priv.h>
804 static const struct pios_ppm_cfg pios_ppm_cfg = {
805  .tim_ic_init = {
806  .TIM_ICPolarity = TIM_ICPolarity_Rising,
807  .TIM_ICSelection = TIM_ICSelection_DirectTI,
808  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
809  .TIM_ICFilter = 0x0,
810  .TIM_Channel = TIM_Channel_3,
811  },
812  .channels = &pios_tim_ppm_channel[0],
813  .num_channels = 1,
814 };
815 #endif /* PIOS_INCLUDE_PPM */
816 
817 #if defined(PIOS_INCLUDE_DSM)
818 /*
819  * Spektrum/JR DSM USART
820  */
821 #include <pios_dsm_priv.h>
822 
823 static const struct pios_dsm_cfg pios_rxport_dsm_cfg = {
824  .bind = {
825  .gpio = GPIOB,
826  .init = {
827  .GPIO_Pin = GPIO_Pin_14, // same pin as PPM input
828  .GPIO_Speed = GPIO_Speed_2MHz,
829  .GPIO_Mode = GPIO_Mode_OUT,
830  .GPIO_OType = GPIO_OType_PP,
831  .GPIO_PuPd = GPIO_PuPd_NOPULL
832  },
833  },
834 };
835 #endif /* defined(PIOS_INCLUDE_DSM) */
836 
837 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
838 
839 // TIme base for timers on APB1 (45MHz)
840 static const TIM_TimeBaseInitTypeDef tim_apb1_time_base = {
841  .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_COUNTER_CLOCK / 1000000) - 1,
842  .TIM_ClockDivision = TIM_CKD_DIV1,
843  .TIM_CounterMode = TIM_CounterMode_Up,
844  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
845  .TIM_RepetitionCounter = 0x0000,
846 };
847 
848 static const struct pios_tim_clock_cfg tim_5_cfg = {
849  .timer = TIM5,
850  .time_base_init = &tim_apb1_time_base,
851  .irq = {
852  .init = {
853  .NVIC_IRQChannel = TIM5_IRQn,
854  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
855  .NVIC_IRQChannelSubPriority = 0,
856  .NVIC_IRQChannelCmd = ENABLE,
857  },
858  },
859 };
860 
861 static const struct pios_tim_clock_cfg tim_8_cfg = {
862  .timer = TIM8,
863  .time_base_init = &tim_apb1_time_base,
864  .irq = {
865  .init = {
866  .NVIC_IRQChannel = TIM8_UP_TIM13_IRQn,
867  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
868  .NVIC_IRQChannelSubPriority = 0,
869  .NVIC_IRQChannelCmd = ENABLE,
870  },
871  },
872 };
873 
874 // TIme base for timers on APB2 (90MHz)
875 static const TIM_TimeBaseInitTypeDef tim_apb2_time_base = {
876  .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_COUNTER_CLOCK / 1000000) - 1,
877  .TIM_ClockDivision = TIM_CKD_DIV1,
878  .TIM_CounterMode = TIM_CounterMode_Up,
879  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
880  .TIM_RepetitionCounter = 0x0000,
881 };
882 
883 static const struct pios_tim_clock_cfg tim_1_cfg = {
884  .timer = TIM1,
885  .time_base_init = &tim_apb2_time_base,
886  .irq = {
887  .init = {
888  .NVIC_IRQChannel = TIM1_UP_TIM10_IRQn,
889  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
890  .NVIC_IRQChannelSubPriority = 0,
891  .NVIC_IRQChannelCmd = ENABLE,
892  },
893  },
894 };
895 
896 /*
897  * OUTPUTS
898  1: TIM5_CH1 (PA0)
899  2: TIM5_CH2 (PA1)
900  3: TIM5_CH3 (PA2)
901  4: TIM5_CH4 (PA3)
902  5: TIM1_CH3 (PA10)
903  6: TIM2_CH1 (PA8)
904  7: TIM8_CH1 (PC6)
905  8: TIM8_CH2 (PC7)
906  */
907 
908 static const struct pios_tim_channel pios_tim_servoport_all_pins[] = {
909  {
910  .timer = TIM5,
911  .timer_chan = TIM_Channel_1,
912  .remap = GPIO_AF_TIM5,
913  .pin = {
914  .gpio = GPIOA,
915  .init = {
916  .GPIO_Pin = GPIO_Pin_0,
917  .GPIO_Speed = GPIO_Speed_2MHz,
918  .GPIO_Mode = GPIO_Mode_AF,
919  .GPIO_OType = GPIO_OType_PP,
920  .GPIO_PuPd = GPIO_PuPd_UP
921  },
922  .pin_source = GPIO_PinSource0,
923  },
924  },
925  {
926  .timer = TIM5,
927  .timer_chan = TIM_Channel_2,
928  .remap = GPIO_AF_TIM5,
929  .pin = {
930  .gpio = GPIOA,
931  .init = {
932  .GPIO_Pin = GPIO_Pin_1,
933  .GPIO_Speed = GPIO_Speed_2MHz,
934  .GPIO_Mode = GPIO_Mode_AF,
935  .GPIO_OType = GPIO_OType_PP,
936  .GPIO_PuPd = GPIO_PuPd_UP
937  },
938  .pin_source = GPIO_PinSource1,
939  },
940  },
941  {
942  .timer = TIM5,
943  .timer_chan = TIM_Channel_3,
944  .remap = GPIO_AF_TIM5,
945  .pin = {
946  .gpio = GPIOA,
947  .init = {
948  .GPIO_Pin = GPIO_Pin_2,
949  .GPIO_Speed = GPIO_Speed_2MHz,
950  .GPIO_Mode = GPIO_Mode_AF,
951  .GPIO_OType = GPIO_OType_PP,
952  .GPIO_PuPd = GPIO_PuPd_UP
953  },
954  .pin_source = GPIO_PinSource2,
955  },
956  },
957  {
958  .timer = TIM5,
959  .timer_chan = TIM_Channel_4,
960  .remap = GPIO_AF_TIM5,
961  .pin = {
962  .gpio = GPIOA,
963  .init = {
964  .GPIO_Pin = GPIO_Pin_3,
965  .GPIO_Speed = GPIO_Speed_2MHz,
966  .GPIO_Mode = GPIO_Mode_AF,
967  .GPIO_OType = GPIO_OType_PP,
968  .GPIO_PuPd = GPIO_PuPd_UP
969  },
970  .pin_source = GPIO_PinSource3,
971  },
972  },
973  {
974  .timer = TIM1,
975  .timer_chan = TIM_Channel_3,
976  .remap = GPIO_AF_TIM1,
977  .pin = {
978  .gpio = GPIOA,
979  .init = {
980  .GPIO_Pin = GPIO_Pin_10,
981  .GPIO_Speed = GPIO_Speed_2MHz,
982  .GPIO_Mode = GPIO_Mode_AF,
983  .GPIO_OType = GPIO_OType_PP,
984  .GPIO_PuPd = GPIO_PuPd_UP
985  },
986  .pin_source = GPIO_PinSource10,
987  },
988  },
989  {
990  .timer = TIM2,
991  .timer_chan = TIM_Channel_1,
992  .remap = GPIO_AF_TIM2,
993  .pin = {
994  .gpio = GPIOA,
995  .init = {
996  .GPIO_Pin = GPIO_Pin_15,
997  .GPIO_Speed = GPIO_Speed_2MHz,
998  .GPIO_Mode = GPIO_Mode_AF,
999  .GPIO_OType = GPIO_OType_PP,
1000  .GPIO_PuPd = GPIO_PuPd_UP
1001  },
1002  .pin_source = GPIO_PinSource15,
1003  },
1004  },
1005  {
1006  .timer = TIM8,
1007  .timer_chan = TIM_Channel_1,
1008  .remap = GPIO_AF_TIM8,
1009  .pin = {
1010  .gpio = GPIOC,
1011  .init = {
1012  .GPIO_Pin = GPIO_Pin_6,
1013  .GPIO_Speed = GPIO_Speed_2MHz,
1014  .GPIO_Mode = GPIO_Mode_AF,
1015  .GPIO_OType = GPIO_OType_PP,
1016  .GPIO_PuPd = GPIO_PuPd_UP
1017  },
1018  .pin_source = GPIO_PinSource6,
1019  },
1020  },
1021  {
1022  .timer = TIM8,
1023  .timer_chan = TIM_Channel_2,
1024  .remap = GPIO_AF_TIM8,
1025  .pin = {
1026  .gpio = GPIOC,
1027  .init = {
1028  .GPIO_Pin = GPIO_Pin_7,
1029  .GPIO_Speed = GPIO_Speed_2MHz,
1030  .GPIO_Mode = GPIO_Mode_AF,
1031  .GPIO_OType = GPIO_OType_PP,
1032  .GPIO_PuPd = GPIO_PuPd_UP
1033  },
1034  .pin_source = GPIO_PinSource7,
1035  },
1036  }
1037 };
1038 
1039 #if defined(PIOS_INCLUDE_DMASHOT)
1040 
1041 #include <pios_dmashot.h>
1042 
1043 static const struct pios_dmashot_timer_cfg dmashot_tim_cfg[] = {
1044  {
1045  .timer = TIM5,
1046  .stream = DMA1_Stream6,
1047  .channel = DMA_Channel_6,
1048  .tcif = DMA_FLAG_TCIF6
1049  },
1050  {
1051  .timer = TIM1,
1052  .stream = DMA2_Stream5,
1053  .channel = DMA_Channel_6,
1054  .tcif = DMA_FLAG_TCIF5
1055  },
1056  {
1057  .timer = TIM2,
1058  .stream = DMA1_Stream7,
1059  .channel = DMA_Channel_3,
1060  .tcif = DMA_FLAG_TCIF7
1061  },
1062  {
1063  .timer = TIM8,
1064  .stream = DMA2_Stream1,
1065  .channel = DMA_Channel_7,
1066  .tcif = DMA_FLAG_TCIF1
1067  }
1068 };
1069 
1070 static const struct pios_dmashot_cfg dmashot_config = {
1071  .timer_cfg = &dmashot_tim_cfg[0],
1072  .num_timers = NELEMENTS(dmashot_tim_cfg)
1073 };
1074 
1075 #endif /* defined(PIOS_INCLUDE_DMASHOT) */
1076 
1077 /*
1078  * Servo outputs
1079  */
1080 #include <pios_servo_priv.h>
1081 
1082 const struct pios_servo_cfg pios_servo_4_cfg = {
1083  .tim_oc_init = {
1084  .TIM_OCMode = TIM_OCMode_PWM1,
1085  .TIM_OutputState = TIM_OutputState_Enable,
1086  .TIM_OutputNState = TIM_OutputNState_Disable,
1087  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1088  .TIM_OCPolarity = TIM_OCPolarity_High,
1089  .TIM_OCNPolarity = TIM_OCPolarity_High,
1090  .TIM_OCIdleState = TIM_OCIdleState_Reset,
1091  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1092  },
1093  .channels = &pios_tim_servoport_all_pins[2],
1094  .num_channels = NELEMENTS(pios_tim_servoport_all_pins) - 4,
1095 };
1096 
1097 const struct pios_servo_cfg pios_servo_6_cfg = {
1098  .tim_oc_init = {
1099  .TIM_OCMode = TIM_OCMode_PWM1,
1100  .TIM_OutputState = TIM_OutputState_Enable,
1101  .TIM_OutputNState = TIM_OutputNState_Disable,
1102  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1103  .TIM_OCPolarity = TIM_OCPolarity_High,
1104  .TIM_OCNPolarity = TIM_OCPolarity_High,
1105  .TIM_OCIdleState = TIM_OCIdleState_Reset,
1106  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1107  },
1108  .channels = pios_tim_servoport_all_pins,
1109  .num_channels = NELEMENTS(pios_tim_servoport_all_pins) - 2,
1110 };
1111 
1112 const struct pios_servo_cfg pios_servo_8_cfg = {
1113  .tim_oc_init = {
1114  .TIM_OCMode = TIM_OCMode_PWM1,
1115  .TIM_OutputState = TIM_OutputState_Enable,
1116  .TIM_OutputNState = TIM_OutputNState_Disable,
1117  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
1118  .TIM_OCPolarity = TIM_OCPolarity_High,
1119  .TIM_OCNPolarity = TIM_OCPolarity_High,
1120  .TIM_OCIdleState = TIM_OCIdleState_Reset,
1121  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
1122  },
1123  .channels = pios_tim_servoport_all_pins,
1124  .num_channels = NELEMENTS(pios_tim_servoport_all_pins),
1125 };
1126 #endif /* defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM) */
1127 
1128 #if defined(PIOS_INCLUDE_VIDEO_QUADSPI)
1129 #include <pios_video.h>
1130 #include "fpga_drv.h"
1131 
1132 static const struct pios_exti_cfg pios_exti_vsync_cfg __exti_config = {
1133  .vector = PIOS_Vsync_ISR,
1134  .line = EXTI_Line5,
1135  .pin = {
1136  .gpio = GPIOB,
1137  .init = {
1138  .GPIO_Pin = GPIO_Pin_5,
1139  .GPIO_Speed = GPIO_Speed_100MHz,
1140  .GPIO_Mode = GPIO_Mode_IN,
1141  .GPIO_OType = GPIO_OType_OD,
1142  .GPIO_PuPd = GPIO_PuPd_NOPULL,
1143  },
1144  },
1145  .irq = {
1146  .init = {
1147  .NVIC_IRQChannel = EXTI9_5_IRQn,
1148  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1149  .NVIC_IRQChannelSubPriority = 0,
1150  .NVIC_IRQChannelCmd = ENABLE,
1151  },
1152  },
1153  .exti = {
1154  .init = {
1155  .EXTI_Line = EXTI_Line5, // matches above GPIO pin
1156  .EXTI_Mode = EXTI_Mode_Interrupt,
1157  .EXTI_Trigger = EXTI_Trigger_Falling,
1158  .EXTI_LineCmd = ENABLE,
1159  },
1160  },
1161 };
1162 
1163 static const struct pios_exti_cfg pios_exti_hsync_cfg __exti_config = {
1165  .line = EXTI_Line2,
1166  .pin = {
1167  .gpio = GPIOC,
1168  .init = {
1169  .GPIO_Pin = GPIO_Pin_2,
1170  .GPIO_Speed = GPIO_Speed_100MHz,
1171  .GPIO_Mode = GPIO_Mode_IN,
1172  .GPIO_OType = GPIO_OType_OD,
1173  .GPIO_PuPd = GPIO_PuPd_NOPULL,
1174  },
1175  },
1176  .irq = {
1177  .init = {
1178  .NVIC_IRQChannel = EXTI2_IRQn,
1179  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1180  .NVIC_IRQChannelSubPriority = 0,
1181  .NVIC_IRQChannelCmd = ENABLE,
1182  },
1183  },
1184  .exti = {
1185  .init = {
1186  .EXTI_Line = EXTI_Line2, // matches above GPIO pin
1187  .EXTI_Mode = EXTI_Mode_Interrupt,
1188  .EXTI_Trigger = EXTI_Trigger_Falling,
1189  .EXTI_LineCmd = ENABLE,
1190  },
1191  },
1192 };
1193 
1194 const struct pios_video_cfg pios_video_cfg = {
1195  .qspi_init = {
1196  .QSPI_SShift = QSPI_SShift_NoShift,
1197  .QSPI_Prescaler = 12, // 180MHz / 12 = 15MHz
1198  .QSPI_CKMode = QSPI_CKMode_Mode0,
1199  .QSPI_CSHTime = QSPI_CSHTime_1Cycle,
1200  .QSPI_FSize = 0x1F,
1201  .QSPI_FSelect = QSPI_FSelect_1,
1202  .QSPI_DFlash = QSPI_DFlash_Disable,
1203  },
1204  .pixel_dma = DMA2,
1205  .dma = {
1206  .irq = {
1207  .flags = (DMA_IT_TCIF7),
1208  .init = {
1209  .NVIC_IRQChannel = DMA2_Stream7_IRQn,
1210  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1211  .NVIC_IRQChannelSubPriority = 0,
1212  .NVIC_IRQChannelCmd = ENABLE,
1213  },
1214  },
1215  /*.rx = {},*/
1216  .tx = {
1217  .channel = DMA2_Stream7,
1218  .init = {
1219  .DMA_Channel = DMA_Channel_3,
1220  .DMA_PeripheralBaseAddr = (uint32_t)&(QUADSPI->DR),
1221  .DMA_DIR = DMA_DIR_MemoryToPeripheral,
1222  .DMA_BufferSize = 400,
1223  .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
1224  .DMA_MemoryInc = DMA_MemoryInc_Enable,
1225  .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
1226  .DMA_MemoryDataSize = DMA_MemoryDataSize_Word,
1227  .DMA_Mode = DMA_Mode_Normal,
1228  .DMA_Priority = DMA_Priority_VeryHigh,
1229  .DMA_FIFOMode = DMA_FIFOMode_Enable,
1230  .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
1231  .DMA_MemoryBurst = DMA_MemoryBurst_INC4,
1232  .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
1233  },
1234  },
1235  },
1236  .sclk = {
1237  .gpio = GPIOB,
1238  .init = {
1239  .GPIO_Pin = GPIO_Pin_2,
1240  .GPIO_Speed = GPIO_Speed_100MHz,
1241  .GPIO_Mode = GPIO_Mode_AF,
1242  .GPIO_OType = GPIO_OType_PP,
1243  .GPIO_PuPd = GPIO_PuPd_NOPULL
1244  },
1245  },
1246  .bk1_io0 = {
1247  .gpio = GPIOC,
1248  .init = {
1249  .GPIO_Pin = GPIO_Pin_9,
1250  .GPIO_Speed = GPIO_Speed_100MHz,
1251  .GPIO_Mode = GPIO_Mode_AF,
1252  .GPIO_OType = GPIO_OType_PP,
1253  .GPIO_PuPd = GPIO_PuPd_NOPULL
1254  },
1255  },
1256  .bk1_io1 = {
1257  .gpio = GPIOC,
1258  .init = {
1259  .GPIO_Pin = GPIO_Pin_10,
1260  .GPIO_Speed = GPIO_Speed_100MHz,
1261  .GPIO_Mode = GPIO_Mode_AF,
1262  .GPIO_OType = GPIO_OType_PP,
1263  .GPIO_PuPd = GPIO_PuPd_NOPULL
1264  },
1265  },
1266 
1267  .vsync = &pios_exti_vsync_cfg,
1268  .hsync = &pios_exti_hsync_cfg,
1269  .set_bw_levels = PIOS_RE1FPGA_SetBwLevels,
1270  .set_x_offset = PIOS_RE1FPGA_SetXOffset,
1271  .set_x_scale = PIOS_RE1FPGA_SetXScale,
1272  .set_3d_config = PIOS_RE1FPGA_Set3DConfig,
1273 };
1274 #endif /* if defined(PIOS_INCLUDE_VIDEO) */
1275 
1276 #if defined(PIOS_INCLUDE_RE1_FPGA)
1277 #include "fpga_drv.h"
1278 
1279 const struct pios_re1fpga_cfg pios_re1fpga_cfg = {
1280  .mco_pin = {
1281  .gpio = GPIOA,
1282  .init = {
1283  .GPIO_Pin = GPIO_Pin_8,
1284  .GPIO_Speed = GPIO_Speed_100MHz,
1285  .GPIO_Mode = GPIO_Mode_AF,
1286  .GPIO_OType = GPIO_OType_PP,
1287  .GPIO_PuPd = GPIO_PuPd_UP
1288  },
1289  },
1290  .rst_pin = {
1291  .gpio = GPIOB,
1292  .init = {
1293  .GPIO_Pin = GPIO_Pin_10,
1294  .GPIO_Speed = GPIO_Speed_2MHz,
1295  .GPIO_Mode = GPIO_Mode_OUT,
1296  .GPIO_OType = GPIO_OType_PP,
1297  .GPIO_PuPd = GPIO_PuPd_DOWN
1298  },
1299  },
1300  .cdone_pin = {
1301  .gpio = GPIOB,
1302  .init = {
1303  .GPIO_Pin = GPIO_Pin_0,
1304  .GPIO_Speed = GPIO_Speed_2MHz,
1305  .GPIO_Mode = GPIO_Mode_IN,
1306  .GPIO_OType = GPIO_OType_PP,
1307  .GPIO_PuPd = GPIO_PuPd_UP
1308  },
1309  },
1310  .cresetb_pin = {
1311  .gpio = GPIOB,
1312  .init = {
1313  .GPIO_Pin = GPIO_Pin_1,
1314  .GPIO_Speed = GPIO_Speed_2MHz,
1315  .GPIO_Mode = GPIO_Mode_OUT,
1316  .GPIO_OType = GPIO_OType_PP,
1317  .GPIO_PuPd = GPIO_PuPd_UP
1318  },
1319  },
1320 };
1321 #endif /* defined(PIOS_INCLUDE_RE1_FPGA) */
1322 
1323 
1324 #if defined(PIOS_INCLUDE_BMI160)
1325 #include "pios_bmi160.h"
1326 
1327 static const struct pios_exti_cfg pios_exti_bmi160_cfg __exti_config = {
1329  .line = EXTI_Line13,
1330  .pin = {
1331  .gpio = GPIOC,
1332  .init = {
1333  .GPIO_Pin = GPIO_Pin_13,
1334  .GPIO_Speed = GPIO_Speed_2MHz, // XXXX
1335  .GPIO_Mode = GPIO_Mode_IN,
1336  .GPIO_OType = GPIO_OType_OD,
1337  .GPIO_PuPd = GPIO_PuPd_NOPULL,
1338  },
1339  },
1340  .irq = {
1341  .init = {
1342  .NVIC_IRQChannel = EXTI15_10_IRQn,
1343  .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1344  .NVIC_IRQChannelSubPriority = 0,
1345  .NVIC_IRQChannelCmd = ENABLE,
1346  },
1347  },
1348  .exti = {
1349  .init = {
1350  .EXTI_Line = EXTI_Line13, // matches above GPIO pin
1351  .EXTI_Mode = EXTI_Mode_Interrupt,
1352  .EXTI_Trigger = EXTI_Trigger_Rising,
1353  .EXTI_LineCmd = ENABLE,
1354  },
1355  },
1356 };
1357 
1358 static const struct pios_bmi160_cfg pios_bmi160_cfg = {
1359  .exti_cfg = &pios_exti_bmi160_cfg,
1360  .orientation = PIOS_BMI160_TOP_0DEG,
1361  .odr = PIOS_BMI160_ODR_1600_Hz,
1362  .acc_range = PIOS_BMI160_RANGE_8G,
1363  .gyro_range = PIOS_BMI160_RANGE_2000DPS,
1364  .temperature_interleaving = 50
1365 };
1366 #endif /* PIOS_INCLUDE_BMI160 */
1367 
void PIOS_RE1FPGA_SetBwLevels(uint8_t black, uint8_t white)
struct stm32_gpio pin
#define DMA2_Stream4_IRQHandler
const struct pios_dmashot_timer_cfg * timer_cfg
Definition: pios_dmashot.h:68
Main PiOS header to include all the compiled in PiOS options.
static const TIM_TimeBaseInitTypeDef tim_apb2_time_base
const struct pios_flash_driver pios_jedec_flash_driver
SPI private definitions.
#define NELEMENTS(x)
Definition: pios.h:192
TIM_TypeDef * timer
Definition: pios_dmashot.h:53
struct stm32_gpio bind
OSD gen module, handles OSD draw. Parts from CL-OSD and SUPEROSD projects.
COM private definitions.
COM MSG private definitions.
APIs for PIOS_USBHOOK layer.
static const struct pios_tim_channel pios_tim_servoport_all_pins[]
GPIO_TypeDef * gpio
Definition: pios_stm32.h:60
const struct pios_servo_cfg pios_servo_8_cfg
Brushed Sparky skips last two output ports.
I2C_TypeDef * regs
Definition: pios_i2c_priv.h:37
ADC private definitions.
#define PIOS_IRQ_PRIO_HIGHEST
Definition: pios_board.h:172
#define JEDEC_MANUFACTURER_SPANSION
#define PIOS_SERVOS_INITIAL_POSITION
Definition: pios_board.h:210
#define FLASH_SECTOR_4KB
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.
int32_t PIOS_RE1FPGA_Buzzer(bool enable)
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
USART private definitions.
void PIOS_RE1FPGA_SetXOffset(int8_t x_offset)
Spektrum/JR DSMx satellite receiver private structures.
void PIOS_RE1FPGA_SetXScale(uint8_t x_scale)
#define FLASH_SECTOR_64KB
Driver for talking to most JEDEC flash chips.
#define PIOS_SERVO_UPDATE_HZ
Definition: pios_board.h:209
static const struct pios_tim_clock_cfg tim_5_cfg
static const TIM_TimeBaseInitTypeDef tim_apb1_time_base
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
const struct pios_annunc * annunciators
void PIOS_I2C_EV_IRQ_Handler(pios_i2c_t i2c_id)
bool PIOS_BMI160_IRQHandler(void)
ppm private structures.
NVIC_InitTypeDef init
Definition: pios_stm32.h:36
#define I2C1_ER_IRQHandler
static const struct pios_tim_clock_cfg tim_1_cfg
#define PIOS_INCLUDE_FLASH_JEDEC
Definition: pios_config.h:44
bool PIOS_Hsync_ISR()
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
void PIOS_I2C_ER_IRQ_Handler(pios_i2c_t i2c_id)
TIM_ICInitTypeDef tim_ic_init
Definition: pios_ppm_priv.h:37
Defines the API to set up the HID-only USB descriptor config.
static const struct pios_tim_clock_cfg tim_12_cfg
void PIOS_RTC_irq_handler(void)
const struct pios_flash_driver * driver
const struct pios_flash_partition pios_flash_partition_table[]
Definition: unittest_init.c:50
const struct pios_exti_cfg * exti_cfg
Definition: pios_bmi160.h:70
bool PIOS_Vsync_ISR()
TIM_TypeDef * timer
Definition: pios_tim_priv.h:14
void PIOS_RE1FPGA_Set3DConfig(enum pios_video_3d_mode mode, uint8_t x_shift_right)
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
static const TIM_TimeBaseInitTypeDef tim_12_time_base
#define PIOS_Assert(test)
Definition: pios_debug.h:52
struct stm32_gpio mco_pin
Definition: fpga_drv.h:39
LED private definitions.
#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.