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 9baac25 commit d2307c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 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
29 changes: 25 additions & 4 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 Down Expand Up @@ -113,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

0 comments on commit d2307c4

Please sign in to comment.