cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F091, GPIO, USART

JuM
Senior

If switching GPIOA mode from 'General purpose output' (set to 1) to Alternate function USART Tx:

Will level of pin break down for a short time or will it stay rock solid at "1" ?

Rem. One has to change MODERy from 01 to 10.

One may go via 01 -> 00 -> 10   or via  01 -> 11 -> 10.

1 ACCEPTED SOLUTION

Accepted Solutions
PatrickF
ST Employee

Your SW should ensure MODER field is written in a single access, so the and/or must be done using internal variable and not directly anding/oring inside the GPIO register.

This is how it is done in the HAL code.

At pure HW level, doing in that way, the two MODER bits will change in 'same time', there is still a potential skew in the range of sub-nanosecond, which cannot be seen on external pin (beware that even if probably is very low, it is not guaranteed that it will never be seen on internal input path on same IO, like EXTI, if used).

Another solution (which could be used in addition to the previous one), to ensure a '1' level even if you temporarily drive input mode (not work for analog mode), is to enable a pull-up on the TX pin (only during MODER changes if you are chasing micro-amps on your application). Obviously, the internal ~50kohms pull-up could only ensure a '1' if external circuitry load does not pull-down the output.

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.

View solution in original post

4 REPLIES 4
S.Ma
Principal

You should program the output digital level BEFORE MODER, otherwise,

Writing the register should be immediate. If having a scope handy, zoom up and check.

JuM
Senior

The digital level IS 1 before switching to UART (as I wrote...).

But: Altering MODER from output to uart (uisng and-ing / or-ing bits) can only be done via input (input or analog). This may drop the Tx line temporary to 0.

PatrickF
ST Employee

Your SW should ensure MODER field is written in a single access, so the and/or must be done using internal variable and not directly anding/oring inside the GPIO register.

This is how it is done in the HAL code.

At pure HW level, doing in that way, the two MODER bits will change in 'same time', there is still a potential skew in the range of sub-nanosecond, which cannot be seen on external pin (beware that even if probably is very low, it is not guaranteed that it will never be seen on internal input path on same IO, like EXTI, if used).

Another solution (which could be used in addition to the previous one), to ensure a '1' level even if you temporarily drive input mode (not work for analog mode), is to enable a pull-up on the TX pin (only during MODER changes if you are chasing micro-amps on your application). Obviously, the internal ~50kohms pull-up could only ensure a '1' if external circuitry load does not pull-down the output.

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.
JuM
Senior

Thank you, use a temp now (same way as it is done in HAL). Pin is quite now.