Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@
elif runner == "openocd" and self.device_config.product == "LPC-LINK2 CMSIS-DAP":
extra_args.append("--cmd-pre-init")
extra_args.append(f'adapter serial {board_id}')
elif runner == 'jlink':
base_args.append('--dev-id')
base_args.append(board_id)
elif runner == 'stm32cubeprogrammer' and self.device_config.product != "BOOT-SERIAL":
base_args.append(f'--tool-opt=sn={board_id}')
base_args.append('--dev-id')
base_args.append(board_id)

Check failure on line 111 in scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Python lint error (SIM114) see https://docs.astral.sh/ruff/rules/if-with-same-arms

/home/runner/work/zephyr/zephyr/scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py:106 Combine `if` branches using logical `or` operator

Check warning on line 111 in scripts/pylib/pytest-twister-harness/src/twister_harness/device/hardware_adapter.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Either merge this branch with the identical one on line "107" or change one of the implementations.

See more on https://sonarcloud.io/project/issues?id=zephyrproject-rtos_zephyr&issues=AZrZJoXbN__bxX7ycvmD&open=AZrZJoXbN__bxX7ycvmD&pullRequest=100220
elif runner == 'linkserver':
base_args.append(f'--probe={board_id}')
return base_args, extra_args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_if_get_command_returns_proper_string_7(patched_which, device: HardwareA
assert isinstance(device.command, list)
assert device.command == [
'west', 'flash', '--skip-rebuild', '--build-dir', 'build', '--runner', 'stm32cubeprogrammer',
'--tool-opt=sn=p_id'
'--dev-id p_id'
]


Expand Down
3 changes: 2 additions & 1 deletion scripts/pylib/twister/twisterlib/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ def _create_command(self, runner, hardware):
# --probe=<serial number> select by probe serial number
command.append(f"--probe={board_id}")
elif runner == "stm32cubeprogrammer" and product != "BOOT-SERIAL":
command.append(f"--tool-opt=sn={board_id}")
command.append('--dev-id')
command.append(board_id)

# Receive parameters from runner_params field.
if hardware.runner_params:
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/twister/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from twisterlib.hardwaremap import DUT
from twisterlib.statuses import TwisterStatus

from . import ZEPHYR_BASE

Check failure on line 35 in scripts/tests/twister/test_handlers.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

E0611

scripts/tests/twister/test_handlers.py:35 No name 'ZEPHYR_BASE' in module 'twister' (no-name-in-module)


@pytest.fixture
Expand Down Expand Up @@ -1140,7 +1140,7 @@
'product',
None,
['west', 'flash', '--skip-rebuild', '-d', '$build_dir',
'--runner', 'stm32cubeprogrammer', '--tool-opt=sn=12345',
'--runner', 'stm32cubeprogrammer', '--dev-id', 12345,
'param1', 'param2']
),
(
Expand Down
7 changes: 6 additions & 1 deletion scripts/west_commands/runners/stm32cubeprogrammer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
self,
cfg: RunnerConfig,
port: str,
dev_id: str | None,
frequency: int | None,
reset_mode: str | None,
download_address: int | None,
Expand All @@ -48,6 +49,7 @@
super().__init__(cfg)

self._port = port
self._dev_id = dev_id
self._frequency = frequency

self._download_address = download_address
Expand Down Expand Up @@ -146,7 +148,7 @@

@classmethod
def capabilities(cls):
return RunnerCaps(commands={"flash"}, erase=True, extload=True, tool_opt=True)
return RunnerCaps(commands={"flash"}, dev_id=True, erase=True, extload=True, tool_opt=True)

@classmethod
def do_add_parser(cls, parser):
Expand Down Expand Up @@ -230,6 +232,7 @@
return STM32CubeProgrammerBinaryRunner(
cfg,
port=args.port,
dev_id=args.dev_id,
frequency=args.frequency,
reset_mode=args.reset_mode,
download_address=args.download_address,
Expand All @@ -248,7 +251,7 @@
if command == "flash":
self.flash(**kwargs)

def flash(self, **kwargs) -> None:

Check failure on line 254 in scripts/west_commands/runners/stm32cubeprogrammer.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=zephyrproject-rtos_zephyr&issues=AZrK3p1jTQFHi6R5-YtU&open=AZrK3p1jTQFHi6R5-YtU&pullRequest=100220
self.require(str(self._cli))

# prepare base command
Expand All @@ -262,6 +265,8 @@
connect_opts += f" reset={reset_mode}"
if self._conn_modifiers:
connect_opts += f" {self._conn_modifiers}"
if self._dev_id:
connect_opts += f" sn={self._dev_id}"

cmd += ["--connect", connect_opts]
cmd += self._tool_opt
Expand Down
19 changes: 18 additions & 1 deletion scripts/west_commands/tests/test_stm32cubeprogrammer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
TEST_CASES = (
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -89,6 +90,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -117,6 +119,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": "4000",
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -144,6 +147,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": "hw",
"download_address": None,
Expand Down Expand Up @@ -171,6 +175,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": "sw",
"download_address": None,
Expand Down Expand Up @@ -198,6 +203,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": "core",
"download_address": None,
Expand Down Expand Up @@ -225,11 +231,12 @@
},
{
"port": "swd",
"dev_id": "TEST",
"frequency": None,
"reset_mode": None,
"download_address": None,
"start_address": None,
"conn_modifiers": "br=115200 sn=TEST",
"conn_modifiers": "br=115200",
"start_modifiers": [],
"download_modifiers": [],
"cli": CLI_PATH,
Expand All @@ -252,6 +259,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -279,6 +287,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -307,6 +316,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -335,6 +345,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -362,6 +373,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -389,6 +401,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": None,
Expand Down Expand Up @@ -416,6 +429,7 @@
},
{
"port": "swd",
"dev_id": None,
"frequency": None,
"reset_mode": None,
"download_address": 0x80000000,
Expand Down Expand Up @@ -475,6 +489,7 @@ def test_stm32cubeprogrammer_init(
runner = STM32CubeProgrammerBinaryRunner(
cfg=runner_config,
port=tc["port"],
dev_id=tc["dev_id"],
frequency=tc["frequency"],
reset_mode=tc["reset_mode"],
download_address=tc["download_address"],
Expand Down Expand Up @@ -514,6 +529,8 @@ def test_stm32cubeprogrammer_create(
system.return_value = tc["system"]

args = ["--port", tc["port"]]
if tc["dev_id"]:
args.extend(["--dev-id", tc["dev_id"]])
if tc["frequency"]:
args.extend(["--frequency", tc["frequency"]])
if tc["reset_mode"]:
Expand Down
Loading