Skip to content

Commit

Permalink
armv7m4: add stlink host reset
Browse files Browse the repository at this point in the history
JIRA: CI-433
  • Loading branch information
maska989 committed Mar 15, 2024
1 parent 909cc0a commit 1ed80b0
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions trunner/target/armv7m4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
import time
import os
from pathlib import Path
from typing import Callable, Optional, Sequence

Expand All @@ -17,16 +18,34 @@
RebooterHarness,
HarnessBuilder,
FlashError,
ProcessError,
)
from trunner.tools import GdbInteractive, OpenocdGdbServer
from trunner.types import AppOptions, TestOptions, TestResult
from .base import TargetBase, find_port


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):
Expand All @@ -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)
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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()
Expand All @@ -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))
Expand Down

0 comments on commit 1ed80b0

Please sign in to comment.