Skip to content

Commit 2f0ac78

Browse files
committed
Fixed handling errors regarding target detection and flashing
1 parent 6763c85 commit 2f0ac78

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

mbed/mbed.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,11 +1443,11 @@ def ignore_build_dir(self):
14431443
def detect_target(self, info=None):
14441444
targets = self.get_detected_targets()
14451445
if targets == False:
1446-
error("The target detection requires that the 'mbed-ls' python module is installed.\nYou can install mbed-ls by running 'pip install mbed-ls'.")
1446+
error("The target detection requires that the 'mbed-ls' python module is installed.\nYou can install mbed-ls by running 'pip install mbed-ls'.", 1)
14471447
elif len(targets) > 1:
1448-
error("Multiple targets were detected.\nOnly 1 target board should be connected to your system.")
1448+
error("Multiple targets were detected.\nOnly 1 target board should be connected to your system.", 1)
14491449
elif len(targets) == 0:
1450-
error("No targets were detected.\nPlease make sure a target board is connected to this system.")
1450+
error("No targets were detected.\nPlease make sure a target board is connected to this system.", 1)
14511451
else:
14521452
action("Detected \"%s\" connected to \"%s\" and using com port \"%s\"" % (targets[0]['name'], targets[0]['mount'], targets[0]['serial']))
14531453
info = {'msd': targets[0]['mount'], 'port': targets[0]['serial'], 'name': targets[0]['name']}
@@ -2231,23 +2231,25 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
22312231
+ (['-v'] if verbose else [])
22322232
+ args,
22332233
env=env)
2234-
2234+
22352235
if flash:
22362236
fw_name = artifact_name if artifact_name else program.name
22372237
fw_fbase = os.path.join(build_path, fw_name)
22382238
fw_file = fw_fbase + ('.hex' if os.path.exists(fw_fbase+'.hex') else '.bin')
2239-
if not fw_file:
2240-
error("Firmware file not found \"%s\"" % fw_file)
2239+
if not os.path.exists(fw_file):
2240+
error("Build program file (firmware) not found \"%s\"" % fw_file, 1)
22412241
detected = program.detect_target()
22422242

22432243
try:
22442244
from mbed_host_tests.host_tests_toolbox import flash_dev, reset_dev
22452245
except (IOError, ImportError, OSError):
2246-
error("The '-f' option requires that the 'mbed-greentea' python module is installed.\nYou can install mbed-ls by running 'pip install mbed-greentea'.")
2247-
return False
2246+
error("The '-f/--flash' option requires that the 'mbed-greentea' python module is installed.\nYou can install mbed-ls by running 'pip install mbed-greentea'.", 1)
22482247

2249-
flash_dev(detected['msd'], fw_file, program_cycle_s=0)
2250-
reset_dev(detected['port'])
2248+
if not flash_dev(detected['msd'], fw_file, program_cycle_s=2):
2249+
error("Unable to flash the target board connected to your system.", 1)
2250+
2251+
if not reset_dev(detected['port']):
2252+
error("Unable to reset the target board connected to your system.", 1)
22512253

22522254
program.set_defaults(target=target, toolchain=tchain)
22532255

0 commit comments

Comments
 (0)