Skip to content

Commit

Permalink
stm32l4x6: Implement openocd reset
Browse files Browse the repository at this point in the history
Utilize new way of rebooting using available debugger (STLink v2) and allow proceed test run via host target

JIRA: CI-433
  • Loading branch information
maska989 committed Dec 10, 2024
1 parent 9a52af6 commit bfd7e77
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions trunner/target/armv7m4.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,29 @@
HarnessBuilder,
FlashError,
)
from trunner.tools import GdbInteractive, OpenocdGdbServer
from trunner.tools import GdbInteractive, OpenocdGdbServer, OpenocdProcess
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 __call__(self, flash=False, hard=False):
"""Sets flash mode and perform hard or soft & debugger reboot based on `hard` flag."""

if hard and self.host.has_gpio():
self._reboot_dut_gpio(hard=hard)
else:
self._reboot_by_debugger()

def _reboot_by_debugger(self):
OpenocdProcess(
interface="stlink",
target="stm32l4x",
extra_args=["-c", "reset_config srst_only srst_nogate connect_assert_srst", "-c init; reset; exit"],
).run()


class STM32L4x6OpenocdGdbServerHarness(IntermediateHarness):
Expand Down Expand Up @@ -123,25 +137,15 @@ def from_context(cls, ctx: TestContext):

def flash_dut(self):
try:
subprocess.run(
[
"openocd",
"-f",
"interface/stlink.cfg",
"-f",
"target/stm32l4x.cfg",
"-c",
"reset_config srst_only srst_nogate connect_assert_srst",
"-c",
f"program {self.image_file} {self.image_addr:#x} verify reset exit",
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=True,
encoding="ascii",
timeout=20,
cwd=self.boot_dir(),
)
extra_args = [
"-c",
"reset_config srst_only srst_nogate connect_assert_srst",
"-c",
f"program {self.image_file} {self.image_addr:#x} verify reset exit",
]

OpenocdProcess(interface="stlink", target="stm32l4x", extra_args=extra_args)

except FileNotFoundError as e:
raise FlashError(msg=str(e)) from e
except subprocess.CalledProcessError as e:
Expand All @@ -152,8 +156,9 @@ def flash_dut(self):
def build_test(self, test: TestOptions):
builder = HarnessBuilder()

if test.should_reboot:
builder.add(RebooterHarness(self.rebooter, hard=False))
# DUT is already rebooted by OpenocdGdbServer when loading tests
if test.should_reboot and not test.bootloader:
builder.add(RebooterHarness(self.rebooter))

if test.bootloader is not None:
app_loader = None
Expand Down

0 comments on commit bfd7e77

Please sign in to comment.