From 1ed80b053ffa0d50cfb236b97d6802353493eb0f Mon Sep 17 00:00:00 2001 From: Maska989 Date: Thu, 14 Mar 2024 15:57:48 +0100 Subject: [PATCH] armv7m4: add stlink host reset JIRA: CI-433 --- trunner/target/armv7m4.py | 47 +++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/trunner/target/armv7m4.py b/trunner/target/armv7m4.py index a49b47c4..723fdb72 100644 --- a/trunner/target/armv7m4.py +++ b/trunner/target/armv7m4.py @@ -1,5 +1,6 @@ import subprocess import time +import os from pathlib import Path from typing import Callable, Optional, Sequence @@ -17,6 +18,7 @@ RebooterHarness, HarnessBuilder, FlashError, + ProcessError, ) from trunner.tools import GdbInteractive, OpenocdGdbServer from trunner.types import AppOptions, TestOptions, TestResult @@ -24,9 +26,26 @@ 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") + 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, + cwd=os.getcwd(), + ) class STM32L4x6OpenocdGdbServerHarness(IntermediateHarness): @@ -46,9 +65,16 @@ def __init__(self, harness: Callable[[TestResult], TestResult]): def __call__(self, result: TestResult) -> TestResult: # Set of config parameters used in Openocd to flash up stm32l4a6 - openocd_args = ["-c", "reset_config srst_only srst_nogate connect_assert_srst", "-c", "init;reset"] - - with OpenocdGdbServer(interface="stlink", target="stm32l4x", extra_args=openocd_args).run(): + openocd_args = [ + "-c", + "reset_config srst_only srst_nogate connect_assert_srst", + "-c", + "init;reset", + ] + + with OpenocdGdbServer( + interface="stlink", target="stm32l4x", extra_args=openocd_args + ).run(): self.harness(result) return self.next_harness(result) @@ -94,7 +120,6 @@ def __call__(self): for app in self.apps: path = self.gdb.cwd / Path(app.file) sz = path.stat().st_size - self.alias(app.file, offset=offset, size=sz) self.app("ramdev", app.file, "ram", "ram") @@ -147,7 +172,9 @@ def flash_dut(self): except subprocess.CalledProcessError as e: raise FlashError(msg=str(e), output=e.stdout) from e except subprocess.TimeoutExpired as e: - raise FlashError(msg=str(e), output=e.stdout.decode("ascii") if e.stdout else None) from e + raise FlashError( + msg=str(e), output=e.stdout.decode("ascii") if e.stdout else None + ) from e def build_test(self, test: TestOptions): builder = HarnessBuilder() @@ -162,7 +189,9 @@ def build_test(self, test: TestOptions): app_loader = STM32L4x6PloAppLoader( dut=self.dut, apps=test.bootloader.apps, - gdb=GdbInteractive(port=3333, cwd=self.root_dir() / test.shell.path), + gdb=GdbInteractive( + port=3333, cwd=self.root_dir() / test.shell.path + ), ) builder.add(PloHarness(self.dut, app_loader=app_loader))