@@ -136,15 +136,27 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
136136 if ( updateInterface == Interface . Dfu )
137137 {
138138 // DFU update
139- dfuDeviceId = dfuDeviceId == null ? connectedStDfuDevices [ 0 ] . serial : dfuDeviceId ;
140- dfuDevice = new StmDfuDevice ( dfuDeviceId ) ;
141139
142- if ( ! dfuDevice . DevicePresent )
140+ try
143141 {
144- // no DFU device found
142+ dfuDeviceId = dfuDeviceId == null ? connectedStDfuDevices [ 0 ] . serial : dfuDeviceId ;
143+ dfuDevice = new StmDfuDevice ( dfuDeviceId ) ;
145144
146- // done here, this command has no further processing
147- return ExitCodes . E1000 ;
145+ if ( ! dfuDevice . DevicePresent )
146+ {
147+ // no DFU device found
148+
149+ // done here, this command has no further processing
150+ return ExitCodes . E1000 ;
151+ }
152+ }
153+ catch ( CantConnectToJtagDeviceException )
154+ {
155+ return ExitCodes . E5002 ;
156+ }
157+ catch ( Exception )
158+ {
159+ return ExitCodes . E5000 ;
148160 }
149161
150162 if ( fitCheck )
@@ -162,9 +174,9 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
162174 {
163175 Console . ForegroundColor = ConsoleColor . Cyan ;
164176
165- Console . WriteLine ( $ "Connected to DFU device with ID { dfuDevice . DfuId } ") ;
177+ Console . WriteLine ( $ "Connected to DFU device with ID { dfuDevice . DfuId } ") ;
166178 Console . WriteLine ( "" ) ;
167- Console . WriteLine ( $ "{ dfuDevice } ") ;
179+ Console . WriteLine ( $ "{ dfuDevice } ") ;
168180 Console . ForegroundColor = ConsoleColor . White ;
169181 }
170182
@@ -201,23 +213,35 @@ public static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync(
201213 else
202214 {
203215 // JTAG device
204- jtagDevice = new StmJtagDevice ( jtagId ) ;
205216
206- if ( ! jtagDevice . DevicePresent )
217+ try
207218 {
208- // no JTAG device found
219+ jtagDevice = new StmJtagDevice ( jtagId ) ;
209220
210- // done here, this command has no further processing
211- return ExitCodes . E5001 ;
221+ if ( ! jtagDevice . DevicePresent )
222+ {
223+ // no JTAG device found
224+
225+ // done here, this command has no further processing
226+ return ExitCodes . E5001 ;
227+ }
228+ }
229+ catch ( CantConnectToJtagDeviceException )
230+ {
231+ return ExitCodes . E5002 ;
232+ }
233+ catch ( Exception )
234+ {
235+ return ExitCodes . E5000 ;
212236 }
213237
214238 if ( verbosity >= VerbosityLevel . Normal )
215239 {
216240 Console . WriteLine ( "" ) ;
217241 Console . ForegroundColor = ConsoleColor . Cyan ;
218- Console . WriteLine ( $ "Connected to JTAG device with ID { jtagDevice . JtagId } ") ;
242+ Console . WriteLine ( $ "Connected to JTAG device with ID { jtagDevice . JtagId } ") ;
219243 Console . WriteLine ( "" ) ;
220- Console . WriteLine ( $ "{ jtagDevice } ") ;
244+ Console . WriteLine ( $ "{ jtagDevice } ") ;
221245 Console . ForegroundColor = ConsoleColor . White ;
222246 }
223247
@@ -316,7 +340,7 @@ public static ExitCodes ResetMcu(
316340
317341 if ( verbosity >= VerbosityLevel . Normal )
318342 {
319- Console . WriteLine ( $ "Connected to JTAG device with ID { jtagDevice . JtagId } ") ;
343+ Console . WriteLine ( $ "Connected to JTAG device with ID { jtagDevice . JtagId } ") ;
320344 }
321345
322346 // set verbosity
@@ -343,7 +367,7 @@ public static ExitCodes MassErase(
343367
344368 if ( verbosity >= VerbosityLevel . Normal )
345369 {
346- Console . WriteLine ( $ "Connected to JTAG device with ID { jtagDevice . JtagId } ") ;
370+ Console . WriteLine ( $ "Connected to JTAG device with ID { jtagDevice . JtagId } ") ;
347371 }
348372
349373 // set verbosity
0 commit comments