Skip to main content
Graduate
January 10, 2025
Solved

SPI vs GPIO - Alternate Functions (AF)

  • January 10, 2025
  • 4 replies
  • 2380 views

@Tesla DeLorean Hi! Thank you for helping me with the BOOTING process. However, I have a question about the peripherals. I am planning to control a TFT screen that requires 40 pins and RGB protocol. At first, I was planning to choose random GPIOs to build the protocol (I am trying to learn by making it rather than just applying something already built), and I noticed that if I choose to use LTDC, some pins light up, as well as for connectivity like SPI... The pins selected by the IDE to do such tasks have any special characteristics? do they toggle faster? or could I do just the same applying the protocol to any other random set of GPIOs?

    This topic has been closed for replies.
    Best answer by Andrew Neil

    Sure, you can use GPIO pins to "bit-bang" any protocol you like (subject to performance limits) - but that requires you to code every single rising edge, delay, falling edge, and sample in code.

    That's very heavy on you writing the code, and on the processor having to run it.

    Therefore microcontrollers have dedicated hardware blocks for doing common things like SPI, I2C, UART, etc

    That relieves both you of having to write, and the processor of having to execute, all that tedious bit-twiddling - you can just pass data to the SPI unit, and it handles it all in hardware.

    And hardware can give much higher performance than "manually" twiddling bits by software.

    This is general across all microcontrollers - not specific to ST or STM32


     

    4 replies

    Super User
    January 10, 2025

    Sure, you can use GPIO pins to "bit-bang" any protocol you like (subject to performance limits) - but that requires you to code every single rising edge, delay, falling edge, and sample in code.

    That's very heavy on you writing the code, and on the processor having to run it.

    Therefore microcontrollers have dedicated hardware blocks for doing common things like SPI, I2C, UART, etc

    That relieves both you of having to write, and the processor of having to execute, all that tedious bit-twiddling - you can just pass data to the SPI unit, and it handles it all in hardware.

    And hardware can give much higher performance than "manually" twiddling bits by software.

    This is general across all microcontrollers - not specific to ST or STM32


     

    Graduate
    January 10, 2025

    I see, so instead of having me to interpret each signal, it is all done in the hardware already. Thank you!!

    Technical Moderator
    January 10, 2025

    Hello @LucasStartTech 

    Infact, the STM32CubeMX (Standalone version or the one integrated on the STM32CubeIDE) will give a selection of pins that have the necessary Alternate functions (or additional function) to make it work on a specific function (Slave select for SS for SPI, MOSI, MISO,...). Those details can be found on the Table of pin and ball definitions (table 10 of the DS9405 for the STM32F429)

    Best Regards.

    STTwo-32

     

    Super User
    January 10, 2025

    @STTwo-32 wrote:

    details can be found on the Table of pin and ball definitions (table 10 of the DS9405 for the STM32F429)


    @LucasStartTech it starts on page 53:

    https://www.st.com/resource/en/datasheet/stm32f427vg.pdf#page=53

    See also Table 12, alternate function mapping - from page 75:

    https://www.st.com/resource/en/datasheet/stm32f427vg.pdf#page=75

    Graduate
    January 10, 2025

    @Andrew Neil, I saw this table already. Since I am new to hardware, I didn't know if the pins were assigned just because of the HAL function or if they actually have something more.

    Graduate
    January 10, 2025

    @Andrew Neil, I will take a look at this reference manual. I've been dedicating a lot of time to learn this since spring semester. I started with the atmega and now I am trying to learn this architecture. I wish I could read faster; all these manuals are very extensive :face_with_tears_of_joy:. 

     

    Thank you for the help and patience!

    Super User
    January 10, 2025

    @LucasStartTech wrote:

     I started with the atmega 


    They are very much simpler devices - so a good place to start for learning!

    You will still have seen the concept of Alternate Functions there - pins that can be used either as plain GPIO, or for things like UART, SPI, I2C.

    But (certainly on the simpler AVRs) there's generally no more than one AF on a pin; so there's no need to decide between multiple different AFs - eg, simply enabling the UART turns its associated pins to the UART AF mode.

    Super User
    January 10, 2025

    Just to add to the confusion, STM32 also has "additional functions" - typically for the analogue features.

    AndrewNeil_0-1736529015417.png

     

    Typically, these are selected just by enabling the "additional" function.

    Graduate II
    January 10, 2025

    With the F469 the pins committed to the LCD RGB signals and SDRAM FMC have very few options/alternatives. The pin-mux routing internal peripherals to pins is relatively fixed and inflexible, ie it's not a giant cross-bar switch permitting an anything-to-anything wiring.

    The "Table 12. Alternate function" might be most illustrative of the options

    https://www.st.com/resource/en/datasheet/stm32f469ii.pdf#page=73