Go to the documentation of this file.
29 #if defined(CPU_FAM_STM32F0)
31 #elif defined(CPU_FAM_STM32F1)
33 #elif defined(CPU_FAM_STM32F2)
35 #elif defined(CPU_FAM_STM32F3)
37 #elif defined(CPU_FAM_STM32F4)
39 #elif defined(CPU_FAM_STM32F7)
41 #elif defined(CPU_FAM_STM32G0)
43 #elif defined(CPU_FAM_STM32G4)
45 #elif defined(CPU_FAM_STM32L0)
47 #elif defined(CPU_FAM_STM32L1)
49 #elif defined(CPU_FAM_STM32L4)
51 #elif defined(CPU_FAM_STM32L5)
53 #elif defined(CPU_FAM_STM32WB)
64 #if defined(CPU_FAM_STM32F0) || defined (CPU_FAM_STM32F1) || \
65 defined(CPU_FAM_STM32F3)
66 #define CLOCK_LSI (40000U)
67 #elif defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1)
68 #define CLOCK_LSI (37000U)
69 #elif defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4) || \
70 defined(CPU_FAM_STM32F7) || defined(CPU_FAM_STM32L4) || \
71 defined(CPU_FAM_STM32WB) || defined(CPU_FAM_STM32G4) || \
72 defined(CPU_FAM_STM32G0) || defined(CPU_FAM_STM32L5) || \
73 defined(CPU_FAM_STM32MP1)
74 #define CLOCK_LSI (32000U)
76 #error "error: LSI clock speed not defined for your target CPU"
84 #define STM32_BOOTLOADER_ADDR
92 #define CPUID_LEN (12U)
98 #define CPUID_ADDR (UID_BASE)
104 #define PROVIDES_PM_LAYERED_OFF
109 #define TIMER_CHANNEL_NUMOF (4U)
114 #define TIM_CHAN(tim, chan) *(&dev(tim)->CCR1 + chan)
119 #define QDEC_CHAN (2U)
125 #define PERIPH_SPI_NEEDS_TRANSFER_BYTE
126 #define PERIPH_SPI_NEEDS_TRANSFER_REG
127 #define PERIPH_SPI_NEEDS_TRANSFER_REGS
137 #define PM_NUM_MODES (2U)
143 #define STM32_PM_STOP (1U)
144 #define STM32_PM_STANDBY (0U)
147 #ifndef PM_EWUP_CONFIG
151 #define PM_EWUP_CONFIG (0U)
160 #define NWDT_TIME_LOWER_LIMIT (1U)
161 #define NWDT_TIME_UPPER_LIMIT (4U * US_PER_MS * 4096U * (1 << 6U) \
164 #define WDT_HAS_STOP (0U)
165 #if defined(CPU_FAM_STM32L4)
166 #define WDT_HAS_INIT (1U)
168 #define WDT_HAS_INIT (0U)
178 #if defined(CPU_FAM_STM32L4) || defined(CPU_FAM_STM32WB) || \
179 defined(CPU_FAM_STM32G4) || defined(CPU_FAM_STM32G0) || \
180 defined(CPU_FAM_STM32L5)
183 #if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32G0)
186 #elif defined(CPU_FAM_STM32L1) || defined(CPU_FAM_STM32F1) || \
187 defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F3)
189 #elif defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4) || \
190 defined(CPU_FAM_STM32L4) || defined(CPU_FAM_STM32F7) || \
191 defined(CPU_FAM_STM32WB) || defined(CPU_FAM_STM32G4) || \
192 defined(CPU_FAM_STM32L5)
196 #elif defined(CPU_FAM_STM32MP1)
201 #warning "unsupported stm32XX family"
203 #if defined(CPU_FAM_STM32WB) || defined(CPU_FAM_STM32MP1)
221 #define GPIO_UNDEF (0xffffffff)
226 #if defined(CPU_FAM_STM32MP1)
227 #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 12)) | y)
229 #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y)
277 #define SPI_HWCS_MASK (0xffffff00)
285 #define SPI_HWCS(x) (SPI_HWCS_MASK | x)
292 #define PERIPH_I2C_NEED_READ_REG
294 #define PERIPH_I2C_NEED_WRITE_REG
295 #define PERIPH_I2C_NEED_READ_REGS
296 #if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
297 defined(CPU_FAM_STM32L1) || defined(CPU_FAM_STM32F4) || \
298 defined(CPU_FAM_STM32MP1)
299 #define PERIPH_I2C_NEED_WRITE_REGS
307 #ifdef CPU_FAM_STM32F1
308 GPIO_AF_OUT_PP = 0xb,
309 GPIO_AF_OUT_OD = 0xf,
319 #ifndef CPU_FAM_STM32F0
332 #ifdef CPU_FAM_STM32F1
343 #define GPIO_MODE(mode, cnf, odr) (mode | (cnf << 2) | (odr << 4))
351 #define HAVE_GPIO_MODE_T
367 #define HAVE_GPIO_PP_T
383 #define GPIO_MODE(io, pr, ot) ((io << 0) | (pr << 2) | (ot << 4))
390 #define HAVE_GPIO_MODE_T
408 #define HAVE_GPIO_FLANK_T
464 #define DMA_CHAN_CONFIG_UNSUPPORTED (UINT8_MAX)
470 #define DMA_INC_SRC_ADDR (0x04)
471 #define DMA_INC_DST_ADDR (0x08)
472 #define DMA_INC_BOTH_ADDR (DMA_INC_SRC_ADDR | DMA_INC_DST_ADDR)
479 #define DMA_DATA_WIDTH_BYTE (0x00)
480 #define DMA_DATA_WIDTH_HALF_WORD (0x01)
481 #define DMA_DATA_WIDTH_WORD (0x02)
482 #define DMA_DATA_WIDTH_MASK (0x03)
483 #define DMA_DATA_WIDTH_SHIFT (0)
489 #if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2)
490 #define ADC_DEVS (2U)
491 #elif defined(CPU_LINE_STM32F401xE) || defined(CPU_LINE_STM32F410Rx) \
492 || defined(CPU_LINE_STM32F411xE) || defined(CPU_LINE_STM32F412Zx) \
493 || defined(CPU_LINE_STM32F413xx) || defined(CPU_LINE_STM32F423xx) \
494 || defined(CPU_MODEL_STM32L452RE) || defined(CPU_MODEL_STM32L432KC)
495 #define ADC_DEVS (1U)
496 #elif defined(CPU_LINE_STM32F405xx) || defined(CPU_LINE_STM32F407xx) \
497 || defined(CPU_LINE_STM32F415xx) || defined(CPU_LINE_STM32F429xx) \
498 || defined(CPU_LINE_STM32F437xx) || defined(CPU_LINE_STM32F446xx) \
499 || defined(CPU_MODEL_STM32L476RG) || defined(CPU_MODEL_STM32L475VG)
500 #define ADC_DEVS (3U)
508 #if !defined(CPU_FAM_STM32F0) && !defined(CPU_FAM_STM32L0) && \
509 !defined(CPU_FAM_STM32L1)
572 #ifndef CPU_FAM_STM32F1
590 #ifndef UART_TXBUF_SIZE
591 #define UART_TXBUF_SIZE (64)
601 #define UART_INVALID_MODE (0x8000000)
607 #define HAVE_UART_PARITY_T
621 #define HAVE_UART_DATA_BITS_T
625 #if defined(USART_CR1_M1)
638 #define HAVE_UART_STOP_BITS_T
650 #define HAVE_SPI_CLK_T
673 #ifndef CPU_FAM_STM32F1
679 #ifdef MODULE_PERIPH_UART_HW_FC
682 #ifndef CPU_FAM_STM32F1
687 #if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L4) || \
688 defined(CPU_FAM_STM32WB) || defined(CPU_FAM_STM32G4) || \
689 defined(CPU_FAM_STM32L5) || defined(CPU_FAM_STM32MP1)
693 #ifdef MODULE_PERIPH_DMA
708 #ifndef CPU_FAM_STM32F1
716 #ifdef MODULE_PERIPH_DMA
729 #define HAVE_I2C_SPEED_T
731 #if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
732 defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L1) || \
733 defined(CPU_FAM_STM32MP1)
738 #if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F3) || \
739 defined(CPU_FAM_STM32F7) || defined(CPU_FAM_STM32L0) || \
740 defined(CPU_FAM_STM32L4) || defined(CPU_FAM_STM32WB) || \
741 defined(CPU_FAM_STM32G4) || defined(CPU_FAM_STM32G0) || \
742 defined(CPU_FAM_STM32L5)
757 #ifndef CPU_FAM_STM32F1
763 #if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F3)
764 uint32_t rcc_sw_mask;
766 #if defined(CPU_FAM_STM32F1) || defined(CPU_FAM_STM32F2) || \
767 defined(CPU_FAM_STM32F4) || defined(CPU_FAM_STM32L1) || \
768 defined(CPU_FAM_STM32MP1)
774 #if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F3) || \
775 defined(CPU_FAM_STM32F7) || defined(CPU_FAM_STM32L0) || \
776 defined(CPU_FAM_STM32L4) || defined(CPU_FAM_STM32WB) || \
777 defined(CPU_FAM_STM32G4) || defined(CPU_FAM_STM32G0) || \
778 defined(CPU_FAM_STM32L5)
796 } i2c_timing_param_t;
820 STM32_USB_OTG_PHY_BUILTIN,
821 STM32_USB_OTG_PHY_ULPI,
904 #ifdef MODULE_PERIPH_DMA
908 #define DMA_STREAM_UNDEF (UINT_MAX)
931 int dma_transfer(
dma_t dma,
int chan,
const volatile void *src,
volatile void *dst,
size_t len,
939 void dma_acquire(
dma_t dma);
946 void dma_release(
dma_t dma);
965 uint16_t dma_suspend(
dma_t dma);
973 void dma_resume(
dma_t dma, uint16_t remaining);
980 void dma_stop(
dma_t dma);
1002 int dma_configure(
dma_t dma,
int chan,
const volatile void *src,
volatile void *dst,
size_t len,
1020 uint8_t width,
bool inc_periph);
1034 #ifdef MODULE_PERIPH_CAN
1096 #define RX_DESC_STAT_LS (BIT8)
1097 #define RX_DESC_STAT_FS (BIT9)
1104 #define RX_DESC_STAT_FL (0x3FFF0000)
1105 #define RX_DESC_STAT_DE (BIT14)
1106 #define RX_DESC_STAT_ES (BIT14)
1107 #define RX_DESC_STAT_OWN (BIT31)
1120 #define RX_DESC_CTRL_RCH (BIT14)
1126 #define TX_DESC_STAT_UF (BIT1)
1127 #define TX_DESC_STAT_EC (BIT8)
1128 #define TX_DESC_STAT_NC (BIT10)
1129 #define TX_DESC_STAT_ES (BIT15)
1130 #define TX_DESC_STAT_TTSS (BIT17)
1138 #define TX_DESC_STAT_TCH (BIT20)
1139 #define TX_DESC_STAT_TER (BIT21)
1150 #define TX_DESC_STAT_CIC (BIT22 | BIT23)
1151 #define TX_DESC_STAT_TTSE (BIT25)
1152 #define TX_DESC_STAT_FS (BIT28)
1153 #define TX_DESC_STAT_LS (BIT29)
1154 #define TX_DESC_STAT_IC (BIT30)
1155 #define TX_DESC_STAT_OWN (BIT31)
@ STM32_USB_OTG_HS
High speed peripheral.
Layout of enhanced RX/TX DMA descriptor.
@ SPI_CLK_400KHZ
drive the SPI bus with 400KHz
@ GPIO_AF4
use alternate function 4
@ UART_PARITY_NONE
no parity
@ GPIO_AF12
use alternate function 12
@ UART_DATA_BITS_5
5 data bits
void gpio_init_analog(gpio_t pin)
Configure the given pin to be used as ADC input.
#define KHZ(x)
A macro to return the Hz in x kHz.
volatile uint32_t reserved2
Reserved for future use.
USART_TypeDef * dev
UART device base register address.
@ SPI_CLK_100KHZ
drive the SPI bus with 100KHz
uint32_t rcc_mask
corresponding bit in the RCC register
@ SMI
Configuration for SMI.
@ GPIO_AF13
use alternate function 13
gpio_af_t sda_af
sda pin alternate function value
uart_stop_bits_t
Definition of possible stop bits lengths in a UART frame.
@ I2C_SPEED_LOW
low speed mode: ~10 kbit/s
bxCAN specific definitions
unsigned dma_t
DMA channel type.
gpio_t pin
pin connected to the line
void periph_lpclk_en(bus_t bus, uint32_t mask)
Enable the given peripheral clock in low power mode.
@ GPIO_IN_PD
configure as input with pull-down resistor
STM32G0 CPU specific definitions for internal peripheral handling.
@ UART_STOP_BITS_2
2 stop bits
#define TIMER_CHANNEL_NUMOF
All STM timers have 4 capture-compare channels.
uint8_t phy_addr
PHY address.
@ GPIO_OD
configure as output in open-drain mode without pull resistor
@ GPIO_AF15
use alternate function 15
void periph_clk_en(bus_t bus, uint32_t mask)
Enable the given peripheral clock.
@ I2C_SPEED_NORMAL
normal mode: ~100 kbit/s
uint32_t rccmask
bit in the RCC peripheral enable register
STM32F3 CPU specific definitions for internal peripheral handling.
@ UART_DATA_BITS_8
8 data bits
gpio_af_t
Available MUX values for configuring a pin's alternate function.
uint32_t rcc_mask
bit in clock enable register
TIM_TypeDef * dev
Timer used.
STM3G4 CPU specific definitions for internal peripheral handling.
TIM_TypeDef * dev
timer device
uint8_t irqn
I2C event interrupt number.
gpio_af_t af
Alternative function.
uint8_t chan
DAC device used for this line.
gpio_af_t scl_af
scl pin alternate function value
bus_t
Available peripheral buses.
@ GPIO_OUT
configure as output in push-pull mode
gpio_t pin
GPIO pin mapped to this channel.
gpio_af_t sclk_af
SCLK pin alternate function.
void dma_wait(dma_t dma)
Wait for a DMA channel to finish the transfer.
stm32_usb_otg_fshs_phy_t phy
Built-in or ULPI phy.
@ GPIO_AF6
use alternate function 6
@ UART_DATA_BITS_6
6 data bits
uart_parity_t
Definition of possible parity modes.
i2c_speed_t
Default mapping of I2C bus speed values.
volatile uint32_t ts_low
Sub-second part of PTP timestamp of transmitted / sent frame.
uint32_t rcc_mask
bit in clock enable register
void periph_clk_dis(bus_t bus, uint32_t mask)
Disable the given peripheral clock in low power mode.
uint8_t cc_chan
capture compare channel used
@ GPIO_FALLING
emit interrupt on falling flank
uint32_t rcc_mask
bit in clock enable register
uint8_t dev
ADCx - 1 device used for the channel.
stm32_usb_otg_fshs_type_t type
FS or HS type.
STM32L0 CPU specific definitions for internal peripheral handling.
uint32_t periph_timer_clk(uint8_t bus)
Get the actual timer clock frequency.
#define QDEC_CHAN
All STM QDEC timers have 2 capture channels.
@ GPIO_IN_PU
configure as input with pull-up resistor
uint8_t dma_chan
DMA channel used for TX.
@ GPIO_RISING
emit interrupt on rising flank
void dma_init(void)
Initialize DMA.
int stream
DMA stream on stm32f2/4/7, channel on others STM32F2/4/7:
PWM device configuration.
volatile uint32_t status
Mostly status bits, some control bits.
@ SPI_CLK_10MHZ
drive the SPI bus with 10MHz
uint32_t spi_clk_t
SPI clock type.
@ GPIO_IN
configure as input without pull resistor
@ GPIO_AF3
use alternate function 3
stm32_usb_otg_fshs_type_t
USB OTG peripheral type.
TIM_TypeDef * dev
Timer used.
eth_mode_t mode
Select configuration mode.
STM32L4 CPU specific definitions for internal peripheral handling.
uint8_t * periph
USB peripheral base address.
gpio_t pin
GPIO pin mapped to this channel.
void dma_start(dma_t dma)
Start a DMA transfer.
STM32F0 CPU specific definitions for internal peripheral handling.
UART device configuration.
@ DMA_PERIPH_TO_MEM
Peripheral to memory.
@ STM32_USART
STM32 USART module type.
gpio_af_t mosi_af
MOSI pin alternate function.
uint8_t bus
APBx bus the timer is clock from.
uint32_t max
Maximum counter value.
@ GPIO_AF14
use alternate function 14
struct eth_dma_desc edma_desc_t
Layout of enhanced RX/TX DMA descriptor.
@ SPI_CLK_5MHZ
drive the SPI bus with 5MHz
#define GPIO_MODE(io, pr, ot)
Generate GPIO mode bitfields.
DAC line configuration data.
@ GPIO_OD_PU
configure as output in open-drain mode with pull resistor enabled
@ UART_PARITY_SPACE
space parity
@ DMA_MEM_TO_MEM
Memory to memory.
gpio_af_t af
alternate function used
gpio_af_t
Available MUX values for configuring a pin's alternate function.
volatile uint32_t reserved1_ext
RX: Extended status, TX: reserved.
STM32F4 CPU specific definitions for internal peripheral handling.
eth_mode_t
STM32 Ethernet configuration mode.
gpio_af_t miso_af
MISO pin alternate function.
uint32_t rcc_mask
bit in clock enable register
stm32 USB OTG configuration
@ DMA_MEM_TO_PERIPH
Memory to peripheral.
void gpio_init_af(gpio_t pin, uint8_t sel, uint8_t over)
Configure an alternate function for the given pin.
uint8_t dma
Locical CMA Descriptor used for TX.
void dma_setup(dma_t dma, unsigned trigger, uint8_t prio, bool irq)
Initialize a previously allocated DMA channel with one-time settings.
volatile uint32_t control
Control bits.
@ GPIO_BOTH
emit interrupt on both flanks
@ GPIO_AF9
use alternate function 9
uint8_t irqn
global IRQ channel
@ UART_PARITY_EVEN
even parity
uint32_t periph_apb_clk(uint8_t bus)
Get the actual bus clock frequency for the APB buses.
gpio_t adc_conf_t
ADC configuration wrapper.
Ethernet Peripheral configuration.
@ STM32_USB_OTG_FS
Full speed peripheral.
void dma_prepare(dma_t dma, uint8_t width, const void *src, void *dst, size_t num, dma_incr_t incr)
Prepare the DMA channel for an individual transfer.
gpio_af_t cs_af
HWCS pin alternate function.
SPI_TypeDef * dev
SPI device base register address.
@ RMII
Configuration for RMII.
stm32_usb_otg_fshs_phy_t
Type of USB OTG peripheral phy.
@ GPIO_AF11
use alternate function 11
uint32_t rcc_mask
bit in clock enable register
uint16_t speed
Speed selection.
gpio_mode_t
Available pin modes.
@ UART_DATA_BITS_7
7 data bits
@ GPIO_AF8
use alternate function 8
char *volatile buffer_addr
RX/TX buffer.
STM32F2 CPU specific definitions for internal peripheral handling.
volatile uint32_t ts_high
Second part of PTP timestamp.
@ GPIO_AF10
use alternate function 10
STM32WB CPU specific definitions for internal peripheral handling.
void periph_lpclk_dis(bus_t bus, uint32_t mask)
Disable the given peripheral clock.
@ MII
Configuration for MII.
STM32L1 CPU specific definitions for internal peripheral handling.
STM32F7 CPU specific definitions for internal peripheral handling.
uint8_t apbbus
APBx bus the device is connected to.
struct eth_dma_desc *volatile desc_next
Address of next DMA descriptor.
@ UART_PARITY_MARK
mark parity
@ GPIO_AF5
use alternate function 5
@ UART_STOP_BITS_1
1 stop bit
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
gpio_af_t af
alternate function used
@ UART_PARITY_ODD
odd parity
@ STM32_LPUART
STM32 Low-power UART (LPUART) module type.
unsigned int gpio_t
GPIO type identifier.
I2C configuration options.
@ GPIO_AF7
use alternate function 7
@ GPIO_AF1
use alternate function 1
@ I2C_SPEED_FAST_PLUS
fast plus mode: ~1000 kbit/s
uart_type_t
UART hardware module types.
@ SPI_CLK_1MHZ
drive the SPI bus with 1MHz
@ I2C_SPEED_FAST
fast mode: ~400 kbit/s
STM32L5 CPU specific definitions for internal peripheral handling.
STM32F1 CPU specific definitions for internal peripheral handling.
uint8_t cc_chan
capture compare channel used
SPI configuration structure type.
#define MHZ(x)
A macro to return the Hz in x MHz.
@ GPIO_AF0
use alternate function 0
@ GPIO_AF2
use alternate function 2