← index #7998Issue #3715
Off-topic · high · value 1.048
QUERY · ISSUE

stm32: Support pins with multiple AFs for the same peripheral.

openby jimmoopened 2021-11-17updated 2026-03-24
port-stm32

For example, on WB55, pin PD3 can be SPI2_SCK on AF3 and SPI2_MISO on AF5.

PortD,PD3,,,,SPI2_SCK,,SPI2_MISO,,,,,QUADSPI_BK1_NCS,,,,,EVENTOUT,

When we configure a default pin in mpconfigboard.h, it is unable (via pin_find_af and the generated code from make-pins.py) to resolve this because the AF_FN_SPI enum assumes that a given peripheral will always use the same AF number on all pins.

// This will fail, and make D3 be SPI2_SCK instead.
#define MICROPY_HW_SPI2_MISO        (pin_D3)

Here are some other AF CSV files and peripherals where different AFs share the same peripheral. Other than the WB55 SPI2 example I didn't see any that are accessible from Python. (i.e. the I2C4 are conflicting with I2C_SMBA).

boards/stm32f091_af.csv
    TIM15, USART7
boards/stm32f405_af.csv
    OTG
boards/stm32f429_af.csv
    LCD, OTG
boards/stm32f439_af.csv
    LCD, OTG
boards/stm32f722_af.csv
    OTG
boards/stm32f746_af.csv
    LCD, OTG
boards/stm32f767_af.csv
    OTG, DFSDM1, LCD, I2C4
boards/stm32h743_af.csv
    DFSDM, TIM8, SDMMC1, LCD, SAI1, TIM1, I2C4, OTG, SAI4
boards/stm32h7b3_af.csv
    OCTOSPIM, DFSDM1, PSSI, FMC, TIM8, LTDC, SDMMC1, SAI1, TIM1, I2C4
boards/stm32l072_af.csv
    TIM2, LPUART1
boards/stm32l432_af.csv
    TIM1, TIM2, COMP2, COMP1
boards/stm32l452_af.csv
    TIM1, TIM2, COMP2, COMP1
boards/stm32l476_af.csv
    TIM5, TIM2, TIM1, TIM8
boards/stm32l496_af.csv
    TIM2, SPI2, TIM8, TIM5, TIM1, QUADSPI
boards/stm32wb55_af.csv
    TIM2, TIM1, SAI1, SPI2
CANDIDATE · ISSUE

stm32: Adding pins and peripherals to the board files

openby rolandvsopened 2018-04-12updated 2021-05-05
enhancementport-stm32

Just while upgrading my collection of STM32 boards I was looking through the pin definitions and one can debate if they are complete. Other boards also suffer from incompleteness. So now the question pops up to support only the bare micropython or add the peripherals too.

For the STM32F4DISC board the following 'needs' to be added. Also like with the OTG_FS_POWER_SWITCH it seems reasonable to add a disable at startup time (like what is done with the NUCLEO_H743ZI board implementation.

There is however a driver for the LIS302DL in python. It would be nice to include a driver for the MP45DT02 microphone and CS43L22 24-bit audio DAC.

So for starters this needs to be added to the pins.csv:

SW,PA0
LED_GREEN,PD12
LED_ORANGE,PD13
LED_RED,PD14
LED_BLUE,PD15
VBUS_FS,PA9
OTG_FS_ID,PA10
OTG_FS_DM,PA11
OTG_FS_DP,PA12
OTG_FS_POWERSWITCH,PC0
OTG_FS_OVERCURRENT,PD5
LIS302DL_CE,PE3
LIS302DL_INT2,PE1
LIS302DL_SCK,PA5
LIS302DL_SDO,PA6
LIS302DL_SDI,PA7
MP45DT02_CLK,PB10
MP45DT02_DOUT,PC3
CS43L22_MCLK,PC7
CS43L22_LRCK,PA4
CS43L22_SCLK,PC10
CS43L22_SDIN,PC12
CS43L22_RESET,PD4
CS43L22_SCL,PB8
CS43L22_SDA,PB9
BOOT1,PB2
SWDIO,PA13
SWCLK,PA14
SWO,PB3

First would be to add these peripheral definitions for all the DISCO and NUCLEO boards. Do we like this approach?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied