-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
rp2: Fix dropped UART REPL bytes on soft reset. #15914
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
rp2: Fix dropped UART REPL bytes on soft reset. #15914
Conversation
Code size report:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. I verified the bug and that this PR fixes it.
It's true that the alternative would be to not reset the UARTs and leave them as they are for a soft reset. That's not too difficult, considering they already have static state. The only thing that really needs deiniting is their IRQ handlers because the Python callback is freed on soft reset.
Maybe that's a nice change, not to deinit UARTs, but it's a much bigger change (and stm32 for example does reset all UARTs on soft reset).
So let's go with this fix!
Actually, no, the RX and TX buffers are only on the GC heap. So the UART really must be deinited on soft reset. |
I guess I was thinking to still deinit the machine.UART objects (including the IRQs and the buffers) but leave the hardware UART peripheral setting alone if that UART is also used for REPL (i.e. the part implemented in rp2/uart.c which AFAIK doesn't interact with any of the machine module code.) This still seems cleaner overall, though. |
The change looks good for me. For a moment I had doubts that using |
Necessary to fix "mpremote run" over hardware UART. Bisect shows bug was introduced by d420b4e, but looks like made more complex by 01c046d. Specifically: resetting and re-initialising the REPL UART during soft reset clears the FIFO before it's done printing the "MPY: soft reboot" line. Fixed by adding a UART TX flush in the deinit path. Signed-off-by: Angus Gratton <angus@redyak.com.au>
318b9bb
to
73feaaf
Compare
Summary
Necessary to fix "mpremote run" over hardware UART (i.e. when
MICROPY_HW_ENABLE_UART_REPL
is set).Bisect shows bug was introduced by d420b4e (#13718), but looks like made more complex by 01c046d (#14041). Specifically: resetting and re-initialising the REPL UART during soft reset clears the FIFO before it's done printing the "MPY: soft reboot" line.
Fixed by adding a UART TX flush in the deinit path.
Testing
MICROPY_HW_ENABLE_UART_REPL
set.Fails without this PR, works with this PR.
Trade-offs and Alternatives