Open fhrbata opened 2 weeks ago
same can also be seen on Linux, thanks for a simple possible fix.
Hello @atanisoft , thank you very much for your feedback! I just tried and even though the mentioned fix seems to be working on windows, it's not working on linux for me and the monitor resets the chip every time. Unfortunately I don't have USB->UART converter with DTR line exposed(just RTS), so I cannot verify it's state, but here is what I think might be happening. It looks like that on windows the common setting for DTR/RTS is to be set OFF(HIGH), while on Linux they seem to be ON(LOW). The pyserial is setting DTR first, after the port is opened with os.open
, so setting DTR OFF(HIGH) before opening the port with pyserial's open
causes the chip to reset. Maybe it should be possible just to drop the initial settings in monitor.
diff --git a/esp_idf_monitor/base/serial_reader.py b/esp_idf_monitor/base/serial_reader.py
index 8b7bdd38815c..afe5647b233b 100644
--- a/esp_idf_monitor/base/serial_reader.py
+++ b/esp_idf_monitor/base/serial_reader.py
@@ -99,10 +99,6 @@ class SerialReader(Reader):
self.close_serial()
def open_serial(self, reset: bool) -> None:
- # set the DTR/RTS into LOW prior open
- self.reset_strategy._setRTS(LOW)
- self.reset_strategy._setDTR(LOW)
-
self.serial.open()
# set DTR/RTS into expected HIGH state, but set the RTS first to avoid reset
I haven't tested this though. Anyway I believe it's not possible to get this 100% right, because we cannot be sure about the actual state of the lines(driver settings, system settings, how the lines were set in DCB), but I for sure can be missing something and other will have better ideas. Thank you
Maybe it should be possible just to drop the initial settings in monitor.
This will not work because pyserial is by default activating(ON) DTR/RTS and this gets also stored in DCB. Probably best would be to deactivate(OFF) DTR/RTS prior calling pyserial open on windows.
Answers checklist.
General issue report
This problem was originally reported by @mjgc in https://github.com/espressif/esp-idf/issues/14040, but it's not directly related to it.
esp-idf-monitor is setting RTS and DTR lines(functions) to LOW/1/ON prior calling pyserial open. On Windows pyserial is storing these values in DCB device-control block by calling
SetCommState
. The default values prior port opening, IIUC, should be HIGH/0/OFF, meaning the RTS/DTR function lines are disabled.I wrote a simple script which reads the DCB and prints the state of RTS and DTR.
With its help it can be seen how the states change after esp-idf-monitor exit. Prior invoking esp-idf-monitor
After running
python -m esp_idf_monitor --no-reset -p com9
Now when the
com9
is opened, it will cause the chip to go to reset, becausefRtsControl
is set to ON in DCB and RTS will be set to LOW. After the file is closed RTS goes to OFF again causing the reset. It can be seen with following simple python code and logical analyzer. I tried with UMFT234XF USB->UART.The
fDtrControl
andfRtsControl
stay set to1
. So each operation opening/closingcom9
will cause chip reset, but opening it e.g. in powershell will change the values back to0
As it turned out
click
is doing parameter expansion(glob) on Windows, which callsstat
, meaning opening/closing thecom9
port and causing the reset before esp-idf-monitor is invoked. This can be partially mitigated by usingwindows_expand_args
in click, but not in general. This probably needs to be fixed on the esp-idf-monitor side. The following patch seems to be working for me, but this will need some further investigation and testing.