Skip to main content
Graduate II
March 19, 2024
Solved

STM32G0x series multiple GPIO Pin functions

  • March 19, 2024
  • 2 replies
  • 1236 views

Hi, 

Can I control the level of a GPIO Pin in software, if the GPIO Pin is in an Alternative function mode ? 

For example, I have an application where I switch a MOSFET in Software, but I would like to use the Hardware or internal Silicon, and Software to turn the Pin on and Off, is this possible with the STM32G031 controllers ?. 

Thanks

 

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

    @Tesla DeLorean wrote:

    Either you or a peripheral control the level.


    @danielbathtub - you can see this in Figure 17  in the Reference Manual:

    AndrewNeil_0-1710866171327.png

    The multiplexer connects either the Output Data Register (ODR) or the Alternate Function (AF) to the output driver.

    Figure 20 shows the case when the output is configured as AF:

    AndrewNeil_1-1710866339027.png

    Note that the ODR is disconnected from the output driver - only the AF is connected.

    So your software writing to the ODR in this case will have no effect.

     

    2 replies

    Technical Moderator
    March 19, 2024

    I haven't quite understood exactly what you want to achieve, but GPIOs can of course be switched on or off. If a MOSFET is to be switched, for example to generate a PWM, then a timer peripheral can also do this in hardware.

    Does this answer your question?

    Regards
    /Peter

    Graduate II
    March 19, 2024

    Either you or a peripheral control the level. If you need to take control, remove it from the peripheral (AF)

    If you want to drive a pattern against a port bank, you can DMA into GPIO->BSRR

    Super User
    March 19, 2024

    @Tesla DeLorean wrote:

    Either you or a peripheral control the level.


    @danielbathtub - you can see this in Figure 17  in the Reference Manual:

    AndrewNeil_0-1710866171327.png

    The multiplexer connects either the Output Data Register (ODR) or the Alternate Function (AF) to the output driver.

    Figure 20 shows the case when the output is configured as AF:

    AndrewNeil_1-1710866339027.png

    Note that the ODR is disconnected from the output driver - only the AF is connected.

    So your software writing to the ODR in this case will have no effect.