micropython / micropython/micropython

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

Open
#7,998 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

port-stm32
Dominant language
C
Stars
22.1k
Forks
9k
Avg merge
6d 4h
Merged PRs (30d)
16

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with pin_find_af, the generated code from tools/make-pins.py, and the AF_FN_SPI enum handling described in the issue. Review boards/stm32wb55_af.csv and mpconfigboard.h, then compare the other listed AF CSV files for similar conflicts. Done means a peripheral can resolve the correct alternate function when one pin exposes multiple AFs, including the SPI2 example.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
embedded-iot
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.