Skip to content

Commit 3fe4c70

Browse files
nandojvegalak
authored andcommitted
runners: bossac: Add speed argument
The current stty command uses a hard code value of 1200. This is not compliant with SAM-BA specs and may create compatibility problems. Add an optional speed argument with 115200 as default value following SAM-BA specifications. All boards that needs a different speed should define board_runner_args(bossac "--speed=<value>") with value as required speed. Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
1 parent 788dd63 commit 3fe4c70

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

scripts/west_commands/runners/bossac.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
from runners.core import ZephyrBinaryRunner, RunnerCaps, BuildConfiguration
1212

1313
DEFAULT_BOSSAC_PORT = '/dev/ttyACM0'
14+
DEFAULT_BOSSAC_SPEED = '115200'
1415

1516

1617
class BossacBinaryRunner(ZephyrBinaryRunner):
1718
'''Runner front-end for bossac.'''
1819

1920
def __init__(self, cfg, bossac='bossac', port=DEFAULT_BOSSAC_PORT,
20-
offset=None):
21+
speed=DEFAULT_BOSSAC_SPEED, offset=None):
2122
super().__init__(cfg)
2223
self.bossac = bossac
2324
self.port = port
25+
self.speed = speed
2426
self.offset = offset
2527

2628
@classmethod
@@ -39,8 +41,12 @@ def do_add_parser(cls, parser):
3941
help='start erase/write/read/verify operation '
4042
'at flash OFFSET; OFFSET must be aligned '
4143
' to a flash page boundary')
42-
parser.add_argument('--bossac-port', default='/dev/ttyACM0',
43-
help='serial port to use, default is /dev/ttyACM0')
44+
parser.add_argument('--bossac-port', default=DEFAULT_BOSSAC_PORT,
45+
help='serial port to use, default is ' +
46+
DEFAULT_BOSSAC_PORT)
47+
parser.add_argument('--speed', default=DEFAULT_BOSSAC_SPEED,
48+
help='serial port speed to use, default is ' +
49+
DEFAULT_BOSSAC_SPEED)
4450

4551
@classmethod
4652
def get_flash_offset(cls, cfg):
@@ -58,7 +64,8 @@ def do_create(cls, cfg, args):
5864
if offset is None:
5965
offset = cls.get_flash_offset(cfg)
6066
return BossacBinaryRunner(cfg, bossac=args.bossac,
61-
port=args.bossac_port, offset=offset)
67+
port=args.bossac_port, speed=args.speed,
68+
offset=offset)
6269

6370
def read_help(self):
6471
"""Run bossac --help and return the output as a list of lines"""
@@ -110,9 +117,9 @@ def do_run(self, command, **kwargs):
110117

111118
if platform.system() == 'Linux':
112119
self.require('stty')
113-
cmd_stty = ['stty', '-F', self.port, 'raw', 'ispeed', '1200',
114-
'ospeed', '1200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
115-
'eof', '255']
120+
cmd_stty = ['stty', '-F', self.port, 'raw', 'ispeed', self.speed,
121+
'ospeed', self.speed, 'cs8', '-cstopb', 'ignpar',
122+
'eol', '255', 'eof', '255']
116123
self.check_call(cmd_stty)
117124

118125
cmd_flash = [self.bossac, '-p', self.port, '-R', '-e', '-w', '-v',

scripts/west_commands/tests/test_bossac.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,39 @@
1616
pytest.skip("skipping Linux-only bossac tests", allow_module_level=True)
1717

1818
TEST_BOSSAC_PORT = 'test-bossac-serial'
19+
TEST_BOSSAC_SPEED = '1200'
1920
TEST_OFFSET = 1234
2021
TEST_FLASH_ADDRESS = 5678
2122

2223
EXPECTED_COMMANDS = [
23-
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '1200', 'ospeed', '1200',
24-
'cs8', '-cstopb', 'ignpar', 'eol', '255', 'eof', '255'],
24+
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
25+
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
26+
'eof', '255'],
27+
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
28+
'-b', RC_KERNEL_BIN],
29+
]
30+
31+
EXPECTED_COMMANDS_WITH_SPEED = [
32+
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', TEST_BOSSAC_SPEED,
33+
'ospeed', TEST_BOSSAC_SPEED, 'cs8', '-cstopb', 'ignpar', 'eol', '255',
34+
'eof', '255'],
2535
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
2636
'-b', RC_KERNEL_BIN],
2737
]
2838

2939
EXPECTED_COMMANDS_WITH_OFFSET = [
30-
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '1200', 'ospeed', '1200',
31-
'cs8', '-cstopb', 'ignpar', 'eol', '255', 'eof', '255'],
40+
['stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
41+
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
42+
'eof', '255'],
3243
['bossac', '-p', TEST_BOSSAC_PORT, '-R', '-e', '-w', '-v',
3344
'-b', RC_KERNEL_BIN, '-o', str(TEST_OFFSET)],
3445
]
3546

3647
EXPECTED_COMMANDS_WITH_FLASH_ADDRESS = [
3748
[
38-
'stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '1200', 'ospeed',
39-
'1200', 'cs8', '-cstopb', 'ignpar', 'eol', '255', 'eof', '255'
49+
'stty', '-F', TEST_BOSSAC_PORT, 'raw', 'ispeed', '115200',
50+
'ospeed', '115200', 'cs8', '-cstopb', 'ignpar', 'eol', '255',
51+
'eof', '255'
4052
],
4153
[
4254
'bossac',
@@ -67,6 +79,7 @@ def test_bossac_init(cc, req, supports, runner_config):
6779
runner.run('flash')
6880
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_OFFSET]
6981

82+
7083
@patch('runners.bossac.BossacBinaryRunner.supports', return_value=True)
7184
@patch('runners.core.BuildConfiguration._init')
7285
@patch('runners.bossac.BossacBinaryRunner.get_flash_offset',
@@ -84,6 +97,25 @@ def test_bossac_create(cc, req, gfa, bcfg, supports, runner_config):
8497
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS]
8598

8699

100+
@patch('runners.bossac.BossacBinaryRunner.supports', return_value=True)
101+
@patch('runners.core.BuildConfiguration._init')
102+
@patch('runners.bossac.BossacBinaryRunner.get_flash_offset',
103+
return_value=None)
104+
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
105+
@patch('runners.core.ZephyrBinaryRunner.check_call')
106+
def test_bossac_create_with_speed(cc, req, gfa, bcfg, supports,
107+
runner_config):
108+
'''Test commands using a runner created from command line parameters.'''
109+
args = ['--bossac-port', str(TEST_BOSSAC_PORT),
110+
'--speed', str(TEST_BOSSAC_SPEED)]
111+
parser = argparse.ArgumentParser()
112+
BossacBinaryRunner.add_parser(parser)
113+
arg_namespace = parser.parse_args(args)
114+
runner = BossacBinaryRunner.create(runner_config, arg_namespace)
115+
runner.run('flash')
116+
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_SPEED]
117+
118+
87119
@patch('runners.bossac.BossacBinaryRunner.supports', return_value=True)
88120
@patch('runners.core.BuildConfiguration._init')
89121
@patch('runners.bossac.BossacBinaryRunner.get_flash_offset',

0 commit comments

Comments
 (0)