@@ -1583,7 +1583,7 @@ def get_target(self, target=None):
1583
1583
target = target if target else target_cfg
1584
1584
1585
1585
if target and (target .lower () == 'detect' or target .lower () == 'auto' ):
1586
- detected = self .detect_target ()
1586
+ detected = self .detect_single_target ()
1587
1587
if detected :
1588
1588
target = detected ['name' ]
1589
1589
@@ -1623,7 +1623,7 @@ def ignore_build_dir(self):
1623
1623
except IOError :
1624
1624
error ("Unable to write build ignore file in \" %s\" " % os .path .join (build_path , '.mbedignore' ), 1 )
1625
1625
1626
- def detect_target (self , info = None ):
1626
+ def detect_single_target (self , info = None ):
1627
1627
targets = self .get_detected_targets ()
1628
1628
if targets == False :
1629
1629
error ("The target detection requires that the 'mbed-ls' python module is installed.\n You can install mbed-ls by running \" pip install mbed-ls\" ." , 1 )
@@ -1633,7 +1633,7 @@ def detect_target(self, info=None):
1633
1633
error ("No targets were detected.\n Please make sure a target board is connected to this system." , 1 )
1634
1634
else :
1635
1635
action ("Detected \" %s\" connected to \" %s\" and using com port \" %s\" " % (targets [0 ]['name' ], targets [0 ]['mount' ], targets [0 ]['serial' ]))
1636
- info = { 'msd' : targets [0 ][ 'mount' ], 'port' : targets [ 0 ][ 'serial' ], 'name' : targets [ 0 ][ 'name' ]}
1636
+ info = targets [0 ]
1637
1637
1638
1638
if info is None :
1639
1639
error ("The detected target doesn't support Mass Storage Device capability (MSD)" , 1 )
@@ -2532,23 +2532,36 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
2532
2532
env = env )
2533
2533
2534
2534
if flash or sterm :
2535
- detected = program .detect_target ()
2536
2535
try :
2537
2536
from mbed_host_tests .host_tests_toolbox import flash_dev
2538
2537
except (IOError , ImportError , OSError ):
2539
2538
error ("The '-f/--flash' option requires that the 'mbed-greentea' python module is installed.\n You can install mbed-greentea by running \" %s -m pip install mbed-greentea\" ." % python_cmd , 1 )
2540
2539
2541
- if flash :
2542
- fw_name = artifact_name if artifact_name else program .name
2543
- fw_fbase = os .path .join (build_path , fw_name )
2544
- fw_file = fw_fbase + ('.hex' if os .path .exists (fw_fbase + '.hex' ) else '.bin' )
2545
- if not os .path .exists (fw_file ):
2546
- error ("Build program file (firmware) not found \" %s\" " % fw_file , 1 )
2547
- if not flash_dev (detected ['msd' ], fw_file , program_cycle_s = 4 ):
2548
- error ("Unable to flash the target board connected to your system." , 1 )
2549
-
2550
- if flash or sterm :
2551
- mbed_sterm (detected ['port' ], reset = flash , sterm = sterm )
2540
+ connected = False
2541
+ targets = program .get_detected_targets ()
2542
+ if targets :
2543
+ for _target in targets :
2544
+ if _target ['name' ] is None :
2545
+ continue
2546
+ elif _target ['name' ].upper () == target .upper ():
2547
+ connected = _target
2548
+
2549
+ # apply new firmware
2550
+ if flash :
2551
+ fw_name = artifact_name if artifact_name else program .name
2552
+ fw_fbase = os .path .join (build_path , fw_name )
2553
+ fw_file = fw_fbase + ('.hex' if os .path .exists (fw_fbase + '.hex' ) else '.bin' )
2554
+ if not os .path .exists (fw_file ):
2555
+ error ("Build program file (firmware) not found \" %s\" " % fw_file , 1 )
2556
+ if not flash_dev (connected ['mount' ], fw_file , program_cycle_s = 4 ):
2557
+ error ("Unable to flash the target board connected to your system." , 1 )
2558
+
2559
+ # reset board and/or connect to serial port
2560
+ if flash or sterm :
2561
+ mbed_sterm (connected ['serial' ], reset = flash , sterm = sterm )
2562
+
2563
+ if not connected :
2564
+ error ("The target board you compiled for is not connected to your system.\n Please reconnect it and retry the last command." , 1 )
2552
2565
2553
2566
program .set_defaults (target = target , toolchain = tchain )
2554
2567
0 commit comments