Skip to content

Commit 4025c3a

Browse files
committed
west: runners: add flash runner for sensry sy1xx socs
With this commit we add a runner that is capable of flashing the sensry sy1xx socs via uart to support the onboard OTP bootloader. Added the sy1xx runner to the list for automated test. Signed-off-by: Sven Ginka <[email protected]>
1 parent f3a3ad3 commit 4025c3a

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

scripts/west_commands/runners/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def _import_runner_module(runner_name):
6060
'spi_burn',
6161
'stm32cubeprogrammer',
6262
'stm32flash',
63+
'sy1xx',
6364
'teensy',
6465
'trace32',
6566
'uf2',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) 2025 sensry.io
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
'''Runner for Sensry SY1xx Soc Flashing Tool.'''
5+
6+
import importlib.util
7+
8+
from runners.core import RunnerCaps, ZephyrBinaryRunner
9+
10+
11+
class Sy1xxBinaryRunner(ZephyrBinaryRunner):
12+
'''Runner front-end for Sensry SY1xx Soc'''
13+
14+
def __init__(self, cfg, dev_id=None):
15+
super().__init__(cfg)
16+
print(cfg)
17+
self.bin_file = cfg.bin_file
18+
self.dev_id = dev_id
19+
20+
@classmethod
21+
def name(cls):
22+
return 'sy1xx'
23+
24+
@classmethod
25+
def capabilities(cls):
26+
return RunnerCaps(commands={'flash'}, dev_id=True)
27+
28+
@classmethod
29+
def do_add_parser(cls, parser):
30+
parser.set_defaults(dev_id='/dev/ttyUSB0')
31+
32+
@classmethod
33+
def dev_id_help(cls) -> str:
34+
return 'Device identifier such as /dev/ttyUSB0'
35+
36+
@classmethod
37+
def do_create(cls, cfg, args):
38+
# make sure the ganymed tools are installed
39+
if importlib.util.find_spec('ganymed') is None:
40+
raise RuntimeError("ganymed not found; can be installed with 'pip install ganymed'")
41+
42+
if not hasattr(args, "dev_id") or args.dev_id is None:
43+
raise RuntimeError("missing --dev-id argument, such as /dev/ttyUSB0")
44+
45+
return Sy1xxBinaryRunner(cfg, args.dev_id)
46+
47+
def do_run(self, command, **kwargs):
48+
if command == 'flash':
49+
self.flash(**kwargs)
50+
51+
def flash(self, **kwargs):
52+
self.logger.info(f'Flashing file: {self.bin_file} to {self.dev_id}')
53+
54+
from ganymed.bootloader import Bootloader
55+
56+
# convert binary to application ganymed-image
57+
application_gnm = Bootloader.convert_zephyr_bin(self.bin_file)
58+
59+
# create the loader
60+
flash_loader = Bootloader()
61+
62+
# connect to serial
63+
flash_loader.connect(self.dev_id)
64+
65+
# set the controller into bootloader mode
66+
flash_loader.enter_loading_mode()
67+
68+
# clear the internal flash
69+
flash_loader.clear_mram()
70+
71+
# write the new binary
72+
flash_loader.write_image(application_gnm)
73+
74+
self.logger.info('Flashing SY1xx finished. You may reset the device.')

scripts/west_commands/tests/test_imports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def test_runner_imports():
5151
'spi_burn',
5252
'stm32cubeprogrammer',
5353
'stm32flash',
54+
'sy1xx',
5455
'teensy',
5556
'trace32',
5657
'uf2',

0 commit comments

Comments
 (0)