Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stm32/uart: remove pullup resistor from UART pins. #4369

Closed
wants to merge 1 commit into from
Closed

stm32/uart: remove pullup resistor from UART pins. #4369

wants to merge 1 commit into from

Conversation

peterzuger
Copy link
Contributor

The internal Pullup resistor can be enabled when needed.

The internal Pullup resistor can be enabled when needed.
@peterhinch
Copy link
Contributor

-1 The default state of a UART input is high. If it were left to float an unconnected UART Rxd line would be likely to pick up meaningless data. What is the objection to the high-value pullup?

@rolandvs
Copy link
Sponsor Contributor

Seems like an idea that needs explaining: having the pin floating by default (when not connected). Better to disable it when the port pin is used for something else or when you are sure it is connected to a push/pull output.

@peterzuger
Copy link
Contributor Author

On an Embedded system the USART RX pin is usually connected to the TX pin of another device,
this gives it a defined state.
If the pin is left open to the world there has to be input protection for the MCU.
This input protection conflicts with the internal pullup, creating a voltage divider and preventing UART packets from being received because RX does not reach 0V.
If a RX pin is left open to the world without protection and the pullup is needed it should be enabled explicitly.

Because of the way the pullup is enabled when initializing the UART it is also not possible to disable the pullup in python.

@peterhinch
Copy link
Contributor

This input protection conflicts with the internal pullup, creating a voltage divider and preventing UART packets from being received because RX does not reach 0V.

I am puzzled by this statement. The internal pullup is on the order of 47KΩ. There will only be a problem with the 0V level if the pin is driven from a high impedance source (which is never ideal). Perhaps you can explain your use case? I've used the UARTs extensively without issue.

One concern is that a naive user might implement an output-only application leaving the input pin floating, and be confused by reams of spurious input.

@robert-hh
Copy link
Contributor

What I understand from @peterzuger's statement is, that he thinks about a resistor between an board pin and the MCU's UART RX, which limits the inrush current in case of voltage spikes. That resistor indeed creates a voltage divider in combination with the pull-up resistor in the MCU, and has effect on the low input level that can be achieved.

@dhylands
Copy link
Contributor

The UART Rx has to have the pullup so that spurious data isn't generated when nothing else is driving the line. Without the pullup, the line will have a tendency to capacitively couple with nearby traces on the circuit board and will tend to follow that nearby trace (CMOS is especially susceptible to this). This can cause excessive power consumption and lots of junk on the Rx line (especially if the trace is near a high frequency clock).

The pullup is only enabled if the UART is actually initialized. If you want to use the pin for something else and not have the pullup, then don't initialize the UART.

The only UARTs that are initialized by default are the ones on the boards where there is a secondary processor providing STLINK debugging and USB-to-serial translation.

@peterhinch
Copy link
Contributor

What I understand from @peterzuger's statement is, that he thinks about a resistor between an board pin and the MCU's UART RX, which limits the inrush current in case of voltage spikes. That resistor indeed creates a voltage divider in combination with the pull-up resistor in the MCU, and has effect on the low input level that can be achieved.

If he's putting such a resistor in place whose value is so high that it's causing this problem I would argue that this is poor design. Pins should be driven from low impedance sources to avoid picking up capacitive noise as @dhylands has pointed out.

If a UART is to be used with long lines where spikes are a serious concern, proper RS232 or RS422 line drivers should be used. Such chips are designed to cope, and will drive the MCU pin from a low impedance output.

@hoihu
Copy link
Sponsor Contributor

hoihu commented Dec 20, 2018

perhaps a bit off topic.. but serie R‘s are beneficial for example against transient bursts, e.g. ESD etc.

low impedance usually doesnt help in that case since they cant get rid of the energy spike that is being forced into the pin. A simple resistor is then used to clamp the inrush current spike to an accetable level.

But there is a tradeoff between this use case and the normal case where properly, low impedance driven data lines are better.

My experience is that several 100s of ohms should be a fair balance between these two cases. and with these values, its not a problem with the 47k pullup.

@peterzuger
Copy link
Contributor Author

As @robert-hh guessed, the problem I have is that the series resistor on the MCU Pin is preventing the UART from receiving data.
As I figured out by now a 40k pullup (STM32F4) would not be a problem, although still not ideal.
But not all pullups are 40k, the specific pin I have to use (PA10 on STM32F412) has a 10k pullup.
I agree that the pullup may not be disabled by default like I proposed, but what about providing a way of disabling the pullup when necessary ?
Also the pullup should not be enabled on the TX pin since it is useless there.

@dpgeorge
Copy link
Member

Having the pull up on the RX pin is, IMO, a useful default.

It's possible to turn off the pull up from Python, eg:

uart = machine.UART("XA", 115200)
machine.Pin("X2", machine.Pin.ALT, alt=machine.Pin.AF8_UART4)

So I'll close this PR in favour of that code snippet.

Also the pullup should not be enabled on the TX pin since it is useless there.

Yes agreed!

@dpgeorge dpgeorge closed this May 18, 2021
dpgeorge added a commit to dpgeorge/micropython that referenced this pull request May 18, 2021
RX and CTS are the input pins and pull-ups are enabled so they don't cause
a problem if left unconnected.

If needed, the pull-ups can be disabled in Python using machine.Pin after
the UART is constructed.

See issue micropython#4369.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge
Copy link
Member

Also the pullup should not be enabled on the TX pin since it is useless there.

See #7277.

dpgeorge added a commit to dpgeorge/micropython that referenced this pull request May 18, 2021
RX and CTS are the input pins and pull-ups are enabled so they don't cause
a problem if left unconnected.  But the output pins don't need a pull up
(they were originally all configured with pull up in commit
8f7491a).

If needed, the pull-ups can be disabled in Python using machine.Pin after
the UART is constructed.

See issue micropython#4369.

Signed-off-by: Damien George <damien@micropython.org>
dpgeorge added a commit to dpgeorge/micropython that referenced this pull request May 20, 2021
RX and CTS are the input pins and pull-ups are enabled so they don't cause
a problem if left unconnected.  But the output pins don't need a pull up
(they were originally all configured with pull up in commit
8f7491a).

If needed, the pull-ups can be disabled in Python using machine.Pin after
the UART is constructed.

See issue micropython#4369.

Signed-off-by: Damien George <damien@micropython.org>
ksekimoto pushed a commit to ksekimoto/micropython that referenced this pull request Jul 16, 2021
RX and CTS are the input pins and pull-ups are enabled so they don't cause
a problem if left unconnected.  But the output pins don't need a pull up
(they were originally all configured with pull up in commit
8f7491a).

If needed, the pull-ups can be disabled in Python using machine.Pin after
the UART is constructed.

See issue micropython#4369.

Signed-off-by: Damien George <damien@micropython.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants