Skip to content

Commit 21ae191

Browse files
committed
Add -m/--target option to mbed sterm to allow workflow based on target name, not com ports etc
Add -b/--baudrate option to `mbed compile --sterm` to allow workflow where custom baudrate is used (e.g. Pelion DM client uses 115200 default baudrate)
1 parent 1370900 commit 21ae191

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

mbed/mbed.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,7 @@ def _safe_append_profile_to_build_path(build_path, profile):
26222622
dict(name=['-c', '--clean'], action='store_true', help='Clean the build directory before compiling'),
26232623
dict(name=['-f', '--flash'], action='store_true', help='Flash the built firmware onto a connected target.'),
26242624
dict(name=['--sterm'], action='store_true', help='Open serial terminal after compiling. Can be chained with --flash'),
2625+
dict(name=['--baudrate'], help='Serial terminal communication baudrate. Default: 9600'),
26252626
dict(name=['-N', '--artifact-name'], help='Name of the built program or library'),
26262627
dict(name=['-S', '--supported'], dest='supported', const=True, choices=["matrix", "toolchains", "targets"], nargs="?", help='Shows supported matrix of targets and toolchains'),
26272628
dict(name='--app-config', dest="app_config", help="Path of an application configuration file. Default is to look for \"mbed_app.json\"."),
@@ -2712,6 +2713,8 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
27122713
env=env)
27132714

27142715
if flash or sterm:
2716+
baudrate = baudrate or program.get_cfg('TERM_BAUDRATE', 9600)
2717+
27152718
try:
27162719
from mbed_host_tests.host_tests_toolbox import flash_dev
27172720
except (IOError, ImportError, OSError):
@@ -2738,7 +2741,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
27382741

27392742
# reset board and/or connect to serial port
27402743
if flash or sterm:
2741-
mbed_sterm(connected['serial'], reset=flash, sterm=sterm)
2744+
mbed_sterm(connected['serial'], baudrate=baudrate, reset=flash, sterm=sterm)
27422745

27432746
if not connected:
27442747
error("The target board you compiled for is not connected to your system.\nPlease reconnect it and retry the last command.", 1)
@@ -3124,15 +3127,16 @@ def detect():
31243127

31253128
# Serial terminal command
31263129
@subcommand('sterm',
3127-
dict(name=['-p', '--port'], help='Communication port. Default: auto-detect'),
3130+
dict(name=['-m', '--target'], help='Compile target MCU. Example: K64F, NUCLEO_F401RE, NRF51822...'),
3131+
dict(name=['-p', '--port'], help='Communication port. Default: auto-detect. Specifying this will also ignore the -m/--target option above.'),
31283132
dict(name=['-b', '--baudrate'], help='Communication baudrate. Default: 9600'),
31293133
dict(name=['-e', '--echo'], help='Switch local echo on/off. Default: on'),
31303134
dict(name=['-r', '--reset'], action='store_true', help='Reset the targets (via SendBreak) before opening terminal.'),
31313135
hidden_aliases=['term'],
31323136
help='Open serial terminal to connected target.\n\n',
31333137
description=(
31343138
"Open serial terminal to connected target (usually board), or connect to a user-specified COM port\n"))
3135-
def sterm(port=None, baudrate=None, echo=None, reset=False, sterm=True):
3139+
def sterm(target=None, port=None, baudrate=None, echo=None, reset=False, sterm=True):
31363140
# Gather remaining arguments
31373141
args = remainder
31383142
# Find the root of the program
@@ -3151,13 +3155,17 @@ def sterm(port=None, baudrate=None, echo=None, reset=False, sterm=True):
31513155
if not targets:
31523156
error("Couldn't detect connected targets/boards to your system.\nYou can manually specify COM port via the '--port' option.", 1)
31533157

3154-
for target in targets:
3155-
if target['name'] is None:
3156-
action("Opening serial terminal to unknown target at \"%s\"" % target['serial'])
3157-
else:
3158-
action("Opening serial terminal to \"%s\"" % target['name'])
3159-
mbed_sterm(target['serial'], baudrate=baudrate, echo=echo, reset=reset, sterm=sterm)
3158+
connected = False
3159+
for _target in targets:
3160+
if _target['name'] is None:
3161+
continue
3162+
elif not target or _target['name'].upper() == target.upper():
3163+
connected = _target
3164+
action("Opening serial terminal to \"%s\"" % _target['name'])
3165+
mbed_sterm(_target['serial'], baudrate=baudrate, echo=echo, reset=reset, sterm=sterm)
31603166

3167+
if not connected:
3168+
error("The specified \"%s\" target/board is not connected to your system" % target)
31613169

31623170
# Generic config command
31633171
@subcommand('config',

0 commit comments

Comments
 (0)