periph_conf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 luisan00
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
16 /* This board provides a LSE, marked as X3 on the board */
17 #ifndef CONFIG_BOARD_HAS_LSE
18 #define CONFIG_BOARD_HAS_LSE 1
19 #endif
20 
21 /* This board provides a HSE, marked as X2 on the board */
22 #ifndef CONFIG_BOARD_HAS_HSE
23 #define CONFIG_BOARD_HAS_HSE 1
24 #endif
25 
26 /* The HSE provides a 8MHz clock */
27 #ifndef CONFIG_CLOCK_HSE
28 #define CONFIG_CLOCK_HSE MHZ(8)
29 #endif
30 
31 #include "periph_cpu.h"
32 #include "clk_conf.h"
33 #include "cfg_rtt_default.h"
34 #include "cfg_timer_tim2.h"
35 #include "cfg_usb_otg_fs.h"
36 
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41 
46 static const dma_conf_t dma_config[] = {
47  {.stream = 14}, /* DMA2 Stream 6 - SPI TX */
48  {.stream = 13}, /* DMA2 Stream 5 - SPI RX */
49 };
50 #define DMA_0_ISR isr_dma2_stream6
51 #define DMA_1_ISR isr_dma2_stream5
52 #define DMA_NUMOF ARRAY_SIZE(dma_config)
61 static const uart_conf_t uart_config[] = {
62  {
63  .dev = USART3,
64  .rcc_mask = RCC_APB1ENR_USART3EN,
65  .rx_pin = GPIO_PIN(PORT_B, 11),
66  .tx_pin = GPIO_PIN(PORT_B, 10),
67  .rx_af = GPIO_AF7,
68  .tx_af = GPIO_AF7,
69  .bus = APB1,
70  .irqn = USART3_IRQn,
71 #ifdef MODULE_PERIPH_DMA
72  .dma = DMA_STREAM_UNDEF,
73  .dma_chan = UINT8_MAX
74 #endif
75  },
76  {
77  .dev = USART6,
78  .rcc_mask = RCC_APB2ENR_USART6EN,
79  .rx_pin = GPIO_PIN(PORT_C, 7),
80  .tx_pin = GPIO_PIN(PORT_C, 6),
81  .rx_af = GPIO_AF8,
82  .tx_af = GPIO_AF8,
83  .bus = APB2,
84  .irqn = USART6_IRQn,
85 #ifdef MODULE_PERIPH_DMA
86  .dma = DMA_STREAM_UNDEF,
87  .dma_chan = UINT8_MAX
88 #endif
89  },
90 };
91 #define UART_0_ISR (isr_usart3)
92 #define UART_1_ISR (isr_usart6)
93 #define UART_NUMOF ARRAY_SIZE(uart_config)
108 static const i2c_conf_t i2c_config[] = {
109  {
110  .dev = I2C1,
111  .speed = I2C_SPEED_NORMAL,
112  .scl_pin = GPIO_PIN(PORT_B, 8),
113  .sda_pin = GPIO_PIN(PORT_B, 9),
114  .scl_af = GPIO_AF4,
115  .sda_af = GPIO_AF4,
116  .bus = APB1,
117  .rcc_mask = RCC_APB1ENR_I2C1EN,
118  .clk = CLOCK_APB1,
119  .irqn = I2C1_EV_IRQn,
120  },
121  {
122  .dev = I2C2,
123  .speed = I2C_SPEED_NORMAL,
124  .scl_pin = GPIO_PIN(PORT_H, 4),
125  .sda_pin = GPIO_PIN(PORT_H, 5),
126  .scl_af = GPIO_AF4,
127  .sda_af = GPIO_AF4,
128  .bus = APB1,
129  .rcc_mask = RCC_APB1ENR_I2C2EN,
130  .clk = CLOCK_APB1,
131  .irqn = I2C2_EV_IRQn,
132  },
133 };
134 #define I2C_0_ISR isr_i2c1_ev
135 #define I2C_1_ISR isr_i2c2_ev
136 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
143 static const spi_conf_t spi_config[] = {
144  {
145  .dev = SPI2,
146  .mosi_pin = GPIO_PIN(PORT_B, 15),
147  .miso_pin = GPIO_PIN(PORT_B, 14),
148  .sclk_pin = GPIO_PIN(PORT_D, 3),
149  .cs_pin = GPIO_PIN(PORT_H, 6),
150  .mosi_af = GPIO_AF5,
151  .miso_af = GPIO_AF5,
152  .sclk_af = GPIO_AF5,
153  .cs_af = GPIO_AF5,
154  .rccmask = RCC_APB1ENR_I2C2EN,
155  .apbbus = APB1,
156 #ifdef MODULE_PERIPH_DMA
157  .tx_dma = 0,
158  .tx_dma_chan = 6,
159  .rx_dma = 1,
160  .rx_dma_chan = 6,
161 #endif
162  },
163 };
164 #define SPI_NUMOF ARRAY_SIZE(spi_config)
171 static const pwm_conf_t pwm_config[] = {
172  {
173  .dev = TIM3,
174  .rcc_mask = RCC_APB1ENR_TIM3EN,
175  .chan = {
176  {.pin = GPIO_PIN(PORT_A, 6), .cc_chan = 0}, /* D6 */
177  {.pin = GPIO_PIN(PORT_B, 5), .cc_chan = 1}, /* CN12-P9 */
178  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
179  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
180  },
181  .af = GPIO_AF2,
182  .bus = APB1,
183  },
184  {
185  .dev = TIM5,
186  .rcc_mask = RCC_APB1ENR_TIM5EN,
187  .chan = {
188  {.pin = GPIO_PIN(PORT_A, 1), .cc_chan = 1}, /* D5 */
189  {.pin = GPIO_PIN(PORT_A, 2), .cc_chan = 2}, /* D3 */
190  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
191  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
192  },
193  .af = GPIO_AF2,
194  .bus = APB1,
195  },
196  {
197  .dev = TIM12,
198  .rcc_mask = RCC_APB1ENR_TIM12EN,
199  .chan = {
200  {.pin = GPIO_PIN(PORT_H, 6), .cc_chan = 0}, /* D10 */
201  {.pin = GPIO_PIN(PORT_B, 15), .cc_chan = 1}, /* D11 */
202  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
203  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
204  },
205  .af = GPIO_AF9,
206  .bus = APB1,
207  },
208  {
209  .dev = TIM14,
210  .rcc_mask = RCC_APB1ENR_TIM14EN,
211  .chan = {
212  {.pin = GPIO_PIN(PORT_A, 7), .cc_chan = 0}, /* D9 */
213  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
214  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
215  {.pin = GPIO_UNDEF, .cc_chan = 0}, /* unused */
216  },
217  .af = GPIO_AF9,
218  .bus = APB1,
219  },
220 };
221 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
231 static const adc_conf_t adc_config[] = {
232  {GPIO_PIN(PORT_B, 1), 2, 9},
233  {GPIO_PIN(PORT_C, 2), 2, 12},
234  {GPIO_PIN(PORT_C, 3), 2, 13},
235  {GPIO_PIN(PORT_C, 4), 2, 14},
236  {GPIO_PIN(PORT_C, 5), 2, 15},
237  {GPIO_PIN(PORT_A, 4), 2, 4},
238  {GPIO_UNDEF, 0, 18}, /* VBAT */
239 };
240 
241 #define VBAT_ADC ADC_LINE(6)
242 #define ADC_NUMOF ARRAY_SIZE(adc_config)
249 static const dac_conf_t dac_config[] = {
250  {GPIO_PIN(PORT_A, 4), .chan = 0},
251  {GPIO_PIN(PORT_A, 5), .chan = 1},
252 };
259 #define DAC_NUMOF ARRAY_SIZE(dac_config)
269 static const fmc_conf_t fmc_config = {
270  .bus = AHB3,
271  .rcc_mask = RCC_AHB3ENR_FMCEN,
272 #if MODULE_PERIPH_FMC_SDRAM
273  .ba0_pin = { .pin = GPIO_PIN(PORT_G, 4), .af = GPIO_AF12, }, /* A14 signal */
274  .ba1_pin = { .pin = GPIO_PIN(PORT_G, 5), .af = GPIO_AF12, }, /* A15 signal */
275  .sdclk_pin = { .pin = GPIO_PIN(PORT_G, 8), .af = GPIO_AF12, }, /* SDCLK signal */
276  .sdnwe_pin = { .pin = GPIO_PIN(PORT_C, 0), .af = GPIO_AF12, }, /* SDNWE signal */
277  .sdnras_pin = { .pin = GPIO_PIN(PORT_F, 11), .af = GPIO_AF12, }, /* SDNRAS signal */
278  .sdncas_pin = { .pin = GPIO_PIN(PORT_G, 15), .af = GPIO_AF12, }, /* SDNCAS signal */
279  .sdcke0_pin = { .pin = GPIO_PIN(PORT_H, 2), .af = GPIO_AF12, }, /* SDCKE0 signal */
280  .sdne0_pin = { .pin = GPIO_PIN(PORT_H, 3), .af = GPIO_AF12, }, /* SDNE0 signal */
281  .addr = {
282  { .pin = GPIO_PIN(PORT_F, 0), .af = GPIO_AF12, }, /* A0 signal */
283  { .pin = GPIO_PIN(PORT_F, 1), .af = GPIO_AF12, }, /* A1 signal */
284  { .pin = GPIO_PIN(PORT_F, 2), .af = GPIO_AF12, }, /* A2 signal */
285  { .pin = GPIO_PIN(PORT_F, 3), .af = GPIO_AF12, }, /* A3 signal */
286  { .pin = GPIO_PIN(PORT_F, 4), .af = GPIO_AF12, }, /* A4 signal */
287  { .pin = GPIO_PIN(PORT_F, 5), .af = GPIO_AF12, }, /* A5 signal */
288  { .pin = GPIO_PIN(PORT_F, 12), .af = GPIO_AF12, }, /* A6 signal */
289  { .pin = GPIO_PIN(PORT_F, 13), .af = GPIO_AF12, }, /* A7 signal */
290  { .pin = GPIO_PIN(PORT_F, 14), .af = GPIO_AF12, }, /* A8 signal */
291  { .pin = GPIO_PIN(PORT_F, 15), .af = GPIO_AF12, }, /* A9 signal */
292  { .pin = GPIO_PIN(PORT_G, 0), .af = GPIO_AF12, }, /* A10 signal */
293  { .pin = GPIO_PIN(PORT_G, 1), .af = GPIO_AF12, }, /* A11 signal */
294  },
295 #endif
296  .data = {
297  { .pin = GPIO_PIN(PORT_D, 14), .af = GPIO_AF12, }, /* D0 signal */
298  { .pin = GPIO_PIN(PORT_D, 15), .af = GPIO_AF12, }, /* D1 signal */
299  { .pin = GPIO_PIN(PORT_D, 0), .af = GPIO_AF12, }, /* D2 signal */
300  { .pin = GPIO_PIN(PORT_D, 1), .af = GPIO_AF12, }, /* D3 signal */
301  { .pin = GPIO_PIN(PORT_E, 7), .af = GPIO_AF12, }, /* D4 signal */
302  { .pin = GPIO_PIN(PORT_E, 8), .af = GPIO_AF12, }, /* D5 signal */
303  { .pin = GPIO_PIN(PORT_E, 9), .af = GPIO_AF12, }, /* D6 signal */
304  { .pin = GPIO_PIN(PORT_E, 10), .af = GPIO_AF12, }, /* D7 signal */
305 #if MODULE_PERIPH_FMC_32BIT
306  { .pin = GPIO_PIN(PORT_E, 11), .af = GPIO_AF12, }, /* D8 signal */
307  { .pin = GPIO_PIN(PORT_E, 12), .af = GPIO_AF12, }, /* D9 signal */
308  { .pin = GPIO_PIN(PORT_E, 13), .af = GPIO_AF12, }, /* D10 signal */
309  { .pin = GPIO_PIN(PORT_E, 14), .af = GPIO_AF12, }, /* D11 signal */
310  { .pin = GPIO_PIN(PORT_E, 15), .af = GPIO_AF12, }, /* D12 signal */
311  { .pin = GPIO_PIN(PORT_D, 8), .af = GPIO_AF12, }, /* D13 signal */
312  { .pin = GPIO_PIN(PORT_D, 9), .af = GPIO_AF12, }, /* D14 signal */
313  { .pin = GPIO_PIN(PORT_D, 10), .af = GPIO_AF12, }, /* D15 signal */
314  { .pin = GPIO_PIN(PORT_H, 8), .af = GPIO_AF12, }, /* D16 signal */
315  { .pin = GPIO_PIN(PORT_H, 9), .af = GPIO_AF12, }, /* D17 signal */
316  { .pin = GPIO_PIN(PORT_H, 10), .af = GPIO_AF12, }, /* D18 signal */
317  { .pin = GPIO_PIN(PORT_H, 11), .af = GPIO_AF12, }, /* D19 signal */
318  { .pin = GPIO_PIN(PORT_H, 12), .af = GPIO_AF12, }, /* D20 signal */
319  { .pin = GPIO_PIN(PORT_H, 13), .af = GPIO_AF12, }, /* D21 signal */
320  { .pin = GPIO_PIN(PORT_H, 14), .af = GPIO_AF12, }, /* D22 signal */
321  { .pin = GPIO_PIN(PORT_H, 15), .af = GPIO_AF12, }, /* D23 signal */
322  { .pin = GPIO_PIN(PORT_I, 0), .af = GPIO_AF12, }, /* D24 signal */
323  { .pin = GPIO_PIN(PORT_I, 1), .af = GPIO_AF12, }, /* D25 signal */
324  { .pin = GPIO_PIN(PORT_I, 2), .af = GPIO_AF12, }, /* D26 signal */
325  { .pin = GPIO_PIN(PORT_I, 3), .af = GPIO_AF12, }, /* D27 signal */
326  { .pin = GPIO_PIN(PORT_I, 6), .af = GPIO_AF12, }, /* D28 signal */
327  { .pin = GPIO_PIN(PORT_I, 7), .af = GPIO_AF12, }, /* D29 signal */
328  { .pin = GPIO_PIN(PORT_I, 9), .af = GPIO_AF12, }, /* D30 signal */
329  { .pin = GPIO_PIN(PORT_I, 10), .af = GPIO_AF12, }, /* D31 signal */
330 #endif
331  },
332  .nbl0_pin = { .pin = GPIO_PIN(PORT_E, 0), .af = GPIO_AF12, }, /* FMC_NBL0 signal (DQM0) */
333  .nbl1_pin = { .pin = GPIO_PIN(PORT_E, 1), .af = GPIO_AF12, }, /* FMC_NBL1 signal (DQM1) */
334  .nbl2_pin = { .pin = GPIO_PIN(PORT_I, 4), .af = GPIO_AF12, }, /* FMC_NBL2 signal (DQM2) */
335  .nbl3_pin = { .pin = GPIO_PIN(PORT_I, 5), .af = GPIO_AF12, }, /* FMC_NBL3 signal (DQM3) */
336 };
337 
346  /* bank 5 is used for SDRAM */
347  {
348  .bank = FMC_BANK_5,
349  .mem_type = FMC_SDRAM,
350  .data_width = FMC_BUS_WIDTH_32BIT,
351  .address = 0xc0000000, /* Bank 6 is mapped to 0xc0000000 */
352  .size = MiB(16), /* Size in MByte, 4M x 32 Bit */
353  .sdram = {
354  .clk_period = 2, /* SDCLK = 2 x HCLK */
355  .row_bits = 12, /* A11..A0 used for row address */
356  .col_bits = 8, /* A7..A0 used for column address */
357  .cas_latency = 2, /* CAS latency is 2 clock cycles */
358  .read_delay = 0, /* No read delay after CAS */
359  .burst_read = true, /* Burst read mode enabled */
360  .burst_write = false, /* Burst write mode disabled */
361  .burst_len = FMC_BURST_LENGTH_1, /* Burst length is 1 */
362  .burst_interleaved = false, /* Burst mode interleaved */
363  .write_protect = false, /* No write protection */
364  .four_banks = true, /* SDRAM has four internal banks */
365  .timing = { /* SDRAM Timing parameters */
366  .row_to_col_delay = 2, /* Row to column delay (2 clock cycles) */
367  .row_precharge = 2, /* Row precharge delay (2 clock cycles) */
368  .recovery_delay = 2, /* Recovery delay is (2 clock cycles) */
369  .row_cylce = 7, /* Row cycle delay is (7 clock cycles) */
370  .self_refresh = 4, /* Self refresh time is (4 clock cycles) */
371  .exit_self_refresh = 7, /* Exit self-refresh delay (7 clock cycles) */
372  .load_mode_register = 2, /* Load Mode Register to Activate delay */
373  .refresh_period = 16, /* Refresh period in ms */
374  },
375  },
376  },
377 };
378 
382 #define FMC_BANK_NUMOF ARRAY_SIZE(fmc_bank_config)
385 #ifdef __cplusplus
386 }
387 #endif
388 
@ 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:35
static const spi_conf_t spi_config[]
SPI configuration.
Definition: periph_conf.h:93
static const i2c_conf_t i2c_config[]
I2C configuration.
Definition: periph_conf.h:65
static const adc_conf_t adc_config[]
ADC configuration.
Definition: periph_conf.h:247
static const pwm_conf_t pwm_config[]
Actual PWM configuration.
Definition: periph_conf.h:218
static const dac_conf_t dac_config[]
DAC configuration.
Definition: periph_conf.h:249
static const fmc_bank_conf_t fmc_bank_config[]
FMC Bank configuration.
Definition: periph_conf.h:345
static const fmc_conf_t fmc_config
FMC controller configuration.
Definition: periph_conf.h:269
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