Skip to content

Commit

Permalink
feat(rfc2217_server): Add hard reset sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
20162026 committed Oct 30, 2023
1 parent 2a57d6c commit d66de5c
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions esp_rfc2217_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
import time

from esptool.config import load_config_file
from esptool.reset import ClassicReset, CustomReset, DEFAULT_RESET_DELAY, UnixTightReset
from esptool.reset import (
ClassicReset,
CustomReset,
DEFAULT_RESET_DELAY,
HardReset,
UnixTightReset,
)

import serial
import serial.rfc2217
Expand All @@ -63,14 +69,23 @@ class EspPortManager(serial.rfc2217.PortManager):

def __init__(self, serial_port, connection, esp32r0_delay, logger=None):
self.esp32r0_delay = esp32r0_delay
self.is_download_mode = False
super(EspPortManager, self).__init__(serial_port, connection, logger)

def _telnet_process_subnegotiation(self, suboption):
if suboption[0:1] == COM_PORT_OPTION and suboption[1:2] == SET_CONTROL:
if suboption[2:3] == SET_CONTROL_DTR_OFF:
self.is_download_mode = False
self.serial.dtr = False
return
elif suboption[2:3] == SET_CONTROL_RTS_ON and not self.serial.dtr:
elif suboption[2:3] == SET_CONTROL_RTS_OFF and not self.is_download_mode:
reset_thread = threading.Thread(target=self._hard_reset_thread)
reset_thread.daemon = True
reset_thread.name = "hard_reset_thread"
reset_thread.start()
return
elif suboption[2:3] == SET_CONTROL_DTR_ON and not self.is_download_mode:
self.is_download_mode = True
reset_thread = threading.Thread(target=self._reset_thread)
reset_thread.daemon = True
reset_thread.name = "reset_thread"
Expand All @@ -85,6 +100,14 @@ def _telnet_process_subnegotiation(self, suboption):
# only in cases not handled above do the original implementation in PortManager
super(EspPortManager, self)._telnet_process_subnegotiation(suboption)

def _hard_reset_thread(self):
"""
The reset logic used for hard resetting the chip.
"""
if self.logger:
self.logger.info("Activating hard reset in thread")
HardReset(self.serial)()

def _reset_thread(self):
"""
The reset logic is used from esptool.py because the RTS and DTR signals
Expand Down

0 comments on commit d66de5c

Please sign in to comment.