dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
board_hw_defs.c
Go to the documentation of this file.
1 
17 /*
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful, but
24  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
25  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26  * for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with this program; if not, see <http://www.gnu.org/licenses/>
30  */
31 
32 #include <pios_config.h>
33 #include <pios_board_info.h>
34 
37 };
38 
39 #if defined(PIOS_INCLUDE_ANNUNC)
40 
41 #include <pios_annunc_priv.h>
42 static const struct pios_annunc pios_annuncs[] = {
43  [PIOS_LED_HEARTBEAT] = {
44  .pin = {
45  .gpio = GPIOB,
46  .init = {
47  .GPIO_Pin = GPIO_Pin_0,
48  .GPIO_Mode = GPIO_Mode_OUT,
49  .GPIO_Speed = GPIO_Speed_50MHz,
50  .GPIO_OType = GPIO_OType_PP,
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 const struct pios_annunc_cfg * PIOS_BOARD_HW_DEFS_GetLedCfg (uint32_t board_revision)
62 {
63  return &pios_annunc_cfg;
64 }
65 
66 #endif /* PIOS_INCLUDE_ANNUNC */
67 
68 #if defined(PIOS_INCLUDE_SPISLAVE)
69 
70 #include "pios_spislave.h"
71 
72 #include "flyingpio_messages.h"
73 
74 static void process_pio_message(void *ctx, int len, int *resp_len);
75 
76 /* SPI command link interface
77  *
78  * NOTE: Leave this declared as const data so that it ends up in the
79  * .rodata section (ie. Flash) rather than in the .data section (RAM).
80  */
81 struct flyingpi_msg rx_buf;
82 struct flyingpi_msg tx_buf;
83 
84 static const struct pios_spislave_cfg pios_spislave_cfg = {
85  .regs = SPI1,
86  .init = {
87  .SPI_Mode = SPI_Mode_Slave,
88  .SPI_Direction = SPI_Direction_2Lines_FullDuplex,
89  .SPI_DataSize = SPI_DataSize_8b,
90  .SPI_NSS = SPI_NSS_Hard,
91  .SPI_FirstBit = SPI_FirstBit_MSB,
92  .SPI_CPOL = SPI_CPOL_Low,
93  .SPI_CPHA = SPI_CPHA_1Edge,
94  /* Next two not used */
95  .SPI_CRCPolynomial = 7,
96  .SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2,
97  },
98  .sclk = {
99  .gpio = GPIOB,
100  .init = {
101  .GPIO_Pin = GPIO_Pin_3,
102  .GPIO_Speed = GPIO_Speed_50MHz,
103  .GPIO_Mode = GPIO_Mode_AF,
104  .GPIO_OType = GPIO_OType_PP,
105  .GPIO_PuPd = GPIO_PuPd_NOPULL
106  },
107  },
108  .miso = {
109  .gpio = GPIOB,
110  .init = {
111  .GPIO_Pin = GPIO_Pin_4,
112  .GPIO_Speed = GPIO_Speed_50MHz,
113  .GPIO_Mode = GPIO_Mode_AF,
114  .GPIO_OType = GPIO_OType_PP,
115  .GPIO_PuPd = GPIO_PuPd_NOPULL
116  },
117  },
118  .mosi = {
119  .gpio = GPIOB,
120  .init = {
121  .GPIO_Pin = GPIO_Pin_5,
122  .GPIO_Speed = GPIO_Speed_50MHz,
123  .GPIO_Mode = GPIO_Mode_AF,
124  .GPIO_OType = GPIO_OType_PP,
125  .GPIO_PuPd = GPIO_PuPd_NOPULL
126  },
127  },
128  .ssel = {
129  .gpio = GPIOA,
130  .init = {
131  .GPIO_Pin = GPIO_Pin_4,
132  .GPIO_Speed = GPIO_Speed_50MHz,
133  .GPIO_Mode = GPIO_Mode_AF,
134  .GPIO_OType = GPIO_OType_PP,
135  .GPIO_PuPd = GPIO_PuPd_UP
136  }
137  },
138  .max_rx_len = sizeof(struct flyingpi_msg),
139  .tx_dma = {
140  .init = {
141  .DMA_PeripheralBaseAddr = (uint32_t) &(SPI1->DR),
142  .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
143  .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
144  .DMA_MemoryBaseAddr = (uint32_t) &tx_buf,
145  .DMA_MemoryInc = DMA_MemoryInc_Enable,
146  .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
147  .DMA_DIR = DMA_DIR_PeripheralDST,
148  .DMA_Priority = DMA_Priority_High,
149  .DMA_Mode = DMA_Mode_Normal,
150  .DMA_M2M = DMA_M2M_Disable,
151  },
152  .channel = DMA1_Channel3,
153  },
154  .rx_dma = {
155  .init = {
156  .DMA_PeripheralBaseAddr = (uint32_t) &(SPI1->DR),
157  .DMA_PeripheralInc = DMA_PeripheralInc_Disable,
158  .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte,
159  .DMA_MemoryBaseAddr = (uint32_t) &rx_buf,
160  .DMA_MemoryInc = DMA_MemoryInc_Enable,
161  .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte,
162  .DMA_DIR = DMA_DIR_PeripheralSRC,
163  .DMA_Priority = DMA_Priority_High,
164  .DMA_Mode = DMA_Mode_Normal,
165  .DMA_M2M = DMA_M2M_Disable,
166  },
167  .channel = DMA1_Channel2,
168  },
169  .process_message = process_pio_message,
170 };
171 
172 #endif /* PIOS_INCLUDE_SPI */
173 
174 #ifdef PIOS_INCLUDE_ADC
175 #include "pios_adc_priv.h"
177 
182 static const struct pios_internal_adc_simple_cfg internal_adc_cfg = {
183  .adc_dev = ADC1,
184  .adc_pins = {
185  {GPIOA, GPIO_Pin_0, ADC_Channel_0 }, // VBat
186  {GPIOA, GPIO_Pin_1, ADC_Channel_1 }, // ADC Pad
187  {NULL, 0, ADC_Channel_Vrefint },
188  {NULL, 0, ADC_Channel_TempSensor },
189  },
190  .adc_pin_count = 4,
191 };
192 
193 #endif /* PIOS_INCLUDE_ADC */
194 
195 #include "pios_tim_priv.h"
196 
197 static const TIM_TimeBaseInitTypeDef tim_time_base = {
198  .TIM_Prescaler = (PIOS_SYSCLK / 1000000) - 1,
199  .TIM_ClockDivision = TIM_CKD_DIV1,
200  .TIM_CounterMode = TIM_CounterMode_Up,
201  .TIM_Period = ((1000000 / PIOS_SERVO_UPDATE_HZ) - 1),
202  .TIM_RepetitionCounter = 0x0000,
203 };
204 
205 static const struct pios_tim_clock_cfg tim_1_cfg = {
206  .timer = TIM1,
207  .time_base_init = &tim_time_base,
208  .irq = {
209  .init = {
210  .NVIC_IRQChannel = TIM1_CC_IRQn,
211  .NVIC_IRQChannelCmd = ENABLE,
212  },
213  },
214 };
215 
216 static const struct pios_tim_clock_cfg tim_3_cfg = {
217  .timer = TIM3,
218  .time_base_init = &tim_time_base,
219  .irq = {
220  .init = {
221  .NVIC_IRQChannel = TIM3_IRQn,
222  .NVIC_IRQChannelCmd = ENABLE,
223  },
224  },
225 };
226 
227 
228 static const struct pios_tim_clock_cfg tim_14_cfg = {
229  .timer = TIM14,
230  .time_base_init = &tim_time_base,
231  .irq = {
232  .init = {
233  .NVIC_IRQChannel = TIM14_IRQn,
234  .NVIC_IRQChannelCmd = ENABLE,
235  },
236  },
237 };
238 
239 
240 // XXX need to confirm channel numbering on left vs board silk
241 // Servo pins:
242 // ch net pin timer
243 // 1 PWM0 - 18:PA8 TIM1CH1
244 // 2 PWM1 - 19:PA9 TIM1CH2
245 // 3 PWM2 - 20:PA10 TIM1CH3
246 // 4 PWM3 - 21:PA11 TIM1CH4
247 // 5 PWM4 - 12:PA6 TIM3CH1
248 // 6 PWM5 - 13:PA7 TIM3CH2
249 
250 // PPM 15:PB1 TIM14CH1 (used) or TIM3CH4
252  .timer = TIM14,
253  .timer_chan = TIM_Channel_1,
254  .remap = GPIO_AF_0,
255  .pin = {
256  .gpio = GPIOB,
257  .init = {
258  .GPIO_Pin = GPIO_Pin_1,
259  .GPIO_Mode = GPIO_Mode_AF,
260  .GPIO_PuPd = GPIO_PuPd_UP,
261  .GPIO_OType = GPIO_OType_PP,
262  .GPIO_Speed = GPIO_Speed_2MHz,
263  },
264  .pin_source = GPIO_PinSource1,
265  },
266 };
267 
268 static const struct pios_tim_channel pios_tim_servoport_pins[] = {
269  {
270  .timer = TIM3,
271  .timer_chan = TIM_Channel_2,
272  .remap = GPIO_AF_1,
273  .pin = {
274  .gpio = GPIOA,
275  .init = {
276  .GPIO_Pin = GPIO_Pin_7,
277  .GPIO_Mode = GPIO_Mode_AF,
278  .GPIO_PuPd = GPIO_PuPd_UP,
279  .GPIO_OType = GPIO_OType_PP,
280  .GPIO_Speed = GPIO_Speed_50MHz,
281  },
282  .pin_source = GPIO_PinSource7,
283  },
284  },
285  {
286  .timer = TIM3,
287  .timer_chan = TIM_Channel_1,
288  .remap = GPIO_AF_1,
289  .pin = {
290  .gpio = GPIOA,
291  .init = {
292  .GPIO_Pin = GPIO_Pin_6,
293  .GPIO_Mode = GPIO_Mode_AF,
294  .GPIO_PuPd = GPIO_PuPd_UP,
295  .GPIO_OType = GPIO_OType_PP,
296  .GPIO_Speed = GPIO_Speed_50MHz,
297  },
298  .pin_source = GPIO_PinSource6,
299  },
300  },
301  {
302  .timer = TIM1,
303  .timer_chan = TIM_Channel_4,
304  .remap = GPIO_AF_2,
305  .pin = {
306  .gpio = GPIOA,
307  .init = {
308  .GPIO_Pin = GPIO_Pin_11,
309  .GPIO_Mode = GPIO_Mode_AF,
310  .GPIO_PuPd = GPIO_PuPd_UP,
311  .GPIO_OType = GPIO_OType_PP,
312  .GPIO_Speed = GPIO_Speed_50MHz,
313  },
314  .pin_source = GPIO_PinSource11,
315  },
316  },
317  {
318  .timer = TIM1,
319  .timer_chan = TIM_Channel_3,
320  .remap = GPIO_AF_2,
321  .pin = {
322  .gpio = GPIOA,
323  .init = {
324  .GPIO_Pin = GPIO_Pin_10,
325  .GPIO_Mode = GPIO_Mode_AF,
326  .GPIO_PuPd = GPIO_PuPd_UP,
327  .GPIO_OType = GPIO_OType_PP,
328  .GPIO_Speed = GPIO_Speed_50MHz,
329  },
330  .pin_source = GPIO_PinSource10,
331  },
332  },
333  {
334  .timer = TIM1,
335  .timer_chan = TIM_Channel_2,
336  .remap = GPIO_AF_2,
337  .pin = {
338  .gpio = GPIOA,
339  .init = {
340  .GPIO_Pin = GPIO_Pin_9,
341  .GPIO_Mode = GPIO_Mode_AF,
342  .GPIO_PuPd = GPIO_PuPd_UP,
343  .GPIO_OType = GPIO_OType_PP,
344  .GPIO_Speed = GPIO_Speed_50MHz,
345  },
346  .pin_source = GPIO_PinSource9,
347  },
348  },
349  {
350  .timer = TIM1,
351  .timer_chan = TIM_Channel_1,
352  .remap = GPIO_AF_2,
353  .pin = {
354  .gpio = GPIOA,
355  .init = {
356  .GPIO_Pin = GPIO_Pin_8,
357  .GPIO_Mode = GPIO_Mode_AF,
358  .GPIO_PuPd = GPIO_PuPd_UP,
359  .GPIO_OType = GPIO_OType_PP,
360  .GPIO_Speed = GPIO_Speed_50MHz,
361  },
362  .pin_source = GPIO_PinSource8,
363  },
364  },
365 };
366 
367 #if defined(PIOS_INCLUDE_USART)
368 
369 #include "pios_usart_priv.h"
370 
371 static const struct pios_usart_cfg pios_usart_rcvr_cfg = {
372  .regs = USART1,
373  .irq = {
374  .init = {
375  .NVIC_IRQChannel = USART1_IRQn,
376  .NVIC_IRQChannelCmd = ENABLE,
377  },
378  },
379  .rx = {
380  .gpio = GPIOB,
381  .init = {
382  .GPIO_Pin = GPIO_Pin_7,
383  .GPIO_Mode = GPIO_Mode_AF,
384  .GPIO_PuPd = GPIO_PuPd_UP,
385  .GPIO_OType = GPIO_OType_PP,
386  .GPIO_Speed = GPIO_Speed_50MHz,
387  },
388  },
389  .tx = {
390  .gpio = GPIOB,
391  .init = {
392  .GPIO_Pin = GPIO_Pin_6,
393  .GPIO_Mode = GPIO_Mode_AF,
394  .GPIO_PuPd = GPIO_PuPd_UP,
395  .GPIO_OType = GPIO_OType_PP,
396  .GPIO_Speed = GPIO_Speed_50MHz,
397  },
398  },
399 };
400 
401 #if defined(PIOS_INCLUDE_DSM)
402 #include <pios_dsm_priv.h>
403 
404 static const struct pios_dsm_cfg pios_dsm_rcvr_cfg = {
405  .bind = {
406  .gpio = GPIOB,
407  .init = {
408  .GPIO_Pin = GPIO_Pin_7,
409  .GPIO_Speed = GPIO_Speed_50MHz,
410  .GPIO_PuPd = GPIO_PuPd_UP,
411  .GPIO_OType = GPIO_OType_PP,
412  .GPIO_Speed = GPIO_Speed_50MHz,
413  },
414  },
415 };
416 #endif /* PIOS_INCLUDE_DSM */
417 
418 #endif /* PIOS_INCLUDE_USART */
419 
420 #if defined(PIOS_INCLUDE_COM)
421 
422 #include "pios_com_priv.h"
423 
424 #endif /* PIOS_INCLUDE_COM */
425 
426 #if defined(PIOS_INCLUDE_RTC)
427 // XXX XXX RTC.
428 /*
429  * Realtime Clock (RTC)
430  */
431 #include <pios_rtc_priv.h>
432 
433 void PIOS_RTC_IRQ_Handler (void);
434 void RTC_WKUP_IRQHandler() __attribute__ ((alias ("PIOS_RTC_IRQ_Handler")));
435 static const struct pios_rtc_cfg pios_rtc_main_cfg = {
436  .clksrc = RCC_RTCCLKSource_HSE_Div32,
437  .prescaler = 25 - 1, // 8MHz / 32 / 16 / 25 == 625Hz
438  .irq = {
439  .init = {
440  .NVIC_IRQChannel = RTC_IRQn,
441  .NVIC_IRQChannelCmd = ENABLE,
442  },
443  },
444 };
445 
446 void PIOS_RTC_IRQ_Handler (void)
447 {
449 }
450 
451 #endif
452 
453 #if defined(PIOS_INCLUDE_SERVO) && defined(PIOS_INCLUDE_TIM)
454 /*
455  * Servo outputs
456  */
457 #include <pios_servo_priv.h>
458 
459 const struct pios_servo_cfg pios_servo_cfg = {
460  .tim_oc_init = {
461  .TIM_OCMode = TIM_OCMode_PWM1,
462  .TIM_OutputState = TIM_OutputState_Enable,
463  .TIM_OutputNState = TIM_OutputNState_Disable,
464  .TIM_Pulse = PIOS_SERVOS_INITIAL_POSITION,
465  .TIM_OCPolarity = TIM_OCPolarity_High,
466  .TIM_OCNPolarity = TIM_OCPolarity_High,
467  .TIM_OCIdleState = TIM_OCIdleState_Reset,
468  .TIM_OCNIdleState = TIM_OCNIdleState_Reset,
469  },
470  .channels = pios_tim_servoport_pins,
471  .num_channels = NELEMENTS(pios_tim_servoport_pins),
472 };
473 
474 #endif /* PIOS_INCLUDE_SERVO && TIM */
475 
476 /*
477  * PPM Inputs
478  */
479 #if defined(PIOS_INCLUDE_PPM)
480 #include <pios_ppm_priv.h>
481 
482 const struct pios_ppm_cfg pios_ppm_cfg = {
483  .tim_ic_init = {
484  .TIM_ICPolarity = TIM_ICPolarity_Rising,
485  .TIM_ICSelection = TIM_ICSelection_DirectTI,
486  .TIM_ICPrescaler = TIM_ICPSC_DIV1,
487  .TIM_ICFilter = 0x0,
488  },
489  /* Use only the first channel for ppm */
490  .channels = &pios_tim_rcvrport_pin,
491  .num_channels = 1,
492 };
493 
494 #endif /* PIOS_INCLUDE_PPM */
495 
496 #if defined(PIOS_INCLUDE_RCVR)
497 #include "pios_rcvr_priv.h"
498 #endif /* PIOS_INCLUDE_RCVR */
499 
501 {
502  (void)board_rev;
503  return NULL;
504 }
505 
struct stm32_gpio pin
static uint8_t board_rev
Definition: firmwareiap.c:71
#define NELEMENTS(x)
Definition: pios.h:192
struct stm32_gpio bind
COM private definitions.
GPIO_TypeDef * gpio
Definition: pios_stm32.h:60
static const TIM_TimeBaseInitTypeDef tim_time_base
static const struct pios_tim_clock_cfg tim_1_cfg
ADC private definitions.
static const struct pios_tim_clock_cfg tim_3_cfg
#define PIOS_SERVOS_INITIAL_POSITION
Definition: pios_board.h:210
SPI private definitions.
#define RTC_WKUP_IRQHandler
USART private definitions.
Spektrum/JR DSMx satellite receiver private structures.
#define PIOS_SERVO_UPDATE_HZ
Definition: pios_board.h:209
static const struct pios_tim_channel pios_tim_servoport_pins[]
TIM_TypeDef * timer
Definition: pios_tim_priv.h:7
const struct pios_annunc * annunciators
ppm private structures.
USART_TypeDef * regs
TIM_OCInitTypeDef tim_oc_init
const struct pios_sbus_cfg * get_sbus_cfg(enum board_revision board_rev)
Servo private structures.
TIM_ICInitTypeDef tim_ic_init
Definition: pios_ppm_priv.h:37
static const struct pios_tim_clock_cfg tim_14_cfg
void PIOS_RTC_irq_handler(void)
SPI_TypeDef * regs
Definition: pios_spislave.h:42
static void process_pio_message(void *ctx, int len, int *resp_len)
Definition: main.c:195
#define PIOS_SYSCLK
Definition: pios_board.h:143
TIM_TypeDef * timer
Definition: pios_tim_priv.h:14
uint32_t clksrc
Definition: pios_rtc_priv.h:37
board_revision
Definition: board_hw_defs.c:35
LED private definitions.
static const struct pios_tim_channel pios_tim_rcvrport_pin
USART private definitions.
#define PIOS_LED_HEARTBEAT
Definition: pios_board.h:85