Skip to content

Commit

Permalink
revert BASE_OPERATION and removed self.esp = None
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Jan 8, 2024
1 parent 6040b38 commit 9ef242c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pytest-embedded-arduino/pytest_embedded_arduino/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def flash(self) -> None:

try:
esptool.main(
EspSerial.BASE_OPERATION + ['--chip', self.app.target, 'write_flash', *flash_files, *flash_setting],
['--chip', self.app.target, 'write_flash', *flash_files, *flash_setting],
esp=self.esp,
)
except Exception:
Expand Down
10 changes: 5 additions & 5 deletions pytest-embedded-idf/pytest_embedded_idf/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def flash(self) -> None:
_args.extend(data['write_flash_args'])

try:
esptool.main(EspSerial.BASE_OPERATION + _args, esp=self.esp)
esptool.main(_args, esp=self.esp)
finally:
if nvs_file:
nvs_file.close()
Expand Down Expand Up @@ -199,10 +199,10 @@ def dump_flash(
raise ValueError('You must specify "partition" or ("address" and "size") to dump flash')

if output:
esptool.main(EspSerial.BASE_OPERATION + ['read_flash', str(_addr), str(_size), str(output)], esp=self.esp)
esptool.main(['read_flash', str(_addr), str(_size), str(output)], esp=self.esp)
else:
output = 'read_flash.tmp'
esptool.main(EspSerial.BASE_OPERATION + ['read_flash', str(_addr), str(_size), output], esp=self.esp)
esptool.main(['read_flash', str(_addr), str(_size), output], esp=self.esp)
content = open(output, 'rb').read()
return content

Expand All @@ -221,7 +221,7 @@ def erase_partition(self, partition_name: str) -> None:
address = self.app.partition_table[partition_name]['offset']
size = self.app.partition_table[partition_name]['size']
logging.info(f'Erasing the partition "{partition_name}" of size {size} at {address}')
esptool.main(EspSerial.BASE_OPERATION + ['erase_region', str(address), str(size)], esp=self.esp)
esptool.main(['erase_region', str(address), str(size)], esp=self.esp)
else:
raise ValueError(f'partition name "{partition_name}" not found in app partition table')

Expand All @@ -244,7 +244,7 @@ def read_flash_elf_sha256(self) -> bytes:

output = 'read_flash_elf_sha256.tmp'
esptool.main(
EspSerial.BASE_OPERATION + ['read_flash', str(bin_offset + self.DEFAULT_SHA256_OFFSET), str(32), output],
['read_flash', str(bin_offset + self.DEFAULT_SHA256_OFFSET), str(32), output],
esp=self.esp,
)
content = open(output, 'rb').read()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class EspSerial(Serial):
"""

ESPTOOL_DEFAULT_BAUDRATE = 921600
BASE_OPERATION = ['--after', 'hard_reset']

def __init__(
self,
Expand Down Expand Up @@ -112,9 +111,6 @@ def __init__(
if not self.esp:
raise ValueError('Couldn\'t auto detect chip. Please manually specify with "--port"')

self.esp: esptool.ESPLoader = None # type: ignore
self.stub: esptool.ESPLoader = None # type: ignore

target = self.esp.CHIP_NAME.lower().replace('-', '')
logging.info('Target: %s, Port: %s', target, self.esp.serial_port)

Expand Down Expand Up @@ -170,13 +166,13 @@ def _start(self):
@use_esptool()
def hard_reset(self):
"""Hard reset your espressif device"""
esptool.main(self.BASE_OPERATION, esp=self.esp)
self.esp.hard_reset()

@use_esptool()
def erase_flash(self):
"""Erase the complete flash"""
logging.info('Erasing the flash')
esptool.main(self.BASE_OPERATION + ['erase_flash'], esp=self.esp)
esptool.main(['erase_flash'], esp=self.esp)

if self._meta:
self._meta.drop_port_app_cache(self.port)

0 comments on commit 9ef242c

Please sign in to comment.