@@ -2622,6 +2622,7 @@ def _safe_append_profile_to_build_path(build_path, profile):
2622
2622
dict (name = ['-c' , '--clean' ], action = 'store_true' , help = 'Clean the build directory before compiling' ),
2623
2623
dict (name = ['-f' , '--flash' ], action = 'store_true' , help = 'Flash the built firmware onto a connected target.' ),
2624
2624
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' ),
2625
2626
dict (name = ['-N' , '--artifact-name' ], help = 'Name of the built program or library' ),
2626
2627
dict (name = ['-S' , '--supported' ], dest = 'supported' , const = True , choices = ["matrix" , "toolchains" , "targets" ], nargs = "?" , help = 'Shows supported matrix of targets and toolchains' ),
2627
2628
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,
2712
2713
env = env )
2713
2714
2714
2715
if flash or sterm :
2716
+ baudrate = baudrate or program .get_cfg ('TERM_BAUDRATE' , 9600 )
2717
+
2715
2718
try :
2716
2719
from mbed_host_tests .host_tests_toolbox import flash_dev
2717
2720
except (IOError , ImportError , OSError ):
@@ -2738,7 +2741,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2738
2741
2739
2742
# reset board and/or connect to serial port
2740
2743
if flash or sterm :
2741
- mbed_sterm (connected ['serial' ], reset = flash , sterm = sterm )
2744
+ mbed_sterm (connected ['serial' ], baudrate = baudrate , reset = flash , sterm = sterm )
2742
2745
2743
2746
if not connected :
2744
2747
error ("The target board you compiled for is not connected to your system.\n Please reconnect it and retry the last command." , 1 )
@@ -3124,15 +3127,16 @@ def detect():
3124
3127
3125
3128
# Serial terminal command
3126
3129
@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.' ),
3128
3132
dict (name = ['-b' , '--baudrate' ], help = 'Communication baudrate. Default: 9600' ),
3129
3133
dict (name = ['-e' , '--echo' ], help = 'Switch local echo on/off. Default: on' ),
3130
3134
dict (name = ['-r' , '--reset' ], action = 'store_true' , help = 'Reset the targets (via SendBreak) before opening terminal.' ),
3131
3135
hidden_aliases = ['term' ],
3132
3136
help = 'Open serial terminal to connected target.\n \n ' ,
3133
3137
description = (
3134
3138
"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 ):
3136
3140
# Gather remaining arguments
3137
3141
args = remainder
3138
3142
# Find the root of the program
@@ -3151,13 +3155,17 @@ def sterm(port=None, baudrate=None, echo=None, reset=False, sterm=True):
3151
3155
if not targets :
3152
3156
error ("Couldn't detect connected targets/boards to your system.\n You can manually specify COM port via the '--port' option." , 1 )
3153
3157
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 )
3160
3166
3167
+ if not connected :
3168
+ error ("The specified \" %s\" target/board is not connected to your system" % target )
3161
3169
3162
3170
# Generic config command
3163
3171
@subcommand ('config' ,
0 commit comments