From e575aa6deba35a11163c841a6c3a502f13efe007 Mon Sep 17 00:00:00 2001 From: Maska989 Date: Fri, 26 Apr 2024 13:17:07 +0200 Subject: [PATCH] armv7m4: add stlink host reset JIRA: CI-433 --- trunner/harness/base.py | 16 +++++++++++++--- trunner/target/armv7m4.py | 28 ++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/trunner/harness/base.py b/trunner/harness/base.py index e9d83d60f..7df7e122a 100644 --- a/trunner/harness/base.py +++ b/trunner/harness/base.py @@ -73,9 +73,10 @@ class FlashError(ProcessError): class Rebooter: """Class that provides all necessary methods needed for rebooting target device.""" - def __init__(self, host: Host, dut: Dut): + def __init__(self, host: Host, dut: Dut, openocd_rst: Optional[bool] = False): self.host = host self.dut = dut + self.openocd_rst = openocd_rst def _reboot_soft(self): self.host.set_reset(0) @@ -101,6 +102,9 @@ def _reboot_dut_gpio(self, hard): def _reboot_dut_text(self, hard): pass + def _reboot_dut_command(self, hard): + pass + def _set_flash_mode(self, flash): pass @@ -110,10 +114,16 @@ def __call__(self, flash=False, hard=False): self._set_flash_mode(flash) if self.host.has_gpio(): - self._reboot_dut_gpio(hard=hard) + if self.openocd_rst == True: + self._reboot_dut_command(hard=hard) + else: + self._reboot_dut_gpio(hard=hard) else: # Perform rebooting with user interaction - self._reboot_dut_text(hard=hard) + if self.openocd_rst == True: + self._reboot_dut_command(hard=hard) + else: + self._reboot_dut_text(hard=hard) class HarnessBase(ABC): diff --git a/trunner/target/armv7m4.py b/trunner/target/armv7m4.py index 6574d48d5..5c24cb577 100644 --- a/trunner/target/armv7m4.py +++ b/trunner/target/armv7m4.py @@ -24,9 +24,28 @@ class ARMv7M4Rebooter(Rebooter): - # TODO add text mode - # NOTE: changing boot modes not needed/supported for this target - pass + + def _reboot_dut_text(self, hard): + self.dut.send(" reboot\r\n") + + def _reboot_dut_command(self, hard): + subprocess.run( + [ + "openocd", + "-f", + "interface/stlink.cfg", + "-f", + "target/stm32l4x.cfg", + "-c", + "reset_config srst_only srst_nogate connect_assert_srst", + "-c", + "init;reset;exit", + ], + encoding="ascii", + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + timeout=20, + ) class STM32L4x6OpenocdGdbServerHarness(IntermediateHarness): @@ -113,6 +132,7 @@ class STM32L4x6Target(TargetBase): experimental = False image_file = "phoenix.disk" image_addr = 0x08000000 + openocd_utility = True def __init__(self, host: Host, port: Optional[str] = None, baudrate: int = 115200): if port is None: @@ -120,7 +140,7 @@ def __init__(self, host: Host, port: Optional[str] = None, baudrate: int = 11520 port = find_port("USB-Serial|UART") self.dut = SerialDut(port, baudrate, encoding="utf-8", codec_errors="ignore") - self.rebooter = ARMv7M4Rebooter(host, self.dut) + self.rebooter = ARMv7M4Rebooter(host, self.dut, openocd_rst=True) super().__init__() @classmethod