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