Skip to content

fix(esp): esptool wrong boot mode issue #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions pytest-embedded-serial-esp/pytest_embedded_serial_esp/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class EspSerial(Serial):

Attributes:
esp: esptool.ESPLoader, will auto upload stub.
stub: esptool.ESPStubLoader, stubbed loader.
"""

DEFAULT_BAUDRATE = 115200
Expand Down Expand Up @@ -58,7 +59,7 @@ def __init__(
raise ValueError('Couldn\'t auto detect chip. Please manually specify with "--port"')

# stub loader has more functionalities, need to run after calling `run_stub()`
self.stub: esptool.ESPLoader = None # type: ignore
self.stub: esptool.ESPLoader = self.esp.run_stub()

if baud > initial_baud:
self.esp.change_baud(baud) # change back to the users settings
Expand All @@ -78,29 +79,21 @@ def _post_init(self):

def use_esptool(func):
"""
1. close the port and open the port to kill the `self._forward_io` thread
2. call `run_stub()`
3. call to the decorated function, could use `self.stub` as the stubbed loader
4. call `hard_reset()`
5. create the `self.forward_io` thread again.
1. call to the decorated function, could use `self.stub` as the stubbed loader
2. call `hard_reset()`
3. create the `self.forward_io` thread again.
"""

@functools.wraps(func)
def wrapper(self, *args, **kwargs):
self.proc.close()
self.proc.open()

settings = self.proc.get_settings()

try:
with DuplicateStdout(self.pexpect_proc):
self.esp.connect('hard_reset')
self.stub = self.esp.run_stub()
ret = func(self, *args, **kwargs)
self.stub.hard_reset()
finally:
self.proc.apply_settings(settings)
self.create_forward_io_thread(self.pexpect_proc)

return ret

Expand Down