@@ -37,16 +37,17 @@ def set_environment():
3737 elif sys .platform == 'darwin' :
3838 jlinkexe = 'JLinkExe'
3939
40- def discover_devices ():
40+ def discover_jlink_devices ():
4141 ports = comports ()
4242 port_sn_list = []
4343 for p in ports :
44- port_sn_list .append ((p .device , p .serial_number ))
44+ if "JLink" in p .description :
45+ port_sn_list .append ((p .device , p .serial_number ))
4546
4647 return port_sn_list
4748
4849def get_device_serial_number (port ):
49- port_sn_list = discover_devices ()
50+ port_sn_list = discover_jlink_devices ()
5051 for device in port_sn_list :
5152 if device [0 ] == port and device [0 ] != None :
5253 return device [1 ]
@@ -156,6 +157,12 @@ def get_mem_contents(addr, bytes, device, port):
156157def read_master_data ():
157158 return xmc_master_data
158159
160+ def find_device_by_value (value ):
161+ master_data = read_master_data ()
162+ for device , config in master_data .items ():
163+ if config ["IDCHIP" ]["value" ] == value :
164+ return device
165+ return None
159166
160167def check_device (device , port ):
161168
@@ -166,10 +173,12 @@ def check_device(device, port):
166173 device_value_masked = f'{ device_value_masked :x} '
167174 device_value_masked = device_value_masked .zfill (int (master_data [device ]['IDCHIP' ]['size' ])* 2 )
168175
169- print (f"Selected Device is: { device .split ('-' )[0 ]} ." )
170-
176+ print (f"Selected Device is: { device } ." )
177+
178+ real_device = find_device_by_value (device_value_masked )
171179 #compare with stored master data
172- if not device_value_masked == master_data [device ]['IDCHIP' ]['value' ]:
180+ if not real_device == device :
181+ print (f"Connected Device is: { real_device } ." )
173182 raise Exception (f"Device connected on port { port } does not match the selected device to flash" )
174183
175184def check_mem (device , port ):
@@ -209,7 +218,7 @@ def check_mem(device, port):
209218def get_default_port (port ):
210219 serial_num = get_device_serial_number (port )
211220 if serial_num == None or port == None :
212- port_sn_list = discover_devices ()
221+ port_sn_list = discover_jlink_devices ()
213222 for port_sn in port_sn_list :
214223 if port_sn [1 ] != None :
215224 real_port = port_sn [0 ]
0 commit comments