Skip to main content
Visitor II
August 25, 2022
Solved

STM32H7 : can I define the same alternate function for 2 different peripherals?

  • August 25, 2022
  • 5 replies
  • 3125 views

Hello!

I'm working on a STM32H743

I use a USB DEVICE driver (pins PB14 and PB15) : only AF12 is possible

I also use a SD card driver (PC8 ... PC12) : only AF12 is possible

(Alternate function mapping is described in the datasheet https://www.mouser.fr/datasheet/2/389/stm32h743vi-1760857.pdf page 89)

But I did not find this information: is it possible to use the same alternate functions for 2 different peripherals, on 2 different ports?

Thanks a lot for your help!

Jean

    This topic has been closed for replies.
    Best answer by FBL

    Hi @jean​ 

    First, STM32CubeMX tool should help for pins assignment and suitable alternate functions activation.

    Second, having each I/O function include a multiplexer to select which pin it should accept input from, and another for output data.

    Such a design makes it possible to have one pin feed multiple I/O functions, while simultaneously eliminating any ambiguities posed by conflicting configurations.

    Please refer to reference manual STM32H742, STM32H743/753 and STM32H750 Value line advanced Arm®-based 32-bit MCUs - Reference manual section 11.4.9 and 11.4.10 for configuring the registers of GPIOx_AFRL & GPIOx_AFRH

    5 replies

    Super User
    August 25, 2022

    AF - here 12 - is just a number written to register which controls the multiplexer on given pin.

    The individual pins are entirely independent of each other.

    So,

    > is it possible to use the same alternate functions for 2 different peripherals, on 2 different ports?

    yes.

    JW

    Visitor II
    August 25, 2022

    Multiple gpios can have same AF. The "only" doesn't apply at first glance.

    What you imagine will apply for EXTI and Gpio pin vs port name.

    Now a fun extended question for JW: what happens if the same peripheral signal is activated on two or more gpios? .... that might not be in the refman.... ?

    Graduate II
    August 25, 2022

    >>what happens if the same peripheral signal is activated on two or more gpios

    Here be Dragons..

    For peripheral outputs, might work, for inputs likely going to fight or interfere

    Into the whole "undefined operation" realm, where the HW doesn't protect you from yourself

    Super User
    August 26, 2022

    >> what happens if the same peripheral signal is activated on two or more gpios

    > Here be Dragons..

    http://www.efton.sk/STM32/gotcha/g92.html

    I understand why ST won't document this ever - the implementations may be flaky and any stated rule would probably quickly find exceptions (there already are known ones, e.g. the built-in USB PHY DP/DM pins in fact ignore the AF setting (and even MODER setting) in GPIO in 'F407, could be looked up here on forum). And, contrary to what I wrote there, I seem to recall that there *is* a rule to use exactly one AF per peripheral pad, in the GPIO chapter, at least in some RM - e.g. RM0390 for 'F446:.

    Note: The application is allowed to select one of the possible peripheral functions for each I/O at a time.

    I might be revising that article. [EDIT] Done. [/EDIT]

    There are more such undefined (e.g. using undefined AF, look at my post starting Through a copy/paste...) or just badly documented things in GPIO, but this all unecessarily confuses @jean - he is concerned about the value 12 being used in distinct pins' setup for distinct peripherals.

    JW

    FBLAnswer
    Technical Moderator
    August 26, 2022

    Hi @jean​ 

    First, STM32CubeMX tool should help for pins assignment and suitable alternate functions activation.

    Second, having each I/O function include a multiplexer to select which pin it should accept input from, and another for output data.

    Such a design makes it possible to have one pin feed multiple I/O functions, while simultaneously eliminating any ambiguities posed by conflicting configurations.

    Please refer to reference manual STM32H742, STM32H743/753 and STM32H750 Value line advanced Arm®-based 32-bit MCUs - Reference manual section 11.4.9 and 11.4.10 for configuring the registers of GPIOx_AFRL & GPIOx_AFRH

    jeanAuthor
    Visitor II
    September 5, 2022

    Hi everybody,

    Thanks a lot for all your explanation and ressources, that's very interesting.

    I confirm that having same alternate functions for different peripherals is working in my case.

    Have a great week!