periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 luisan00
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
9 #pragma once
10 
19 /* This board provides a LSE, marked as X3 on the board */
20 #ifndef CONFIG_BOARD_HAS_LSE
21 #define CONFIG_BOARD_HAS_LSE 1
22 #endif
23 
24 /* This board provides a HSE, marked as X2 on the board */
25 #ifndef CONFIG_BOARD_HAS_HSE
26 #define CONFIG_BOARD_HAS_HSE 1
27 #endif
28 
29 /* The HSE provides a 8MHz clock */
30 #ifndef CONFIG_CLOCK_HSE
31 #define CONFIG_CLOCK_HSE MHZ(8)
32 #endif
33 
34 #include "periph_cpu.h"
35 #include "clk_conf.h"
36 #include "cfg_rtt_default.h"
37 #include "cfg_timer_tim2.h"
38 #include "cfg_usb_otg_fs.h"
39 
40 #ifdef __cplusplus
41 extern "C"
42 {
43 #endif
44 
49 static const dma_conf_t dma_config[] = {
50  {.stream = 14}, /* DMA2 Stream 6 - SPI TX */
51  {.stream = 13}, /* DMA2 Stream 5 - SPI RX */
52 };
53 #define DMA_0_ISR isr_dma2_stream6
54 #define DMA_1_ISR isr_dma2_stream5
55 #define DMA_NUMOF ARRAY_SIZE(dma_config)
64 static const uart_conf_t uart_config[] = {
65  {
66  .dev = USART3,
67  .rcc_mask = RCC_APB1ENR_USART3EN,
68  .rx_pin = GPIO_PIN(PORT_B, 11),
69  .tx_pin = GPIO_PIN(PORT_B, 10),
70  .rx_af = GPIO_AF7,
71  .tx_af = GPIO_AF7,
72  .bus = APB1,
73  .irqn = USART3_IRQn,
74 #ifdef MODULE_PERIPH_DMA
75  .dma = DMA_STREAM_UNDEF,
76  .dma_chan = UINT8_MAX
77 #endif
78  },
79  {
80  .dev = USART6,
81  .rcc_mask = RCC_APB2ENR_USART6EN,
82  .rx_pin = GPIO_PIN(PORT_C, 7),
83  .tx_pin = GPIO_PIN(PORT_C, 6),
84  .rx_af = GPIO_AF8,
85  .tx_af = GPIO_AF8,
86  .bus = APB2,
87  .irqn = USART6_IRQn,
88 #ifdef MODULE_PERIPH_DMA
89  .dma = DMA_STREAM_UNDEF,
90  .dma_chan = UINT8_MAX
91 #endif
92  },
93 };
94 #define UART_0_ISR (isr_usart3)
95 #define UART_1_ISR (isr_usart6)
96 #define UART_NUMOF ARRAY_SIZE(uart_config)
111 static const i2c_conf_t i2c_config[] = {
112  {
113  .dev = I2C1,
114  .speed = I2C_SPEED_NORMAL,
115  .scl_pin = GPIO_PIN(PORT_B, 8),
116  .sda_pin = GPIO_PIN(PORT_B, 9),
117  .scl_af = GPIO_AF4,
118  .sda_af = GPIO_AF4,
119  .bus = APB1,
120  .rcc_mask = RCC_APB1ENR_I2C1EN,
121  .clk = CLOCK_APB1,
122  .irqn = I2C1_EV_IRQn,
123  },
124  {
125  .dev = I2C2,
126  .speed = I2C_SPEED_NORMAL,
127  .scl_pin = GPIO_PIN(PORT_H, 4),
128  .sda_pin = GPIO_PIN(PORT_H, 5),
129  .scl_af = GPIO_AF4,
130  .sda_af = GPIO_AF4,
131  .bus = APB1,
132  .rcc_mask = RCC_APB1ENR_I2C2EN,
133  .clk = CLOCK_APB1,
134  .irqn = I2C2_EV_IRQn,
135  },
136 };
137 #define I2C_0_ISR isr_i2c1_ev
138 #define I2C_1_ISR isr_i2c2_ev
139 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
146 static const spi_conf_t spi_config[] = {
147  {
148  .dev = SPI2,
149  .mosi_pin = GPIO_PIN(PORT_B, 15),
150  .miso_pin = GPIO_PIN(PORT_B, 14),
151  .sclk_pin = GPIO_PIN(PORT_D, 3),
152  .cs_pin = GPIO_PIN(PORT_H, 6),
153  .mosi_af = GPIO_AF5,
154  .miso_af = GPIO_AF5,
155  .sclk_af = GPIO_AF5,
156  .cs_af = GPIO_AF5,
157  .rccmask = RCC_APB1ENR_I2C2EN,
158  .apbbus = APB1,
159 #ifdef MODULE_PERIPH_DMA
160  .tx_dma = 0,
161  .tx_dma_chan = 6,
162  .rx_dma = 1,
163  .rx_dma_chan = 6,
164 #endif
165  },
166 };
167 #define SPI_NUMOF ARRAY_SIZE(spi_config)
174 static const pwm_conf_t pwm_config[] = {
175  {
176  .dev = TIM3,
177  .rcc_mask = RCC_APB1ENR_TIM3EN,
178  .chan = {
179  {.pin = GPIO_PIN(PORT_A, 6), .cc_chan = 0}, /* D6 */
180  {.pin = GPIO_PIN(PORT_B, 5), .cc_chan = 1}, /* CN12-P9 */
181  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
182  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
183  },
184  .af = GPIO_AF2,
185  .bus = APB1,
186  },
187  {
188  .dev = TIM5,
189  .rcc_mask = RCC_APB1ENR_TIM5EN,
190  .chan = {
191  {.pin = GPIO_PIN(PORT_A, 1), .cc_chan = 1}, /* D5 */
192  {.pin = GPIO_PIN(PORT_A, 2), .cc_chan = 2}, /* D3 */
193  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
194  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
195  },
196  .af = GPIO_AF2,
197  .bus = APB1,
198  },
199  {
200  .dev = TIM12,
201  .rcc_mask = RCC_APB1ENR_TIM12EN,
202  .chan = {
203  {.pin = GPIO_PIN(PORT_H, 6), .cc_chan = 0}, /* D10 */
204  {.pin = GPIO_PIN(PORT_B, 15), .cc_chan = 1}, /* D11 */
205  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
206  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
207  },
208  .af = GPIO_AF9,
209  .bus = APB1,
210  },
211  {
212  .dev = TIM14,
213  .rcc_mask = RCC_APB1ENR_TIM14EN,
214  .chan = {
215  {.pin = GPIO_PIN(PORT_A, 7), .cc_chan = 0}, /* D9 */
216  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
217  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
218  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
219  },
220  .af = GPIO_AF9,
221  .bus = APB1,
222  },
223 };
224 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
234 static const adc_conf_t adc_config[] = {
235  {GPIO_PIN(PORT_B, 1), 2, 9},
236  {GPIO_PIN(PORT_C, 2), 2, 12},
237  {GPIO_PIN(PORT_C, 3), 2, 13},
238  {GPIO_PIN(PORT_C, 4), 2, 14},
239  {GPIO_PIN(PORT_C, 5), 2, 15},
240  {GPIO_PIN(PORT_A, 4), 2, 4},
241  {GPIO_UNDEF, 0, 18}, /* VBAT */
242 };
243 
244 #define VBAT_ADC ADC_LINE(6)
245 #define ADC_NUMOF ARRAY_SIZE(adc_config)
252 static const dac_conf_t dac_config[] = {
253  {GPIO_PIN(PORT_A, 4), .chan = 0},
254  {GPIO_PIN(PORT_A, 5), .chan = 1},
255 };
262 #define DAC_NUMOF ARRAY_SIZE(dac_config)
272 static const fmc_conf_t fmc_config = {
273  .bus = AHB3,
274  .rcc_mask = RCC_AHB3ENR_FMCEN,
275 #if MODULE_PERIPH_FMC_SDRAM
276  .ba0_pin = { .pin = GPIO_PIN(PORT_G, 4), .af = GPIO_AF12, }, /* A14 signal */
277  .ba1_pin = { .pin = GPIO_PIN(PORT_G, 5), .af = GPIO_AF12, }, /* A15 signal */
278  .sdclk_pin = { .pin = GPIO_PIN(PORT_G, 8), .af = GPIO_AF12, }, /* SDCLK signal */
279  .sdnwe_pin = { .pin = GPIO_PIN(PORT_C, 0), .af = GPIO_AF12, }, /* SDNWE signal */
280  .sdnras_pin = { .pin = GPIO_PIN(PORT_F, 11), .af = GPIO_AF12, }, /* SDNRAS signal */
281  .sdncas_pin = { .pin = GPIO_PIN(PORT_G, 15), .af = GPIO_AF12, }, /* SDNCAS signal */
282  .sdcke0_pin = { .pin = GPIO_PIN(PORT_H, 2), .af = GPIO_AF12, }, /* SDCKE0 signal */
283  .sdne0_pin = { .pin = GPIO_PIN(PORT_H, 3), .af = GPIO_AF12, }, /* SDNE0 signal */
284  .addr = {
285  { .pin = GPIO_PIN(PORT_F, 0), .af = GPIO_AF12, }, /* A0 signal */
286  { .pin = GPIO_PIN(PORT_F, 1), .af = GPIO_AF12, }, /* A1 signal */
287  { .pin = GPIO_PIN(PORT_F, 2), .af = GPIO_AF12, }, /* A2 signal */
288  { .pin = GPIO_PIN(PORT_F, 3), .af = GPIO_AF12, }, /* A3 signal */
289  { .pin = GPIO_PIN(PORT_F, 4), .af = GPIO_AF12, }, /* A4 signal */
290  { .pin = GPIO_PIN(PORT_F, 5), .af = GPIO_AF12, }, /* A5 signal */
291  { .pin = GPIO_PIN(PORT_F, 12), .af = GPIO_AF12, }, /* A6 signal */
292  { .pin = GPIO_PIN(PORT_F, 13), .af = GPIO_AF12, }, /* A7 signal */
293  { .pin = GPIO_PIN(PORT_F, 14), .af = GPIO_AF12, }, /* A8 signal */
294  { .pin = GPIO_PIN(PORT_F, 15), .af = GPIO_AF12, }, /* A9 signal */
295  { .pin = GPIO_PIN(PORT_G, 0), .af = GPIO_AF12, }, /* A10 signal */
296  { .pin = GPIO_PIN(PORT_G, 1), .af = GPIO_AF12, }, /* A11 signal */
297  },
298 #endif
299  .data = {
300  { .pin = GPIO_PIN(PORT_D, 14), .af = GPIO_AF12, }, /* D0 signal */
301  { .pin = GPIO_PIN(PORT_D, 15), .af = GPIO_AF12, }, /* D1 signal */
302  { .pin = GPIO_PIN(PORT_D, 0), .af = GPIO_AF12, }, /* D2 signal */
303  { .pin = GPIO_PIN(PORT_D, 1), .af = GPIO_AF12, }, /* D3 signal */
304  { .pin = GPIO_PIN(PORT_E, 7), .af = GPIO_AF12, }, /* D4 signal */
305  { .pin = GPIO_PIN(PORT_E, 8), .af = GPIO_AF12, }, /* D5 signal */
306  { .pin = GPIO_PIN(PORT_E, 9), .af = GPIO_AF12, }, /* D6 signal */
307  { .pin = GPIO_PIN(PORT_E, 10), .af = GPIO_AF12, }, /* D7 signal */
308 #if MODULE_PERIPH_FMC_32BIT
309  { .pin = GPIO_PIN(PORT_E, 11), .af = GPIO_AF12, }, /* D8 signal */
310  { .pin = GPIO_PIN(PORT_E, 12), .af = GPIO_AF12, }, /* D9 signal */
311  { .pin = GPIO_PIN(PORT_E, 13), .af = GPIO_AF12, }, /* D10 signal */
312  { .pin = GPIO_PIN(PORT_E, 14), .af = GPIO_AF12, }, /* D11 signal */
313  { .pin = GPIO_PIN(PORT_E, 15), .af = GPIO_AF12, }, /* D12 signal */
314  { .pin = GPIO_PIN(PORT_D, 8), .af = GPIO_AF12, }, /* D13 signal */
315  { .pin = GPIO_PIN(PORT_D, 9), .af = GPIO_AF12, }, /* D14 signal */
316  { .pin = GPIO_PIN(PORT_D, 10), .af = GPIO_AF12, }, /* D15 signal */
317  { .pin = GPIO_PIN(PORT_H, 8), .af = GPIO_AF12, }, /* D16 signal */
318  { .pin = GPIO_PIN(PORT_H, 9), .af = GPIO_AF12, }, /* D17 signal */
319  { .pin = GPIO_PIN(PORT_H, 10), .af = GPIO_AF12, }, /* D18 signal */
320  { .pin = GPIO_PIN(PORT_H, 11), .af = GPIO_AF12, }, /* D19 signal */
321  { .pin = GPIO_PIN(PORT_H, 12), .af = GPIO_AF12, }, /* D20 signal */
322  { .pin = GPIO_PIN(PORT_H, 13), .af = GPIO_AF12, }, /* D21 signal */
323  { .pin = GPIO_PIN(PORT_H, 14), .af = GPIO_AF12, }, /* D22 signal */
324  { .pin = GPIO_PIN(PORT_H, 15), .af = GPIO_AF12, }, /* D23 signal */
325  { .pin = GPIO_PIN(PORT_I, 0), .af = GPIO_AF12, }, /* D24 signal */
326  { .pin = GPIO_PIN(PORT_I, 1), .af = GPIO_AF12, }, /* D25 signal */
327  { .pin = GPIO_PIN(PORT_I, 2), .af = GPIO_AF12, }, /* D26 signal */
328  { .pin = GPIO_PIN(PORT_I, 3), .af = GPIO_AF12, }, /* D27 signal */
329  { .pin = GPIO_PIN(PORT_I, 6), .af = GPIO_AF12, }, /* D28 signal */
330  { .pin = GPIO_PIN(PORT_I, 7), .af = GPIO_AF12, }, /* D29 signal */
331  { .pin = GPIO_PIN(PORT_I, 9), .af = GPIO_AF12, }, /* D30 signal */
332  { .pin = GPIO_PIN(PORT_I, 10), .af = GPIO_AF12, }, /* D31 signal */
333 #endif
334  },
335  .nbl0_pin = { .pin = GPIO_PIN(PORT_E, 0), .af = GPIO_AF12, }, /* FMC_NBL0 signal (DQM0) */
336  .nbl1_pin = { .pin = GPIO_PIN(PORT_E, 1), .af = GPIO_AF12, }, /* FMC_NBL1 signal (DQM1) */
337  .nbl2_pin = { .pin = GPIO_PIN(PORT_I, 4), .af = GPIO_AF12, }, /* FMC_NBL2 signal (DQM2) */
338  .nbl3_pin = { .pin = GPIO_PIN(PORT_I, 5), .af = GPIO_AF12, }, /* FMC_NBL3 signal (DQM3) */
339 };
340 
349  /* bank 5 is used for SDRAM */
350  {
351  .bank = FMC_BANK_5,
352  .mem_type = FMC_SDRAM,
353  .data_width = FMC_BUS_WIDTH_32BIT,
354  .address = 0xc0000000, /* Bank 6 is mapped to 0xc0000000 */
355  .size = MiB(16), /* Size in MByte, 4M x 32 Bit */
356  .sdram = {
357  .clk_period = 2, /* SDCLK = 2 x HCLK */
358  .row_bits = 12, /* A11..A0 used for row address */
359  .col_bits = 8, /* A7..A0 used for column address */
360  .cas_latency = 2, /* CAS latency is 2 clock cycles */
361  .read_delay = 0, /* No read delay after CAS */
362  .burst_read = true, /* Burst read mode enabled */
363  .burst_write = false, /* Burst write mode disabled */
364  .burst_len = FMC_BURST_LENGTH_1, /* Burst length is 1 */
365  .burst_interleaved = false, /* Burst mode interleaved */
366  .write_protect = false, /* No write protection */
367  .four_banks = true, /* SDRAM has four internal banks */
368  .timing = { /* SDRAM Timing parameters */
369  .row_to_col_delay = 2, /* Row to column delay (2 clock cycles) */
370  .row_precharge = 2, /* Row precharge delay (2 clock cycles) */
371  .recovery_delay = 2, /* Recovery delay is (2 clock cycles) */
372  .row_cylce = 7, /* Row cycle delay is (7 clock cycles) */
373  .self_refresh = 4, /* Self refresh time is (4 clock cycles) */
374  .exit_self_refresh = 7, /* Exit self-refresh delay (7 clock cycles) */
375  .load_mode_register = 2, /* Load Mode Register to Activate delay */
376  .refresh_period = 16, /* Refresh period in ms */
377  },
378  },
379  },
380 };
381 
385 #define FMC_BANK_NUMOF ARRAY_SIZE(fmc_bank_config)
388 #ifdef __cplusplus
389 }
390 #endif
391 
@ PORT_B
port B
Definition: periph_cpu.h:47
@ PORT_G
port G
Definition: periph_cpu.h:52
@ PORT_C
port C
Definition: periph_cpu.h:48
@ PORT_F
port F
Definition: periph_cpu.h:51
@ PORT_E
port E
Definition: periph_cpu.h:50
@ PORT_A
port A
Definition: periph_cpu.h:46
@ PORT_D
port D
Definition: periph_cpu.h:49
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
@ PORT_H
port H
Definition: periph_cpu.h:51
#define GPIO_UNDEF
Definition of a fitting UNDEF value.
static const uart_conf_t uart_config[]
UART configuration.
Definition: periph_conf.h:38
static const spi_conf_t spi_config[]
SPI configuration.
Definition: periph_conf.h:96
static const i2c_conf_t i2c_config[]
I2C configuration.
Definition: periph_conf.h:68
static const adc_conf_t adc_config[]
ADC configuration.
Definition: periph_conf.h:250
static const pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:221
static const dac_conf_t dac_config[]
DAC configuration.
Definition: periph_conf.h:252
static const fmc_bank_conf_t fmc_bank_config[]
FMC Bank configuration.
Definition: periph_conf.h:348
static const fmc_conf_t fmc_config
FMC controller configuration.
Definition: periph_conf.h:272
Common configuration for STM32 Timer peripheral based on TIM2.
Common configuration for STM32 OTG FS peripheral.
@ GPIO_AF2
use alternate function 2
Definition: cpu_gpio.h:103
@ GPIO_AF5
use alternate function 5
Definition: cpu_gpio.h:106
@ GPIO_AF4
use alternate function 4
Definition: cpu_gpio.h:105
@ GPIO_AF8
use alternate function 8
Definition: cpu_gpio.h:110
@ GPIO_AF9
use alternate function 9
Definition: cpu_gpio.h:111
@ GPIO_AF12
use alternate function 12
Definition: cpu_gpio.h:114
@ GPIO_AF7
use alternate function 7
Definition: cpu_gpio.h:108
@ APB1
Advanced Peripheral Bus 1
Definition: periph_cpu.h:78
@ APB2
Advanced Peripheral Bus 2
Definition: periph_cpu.h:79
@ FMC_SDRAM
SDRAM Controller used.
Definition: cpu_fmc.h:344
@ FMC_BUS_WIDTH_32BIT
32 bit data bus width
Definition: cpu_fmc.h:353
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
Definition: periph_cpu.h:277
#define CLOCK_APB1
Half AHB clock.
ADC device configuration.
Definition: periph_cpu.h:377
DAC line configuration data.
Definition: periph_cpu.h:300
DMA configuration.
Definition: cpu_dma.h:31
int stream
DMA stream on stm32f2/4/7, channel on others STM32F2/4/7:
Definition: cpu_dma.h:54
Bank configuration structure.
Definition: cpu_fmc.h:359
fmc_bank_t bank
Bank1 .
Definition: cpu_fmc.h:360
FMC peripheral configuration.
Definition: cpu_fmc.h:277
uint8_t bus
AHB/APB bus.
Definition: cpu_fmc.h:278
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
PWM device configuration.
mini_timer_t * dev
Timer used.
SPI device configuration.
Definition: periph_cpu.h:336
SPI_t * dev
pointer to the used SPI device
Definition: periph_cpu.h:337
UART device configuration.
Definition: periph_cpu.h:217
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:218
#define MiB(x)
A macro to return the bytes in x MiB.
Definition: units.h:33