← index #16611PR #16047
Related · high · value 1.813
QUERY · ISSUE

[feature request] being able to change UART(0) speed without recompiling.

openby 0wwafaopened 2025-01-19updated 2025-02-27
enhancementport-esp32

Description

As a followup to https://github.com/micropython/micropython/issues/6862

I propose to find a way to change URAT(0) speed globally or momentarily.

Globally: a simple entry in a configuration file would be nice.

Programmatically:

something like:

micropython. repl_stop()

Then:
uart = machine.UART(0,921600)

uart.write("Hello 921600 World!")

micropython. repl_restart()

Code Size

Probably small.

Implementation

I hope the MicroPython maintainers or community will implement this feature

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

Revert "stm32/machine_uart: Allow changing only the baudrate."

mergedby dpgeorgeopened 2024-10-20updated 2024-10-22
port-stm32

Summary

This reverts commit c94a3205b044fb27fa703d5c280fb02a094f12e3.

The idea behind this reverted commit was that it allowed to reconfigure the UART to change only the baudrate, which is important in the context of a PPP connection where the baudrate may be changed as part of the protocol. Also, other ports like the rp2 port have this behaviour, where individual parameters of the UART can be changed with the .init() method.

But this commit was no good for a few reasons:

  1. It's a subtle breaking change to the UART API, because existing code that constructs or initialises a UART with just the baudrate would expect all other parameters to be reset to their defaults. But with this commit those parameters would remain unchanged.

  2. Constructing a UART like UART(1, 9600) also hits this code path of only changing the baudrate and does not reset other parameters, which is unexpected.

  3. It doesn't support setting the baudrate via keyword, eg UART.init(baudrate=9600).

  4. The timeout_char field is not updated when changing only the baudrate, which can lead to unexpected timeouts when reading/writing.

Due to point (4), this commit broke the tests/ports/stm32/uart.py test, the uart.writechar(1) has a timeout because the uart.init(2400) does not set the timeout_char for the new baudrate.

Points (2)-(4) could be fixed, but point (1) (being a breaking change) would remain as an issue. So the commit is reverted.

Testing

Prior to reverting, tests/ports/stm32/uart.py failed on PYBv1.0 and PYBD-SF2 (and most likely all other stm32 boards). Once reverted, this tests passes.

Trade-offs and Alternatives

The alternative is to fix points (2)-(4) above. But the API is going to be different and it's not a good idea to change that.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied