[feature request] being able to change UART(0) speed without recompiling.
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
Revert "stm32/machine_uart: Allow changing only the baudrate."
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:
-
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.
-
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. -
It doesn't support setting the baudrate via keyword, eg
UART.init(baudrate=9600). -
The
timeout_charfield 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.