From 197a0f39fb3a57c0164f846ccd11520fa37927ee Mon Sep 17 00:00:00 2001 From: Peter van der Perk Date: Sun, 21 Jan 2024 22:44:08 +0100 Subject: [PATCH] teensy: add west flash teensy_loader_cli integration Adds loader, and flash target for teensy boards Signed-off-by: Peter van der Perk --- boards/common/teensy.board.cmake | 4 ++ boards/pjrc/teensy4/board.cmake | 11 ++++ scripts/west_commands/runners/__init__.py | 1 + scripts/west_commands/runners/teensy.py | 62 +++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 boards/common/teensy.board.cmake create mode 100644 boards/pjrc/teensy4/board.cmake create mode 100644 scripts/west_commands/runners/teensy.py diff --git a/boards/common/teensy.board.cmake b/boards/common/teensy.board.cmake new file mode 100644 index 0000000000..0b4d78eb35 --- /dev/null +++ b/boards/common/teensy.board.cmake @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 + +board_set_flasher_ifnset(teensy) +board_finalize_runner_args(teensy) diff --git a/boards/pjrc/teensy4/board.cmake b/boards/pjrc/teensy4/board.cmake new file mode 100644 index 0000000000..bd6ec2b59e --- /dev/null +++ b/boards/pjrc/teensy4/board.cmake @@ -0,0 +1,11 @@ +#SPDX-License-Identifier: Apache-2.0 + +board_set_flasher_ifnset(teensy) + +if(CONFIG_BOARD_TEENSY40) +board_runner_args(teensy "--mcu=TEENSY40") +else() +board_runner_args(teensy "--mcu=TEENSY41") +endif() + +include(${ZEPHYR_BASE}/boards/common/teensy.board.cmake) diff --git a/scripts/west_commands/runners/__init__.py b/scripts/west_commands/runners/__init__.py index 7e88d56edc..aa5686f73b 100644 --- a/scripts/west_commands/runners/__init__.py +++ b/scripts/west_commands/runners/__init__.py @@ -53,6 +53,7 @@ _names = [ 'spi_burn', 'stm32cubeprogrammer', 'stm32flash', + 'teensy', 'trace32', 'uf2', 'xtensa', diff --git a/scripts/west_commands/runners/teensy.py b/scripts/west_commands/runners/teensy.py new file mode 100644 index 0000000000..a0854f619b --- /dev/null +++ b/scripts/west_commands/runners/teensy.py @@ -0,0 +1,62 @@ +# Copyright (c) 2024 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +'''Runner for teensy .''' + +import os +import subprocess + +from runners.core import ZephyrBinaryRunner + +class TeensyBinaryRunner(ZephyrBinaryRunner): + '''Runner front-end for teensy.''' + + def __init__(self, cfg, mcu, teensy_loader): + super().__init__(cfg) + + self.mcu_args = ['--mcu', mcu] + self.teensy_loader = teensy_loader + self.hex_name = cfg.hex_file + + @classmethod + def name(cls): + return 'teensy' + + @classmethod + def do_add_parser(cls, parser): + parser.add_argument('--mcu', required=True, + help='Teensy mcu target') + parser.add_argument('--teensy', default='teensy_loader_cli', + help='path to teensy cli tool, default is teensy_loader_cli') + + @classmethod + def do_create(cls, cfg, args): + ret = TeensyBinaryRunner( + cfg, args.mcu, + teensy_loader=args.teensy) + return ret + + def do_run(self, command): + self.require(self.teensy_loader) + if command == 'flash': + self.flash() + + def flash(self): + if self.hex_name is not None and os.path.isfile(self.hex_name): + fname = self.hex_name + else: + raise ValueError( + 'Cannot flash; no hex ({}) file found. '.format(self.hex_name)) + + cmd = ([self.teensy_loader] + + self.mcu_args + + [fname]) + + self.logger.info('Flashing file: {}'.format(fname)) + + try: + self.check_output(cmd) + self.logger.info('Success') + except subprocess.CalledProcessError as grepexc: + self.logger.error("Failure %i" % grepexc.returncode)