Skip to content

Commit

Permalink
fix: use force arg
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Feb 4, 2024
1 parent 21ef8d5 commit 8b82053
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 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(
['--chip', self.app.target, 'write_flash', *flash_files, *flash_settings],
['--chip', self.app.target, 'write_flash', *flash_files, *flash_settings, '--force'],
esp=self.esp,
)
except Exception:
Expand Down
33 changes: 27 additions & 6 deletions pytest-embedded-idf/pytest_embedded_idf/serial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import contextlib
import hashlib
import logging
import os
import tempfile
from typing import Optional, TextIO, Union

Expand Down Expand Up @@ -132,7 +131,10 @@ def flash(self) -> None:
_args.append(f'--{k}')
else:
_args.append(f'--{k}')
_args.append(str(v))
if k == 'after':
_args.append('hard_reset')
else:
_args.append(str(v))

_args.append('write_flash')

Expand All @@ -147,11 +149,30 @@ def flash(self) -> None:
)
self.esp.connect()

for k, v in self.app.flash_args['flash_files'].items():
_args.append(str(k))
_args.append(os.path.join(self.app.binary_path, str(v)))
encrypt_files = []
flash_files = []
for file in self.app.flash_files:
if file.encrypted:
encrypt_files.append(hex(file.offset))
encrypt_files.append(str(file.file_path))
else:
flash_files.append(hex(file.offset))
flash_files.append(file.file_path)

if flash_files and encrypt_files:
_args.extend(flash_files)
_args.append('--encrypt-files')
_args.extend(encrypt_files)
else:
if flash_files:
_args.extend(flash_files)
else:
_args.append('--encrypt')
_args.extend(encrypt_files)

_args.extend(self.app.flash_args['write_flash_args'])

_args.append('--force')
esptool.main(_args, esp=self.esp)

if self._meta:
Expand Down Expand Up @@ -211,7 +232,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(['erase_region', str(address), str(size)], esp=self.esp)
esptool.main(['erase_region', str(address), str(size), '--force'], esp=self.esp)
else:
raise ValueError(f'partition name "{partition_name}" not found in app partition table')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ def decorator(func):
def wrapper(self, *args, **kwargs):
with self.disable_redirect_thread():
with contextlib.redirect_stdout(self._q):
settings = self.proc.get_settings()
self.esp.connect()
ret = func(self, *args, **kwargs)
self.proc.apply_settings(settings)
return ret

return wrapper
Expand All @@ -165,7 +167,6 @@ def wrapper(self, *args, **kwargs):
def _start(self):
self.hard_reset()

@use_esptool()
def hard_reset(self):
"""Hard reset your espressif device"""
self.esp.hard_reset()
Expand All @@ -174,7 +175,7 @@ def hard_reset(self):
def erase_flash(self):
"""Erase the complete flash"""
logging.info('Erasing the flash')
esptool.main(['erase_flash'], esp=self.esp)
esptool.main(['erase_flash', '--force'], esp=self.esp)

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

0 comments on commit 8b82053

Please sign in to comment.