Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / targets / boards / discoveryf4bare / board_hw_defs.c
blobb733c6f6fc30b8f9a95b11647f42bf38b4ba4a33
1 /**
2 ******************************************************************************
3 * @file board_hw_defs.c
4 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
5 * @author PhoenixPilot, http://github.com/PhoenixPilot, Copyright (C) 2012
6 * @addtogroup OpenPilotSystem OpenPilot System
7 * @{
8 * @addtogroup OpenPilotCore OpenPilot Core
9 * @{
10 * @brief Defines board specific static initializers for hardware for the Revolution board.
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #if defined(PIOS_INCLUDE_LED)
30 #include <pios_led_priv.h>
31 static const struct pios_gpio pios_leds[] = {
32 [PIOS_LED_HEARTBEAT] = {
33 .pin = {
34 .gpio = GPIOD,
35 .init = {
36 .GPIO_Pin = GPIO_Pin_15,
37 .GPIO_Speed = GPIO_Speed_50MHz,
38 .GPIO_Mode = GPIO_Mode_OUT,
39 .GPIO_OType = GPIO_OType_PP,
40 .GPIO_PuPd = GPIO_PuPd_UP
43 .active_low = false
45 [PIOS_LED_ALARM] = {
46 .pin = {
47 .gpio = GPIOD,
48 .init = {
49 .GPIO_Pin = GPIO_Pin_14,
50 .GPIO_Speed = GPIO_Speed_50MHz,
51 .GPIO_Mode = GPIO_Mode_OUT,
52 .GPIO_OType = GPIO_OType_PP,
53 .GPIO_PuPd = GPIO_PuPd_UP
56 .active_low = false
58 [PIOS_LED_D1] = {
59 .pin = {
60 .gpio = GPIOD,
61 .init = {
62 .GPIO_Pin = GPIO_Pin_13,
63 .GPIO_Speed = GPIO_Speed_50MHz,
64 .GPIO_Mode = GPIO_Mode_OUT,
65 .GPIO_OType = GPIO_OType_PP,
66 .GPIO_PuPd = GPIO_PuPd_UP
69 .active_low = false
71 [PIOS_LED_D2] = {
72 .pin = {
73 .gpio = GPIOD,
74 .init = {
75 .GPIO_Pin = GPIO_Pin_12,
76 .GPIO_Speed = GPIO_Speed_50MHz,
77 .GPIO_Mode = GPIO_Mode_OUT,
78 .GPIO_OType = GPIO_OType_PP,
79 .GPIO_PuPd = GPIO_PuPd_UP
82 .active_low = false
86 static const struct pios_gpio_cfg pios_led_cfg = {
87 .gpios = pios_leds,
88 .num_gpios = NELEMENTS(pios_leds),
92 const struct pios_gpio_cfg *PIOS_BOARD_HW_DEFS_GetLedCfg(__attribute__((unused)) uint32_t board_revision)
94 return &pios_led_cfg;
97 #endif /* PIOS_INCLUDE_LED */
99 #if defined(PIOS_INCLUDE_SPI)
100 #include <pios_spi_priv.h>
102 #if defined(PIOS_OVERO_SPI)
103 /* SPI2 Interface
104 * - Used for Flexi/IO/Overo communications
105 3: PB12 = SPI2 NSS, CAN2 RX
106 4: PB13 = SPI2 SCK, CAN2 TX, USART3 CTS
107 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
108 6: PB15 = SPI2 MOSI, TIM12 CH2
110 #include <pios_overo_priv.h>
111 void PIOS_OVERO_irq_handler(void);
112 void DMA1_Stream7_IRQHandler(void) __attribute__((alias("PIOS_OVERO_irq_handler")));
113 static const struct pios_overo_cfg pios_overo_cfg = {
114 .regs = SPI2,
115 .remap = GPIO_AF_SPI2,
116 .init = {
117 .SPI_Mode = SPI_Mode_Slave,
118 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
119 .SPI_DataSize = SPI_DataSize_8b,
120 .SPI_NSS = SPI_NSS_Hard,
121 .SPI_FirstBit = SPI_FirstBit_MSB,
122 .SPI_CRCPolynomial = 7,
123 .SPI_CPOL = SPI_CPOL_High,
124 .SPI_CPHA = SPI_CPHA_2Edge,
125 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2,
127 .use_crc = false,
128 .dma = {
129 .irq = {
130 // Note this is the stream ID that triggers interrupts (in this case TX)
131 .flags = (DMA_IT_TCIF7),
132 .init = {
133 .NVIC_IRQChannel = DMA1_Stream7_IRQn,
134 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
135 .NVIC_IRQChannelSubPriority = 0,
136 .NVIC_IRQChannelCmd = ENABLE,
140 .rx = {
141 .channel = DMA1_Stream0,
142 .init = {
143 .DMA_Channel = DMA_Channel_0,
144 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
145 .DMA_DIR = DMA_DIR_PeripheralToMemory,
146 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
147 .DMA_MemoryInc = DMA_MemoryInc_Enable,
148 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
149 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
150 .DMA_Mode = DMA_Mode_Circular,
151 .DMA_Priority = DMA_Priority_Medium,
152 // TODO: Enable FIFO
153 .DMA_FIFOMode = DMA_FIFOMode_Disable,
154 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
155 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
156 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
159 .tx = {
160 .channel = DMA1_Stream7,
161 .init = {
162 .DMA_Channel = DMA_Channel_0,
163 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR),
164 .DMA_DIR = DMA_DIR_MemoryToPeripheral,
165 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
166 .DMA_MemoryInc = DMA_MemoryInc_Enable,
167 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
168 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
169 .DMA_Mode = DMA_Mode_Circular,
170 .DMA_Priority = DMA_Priority_Medium,
171 .DMA_FIFOMode = DMA_FIFOMode_Disable,
172 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
173 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
174 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
178 .sclk = {
179 .gpio = GPIOB,
180 .init = {
181 .GPIO_Pin = GPIO_Pin_13,
182 .GPIO_Speed = GPIO_Speed_100MHz,
183 .GPIO_Mode = GPIO_Mode_AF,
184 .GPIO_OType = GPIO_OType_PP,
185 .GPIO_PuPd = GPIO_PuPd_NOPULL
188 .miso = {
189 .gpio = GPIOB,
190 .init = {
191 .GPIO_Pin = GPIO_Pin_14,
192 .GPIO_Speed = GPIO_Speed_50MHz,
193 .GPIO_Mode = GPIO_Mode_AF,
194 .GPIO_OType = GPIO_OType_PP,
195 .GPIO_PuPd = GPIO_PuPd_NOPULL
198 .mosi = {
199 .gpio = GPIOB,
200 .init = {
201 .GPIO_Pin = GPIO_Pin_15,
202 .GPIO_Speed = GPIO_Speed_50MHz,
203 .GPIO_Mode = GPIO_Mode_AF,
204 .GPIO_OType = GPIO_OType_PP,
205 .GPIO_PuPd = GPIO_PuPd_NOPULL
208 .slave_count = 1,
209 .ssel = {
211 .gpio = GPIOB,
212 .init = {
213 .GPIO_Pin = GPIO_Pin_12,
214 .GPIO_Speed = GPIO_Speed_50MHz,
215 .GPIO_Mode = GPIO_Mode_OUT,
216 .GPIO_OType = GPIO_OType_PP,
217 .GPIO_PuPd = GPIO_PuPd_UP
222 uint32_t pios_overo_id = 0;
223 void PIOS_OVERO_irq_handler(void)
225 /* Call into the generic code to handle the IRQ for this specific device */
226 PIOS_OVERO_DMA_irq_handler(pios_overo_id);
229 #endif /* PIOS_OVERO_SPI */
232 * SPI1 Interface
233 * Used for MPU6000 gyro and accelerometer
235 void PIOS_SPI_gyro_irq_handler(void);
236 void DMA2_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
237 void DMA2_Stream3_IRQHandler(void) __attribute__((alias("PIOS_SPI_gyro_irq_handler")));
238 static const struct pios_spi_cfg pios_spi_gyro_cfg = {
239 .regs = SPI1,
240 .remap = GPIO_AF_SPI1,
241 .init = {
242 .SPI_Mode = SPI_Mode_Master,
243 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
244 .SPI_DataSize = SPI_DataSize_8b,
245 .SPI_NSS = SPI_NSS_Soft,
246 .SPI_FirstBit = SPI_FirstBit_MSB,
247 .SPI_CRCPolynomial = 7,
248 .SPI_CPOL = SPI_CPOL_High,
249 .SPI_CPHA = SPI_CPHA_2Edge,
250 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16,
252 .use_crc = false,
253 .dma = {
254 .irq = {
255 .flags = (DMA_IT_TCIF0 | DMA_IT_TEIF0 | DMA_IT_HTIF0),
256 .init = {
257 .NVIC_IRQChannel = DMA2_Stream0_IRQn,
258 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
259 .NVIC_IRQChannelSubPriority = 0,
260 .NVIC_IRQChannelCmd = ENABLE,
264 .rx = {
265 .channel = DMA2_Stream0,
266 .init = {
267 .DMA_Channel = DMA_Channel_3,
268 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
269 .DMA_DIR = DMA_DIR_PeripheralToMemory,
270 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
271 .DMA_MemoryInc = DMA_MemoryInc_Enable,
272 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
273 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
274 .DMA_Mode = DMA_Mode_Normal,
275 .DMA_Priority = DMA_Priority_Medium,
276 .DMA_FIFOMode = DMA_FIFOMode_Disable,
277 /* .DMA_FIFOThreshold */
278 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
279 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
282 .tx = {
283 .channel = DMA2_Stream3,
284 .init = {
285 .DMA_Channel = DMA_Channel_3,
286 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR),
287 .DMA_DIR = DMA_DIR_MemoryToPeripheral,
288 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
289 .DMA_MemoryInc = DMA_MemoryInc_Enable,
290 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
291 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
292 .DMA_Mode = DMA_Mode_Normal,
293 .DMA_Priority = DMA_Priority_High,
294 .DMA_FIFOMode = DMA_FIFOMode_Disable,
295 /* .DMA_FIFOThreshold */
296 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
297 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
301 .sclk = {
302 .gpio = GPIOA,
303 .init = {
304 .GPIO_Pin = GPIO_Pin_5,
305 .GPIO_Speed = GPIO_Speed_100MHz,
306 .GPIO_Mode = GPIO_Mode_AF,
307 .GPIO_OType = GPIO_OType_PP,
308 .GPIO_PuPd = GPIO_PuPd_UP
311 .miso = {
312 .gpio = GPIOA,
313 .init = {
314 .GPIO_Pin = GPIO_Pin_6,
315 .GPIO_Speed = GPIO_Speed_50MHz,
316 .GPIO_Mode = GPIO_Mode_AF,
317 .GPIO_OType = GPIO_OType_PP,
318 .GPIO_PuPd = GPIO_PuPd_UP
321 .mosi = {
322 .gpio = GPIOA,
323 .init = {
324 .GPIO_Pin = GPIO_Pin_7,
325 .GPIO_Speed = GPIO_Speed_50MHz,
326 .GPIO_Mode = GPIO_Mode_AF,
327 .GPIO_OType = GPIO_OType_PP,
328 .GPIO_PuPd = GPIO_PuPd_UP
331 .slave_count = 1,
332 .ssel = {
334 .gpio = GPIOA,
335 .init = {
336 .GPIO_Pin = GPIO_Pin_4,
337 .GPIO_Speed = GPIO_Speed_50MHz,
338 .GPIO_Mode = GPIO_Mode_OUT,
339 .GPIO_OType = GPIO_OType_PP,
340 .GPIO_PuPd = GPIO_PuPd_UP
346 uint32_t pios_spi_gyro_adapter_id;
347 void PIOS_SPI_gyro_irq_handler(void)
349 /* Call into the generic code to handle the IRQ for this specific device */
350 PIOS_SPI_IRQ_Handler(pios_spi_gyro_adapter_id);
354 #ifdef PIOS_INCLUDE_RFM22B
356 * SPI3 Interface
357 * Used for Flash and the RFM22B
359 void PIOS_SPI_telem_flash_irq_handler(void);
360 void DMA1_Stream0_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
361 void DMA1_Stream5_IRQHandler(void) __attribute__((alias("PIOS_SPI_telem_flash_irq_handler")));
362 static const struct pios_spi_cfg pios_spi_telem_flash_cfg = {
363 .regs = SPI3,
364 .remap = GPIO_AF_SPI3,
365 .init = {
366 .SPI_Mode = SPI_Mode_Master,
367 .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
368 .SPI_DataSize = SPI_DataSize_8b,
369 .SPI_NSS = SPI_NSS_Soft,
370 .SPI_FirstBit = SPI_FirstBit_MSB,
371 .SPI_CRCPolynomial = 7,
372 .SPI_CPOL = SPI_CPOL_Low,
373 .SPI_CPHA = SPI_CPHA_1Edge,
374 .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8,
376 .use_crc = false,
377 .dma = {
378 .irq = {
379 // Note this is the stream ID that triggers interrupts (in this case RX)
380 .flags = (DMA_IT_TCIF0 | DMA_IT_TEIF0 | DMA_IT_HTIF0),
381 .init = {
382 .NVIC_IRQChannel = DMA1_Stream0_IRQn,
383 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
384 .NVIC_IRQChannelSubPriority = 0,
385 .NVIC_IRQChannelCmd = ENABLE,
389 .rx = {
390 .channel = DMA1_Stream0,
391 .init = {
392 .DMA_Channel = DMA_Channel_0,
393 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI3->DR),
394 .DMA_DIR = DMA_DIR_PeripheralToMemory,
395 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
396 .DMA_MemoryInc = DMA_MemoryInc_Enable,
397 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
398 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
399 .DMA_Mode = DMA_Mode_Normal,
400 .DMA_Priority = DMA_Priority_Medium,
401 // TODO: Enable FIFO
402 .DMA_FIFOMode = DMA_FIFOMode_Disable,
403 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
404 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
405 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
408 .tx = {
409 .channel = DMA1_Stream5,
410 .init = {
411 .DMA_Channel = DMA_Channel_0,
412 .DMA_PeripheralBaseAddr = (uint32_t)&(SPI3->DR),
413 .DMA_DIR = DMA_DIR_MemoryToPeripheral,
414 .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
415 .DMA_MemoryInc = DMA_MemoryInc_Enable,
416 .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
417 .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
418 .DMA_Mode = DMA_Mode_Normal,
419 .DMA_Priority = DMA_Priority_Medium,
420 .DMA_FIFOMode = DMA_FIFOMode_Disable,
421 .DMA_FIFOThreshold = DMA_FIFOThreshold_Full,
422 .DMA_MemoryBurst = DMA_MemoryBurst_Single,
423 .DMA_PeripheralBurst = DMA_PeripheralBurst_Single,
427 .sclk = {
428 .gpio = GPIOC,
429 .init = {
430 .GPIO_Pin = GPIO_Pin_10,
431 .GPIO_Speed = GPIO_Speed_100MHz,
432 .GPIO_Mode = GPIO_Mode_AF,
433 .GPIO_OType = GPIO_OType_PP,
434 .GPIO_PuPd = GPIO_PuPd_NOPULL
437 .miso = {
438 .gpio = GPIOC,
439 .init = {
440 .GPIO_Pin = GPIO_Pin_11,
441 .GPIO_Speed = GPIO_Speed_50MHz,
442 .GPIO_Mode = GPIO_Mode_AF,
443 .GPIO_OType = GPIO_OType_PP,
444 .GPIO_PuPd = GPIO_PuPd_NOPULL
447 .mosi = {
448 .gpio = GPIOC,
449 .init = {
450 .GPIO_Pin = GPIO_Pin_12,
451 .GPIO_Speed = GPIO_Speed_50MHz,
452 .GPIO_Mode = GPIO_Mode_AF,
453 .GPIO_OType = GPIO_OType_PP,
454 .GPIO_PuPd = GPIO_PuPd_NOPULL
457 .slave_count = 2,
458 .ssel = {
459 { // RFM22b
460 .gpio = GPIOA,
461 .init = {
462 .GPIO_Pin = GPIO_Pin_15,
463 .GPIO_Speed = GPIO_Speed_50MHz,
464 .GPIO_Mode = GPIO_Mode_OUT,
465 .GPIO_OType = GPIO_OType_PP,
466 .GPIO_PuPd = GPIO_PuPd_UP
469 { // Flash
470 .gpio = GPIOB,
471 .init = {
472 .GPIO_Pin = GPIO_Pin_3,
473 .GPIO_Speed = GPIO_Speed_50MHz,
474 .GPIO_Mode = GPIO_Mode_OUT,
475 .GPIO_OType = GPIO_OType_PP,
476 .GPIO_PuPd = GPIO_PuPd_UP
482 uint32_t pios_spi_telem_flash_adapter_id;
483 void PIOS_SPI_telem_flash_irq_handler(void)
485 /* Call into the generic code to handle the IRQ for this specific device */
486 PIOS_SPI_IRQ_Handler(pios_spi_telem_flash_adapter_id);
490 #if defined(PIOS_INCLUDE_RFM22B)
491 #include <pios_rfm22b_priv.h>
493 static const struct pios_exti_cfg pios_exti_rfm22b_cfg __exti_config = {
494 .vector = PIOS_RFM22_EXT_Int,
495 .line = EXTI_Line2,
496 .pin = {
497 .gpio = GPIOD,
498 .init = {
499 .GPIO_Pin = GPIO_Pin_2,
500 .GPIO_Speed = GPIO_Speed_100MHz,
501 .GPIO_Mode = GPIO_Mode_IN,
502 .GPIO_OType = GPIO_OType_OD,
503 .GPIO_PuPd = GPIO_PuPd_NOPULL,
506 .irq = {
507 .init = {
508 .NVIC_IRQChannel = EXTI2_IRQn,
509 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
510 .NVIC_IRQChannelSubPriority = 0,
511 .NVIC_IRQChannelCmd = ENABLE,
514 .exti = {
515 .init = {
516 .EXTI_Line = EXTI_Line2, // matches above GPIO pin
517 .EXTI_Mode = EXTI_Mode_Interrupt,
518 .EXTI_Trigger = EXTI_Trigger_Falling,
519 .EXTI_LineCmd = ENABLE,
524 const struct pios_rfm22b_cfg pios_rfm22b_rm1_cfg = {
525 .spi_cfg = &pios_spi_telem_flash_cfg,
526 .exti_cfg = &pios_exti_rfm22b_cfg,
527 .RFXtalCap = 0x7f,
528 .slave_num = 0,
529 .gpio_direction = GPIO0_RX_GPIO1_TX,
532 const struct pios_rfm22b_cfg pios_rfm22b_rm2_cfg = {
533 .spi_cfg = &pios_spi_telem_flash_cfg,
534 .exti_cfg = &pios_exti_rfm22b_cfg,
535 .RFXtalCap = 0x7f,
536 .slave_num = 0,
537 .gpio_direction = GPIO0_TX_GPIO1_RX,
540 const struct pios_rfm22b_cfg *PIOS_BOARD_HW_DEFS_GetRfm22bCfg(uint32_t board_revision)
542 switch (board_revision) {
543 case 2:
544 return &pios_rfm22b_rm1_cfg;
546 break;
547 case 3:
548 return &pios_rfm22b_rm2_cfg;
550 break;
551 default:
552 PIOS_DEBUG_Assert(0);
554 return NULL;
557 #endif /* PIOS_INCLUDE_RFM22B */
558 #endif /* false */
559 #endif /* PIOS_INCLUDE_SPI */
561 #if defined(PIOS_INCLUDE_FLASH)
562 #include "pios_flashfs_logfs_priv.h"
563 #include "pios_flash_jedec_priv.h"
564 #include "pios_flash_internal_priv.h"
566 static const struct flashfs_logfs_cfg flashfs_external_cfg = {
567 .fs_magic = 0x99abceef,
568 .total_fs_size = 0x00200000, /* 2M bytes (32 sectors = entire chip) */
569 .arena_size = 0x00010000, /* 256 * slot size */
570 .slot_size = 0x00000100, /* 256 bytes */
572 .start_offset = 0, /* start at the beginning of the chip */
573 .sector_size = 0x00010000, /* 64K bytes */
574 .page_size = 0x00000100, /* 256 bytes */
578 static const struct pios_flash_internal_cfg flash_internal_system_cfg = {};
580 static const struct flashfs_logfs_cfg flashfs_internal_cfg = {
581 .fs_magic = 0x99abcfef,
582 .total_fs_size = EE_BANK_SIZE, /* 32K bytes (2x16KB sectors) */
583 .arena_size = 0x00004000, /* 64 * slot size = 16K bytes = 1 sector */
584 .slot_size = 0x00000100, /* 256 bytes */
586 .start_offset = EE_BANK_BASE, /* start after the bootloader */
587 .sector_size = 0x00004000, /* 16K bytes */
588 .page_size = 0x00004000, /* 16K bytes */
591 static const struct flashfs_logfs_cfg flashfs_internal_user_cfg = {
592 .fs_magic = 0x99abcfef,
593 .total_fs_size = USER_EE_BANK_SIZE, /* 128K bytes (2x16KB sectors) */
594 .arena_size = 0x00020000, /* 64 * slot size = 16K bytes = 1 sector */
595 .slot_size = 0x00000100, /* 256 bytes */
597 .start_offset = USER_EE_BANK_BASE, /* start after the bootloader */
598 .sector_size = 0x00020000, /* 128K bytes */
599 .page_size = 0x00020000, /* 128K bytes */
601 #endif /* PIOS_INCLUDE_FLASH */
603 #ifdef PIOS_INCLUDE_USART
604 #include <pios_usart_priv.h>
607 * MAIN USART
610 static const struct pios_usart_cfg pios_usart_main_cfg = {
611 .regs = USART1,
612 .remap = GPIO_AF_USART1,
613 .rx = {
614 .gpio = GPIOA,
615 .init = {
616 .GPIO_Pin = GPIO_Pin_10,
617 .GPIO_Speed = GPIO_Speed_2MHz,
618 .GPIO_Mode = GPIO_Mode_AF,
619 .GPIO_OType = GPIO_OType_PP,
620 .GPIO_PuPd = GPIO_PuPd_UP
623 .tx = {
624 .gpio = GPIOA,
625 .init = {
626 .GPIO_Pin = GPIO_Pin_9,
627 .GPIO_Speed = GPIO_Speed_2MHz,
628 .GPIO_Mode = GPIO_Mode_AF,
629 .GPIO_OType = GPIO_OType_PP,
630 .GPIO_PuPd = GPIO_PuPd_UP
636 * FLEXI PORT
638 static const struct pios_usart_cfg pios_usart_flexi_cfg = {
639 .regs = USART3,
640 .remap = GPIO_AF_USART3,
641 .rx = {
642 .gpio = GPIOB,
643 .init = {
644 .GPIO_Pin = GPIO_Pin_11,
645 .GPIO_Speed = GPIO_Speed_2MHz,
646 .GPIO_Mode = GPIO_Mode_AF,
647 .GPIO_OType = GPIO_OType_PP,
648 .GPIO_PuPd = GPIO_PuPd_UP
651 .tx = {
652 .gpio = GPIOB,
653 .init = {
654 .GPIO_Pin = GPIO_Pin_10,
655 .GPIO_Speed = GPIO_Speed_2MHz,
656 .GPIO_Mode = GPIO_Mode_AF,
657 .GPIO_OType = GPIO_OType_PP,
658 .GPIO_PuPd = GPIO_PuPd_UP
664 static const struct pios_usart_cfg pios_usart_flexiio_cfg = {
665 .regs = USART6,
666 .remap = GPIO_AF_USART6,
667 .dtr = {
668 // FlexIO pin 9
669 .gpio = GPIOC,
670 .init = {
671 .GPIO_Pin = GPIO_Pin_8,
672 .GPIO_Speed = GPIO_Speed_25MHz,
673 .GPIO_Mode = GPIO_Mode_OUT,
674 .GPIO_OType = GPIO_OType_PP,
678 .tx = {
679 // * 7: PC6 = TIM8 CH1, USART6 TX
680 .gpio = GPIOC,
681 .init = {
682 .GPIO_Pin = GPIO_Pin_6,
683 .GPIO_Speed = GPIO_Speed_2MHz,
684 .GPIO_Mode = GPIO_Mode_AF,
685 .GPIO_OType = GPIO_OType_PP,
686 .GPIO_PuPd = GPIO_PuPd_UP
688 .pin_source = GPIO_PinSource6,
691 .rx = {
692 // * 8: PC7 = TIM8 CH2, USART6 RX
693 .gpio = GPIOC,
694 .init = {
695 .GPIO_Pin = GPIO_Pin_7,
696 .GPIO_Speed = GPIO_Speed_2MHz,
697 .GPIO_Mode = GPIO_Mode_AF,
698 .GPIO_OType = GPIO_OType_PP,
699 .GPIO_PuPd = GPIO_PuPd_UP
701 .pin_source = GPIO_PinSource7,
704 #endif /* PIOS_INCLUDE_USART */
706 #if defined(PIOS_INCLUDE_COM)
708 #include <pios_com_priv.h>
710 #endif /* PIOS_INCLUDE_COM */
712 #if defined(PIOS_INCLUDE_I2C)
714 #include <pios_i2c_priv.h>
717 * I2C Adapters
719 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void);
720 void PIOS_I2C_mag_pressureadapter_er_irq_handler(void);
721 void I2C1_EV_IRQHandler()
722 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_ev_irq_handler")));
723 void I2C1_ER_IRQHandler()
724 __attribute__((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler")));
726 static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg = {
727 .regs = I2C1,
728 .remapSCL = GPIO_AF_I2C1,
729 .remapSDA = GPIO_AF_I2C1,
730 .init = {
731 .I2C_Mode = I2C_Mode_I2C,
732 .I2C_OwnAddress1 = 0,
733 .I2C_Ack = I2C_Ack_Enable,
734 .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
735 .I2C_DutyCycle = I2C_DutyCycle_2,
736 .I2C_ClockSpeed = 400000, /* bits/s */
738 .transfer_timeout_ms = 50,
739 .scl = {
740 .gpio = GPIOB,
741 .init = {
742 .GPIO_Pin = GPIO_Pin_8,
743 .GPIO_Mode = GPIO_Mode_AF,
744 .GPIO_Speed = GPIO_Speed_50MHz,
745 .GPIO_OType = GPIO_OType_OD,
746 .GPIO_PuPd = GPIO_PuPd_NOPULL,
749 .sda = {
750 .gpio = GPIOB,
751 .init = {
752 .GPIO_Pin = GPIO_Pin_9,
753 .GPIO_Mode = GPIO_Mode_AF,
754 .GPIO_Speed = GPIO_Speed_50MHz,
755 .GPIO_OType = GPIO_OType_OD,
756 .GPIO_PuPd = GPIO_PuPd_NOPULL,
759 .event = {
760 .flags = 0, /* FIXME: check this */
761 .init = {
762 .NVIC_IRQChannel = I2C1_EV_IRQn,
763 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
764 .NVIC_IRQChannelSubPriority = 0,
765 .NVIC_IRQChannelCmd = ENABLE,
768 .error = {
769 .flags = 0, /* FIXME: check this */
770 .init = {
771 .NVIC_IRQChannel = I2C1_ER_IRQn,
772 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
773 .NVIC_IRQChannelSubPriority = 0,
774 .NVIC_IRQChannelCmd = ENABLE,
779 uint32_t pios_i2c_mag_pressure_adapter_id;
780 void PIOS_I2C_mag_pressure_adapter_ev_irq_handler(void)
782 /* Call into the generic code to handle the IRQ for this specific device */
783 PIOS_I2C_EV_IRQ_Handler(pios_i2c_mag_pressure_adapter_id);
786 void PIOS_I2C_mag_pressure_adapter_er_irq_handler(void)
788 /* Call into the generic code to handle the IRQ for this specific device */
789 PIOS_I2C_ER_IRQ_Handler(pios_i2c_mag_pressure_adapter_id);
793 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void);
794 void PIOS_I2C_flexiport_adapter_er_irq_handler(void);
795 void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_irq_handler")));
796 void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler")));
798 static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = {
799 .regs = I2C2,
800 .remapSCL = GPIO_AF_I2C2,
801 .remapSDA = GPIO_AF_I2C2,
802 .init = {
803 .I2C_Mode = I2C_Mode_I2C,
804 .I2C_OwnAddress1 = 0,
805 .I2C_Ack = I2C_Ack_Enable,
806 .I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit,
807 .I2C_DutyCycle = I2C_DutyCycle_2,
808 .I2C_ClockSpeed = 400000, /* bits/s */
810 .transfer_timeout_ms = 50,
811 .scl = {
812 .gpio = GPIOB,
813 .init = {
814 .GPIO_Pin = GPIO_Pin_10,
815 .GPIO_Mode = GPIO_Mode_AF,
816 .GPIO_Speed = GPIO_Speed_50MHz,
817 .GPIO_OType = GPIO_OType_OD,
818 .GPIO_PuPd = GPIO_PuPd_UP,
821 .sda = {
822 .gpio = GPIOB,
823 .init = {
824 .GPIO_Pin = GPIO_Pin_11,
825 .GPIO_Mode = GPIO_Mode_AF,
826 .GPIO_Speed = GPIO_Speed_50MHz,
827 .GPIO_OType = GPIO_OType_OD,
828 .GPIO_PuPd = GPIO_PuPd_UP,
831 .event = {
832 .flags = 0, /* FIXME: check this */
833 .init = {
834 .NVIC_IRQChannel = I2C2_EV_IRQn,
835 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
836 .NVIC_IRQChannelSubPriority = 0,
837 .NVIC_IRQChannelCmd = ENABLE,
840 .error = {
841 .flags = 0, /* FIXME: check this */
842 .init = {
843 .NVIC_IRQChannel = I2C2_ER_IRQn,
844 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
845 .NVIC_IRQChannelSubPriority = 0,
846 .NVIC_IRQChannelCmd = ENABLE,
851 uint32_t pios_i2c_flexiport_adapter_id;
852 void PIOS_I2C_flexiport_adapter_ev_irq_handler(void)
854 /* Call into the generic code to handle the IRQ for this specific device */
855 PIOS_I2C_EV_IRQ_Handler(pios_i2c_flexiport_adapter_id);
858 void PIOS_I2C_flexiport_adapter_er_irq_handler(void)
860 /* Call into the generic code to handle the IRQ for this specific device */
861 PIOS_I2C_ER_IRQ_Handler(pios_i2c_flexiport_adapter_id);
865 void PIOS_I2C_pressure_adapter_ev_irq_handler(void);
866 void PIOS_I2C_pressure_adapter_er_irq_handler(void);
868 #endif /* PIOS_INCLUDE_I2C */
870 #if defined(PIOS_INCLUDE_RTC)
872 * Realtime Clock (RTC)
874 #include <pios_rtc_priv.h>
876 void PIOS_RTC_IRQ_Handler(void);
877 void RTC_WKUP_IRQHandler() __attribute__((alias("PIOS_RTC_IRQ_Handler")));
878 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
879 .clksrc = RCC_RTCCLKSource_HSE_Div8, // Divide 8 Mhz crystal down to 1
880 // For some reason it's acting like crystal is 16 Mhz. This clock is then divided
881 // by another 16 to give a nominal 62.5 khz clock
882 .prescaler = 100, // Every 100 cycles gives 625 Hz
883 .irq = {
884 .init = {
885 .NVIC_IRQChannel = RTC_WKUP_IRQn,
886 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
887 .NVIC_IRQChannelSubPriority = 0,
888 .NVIC_IRQChannelCmd = ENABLE,
893 void PIOS_RTC_IRQ_Handler(void)
895 PIOS_RTC_irq_handler();
898 #endif /* if defined(PIOS_INCLUDE_RTC) */
900 #include "pios_tim_priv.h"
902 static const TIM_TimeBaseInitTypeDef tim_3_5_time_base = {
903 .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000) - 1,
904 .TIM_ClockDivision = TIM_CKD_DIV1,
905 .TIM_CounterMode = TIM_CounterMode_Up,
906 .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
907 .TIM_RepetitionCounter = 0x0000,
909 static const TIM_TimeBaseInitTypeDef tim_9_10_11_time_base = {
910 .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
911 .TIM_ClockDivision = TIM_CKD_DIV1,
912 .TIM_CounterMode = TIM_CounterMode_Up,
913 .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
914 .TIM_RepetitionCounter = 0x0000,
917 static const struct pios_tim_clock_cfg tim_3_cfg = {
918 .timer = TIM3,
919 .time_base_init = &tim_3_5_time_base,
920 .irq = {
921 .init = {
922 .NVIC_IRQChannel = TIM3_IRQn,
923 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
924 .NVIC_IRQChannelSubPriority = 0,
925 .NVIC_IRQChannelCmd = ENABLE,
930 static const struct pios_tim_clock_cfg tim_5_cfg = {
931 .timer = TIM5,
932 .time_base_init = &tim_3_5_time_base,
933 .irq = {
934 .init = {
935 .NVIC_IRQChannel = TIM5_IRQn,
936 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
937 .NVIC_IRQChannelSubPriority = 0,
938 .NVIC_IRQChannelCmd = ENABLE,
943 static const struct pios_tim_clock_cfg tim_9_cfg = {
944 .timer = TIM9,
945 .time_base_init = &tim_9_10_11_time_base,
946 .irq = {
947 .init = {
948 .NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn,
949 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
950 .NVIC_IRQChannelSubPriority = 0,
951 .NVIC_IRQChannelCmd = ENABLE,
956 static const struct pios_tim_clock_cfg tim_10_cfg = {
957 .timer = TIM10,
958 .time_base_init = &tim_9_10_11_time_base,
959 .irq = {
960 .init = {
961 .NVIC_IRQChannel = TIM1_UP_TIM10_IRQn,
962 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
963 .NVIC_IRQChannelSubPriority = 0,
964 .NVIC_IRQChannelCmd = ENABLE,
969 static const struct pios_tim_clock_cfg tim_11_cfg = {
970 .timer = TIM11,
971 .time_base_init = &tim_9_10_11_time_base,
972 .irq = {
973 .init = {
974 .NVIC_IRQChannel = TIM1_TRG_COM_TIM11_IRQn,
975 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
976 .NVIC_IRQChannelSubPriority = 0,
977 .NVIC_IRQChannelCmd = ENABLE,
982 // Set up timers that only have inputs on APB1
983 // TIM2,3,4,5,6,7,12,13,14
984 static const TIM_TimeBaseInitTypeDef tim_apb1_time_base = {
985 .TIM_Prescaler = (PIOS_PERIPHERAL_APB1_CLOCK / 1000000) - 1,
986 .TIM_ClockDivision = TIM_CKD_DIV1,
987 .TIM_CounterMode = TIM_CounterMode_Up,
988 .TIM_Period = 0xFFFF,
989 .TIM_RepetitionCounter = 0x0000,
993 // Set up timers that only have inputs on APB2
994 // TIM1,8,9,10,11
995 static const TIM_TimeBaseInitTypeDef tim_apb2_time_base = {
996 .TIM_Prescaler = (PIOS_PERIPHERAL_APB2_CLOCK / 1000000) - 1,
997 .TIM_ClockDivision = TIM_CKD_DIV1,
998 .TIM_CounterMode = TIM_CounterMode_Up,
999 .TIM_Period = 0xFFFF,
1000 .TIM_RepetitionCounter = 0x0000,
1003 static const struct pios_tim_clock_cfg tim_1_cfg = {
1004 .timer = TIM1,
1005 .time_base_init = &tim_apb2_time_base,
1006 .irq = {
1007 .init = {
1008 .NVIC_IRQChannel = TIM1_CC_IRQn,
1009 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1010 .NVIC_IRQChannelSubPriority = 0,
1011 .NVIC_IRQChannelCmd = ENABLE,
1016 static const struct pios_tim_clock_cfg tim_4_cfg = {
1017 .timer = TIM4,
1018 .time_base_init = &tim_apb1_time_base,
1019 .irq = {
1020 .init = {
1021 .NVIC_IRQChannel = TIM4_IRQn,
1022 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1023 .NVIC_IRQChannelSubPriority = 0,
1024 .NVIC_IRQChannelCmd = ENABLE,
1028 static const struct pios_tim_clock_cfg tim_8_cfg = {
1029 .timer = TIM8,
1030 .time_base_init = &tim_apb2_time_base,
1031 .irq = {
1032 .init = {
1033 .NVIC_IRQChannel = TIM8_CC_IRQn,
1034 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1035 .NVIC_IRQChannelSubPriority = 0,
1036 .NVIC_IRQChannelCmd = ENABLE,
1041 static const struct pios_tim_clock_cfg tim_12_cfg = {
1042 .timer = TIM12,
1043 .time_base_init = &tim_apb1_time_base,
1044 .irq = {
1045 .init = {
1046 .NVIC_IRQChannel = TIM8_BRK_TIM12_IRQn,
1047 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
1048 .NVIC_IRQChannelSubPriority = 0,
1049 .NVIC_IRQChannelCmd = ENABLE,
1056 * Pios servo configuration structures
1057 * Using TIM3, TIM9, TIM2, TIM5
1059 #include <pios_servo_priv.h>
1060 #include <pios_servo_config.h>
1062 static const struct pios_tim_channel pios_tim_servoport_all_pins[] = {
1063 TIM_SERVO_CHANNEL_CONFIG(TIM3, 3, B, 0),
1064 TIM_SERVO_CHANNEL_CONFIG(TIM3, 4, B, 1),
1065 TIM_SERVO_CHANNEL_CONFIG(TIM9, 2, A, 3),
1066 TIM_SERVO_CHANNEL_CONFIG(TIM2, 3, A, 2),
1067 TIM_SERVO_CHANNEL_CONFIG(TIM5, 2, A, 1),
1068 TIM_SERVO_CHANNEL_CONFIG(TIM5, 1, A, 0),
1069 // PWM pins on FlexiIO(receiver) port
1070 TIM_SERVO_CHANNEL_CONFIG(TIM12, 2, B, 15), // * 6: PB15 = SPI2 MOSI, TIM12 CH2
1071 TIM_SERVO_CHANNEL_CONFIG(TIM8, 1, C, 6), // * 7: PC6 = TIM8 CH1, USART6 TX
1072 TIM_SERVO_CHANNEL_CONFIG(TIM8, 2, C, 7), // * 8: PC7 = TIM8 CH2, USART6 RX
1073 TIM_SERVO_CHANNEL_CONFIG(TIM8, 3, C, 8), // * 9: PC8 = TIM8 CH3
1074 TIM_SERVO_CHANNEL_CONFIG(TIM8, 4, C, 9), // * 10: PC9 = TIM8 CH4
1075 TIM_SERVO_CHANNEL_CONFIG(TIM12, 1, B, 14), // * 5: PB14 = SPI2 MISO, TIM12 CH1, USART3 RTS
1078 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT 6
1079 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM 11
1080 #define PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN 12
1082 const struct pios_servo_cfg pios_servo_cfg_out = {
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,
1093 .channels = pios_tim_servoport_all_pins,
1094 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT,
1096 // All servo outputs, servo input ch1 ppm, ch2-6 outputs
1097 const struct pios_servo_cfg pios_servo_cfg_out_in_ppm = {
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,
1108 .channels = pios_tim_servoport_all_pins,
1109 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN_PPM,
1111 // All servo outputs, servo inputs ch1-6 Outputs
1112 const struct pios_servo_cfg pios_servo_cfg_out_in = {
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,
1123 .channels = pios_tim_servoport_all_pins,
1124 .num_channels = PIOS_SERVOPORT_ALL_PINS_PWMOUT_IN,
1129 * PWM Inputs
1130 * TIM1, TIM8, TIM12
1132 #if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM)
1133 #include <pios_pwm_priv.h>
1134 static const struct pios_tim_channel pios_tim_rcvrport_all_channels[] = {
1135 TIM_SERVO_CHANNEL_CONFIG(TIM12, 1, B, 14),
1136 TIM_SERVO_CHANNEL_CONFIG(TIM12, 2, B, 15),
1137 TIM_SERVO_CHANNEL_CONFIG(TIM8, 1, C, 6),
1138 TIM_SERVO_CHANNEL_CONFIG(TIM8, 2, C, 7),
1139 TIM_SERVO_CHANNEL_CONFIG(TIM8, 3, C, 8),
1140 TIM_SERVO_CHANNEL_CONFIG(TIM8, 4, C, 9),
1143 const struct pios_pwm_cfg pios_pwm_cfg = {
1144 .tim_ic_init = {
1145 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1146 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1147 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1148 .TIM_ICFilter = 0x0,
1150 .channels = pios_tim_rcvrport_all_channels,
1151 .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels),
1153 // this configures outputs 2-6 as pwm inputs
1154 const struct pios_pwm_cfg pios_pwm_ppm_cfg = {
1155 .tim_ic_init = {
1156 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1157 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1158 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1159 .TIM_ICFilter = 0x0,
1161 .channels = &pios_tim_rcvrport_all_channels[1],
1162 .num_channels = NELEMENTS(pios_tim_rcvrport_all_channels) - 1,
1165 #endif /* if defined(PIOS_INCLUDE_PWM) || defined(PIOS_INCLUDE_PPM) */
1168 * PPM Input
1170 #if defined(PIOS_INCLUDE_PPM)
1171 #include <pios_ppm_priv.h>
1172 static const struct pios_ppm_cfg pios_ppm_cfg = {
1173 .tim_ic_init = {
1174 .TIM_ICPolarity = TIM_ICPolarity_Rising,
1175 .TIM_ICSelection = TIM_ICSelection_DirectTI,
1176 .TIM_ICPrescaler = TIM_ICPSC_DIV1,
1177 .TIM_ICFilter = 0x0,
1178 .TIM_Channel = TIM_Channel_1,
1180 /* Use only the first channel for ppm */
1181 .channels = &pios_tim_rcvrport_all_channels[0],
1182 .num_channels = 1,
1185 #endif // PPM
1187 #if defined(PIOS_INCLUDE_GCSRCVR)
1188 #include "pios_gcsrcvr_priv.h"
1189 #endif /* PIOS_INCLUDE_GCSRCVR */
1191 #if defined(PIOS_INCLUDE_RCVR)
1192 #include "pios_rcvr_priv.h"
1193 #endif /* PIOS_INCLUDE_RCVR */
1195 #if defined(PIOS_INCLUDE_USB)
1196 #include "pios_usb_priv.h"
1198 static const struct pios_usb_cfg pios_usb_discovery_cfg = {
1199 .irq = {
1200 .init = {
1201 .NVIC_IRQChannel = OTG_FS_IRQn,
1202 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
1203 .NVIC_IRQChannelSubPriority = 0, // PriorityGroup=4
1204 .NVIC_IRQChannelCmd = ENABLE,
1207 .vsense = {
1208 .gpio = GPIOA,
1209 .init = {
1210 .GPIO_Pin = GPIO_Pin_9,
1211 .GPIO_Speed = GPIO_Speed_25MHz,
1212 .GPIO_Mode = GPIO_Mode_IN,
1213 .GPIO_OType = GPIO_OType_OD,
1216 .vsense_active_low = false
1219 const struct pios_usb_cfg *PIOS_BOARD_HW_DEFS_GetUsbCfg(__attribute__((unused)) uint32_t board_revision)
1221 return &pios_usb_discovery_cfg;
1224 #include "pios_usb_board_data_priv.h"
1225 #include "pios_usb_desc_hid_cdc_priv.h"
1226 #include "pios_usb_desc_hid_only_priv.h"
1227 #include "pios_usbhook.h"
1229 #endif /* PIOS_INCLUDE_USB */
1231 #if defined(PIOS_INCLUDE_COM_MSG)
1233 #include <pios_com_msg_priv.h>
1235 #endif /* PIOS_INCLUDE_COM_MSG */
1237 #ifdef PIOS_INCLUDE_WS2811
1238 #include <pios_ws2811_cfg.h>
1239 #define PIOS_WS2811_TIM_DIVIDER (PIOS_PERIPHERAL_APB2_CLOCK / (800000 * PIOS_WS2811_TIM_PERIOD))
1241 void DMA2_Stream1_IRQHandler(void) __attribute__((alias("PIOS_WS2811_irq_handler")));
1243 const struct pios_ws2811_pin_cfg pios_ws2811_pin_cfg = {
1244 .gpio = GPIOA,
1245 .gpioInit = {
1246 .GPIO_Pin = GPIO_Pin_3,
1247 .GPIO_Speed = GPIO_Speed_50MHz,
1248 .GPIO_Mode = GPIO_Mode_OUT,
1249 .GPIO_OType = GPIO_OType_PP,
1253 const struct pios_ws2811_cfg pios_ws2811_cfg = {
1254 .timer = TIM1,
1255 .timerInit = {
1256 .TIM_Prescaler = PIOS_WS2811_TIM_DIVIDER - 1,
1257 .TIM_ClockDivision = TIM_CKD_DIV1,
1258 .TIM_CounterMode = TIM_CounterMode_Up,
1259 // period (1.25 uS per period
1260 .TIM_Period = PIOS_WS2811_TIM_PERIOD,
1261 .TIM_RepetitionCounter = 0x0000,
1264 .timerCh1 = 1,
1265 .streamCh1 = DMA2_Stream1,
1266 .timerCh2 = 3,
1267 .streamCh2 = DMA2_Stream6,
1268 .streamUpdate = DMA2_Stream5,
1270 // DMA streamCh1, triggered by timerCh1 pwm signal.
1271 // if FrameBuffer indicates, reset output value early to indicate "0" bit to ws2812
1272 .dmaInitCh1 = PIOS_WS2811_DMA_CH1_CONFIG(DMA_Channel_6),
1273 .dmaItCh1 = DMA_IT_TEIF1 | DMA_IT_TCIF1,
1275 // DMA streamCh2, triggered by timerCh2 pwm signal.
1276 // Reset output value late to indicate "1" bit to ws2812.
1277 .dmaInitCh2 = PIOS_WS2811_DMA_CH2_CONFIG(DMA_Channel_6),
1278 .dmaItCh2 = DMA_IT_TEIF6 | DMA_IT_TCIF6,
1280 // DMA streamUpdate Triggered by timer update event
1281 // Outputs a high logic level at beginning of a cycle
1282 .dmaInitUpdate = PIOS_WS2811_DMA_UPDATE_CONFIG(DMA_Channel_6),
1283 .dmaItUpdate = DMA_IT_TEIF5 | DMA_IT_TCIF5,
1284 .dmaSource = TIM_DMA_CC1 | TIM_DMA_CC3 | TIM_DMA_Update,
1286 // DMA streamCh1 interrupt vector, used to block timer at end of framebuffer transfer
1287 .irq = {
1288 .flags = (DMA_IT_TCIF1),
1289 .init = {
1290 .NVIC_IRQChannel = DMA2_Stream1_IRQn,
1291 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
1292 .NVIC_IRQChannelSubPriority = 0,
1293 .NVIC_IRQChannelCmd = ENABLE,
1298 void PIOS_WS2811_irq_handler(void)
1300 PIOS_WS2811_DMA_irq_handler();
1302 #endif // PIOS_INCLUDE_WS2811
1305 * Sensor configurations
1308 #if defined(PIOS_INCLUDE_ADC)
1309 #include "pios_adc_priv.h"
1310 void PIOS_ADC_DMC_irq_handler(void);
1311 void DMA2_Stream4_IRQHandler(void) __attribute__((alias("PIOS_ADC_DMC_irq_handler")));
1312 struct pios_adc_cfg pios_adc_cfg = {
1313 .adc_dev = ADC1,
1314 .dma = {
1315 .irq = {
1316 .flags = (DMA_FLAG_TCIF4 | DMA_FLAG_TEIF4 | DMA_FLAG_HTIF4),
1317 .init = {
1318 .NVIC_IRQChannel = DMA2_Stream4_IRQn,
1319 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1320 .NVIC_IRQChannelSubPriority = 0,
1321 .NVIC_IRQChannelCmd = ENABLE,
1324 .rx = {
1325 .channel = DMA2_Stream4,
1326 .init = {
1327 .DMA_Channel = DMA_Channel_0,
1328 .DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR
1332 .half_flag = DMA_IT_HTIF4,
1333 .full_flag = DMA_IT_TCIF4,
1335 void PIOS_ADC_DMC_irq_handler(void)
1337 /* Call into the generic code to handle the IRQ for this specific device */
1338 PIOS_ADC_DMA_Handler();
1341 const struct pios_adc_cfg *PIOS_BOARD_HW_DEFS_GetAdcCfg(__attribute__((unused)) uint32_t board_revision)
1343 return &pios_adc_cfg;
1345 #endif /* if defined(PIOS_INCLUDE_ADC) */
1347 #if defined(PIOS_INCLUDE_HMC5X83)
1348 #include "pios_hmc5x83.h"
1350 #ifdef PIOS_HMC5X83_HAS_GPIOS
1351 bool pios_board_internal_mag_handler()
1353 return PIOS_HMC5x83_IRQHandler(pios_hmc5x83_internal_id);
1356 static const struct pios_exti_cfg pios_exti_hmc5x83_cfg __exti_config = {
1357 .vector = pios_board_internal_mag_handler,
1358 .line = EXTI_Line7,
1359 .pin = {
1360 .gpio = GPIOB,
1361 .init = {
1362 .GPIO_Pin = GPIO_Pin_7,
1363 .GPIO_Speed = GPIO_Speed_100MHz,
1364 .GPIO_Mode = GPIO_Mode_IN,
1365 .GPIO_OType = GPIO_OType_OD,
1366 .GPIO_PuPd = GPIO_PuPd_NOPULL,
1369 .irq = {
1370 .init = {
1371 .NVIC_IRQChannel = EXTI9_5_IRQn,
1372 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_LOW,
1373 .NVIC_IRQChannelSubPriority = 0,
1374 .NVIC_IRQChannelCmd = ENABLE,
1377 .exti = {
1378 .init = {
1379 .EXTI_Line = EXTI_Line7, // matches above GPIO pin
1380 .EXTI_Mode = EXTI_Mode_Interrupt,
1381 .EXTI_Trigger = EXTI_Trigger_Rising,
1382 .EXTI_LineCmd = ENABLE,
1386 #endif /* PIOS_HMC5X83_HAS_GPIOS */
1388 static const struct pios_hmc5x83_cfg pios_hmc5x83_internal_cfg = {
1389 #ifdef PIOS_HMC5X83_HAS_GPIOS
1390 .exti_cfg = &pios_exti_hmc5x83_cfg,
1391 #endif
1392 .M_ODR = PIOS_HMC5x83_ODR_75,
1393 .Meas_Conf = PIOS_HMC5x83_MEASCONF_NORMAL,
1394 .Gain = PIOS_HMC5x83_GAIN_1_9,
1395 .Mode = PIOS_HMC5x83_MODE_CONTINUOUS,
1396 .TempCompensation = false,
1397 .Driver = &PIOS_HMC5x83_I2C_DRIVER,
1398 .Orientation = PIOS_HMC5X83_ORIENTATION_EAST_NORTH_UP,
1401 static const struct pios_hmc5x83_cfg pios_hmc5x83_external_cfg = {
1402 #ifdef PIOS_HMC5X83_HAS_GPIOS
1403 .exti_cfg = NULL,
1404 #endif
1405 .M_ODR = PIOS_HMC5x83_ODR_75, // if you change this for auxmag, change AUX_MAG_SKIP in sensors.c
1406 .Meas_Conf = PIOS_HMC5x83_MEASCONF_NORMAL,
1407 .Gain = PIOS_HMC5x83_GAIN_1_9,
1408 .Mode = PIOS_HMC5x83_MODE_CONTINUOUS,
1409 .TempCompensation = false,
1410 .Driver = &PIOS_HMC5x83_I2C_DRIVER,
1411 .Orientation = PIOS_HMC5X83_ORIENTATION_EAST_NORTH_UP, // ENU for GPSV9, WND for typical I2C mag
1414 const struct pios_hmc5x83_cfg *PIOS_BOARD_HW_DEFS_GetInternalHMC5x83Cfg(__attribute__((unused)) uint32_t board_revision)
1416 return &pios_hmc5x83_internal_cfg;
1419 const struct pios_hmc5x83_cfg *PIOS_BOARD_HW_DEFS_GetExternalHMC5x83Cfg(__attribute__((unused)) uint32_t board_revision)
1421 return &pios_hmc5x83_external_cfg;
1423 #endif /* PIOS_INCLUDE_HMC5X83 */
1426 * Configuration for the MS5611 chip
1428 #if defined(PIOS_INCLUDE_MS56XX)
1429 #include "pios_ms56xx.h"
1430 static const struct pios_ms56xx_cfg pios_ms56xx_cfg = {
1431 .address = 0x77,
1432 .version = MS56XX_VERSION_5611,
1433 .oversampling = MS56XX_OSR_512,
1435 const struct pios_ms56xx_cfg *PIOS_BOARD_HW_DEFS_GetMS56xxCfg(__attribute__((unused)) uint32_t board_revision)
1437 return &pios_ms56xx_cfg;
1439 #endif /* PIOS_INCLUDE_MS56XX */
1443 * Configuration for the MPU6000 chip
1445 #if defined(PIOS_INCLUDE_MPU6000)
1446 #include "pios_mpu6000.h"
1447 static const struct pios_exti_cfg pios_exti_mpu6000_cfg __exti_config = {
1448 .vector = PIOS_MPU6000_IRQHandler,
1449 .line = EXTI_Line4,
1450 .pin = {
1451 .gpio = GPIOC,
1452 .init = {
1453 .GPIO_Pin = GPIO_Pin_4,
1454 .GPIO_Speed = GPIO_Speed_100MHz,
1455 .GPIO_Mode = GPIO_Mode_IN,
1456 .GPIO_OType = GPIO_OType_OD,
1457 .GPIO_PuPd = GPIO_PuPd_NOPULL,
1460 .irq = {
1461 .init = {
1462 .NVIC_IRQChannel = EXTI4_IRQn,
1463 .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
1464 .NVIC_IRQChannelSubPriority = 0,
1465 .NVIC_IRQChannelCmd = ENABLE,
1468 .exti = {
1469 .init = {
1470 .EXTI_Line = EXTI_Line4, // matches above GPIO pin
1471 .EXTI_Mode = EXTI_Mode_Interrupt,
1472 .EXTI_Trigger = EXTI_Trigger_Rising,
1473 .EXTI_LineCmd = ENABLE,
1478 static const struct pios_mpu6000_cfg pios_mpu6000_cfg = {
1479 .exti_cfg = &pios_exti_mpu6000_cfg,
1480 .Fifo_store = PIOS_MPU6000_FIFO_TEMP_OUT | PIOS_MPU6000_FIFO_GYRO_X_OUT | PIOS_MPU6000_FIFO_GYRO_Y_OUT | PIOS_MPU6000_FIFO_GYRO_Z_OUT,
1481 // Clock at 8 khz, downsampled by 12 for 666Hz
1482 .Smpl_rate_div_no_dlp = 11,
1483 // with dlp on output rate is 500Hz
1484 .Smpl_rate_div_dlp = 1,
1485 .interrupt_cfg = PIOS_MPU6000_INT_CLR_ANYRD,
1486 .interrupt_en = PIOS_MPU6000_INTEN_DATA_RDY,
1487 .User_ctl = PIOS_MPU6000_USERCTL_FIFO_EN | PIOS_MPU6000_USERCTL_DIS_I2C,
1488 .Pwr_mgmt_clk = PIOS_MPU6000_PWRMGMT_PLL_X_CLK,
1489 .accel_range = PIOS_MPU6000_ACCEL_8G,
1490 .gyro_range = PIOS_MPU6000_SCALE_2000_DEG,
1491 .filter = PIOS_MPU6000_LOWPASS_256_HZ,
1492 .orientation = PIOS_MPU6000_TOP_180DEG
1495 const struct pios_mpu6000_cfg *PIOS_BOARD_HW_DEFS_GetMPU6000Cfg(__attribute__((unused)) uint32_t board_revision)
1497 return &pios_mpu6000_cfg;
1500 #endif /* PIOS_INCLUDE_MPU6000 */