From 27d2a0a2d52d4430795812439952338fae177c89 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Sat, 27 Apr 2024 21:52:39 +0200 Subject: [PATCH] add target reset (#21292) --- pio-tools/custom_target.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pio-tools/custom_target.py b/pio-tools/custom_target.py index 75da53cac..a29be71c9 100644 --- a/pio-tools/custom_target.py +++ b/pio-tools/custom_target.py @@ -335,6 +335,35 @@ def esp32_use_external_crashreport(*args, **kwargs): ) print(Fore.YELLOW + output[0]+": \n"+output[1]+" in "+output[2]) + +def reset_target(*args, **kwargs): + esptoolpy = join(platform.get_package_dir("tool-esptoolpy") or "", "esptool.py") + upload_port = join(env.get("UPLOAD_PORT", "none")) + if "none" in upload_port: + env.AutodetectUploadPort() + upload_port = join(env.get("UPLOAD_PORT", "none")) + esptoolpy_flags = [ + "--no-stub", + "--chip", mcu, + "--port", upload_port, + "flash_id" + ] + esptoolpy_cmd = [env["PYTHONEXE"], esptoolpy] + esptoolpy_flags + print("Try to reset device") + subprocess.call(esptoolpy_cmd, shell=False) + + +env.AddCustomTarget( + name="reset_target", + dependencies=None, + actions=[ + reset_target + ], + title="Reset ESP32 target", + description="This command resets ESP32x target via esptoolpy", +) + + env.AddCustomTarget( name="downloadfs", dependencies=None,