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