Revert "stm32/machine_uart: Allow changing only the baudrate." #16047
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This reverts commit c94a320.
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.pytest, theuart.writechar(1)has a timeout because theuart.init(2400)does not set thetimeout_charfor 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.pyfailed 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.