periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 TriaGnoSys GmbH
3  * 2017 Alexander Kurth, Sören Tempel, Tristan Bruns
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
10 #pragma once
11 
26 /* blxxxpill boards provide an LSE */
27 #ifndef CONFIG_BOARD_HAS_LSE
28 #define CONFIG_BOARD_HAS_LSE 1
29 #endif
30 
31 /* blxxxpill boards provide an HSE */
32 #ifndef CONFIG_BOARD_HAS_HSE
33 #define CONFIG_BOARD_HAS_HSE 1
34 #endif
35 
36 #include "periph_cpu.h"
37 #include "clk_conf.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
47 #ifndef RTT_FREQUENCY
48 #define RTT_FREQUENCY (16384) /* in Hz */
49 #endif
56 static const adc_conf_t adc_config[] = {
57  { .pin = GPIO_PIN(PORT_A, 0), .dev = 0, .chan = 0 },
58  { .pin = GPIO_PIN(PORT_A, 1), .dev = 0, .chan = 1 },
59  { .pin = GPIO_PIN(PORT_A, 4), .dev = 0, .chan = 4 },
60  { .pin = GPIO_PIN(PORT_A, 5), .dev = 0, .chan = 5 },
61  { .pin = GPIO_PIN(PORT_A, 6), .dev = 0, .chan = 6 },
62  { .pin = GPIO_PIN(PORT_A, 7), .dev = 0, .chan = 7 },
63  /* ADC Temperature channel */
64  { .pin = GPIO_UNDEF, .dev = 0, .chan = 16 },
65  /* ADC VREF channel */
66  { .pin = GPIO_UNDEF, .dev = 0, .chan = 17 },
67  /* The blackpill has a few pins less. PB0 and PB1 are among the GPIOs not
68  * exposed due to the lower pincount.
69  *
70  * Also, this conflicts with PWM. We prefer PWM over ADC here to provide
71  * 6 external ADC inputs, and 4 PWM outputs (instead of 8 ADC inputs and
72  * 2 PWM outputs). */
73 #if !defined(BOARD_BLACKPILL_STM32F103C8) \
74  && !defined(BOARD_BLACKPILL_STM32F103CB) \
75  && !defined(MODULE_PERIPH_PWM)
76  { .pin = GPIO_PIN(PORT_B, 0), .dev = 0, .chan = 8 },
77  { .pin = GPIO_PIN(PORT_B, 1), .dev = 0, .chan = 9 },
78 #endif
79 };
80 
81 #define ADC_NUMOF ARRAY_SIZE(adc_config)
88 static const dma_conf_t dma_config[] = {
89  { .stream = 1 }, /* DMA1 Channel 2 - SPI1_RX / USART3_TX */
90  { .stream = 2 }, /* DMA1 Channel 3 - SPI1_TX */
91  { .stream = 3 }, /* DMA1 Channel 4 - SPI2_RX / USART1_TX */
92  { .stream = 4 }, /* DMA1 Channel 5 - SPI2_TX */
93  { .stream = 6 }, /* DMA1 Channel 7 - USART2_TX */
94 };
95 
96 #define DMA_0_ISR isr_dma1_channel2
97 #define DMA_1_ISR isr_dma1_channel3
98 #define DMA_2_ISR isr_dma1_channel4
99 #define DMA_3_ISR isr_dma1_channel5
100 #define DMA_4_ISR isr_dma1_channel7
101 
102 #define DMA_NUMOF ARRAY_SIZE(dma_config)
109 static const timer_conf_t timer_config[] = {
110  {
111  .dev = TIM2,
112  .max = 0x0000ffff,
113  .rcc_mask = RCC_APB1ENR_TIM2EN,
114  .bus = APB1,
115  .irqn = TIM2_IRQn
116  },
117  {
118  .dev = TIM3,
119  .max = 0x0000ffff,
120  .rcc_mask = RCC_APB1ENR_TIM3EN,
121  .bus = APB1,
122  .irqn = TIM3_IRQn
123  },
124  {
125  .dev = TIM4,
126  .max = 0x0000ffff,
127  .rcc_mask = RCC_APB1ENR_TIM4EN,
128  .bus = APB1,
129  .irqn = TIM4_IRQn
130  }
131 };
132 
133 #define TIMER_0_ISR isr_tim2
134 #define TIMER_1_ISR isr_tim3
135 #define TIMER_2_ISR isr_tim4
136 
137 #define TIMER_NUMOF ARRAY_SIZE(timer_config)
145 static const qdec_conf_t qdec_config[] = {
146  {
147  .dev = TIM4,
148  .max = 0x0000ffff,
149  .rcc_mask = RCC_APB1ENR_TIM4EN,
150  .chan = { { .pin = GPIO_PIN(PORT_B, 6), .cc_chan = 0 },
151  { .pin = GPIO_PIN(PORT_B, 7), .cc_chan = 1 } },
152  .bus = APB1,
153  .irqn = TIM4_IRQn,
154  },
155  /* this conflicts with PWM */
156 #ifndef MODULE_PERIPH_PWM
157  {
158  .dev = TIM3,
159  .max = 0x0000ffff,
160  .rcc_mask = RCC_APB1ENR_TIM3EN,
161  .chan = { { .pin = GPIO_PIN(PORT_B, 4), .cc_chan = 0 },
162  { .pin = GPIO_PIN(PORT_B, 5), .cc_chan = 1 } },
163  /* by default TIM3 is routed to PA6 (cc_chan 0) and PA7 (cc_chan 1) */
164  .remap = AFIO_MAPR_TIM3_REMAP_1,
165  .bus = APB1,
166  .irqn = TIM3_IRQn,
167  },
168 #endif
169  /* this conflicts with UART_DEV(0) */
170 #ifndef MODULE_PERIPH_UART
171  {
172  .dev = TIM1,
173  .max = 0x0000ffff,
174  .rcc_mask = RCC_APB2ENR_TIM1EN,
175  .chan = { { .pin = GPIO_PIN(PORT_A, 8), .cc_chan = 0 },
176  { .pin = GPIO_PIN(PORT_A, 9), .cc_chan = 1 } },
177  .bus = APB2,
178  .irqn = TIM1_UP_IRQn
179  },
180 #endif
181 };
182 
183 #define QDEC_NUMOF ARRAY_SIZE(qdec_config)
190 static const uart_conf_t uart_config[] = {
191  {
192  .dev = USART1,
193  .rcc_mask = RCC_APB2ENR_USART1EN,
194  .rx_pin = GPIO_PIN(PORT_A, 10),
195  .tx_pin = GPIO_PIN(PORT_A, 9),
196  .bus = APB2,
197  .irqn = USART1_IRQn,
198 #ifdef MODULE_PERIPH_DMA
199  .dma = 2,
200  .dma_chan = DMA_CHAN_CONFIG_UNSUPPORTED
201 #endif
202  },
203  {
204  .dev = USART2,
205  .rcc_mask = RCC_APB1ENR_USART2EN,
206  .rx_pin = GPIO_PIN(PORT_A, 3),
207  .tx_pin = GPIO_PIN(PORT_A, 2),
208  .bus = APB1,
209  .irqn = USART2_IRQn,
210 #ifdef MODULE_PERIPH_DMA
211  .dma = 4,
212  .dma_chan = DMA_CHAN_CONFIG_UNSUPPORTED
213 #endif
214  },
215  {
216  .dev = USART3,
217  .rcc_mask = RCC_APB1ENR_USART3EN,
218  .rx_pin = GPIO_PIN(PORT_B, 11),
219  .tx_pin = GPIO_PIN(PORT_B, 10),
220  .bus = APB1,
221  .irqn = USART3_IRQn,
222 #ifdef MODULE_PERIPH_DMA
223  .dma = 0,
224  .dma_chan = DMA_CHAN_CONFIG_UNSUPPORTED
225 #endif
226  }
227 };
228 
229 #define UART_0_ISR (isr_usart1)
230 #define UART_1_ISR (isr_usart2)
231 #define UART_2_ISR (isr_usart3)
232 
233 #define UART_NUMOF ARRAY_SIZE(uart_config)
241 static const i2c_conf_t i2c_config[] = {
242  {
243  .dev = I2C1,
244  .speed = I2C_SPEED_NORMAL,
245  .scl_pin = GPIO_PIN(PORT_B, 8),
246  .sda_pin = GPIO_PIN(PORT_B, 9),
247  .bus = APB1,
248  .rcc_mask = RCC_APB1ENR_I2C1EN,
249  .clk = CLOCK_APB1,
250  .irqn = I2C1_EV_IRQn
251  },
252  {
253  .dev = I2C2,
254  .speed = I2C_SPEED_NORMAL,
255  .scl_pin = GPIO_PIN(PORT_B, 10),
256  .sda_pin = GPIO_PIN(PORT_B, 11),
257  .bus = APB1,
258  .rcc_mask = RCC_APB1ENR_I2C2EN,
259  .clk = CLOCK_APB1,
260  .irqn = I2C2_EV_IRQn
261  }
262 };
263 
264 #define I2C_0_ISR isr_i2c1_ev
265 #define I2C_1_ISR isr_i2c2_ev
266 
267 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
274 static const pwm_conf_t pwm_config[] = {
275  {
276  .dev = TIM3,
277  .rcc_mask = RCC_APB1ENR_TIM3EN,
278  /* by default TIM3 is routed to PA6 (cc_chan 0) and PA7 (cc_chan 1) */
279  .remap = AFIO_MAPR_TIM3_REMAP_1,
280  .chan = {
281  { .pin = GPIO_PIN(PORT_B, 4), .cc_chan = 0 },
282  { .pin = GPIO_PIN(PORT_B, 5), .cc_chan = 1 },
283 #if !defined(BOARD_BLACKPILL_STM32F103C8) \
284  && !defined(BOARD_BLACKPILL_STM32F103CB)
285  /* The blackpill has a few pins less. PB0 and PB1 are
286  * among the GPIOs not exposed due to the lower
287  * pincount */
288  { .pin = GPIO_PIN(PORT_B, 0), .cc_chan = 2 },
289  { .pin = GPIO_PIN(PORT_B, 1), .cc_chan = 3 },
290 #endif
291  },
292  .af = GPIO_AF_OUT_PP,
293  .bus = APB1,
294  },
295 };
296 
297 #define PWM_NUMOF ARRAY_SIZE(pwm_config)
304 static const spi_conf_t spi_config[] = {
305  {
306  .dev = SPI2,
307  .mosi_pin = GPIO_PIN(PORT_B, 15),
308  .miso_pin = GPIO_PIN(PORT_B, 14),
309  .sclk_pin = GPIO_PIN(PORT_B, 13),
310  .cs_pin = GPIO_PIN(PORT_B, 12),
311  .rccmask = RCC_APB1ENR_SPI2EN,
312  .apbbus = APB1,
313 #ifdef MODULE_PERIPH_DMA
314  .tx_dma = 3,
315  .tx_dma_chan = DMA_CHAN_CONFIG_UNSUPPORTED,
316  .rx_dma = 2,
317  .rx_dma_chan = DMA_CHAN_CONFIG_UNSUPPORTED
318 #endif
319  },
320 #ifndef MODULE_PERIPH_ADC
321  {
322  .dev = SPI1,
323  .mosi_pin = GPIO_PIN(PORT_A, 7),
324  .miso_pin = GPIO_PIN(PORT_A, 6),
325  .sclk_pin = GPIO_PIN(PORT_A, 5),
326  .cs_pin = GPIO_PIN(PORT_A, 4),
327  .rccmask = RCC_APB2ENR_SPI1EN,
328  .apbbus = APB2,
329 #ifdef MODULE_PERIPH_DMA
330  .tx_dma = 1,
331  .tx_dma_chan = DMA_CHAN_CONFIG_UNSUPPORTED,
332  .rx_dma = 0,
333  .rx_dma_chan = DMA_CHAN_CONFIG_UNSUPPORTED
334 #endif
335  },
336 #endif
337 };
338 
339 #define SPI_NUMOF ARRAY_SIZE(spi_config)
346  {
347  .base_addr = (uintptr_t)USB,
348  .rcc_mask = RCC_APB1ENR_USBEN,
349  .irqn = USB_LP_CAN1_RX0_IRQn,
350  .apb = APB1,
351  .dm = GPIO_PIN(PORT_A, 11),
352  .dp = GPIO_PIN(PORT_A, 12),
353  .af = GPIO_AF_UNDEF,
354  .disconn = GPIO_UNDEF,
355  },
356 };
357 
361 #define USBDEV_ISR isr_usb_lp_can1_rx0
362 
366 #define USBDEV_NUMOF ARRAY_SIZE(stm32_usbdev_fs_config)
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 
@ PORT_B
port B
Definition: periph_cpu.h:47
@ PORT_A
port A
Definition: periph_cpu.h:46
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:45
#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 timer_conf_t timer_config[]
All timers on board.
Definition: periph_conf.h:39
static const stm32_usbdev_fs_config_t stm32_usbdev_fs_config[]
USB device FS configuration.
Definition: periph_conf.h:345
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
#define DMA_CHAN_CONFIG_UNSUPPORTED
DMA channel/trigger configuration for DMA peripherals without channel/trigger filtering such as the s...
Definition: cpu_dma.h:95
@ GPIO_AF_UNDEF
an UNDEF value definition, e.g.
Definition: cpu_gpio.h:120
@ GPIO_AF_OUT_PP
alternate function output - push-pull
Definition: periph_cpu.h:166
@ APB1
Advanced Peripheral Bus 1
Definition: periph_cpu.h:78
@ APB2
Advanced Peripheral Bus 2
Definition: periph_cpu.h:79
@ 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
gpio_t pin
pin connected to the channel
Definition: periph_cpu.h:287
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
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.
Quadrature decoder configuration struct.
TIM_TypeDef * dev
Timer used.
Definition: cpu_qdec.h:49
SPI device configuration.
Definition: periph_cpu.h:336
SPI_t * dev
pointer to the used SPI device
Definition: periph_cpu.h:337
stm32 USB device FS configuration
Definition: cpu_usbdev.h:44
uintptr_t base_addr
USB peripheral base address.
Definition: cpu_usbdev.h:45
Timer device configuration.
Definition: periph_cpu.h:263
TC0_t * dev
Pointer to the used as Timer device.
Definition: periph_cpu.h:264
UART device configuration.
Definition: periph_cpu.h:217
USART_t * dev
pointer to the used UART device
Definition: periph_cpu.h:218