Skip to main content
Associate III
March 19, 2024
Solved

STM32G0x series multiple GPIO Pin functions

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.
Andrew Neil
Andrew NeilBest answer
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.

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.

3 replies

Peter BENSCH
ST 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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Tesla DeLorean
Guru
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

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Andrew NeilBest answer
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.

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.