Skip to content

Commit 4f13cf6

Browse files
committed
fix(rfc2217_server): Use new reset sequences
1 parent 0095a26 commit 4f13cf6

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

esp_rfc2217_server.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@
3030
# SPDX-License-Identifier: BSD-3-Clause
3131

3232
import logging
33+
import os
3334
import socket
3435
import sys
3536
import threading
3637
import time
3738

39+
from esptool.config import load_config_file
40+
from esptool.reset import ClassicReset, CustomReset, DEFAULT_RESET_DELAY, UnixTightReset
41+
3842
import serial
3943
import serial.rfc2217
4044
from serial.rfc2217 import (
@@ -46,6 +50,9 @@
4650
SET_CONTROL_RTS_ON,
4751
)
4852

53+
cfg, _ = load_config_file(verbose=True)
54+
cfg = cfg["esptool"]
55+
4956

5057
class EspPortManager(serial.rfc2217.PortManager):
5158
"""
@@ -78,34 +85,25 @@ def _telnet_process_subnegotiation(self, suboption):
7885
# only in cases not handled above do the original implementation in PortManager
7986
super(EspPortManager, self)._telnet_process_subnegotiation(suboption)
8087

81-
def _setDTR(self, state):
82-
self.serial.setDTR(state)
83-
84-
def _setRTS(self, state):
85-
self.serial.setRTS(state)
86-
# Work-around for adapters on Windows using the usbser.sys driver:
87-
# generate a dummy change to DTR so that the set-control-line-state
88-
# request is sent with the updated RTS state and the same DTR state
89-
self.serial.setDTR(self.serial.dtr)
90-
9188
def _reset_thread(self):
9289
"""
9390
The reset logic is used from esptool.py because the RTS and DTR signals
9491
cannot be retransmitted through RFC 2217 with proper timing.
9592
"""
9693
if self.logger:
9794
self.logger.info("Activating reset in thread")
98-
self._setDTR(False) # IO0=HIGH
99-
self._setRTS(True) # EN=LOW, chip in reset
100-
time.sleep(0.1)
101-
if self.esp32r0_delay:
102-
time.sleep(1.2)
103-
self._setDTR(True) # IO0=LOW
104-
self._setRTS(False) # EN=HIGH, chip out of reset
95+
96+
delay = DEFAULT_RESET_DELAY
10597
if self.esp32r0_delay:
106-
time.sleep(0.4)
107-
time.sleep(0.05)
108-
self._setDTR(False) # IO0=HIGH, done
98+
delay += 0.5
99+
100+
cfg_custom_reset_sequence = cfg.get("custom_reset_sequence")
101+
if cfg_custom_reset_sequence is not None:
102+
CustomReset(self.serial, cfg_custom_reset_sequence)()
103+
elif os.name != "nt":
104+
UnixTightReset(self.serial, delay)()
105+
else:
106+
ClassicReset(self.serial, delay)()
109107

110108

111109
class Redirector(object):

0 commit comments

Comments
 (0)