For the folks running Thonny #279
Replies: 2 comments 2 replies
-
Yeah - the DTR and RTS handing on ESP32 is SNAFU. It's not possible to fix it for all boards unfortunately. This is my command-line program which lets you access the repl over any serial, for any board: "Thonny" and "ampy" and "mpfshell" all use underlying python modules which have bugs in them (initialising the serial pulses pins), for which there is a workaround (initialize without telling it what port to use, then tell it the port afterwards). I've done extensive work getting versions of all these things working, but not had any luck getting original folks to fix any bugs. I've also added a pile of extra checking into them all (their "detection" of a working REPL was a total mess). It doesn't help that there's multiple versions of everything (windows, linux, apple...). Anyhow - if anyone wants all the fixes to get nicely working tools to talk to any esp32 chip, let me know. (yes - any esp32 - HUGE ask - since a mutually-exclusive set of them do (or do not) work depending on initial DTR/RTS settings.) |
Beta Was this translation helpful? Give feedback.
-
Here is my "ampy": https://github.com/gitcnd/ampy - not sure if it's the latest version or not of what I'm using locally. If it doesn't work for you, let me know. I'm on WSL1 (Ubuntu) on windows.
|
Beta Was this translation helpful? Give feedback.
-
Thonny and MicroPython do not play nice nice with each other with regards to resetting the ESP32. MicroPython has provided no mechanism to be able to gracefully shutdown any hardware that is in use from C code when soft resetting the ESP32. MicroPython's built in wrapper code for hardware gets shit down properly and that is because of function calls that are made from the core of MicroPython to shut down and clean up this things specifically. It is actually rather frustrating that there is no way to handle this properly.
The only way to get the hardware to get cleaned up properly is to perform a hard reset. Thonny only does a soft reset so we need to change the code in Thonny so it does a hard reset. There is yet another frustrating issue with this is USB-CDC. Instead of using the hardware USB CDC stack that is built into the any ESP32 that supports direct USB connections MicroPython authors have made the decision to use a software USB CDC stack instead. The problem there is they did not add the handling of the DTR and CTS signals which are what is used to perform a hard reset and boot mode selection... So that means the omnly way to get the ESP32's to hard reset is to actually close the serial connection to the ESP32. EVEN when doing that I am not 100% certain that the ESP32 will actually hard reset when connected using the USB CDC.
If you want to give it a run then here are the instructions. I have not tested this at all so whoever tries it please let me know if it works properly and what the errors are that come up.
Download the attached file and remove the .txt extension from the end of the filename and drop the file into
thonny/plugins/micropython
.serial_connection.py.txt
Let me know if it works on ESP32's using USB CDC as well.
Beta Was this translation helpful? Give feedback.
All reactions