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 Apr 26, 2024
1 parent 04b1486 commit 14151d9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
16 changes: 13 additions & 3 deletions trunner/harness/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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:

Check failure on line 117 in trunner/harness/base.py

View workflow job for this annotation

GitHub Actions / build (3.9)

E712 comparison to True should be 'if cond is True:' or 'if cond:'

Check failure on line 117 in trunner/harness/base.py

View workflow job for this annotation

GitHub Actions / build (3.10)

E712 comparison to True should be 'if cond is True:' or 'if cond:'

Check failure on line 117 in trunner/harness/base.py

View workflow job for this annotation

GitHub Actions / build (3.11)

E712 comparison to True should be 'if cond is True:' or 'if cond:'
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:

Check failure on line 123 in trunner/harness/base.py

View workflow job for this annotation

GitHub Actions / build (3.9)

E712 comparison to True should be 'if cond is True:' or 'if cond:'

Check failure on line 123 in trunner/harness/base.py

View workflow job for this annotation

GitHub Actions / build (3.10)

E712 comparison to True should be 'if cond is True:' or 'if cond:'

Check failure on line 123 in trunner/harness/base.py

View workflow job for this annotation

GitHub Actions / build (3.11)

E712 comparison to True should be 'if cond is True:' or 'if cond:'
self._reboot_dut_command(hard=hard)
else:
self._reboot_dut_text(hard=hard)


class HarnessBase(ABC):
Expand Down
51 changes: 41 additions & 10 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

Check warning on line 3 in trunner/target/armv7m4.py

View workflow job for this annotation

GitHub Actions / build (3.9)

F401 'os' imported but unused

Check warning on line 3 in trunner/target/armv7m4.py

View workflow job for this annotation

GitHub Actions / build (3.10)

F401 'os' imported but unused

Check warning on line 3 in trunner/target/armv7m4.py

View workflow job for this annotation

GitHub Actions / build (3.11)

F401 'os' imported but unused
from pathlib import Path
from typing import Callable, Optional, Sequence

Expand All @@ -24,9 +25,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):
Expand All @@ -46,9 +66,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 +121,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 All @@ -107,14 +133,15 @@ 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:
# Try to find USB-Serial controller
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
Expand Down Expand Up @@ -147,7 +174,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 +191,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 14151d9

Please sign in to comment.