periph_conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Inria
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
22 /* Add specific clock configuration (HSE, LSE) for this board here */
23 #ifndef CONFIG_BOARD_HAS_LSE
24 #define CONFIG_BOARD_HAS_LSE 1
25 #endif
26 
27 /* This board provides a 32MHz HSE oscillator */
28 #ifndef CONFIG_BOARD_HAS_HSE
29 #define CONFIG_BOARD_HAS_HSE 1
30 #endif
31 
32 #ifndef CONFIG_CLOCK_HSE
33 #define CONFIG_CLOCK_HSE MHZ(32)
34 #endif
35 
36 #include "periph_cpu.h"
37 #include "clk_conf.h"
38 #include "cfg_rtt_default.h"
39 #include "cfg_timer_tim2.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
49 static const uart_conf_t uart_config[] = {
50  {
51  .dev = USART1,
52  .rcc_mask = RCC_APB2ENR_USART1EN,
53  .rx_pin = GPIO_PIN(PORT_B, 7),
54  .tx_pin = GPIO_PIN(PORT_B, 6),
55  .rx_af = GPIO_AF7,
56  .tx_af = GPIO_AF7,
57  .bus = APB2,
58  .irqn = USART1_IRQn,
59  .type = STM32_USART,
60  .clk_src = 0, /* Use APB clock */
61  },
62  {
63  .dev = USART2,
64  .rcc_mask = RCC_APB1ENR1_USART2EN,
65  .rx_pin = GPIO_PIN(PORT_A, 3),
66  .tx_pin = GPIO_PIN(PORT_A, 2),
67  .rx_af = GPIO_AF7,
68  .tx_af = GPIO_AF7,
69  .bus = APB1,
70  .irqn = USART2_IRQn,
71  .type = STM32_USART,
72  .clk_src = 0, /* Use APB clock */
73  },
74  {
75  .dev = LPUART1,
76  .rcc_mask = RCC_APB1ENR2_LPUART1EN,
77  .rx_pin = GPIO_PIN(PORT_C, 1),
78  .tx_pin = GPIO_PIN(PORT_C, 0),
79  .rx_af = GPIO_AF8,
80  .tx_af = GPIO_AF8,
81  .bus = APB12,
82  .irqn = LPUART1_IRQn,
83  .type = STM32_LPUART,
84  .clk_src = 0, /* Use APB clock */
85  },
86 };
87 
88 #define UART_0_ISR isr_usart1
89 #define UART_1_ISR isr_usart2
90 #define UART_2_ISR isr_lpuart1
91 
92 #define UART_NUMOF ARRAY_SIZE(uart_config)
98 static const spi_conf_t spi_config[] = {
99  {
100  .dev = SUBGHZSPI, /* Internally connected to Sub-GHz radio Modem */
101  .mosi_pin = GPIO_UNDEF,
102  .miso_pin = GPIO_UNDEF,
103  .sclk_pin = GPIO_UNDEF,
104  .cs_pin = SPI_CS_UNDEF,
105  .mosi_af = GPIO_AF_UNDEF,
106  .miso_af = GPIO_AF_UNDEF,
107  .sclk_af = GPIO_AF_UNDEF,
108  .cs_af = GPIO_AF_UNDEF,
109  .rccmask = RCC_APB3ENR_SUBGHZSPIEN,
110  .apbbus = APB3,
111  },
112 /* SUBGHZ DEBUG PINS use the SPI1 pins */
113 #if !IS_ACTIVE(CONFIG_STM32_WLX5XX)
114  {
115  .dev = SPI2,
116  .mosi_pin = GPIO_PIN(PORT_A, 10),
117  .miso_pin = GPIO_PIN(PORT_B, 14),
118  .sclk_pin = GPIO_PIN(PORT_B, 13),
119  .cs_pin = SPI_CS_UNDEF,
120  .mosi_af = GPIO_AF5,
121  .miso_af = GPIO_AF5,
122  .sclk_af = GPIO_AF5,
123  .cs_af = GPIO_AF5,
124  .rccmask = RCC_APB1ENR1_SPI2EN,
125  .apbbus = APB1,
126  }
127 #endif
128 };
129 
130 #define SPI_NUMOF ARRAY_SIZE(spi_config)
137 static const i2c_conf_t i2c_config[] = {
138  {
139  .dev = I2C2,
140  .speed = I2C_SPEED_NORMAL,
141  .scl_pin = GPIO_PIN(PORT_B, 15),
142  .sda_pin = GPIO_PIN(PORT_A, 15),
143  .scl_af = GPIO_AF4,
144  .sda_af = GPIO_AF4,
145  .bus = APB1,
146  .rcc_mask = RCC_APB1ENR1_I2C2EN,
147  .rcc_sw_mask = RCC_CCIPR_I2C2SEL_1, /* HSI (16 MHz) */
148  .irqn = I2C2_ER_IRQn,
149  }
150 };
151 
152 #define I2C_1_ISR isr_i2c2_er
153 
154 #define I2C_NUMOF ARRAY_SIZE(i2c_config)
161 static const adc_conf_t adc_config[] = {
162  { GPIO_PIN(PORT_B, 3), 2 },
163  { GPIO_PIN(PORT_B, 4), 3 },
164  { GPIO_UNDEF, 14 }, /* VBAT */
165 };
166 
167 #define VBAT_ADC ADC_LINE(2)
168 #define ADC_NUMOF ARRAY_SIZE(adc_config)
171 #ifdef __cplusplus
172 }
173 #endif
174 
@ PORT_B
port B
Definition: periph_cpu.h:47
@ PORT_C
port C
Definition: periph_cpu.h:48
@ 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 adc_conf_t adc_config[]
ADC configuration.
Definition: periph_conf.h:250
Common configuration for STM32 Timer peripheral based on TIM2.
@ 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_AF_UNDEF
an UNDEF value definition, e.g.
Definition: cpu_gpio.h:120
@ GPIO_AF7
use alternate function 7
Definition: cpu_gpio.h:108
@ STM32_LPUART
STM32 Low-power UART (LPUART) module type.
Definition: cpu_uart.h:38
@ STM32_USART
STM32 USART module type.
Definition: cpu_uart.h:37
#define SPI_CS_UNDEF
Define value for unused CS line.
Definition: periph_cpu.h:362
@ 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
ADC device configuration.
Definition: periph_cpu.h:377
I2C configuration structure.
Definition: periph_cpu.h:298
TWI_t * dev
Pointer to hardware module registers.
Definition: periph_cpu.h:299
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