Restore UART0 to REPL after using it for own purposes? #13696
Replies: 6 comments
-
I see that at one stage, it was impossible to do anything with UART0 but this changed with commit 919e586 from @pi-anl in March, 2022. I've tried other things like assigning the UART0 pins to UART1 But all the variations that I've tried have failed to work. I guess, I'm misunderstanding how |
Beta Was this translation helpful? Give feedback.
-
Forcing the board to E.g. in this modification of the little demo in my first post, you can:
While this achieves what I want, it feels like the nuclear option to force the board to reset. I feel one should be able to restore UART0 to the REPL programmatically. Also, I note that some state seems to survive the reset, e.g. if I assign pins 1 and 3 to UART1 above rather than UART0, i.e. do:
... then, on resetting and exiting to the REPL, everything looks good initially - I see the REPL's banner text ( |
Beta Was this translation helpful? Give feedback.
-
The code to handle the UART REPL and machine.UART()s is totally different on ESP32. Both the same set of UARTs, but totally different code. The code that initializes the UART REPL is not run again on a µpy soft reboot, nor is there any python interface to it. So there's no way to get it back, other than to reset the whole MCU. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply, Trent. So, is it the case that I can reliably expect to be able to take control of the REPL UART, i.e. create a It's a little unclear to me what I should and shouldn't expect to be able to do with UART0 from within a Python program, i.e. are there restrictions on what one can do with it? Looking at commit 919e586 from @pi-anl, it doesn't feel as if one has the same degree of control as with other UARTs (but perhaps I misunderstood the context of this commit, and perhaps things have changed since then). You said:
I'm using |
Beta Was this translation helpful? Give feedback.
-
I don't know about that. The code in ports/esp32/uart.c, which handles the REPL UART, doesn't appear to be written with the idea that the code in ports/esp32/machine_uart.c can take the uart away from it. Simply changing the baud rate is one thing. Trying to get to the TX and RX FIFOs first when other code had registered an interrupt handler is a different thing. I'm surprised it seems to work at all. I'd either disable the REPL, move it from UART0, or just use another UART for your app. I'm pretty sure you can move the REPL UART to another UART, leaving UART0 (which the ROM bootloader can not be moved from) for another use. If you must have both the REPL and your app's serial IO on the same UART, then use |
Beta Was this translation helpful? Give feedback.
-
So, what if I want to set momentarily UART0 to 921600, output to it and then reset it? |
Beta Was this translation helpful? Give feedback.
-
I have a classic ESP32 board and want to communicate with it using serial over the board's USB-C connection.
I thought I could take UART0 from the REPL like so:
And then return it for use by the REPL and exit the program like so:
However:
os.dupterm(None, 0)
does anything - including it or leaving it out seems to make no difference. Is it necessary?I.e. I see a few bytes of gibberish (presumably somehow the baud rate doesn't adjust immediately), then various
uart driver error
messages mixed in with the output from the REPL.So, it seems to have partially worked - I'm seeing some output from the REPL but any key press results in the key being echoed followed by:
I'm not sure what to make of the
E
numbers - I see lots of different numbers that don't seem to map to error codes.I've tried varying the arguments used when constructing the
UART
for return to the REPL, e.g. settingtimeout=0
, but nothing I've tried so far has made an obvious improvement over the current situation. I've also tried usinginit
to change the settings ofuart0
and passing that toos.dupterm
rather than creating a newUART
instance but that didn't change things.Any help would be much appreciated.
I wrote a super simple program to demonstrate my problem. I have a button connected to pin 0 and when I press it, I take control or UART0 and when I release it, I attempt to return UART0 to the REPL and exit the program:
Beta Was this translation helpful? Give feedback.
All reactions