mirror of
https://github.com/espressif/esptool.git
synced 2025-10-16 14:28:54 +08:00
fix: ignore resetting on unsupported ports
Closes https://github.com/espressif/esptool/issues/762
This commit is contained in:

committed by
Roland Dobai

parent
6ca9b81c2b
commit
e9489931f1
@@ -3,11 +3,12 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
import errno
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from .util import FatalError
|
from .util import FatalError, PrintOnce
|
||||||
|
|
||||||
# Used for resetting into bootloader on Unix-like systems
|
# Used for resetting into bootloader on Unix-like systems
|
||||||
if os.name != "nt":
|
if os.name != "nt":
|
||||||
@@ -26,11 +27,28 @@ DEFAULT_RESET_DELAY = 0.05 # default time to wait before releasing boot pin aft
|
|||||||
|
|
||||||
|
|
||||||
class ResetStrategy(object):
|
class ResetStrategy(object):
|
||||||
|
print_once = PrintOnce()
|
||||||
|
|
||||||
def __init__(self, port, reset_delay=DEFAULT_RESET_DELAY):
|
def __init__(self, port, reset_delay=DEFAULT_RESET_DELAY):
|
||||||
self.port = port
|
self.port = port
|
||||||
self.reset_delay = reset_delay
|
self.reset_delay = reset_delay
|
||||||
|
|
||||||
def __call__():
|
def __call__(self):
|
||||||
|
try:
|
||||||
|
self.reset()
|
||||||
|
except OSError as e:
|
||||||
|
# ENOTTY for TIOCMSET; EINVAL for TIOCMGET
|
||||||
|
if e.errno in [errno.ENOTTY, errno.EINVAL]:
|
||||||
|
self.print_once(
|
||||||
|
"WARNING: Chip was NOT reset. Setting RTS/DTR lines is not "
|
||||||
|
f"supported for port '{self.port.name}'. Set --before and --after "
|
||||||
|
"arguments to 'no_reset' and switch to bootloader manually to "
|
||||||
|
"avoid this warning."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _setDTR(self, state):
|
def _setDTR(self, state):
|
||||||
@@ -63,7 +81,7 @@ class ClassicReset(ResetStrategy):
|
|||||||
Classic reset sequence, sets DTR and RTS lines sequentially.
|
Classic reset sequence, sets DTR and RTS lines sequentially.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __call__(self):
|
def reset(self):
|
||||||
self._setDTR(False) # IO0=HIGH
|
self._setDTR(False) # IO0=HIGH
|
||||||
self._setRTS(True) # EN=LOW, chip in reset
|
self._setRTS(True) # EN=LOW, chip in reset
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@@ -79,7 +97,7 @@ class UnixTightReset(ResetStrategy):
|
|||||||
which allows setting DTR and RTS lines at the same time.
|
which allows setting DTR and RTS lines at the same time.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __call__(self):
|
def reset(self):
|
||||||
self._setDTRandRTS(False, False)
|
self._setDTRandRTS(False, False)
|
||||||
self._setDTRandRTS(True, True)
|
self._setDTRandRTS(True, True)
|
||||||
self._setDTRandRTS(False, True) # IO0=HIGH & EN=LOW, chip in reset
|
self._setDTRandRTS(False, True) # IO0=HIGH & EN=LOW, chip in reset
|
||||||
@@ -96,7 +114,7 @@ class USBJTAGSerialReset(ResetStrategy):
|
|||||||
is connecting via its USB-JTAG-Serial peripheral.
|
is connecting via its USB-JTAG-Serial peripheral.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __call__(self):
|
def reset(self):
|
||||||
self._setRTS(False)
|
self._setRTS(False)
|
||||||
self._setDTR(False) # Idle
|
self._setDTR(False) # Idle
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@@ -121,7 +139,7 @@ class HardReset(ResetStrategy):
|
|||||||
super().__init__(port)
|
super().__init__(port)
|
||||||
self.uses_usb_otg = uses_usb_otg
|
self.uses_usb_otg = uses_usb_otg
|
||||||
|
|
||||||
def __call__(self):
|
def reset(self):
|
||||||
self._setRTS(True) # EN->LOW
|
self._setRTS(True) # EN->LOW
|
||||||
if self.uses_usb_otg:
|
if self.uses_usb_otg:
|
||||||
# Give the chip some time to come out of reset,
|
# Give the chip some time to come out of reset,
|
||||||
@@ -162,7 +180,7 @@ class CustomReset(ResetStrategy):
|
|||||||
"U": "self._setDTRandRTS({})",
|
"U": "self._setDTRandRTS({})",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __call__(self):
|
def reset(self):
|
||||||
exec(self.constructed_strategy)
|
exec(self.constructed_strategy)
|
||||||
|
|
||||||
def __init__(self, port, seq_str):
|
def __init__(self, port, seq_str):
|
||||||
|
@@ -99,6 +99,20 @@ def get_file_size(path_to_file):
|
|||||||
return file_size
|
return file_size
|
||||||
|
|
||||||
|
|
||||||
|
class PrintOnce:
|
||||||
|
"""
|
||||||
|
Class for printing messages just once. Can be useful when running in a loop
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.already_printed = False
|
||||||
|
|
||||||
|
def __call__(self, text) -> None:
|
||||||
|
if not self.already_printed:
|
||||||
|
print(text)
|
||||||
|
self.already_printed = True
|
||||||
|
|
||||||
|
|
||||||
class FatalError(RuntimeError):
|
class FatalError(RuntimeError):
|
||||||
"""
|
"""
|
||||||
Wrapper class for runtime errors that aren't caused by internal bugs, but by
|
Wrapper class for runtime errors that aren't caused by internal bugs, but by
|
||||||
|
@@ -1204,6 +1204,30 @@ class TestVirtualPort(TestAutoDetect):
|
|||||||
)
|
)
|
||||||
self.verify_readback(0, 50 * 1024, "images/fifty_kb.bin")
|
self.verify_readback(0, 50 * 1024, "images/fifty_kb.bin")
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def pty_port(self):
|
||||||
|
import pty
|
||||||
|
|
||||||
|
master_fd, slave_fd = pty.openpty()
|
||||||
|
yield os.ttyname(slave_fd)
|
||||||
|
os.close(master_fd)
|
||||||
|
os.close(slave_fd)
|
||||||
|
|
||||||
|
@pytest.mark.host_test
|
||||||
|
def test_pty_port(self, pty_port):
|
||||||
|
cmd = [sys.executable, "-m", "esptool", "--port", pty_port, "chip_id"]
|
||||||
|
output = subprocess.run(
|
||||||
|
cmd,
|
||||||
|
cwd=TEST_DIR,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
)
|
||||||
|
# no chip connected so command should fail
|
||||||
|
assert output.returncode != 0
|
||||||
|
output = output.stdout.decode("utf-8")
|
||||||
|
print(output) # for logging
|
||||||
|
assert "WARNING: Chip was NOT reset." in output
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.quick_test
|
@pytest.mark.quick_test
|
||||||
class TestReadWriteMemory(EsptoolTestCase):
|
class TestReadWriteMemory(EsptoolTestCase):
|
||||||
|
Reference in New Issue
Block a user