@@ -96,31 +96,13 @@ public ExitCodes FlashHexFiles(IList<string> files)
9696 // erase flash
9797 if ( DoMassErase )
9898 {
99- if ( Verbosity >= VerbosityLevel . Normal )
100- {
101- Console . ForegroundColor = ConsoleColor . White ;
102- Console . Write ( "Mass erase device..." ) ;
103- }
99+ var eraseResult = MassErase ( ) ;
104100
105- cliOutput = RunSTM32ProgrammerCLI ( $ "-c port=SWD sn={ DeviceId } mode=UR -e all") ;
106-
107- if ( ! cliOutput . Contains ( "Flash memory erased." ) )
101+ if ( eraseResult != ExitCodes . OK )
108102 {
109- return ExitCodes . E5005 ;
103+ return eraseResult ;
110104 }
111105
112- if ( Verbosity >= VerbosityLevel . Normal )
113- {
114- Console . ForegroundColor = ConsoleColor . Green ;
115- Console . WriteLine ( " OK" ) ;
116- }
117- else
118- {
119- Console . ForegroundColor = ConsoleColor . White ;
120- Console . WriteLine ( "" ) ;
121- }
122- Console . ForegroundColor = ConsoleColor . White ;
123-
124106 // toggle mass erase so it's only performed before the first file is flashed
125107 DoMassErase = false ;
126108 }
@@ -221,32 +203,13 @@ public ExitCodes FlashBinFiles(IList<string> files, IList<string> addresses)
221203 // erase flash
222204 if ( DoMassErase )
223205 {
224- if ( Verbosity >= VerbosityLevel . Normal )
225- {
226- Console . ForegroundColor = ConsoleColor . White ;
227- Console . Write ( "Mass erase device..." ) ;
228- }
229-
230- cliOutput = RunSTM32ProgrammerCLI ( $ "-c port=SWD sn={ DeviceId } mode=UR -e all") ;
206+ var eraseResult = MassErase ( ) ;
231207
232- if ( ! cliOutput . Contains ( "Flash memory erased." ) )
208+ if ( eraseResult != ExitCodes . OK )
233209 {
234- Console . ForegroundColor = ConsoleColor . Red ;
235- Console . WriteLine ( "ERROR" ) ;
236- return ExitCodes . E5005 ;
210+ return eraseResult ;
237211 }
238212
239- if ( Verbosity >= VerbosityLevel . Normal )
240- {
241- Console . ForegroundColor = ConsoleColor . Green ;
242- Console . WriteLine ( " OK" ) ;
243- }
244- else
245- {
246- Console . WriteLine ( "" ) ;
247- }
248- Console . ForegroundColor = ConsoleColor . White ;
249-
250213 // toggle mass erase so it's only performed before the first file is flashed
251214 DoMassErase = false ;
252215 }
@@ -369,6 +332,42 @@ public ExitCodes ResetMcu()
369332 return ExitCodes . OK ;
370333 }
371334
335+
336+ /// <summary>
337+ /// Reset MCU of connected JTAG device.
338+ /// </summary>
339+ public ExitCodes MassErase ( )
340+ {
341+ if ( Verbosity >= VerbosityLevel . Normal )
342+ {
343+ Console . ForegroundColor = ConsoleColor . White ;
344+ Console . Write ( "Mass erase device..." ) ;
345+ }
346+
347+ var cliOutput = RunSTM32ProgrammerCLI ( $ "-c port=SWD sn={ DeviceId } mode=UR -e all") ;
348+
349+ if ( ! cliOutput . Contains ( "Mass erase successfully achieved" ) )
350+ {
351+ Console . ForegroundColor = ConsoleColor . Red ;
352+ Console . WriteLine ( "ERROR" ) ;
353+ return ExitCodes . E5005 ;
354+ }
355+
356+ if ( Verbosity >= VerbosityLevel . Normal )
357+ {
358+ Console . ForegroundColor = ConsoleColor . Green ;
359+ Console . WriteLine ( " OK" ) ;
360+ }
361+ else
362+ {
363+ Console . WriteLine ( "" ) ;
364+ }
365+
366+ Console . ForegroundColor = ConsoleColor . White ;
367+
368+ return ExitCodes . OK ;
369+ }
370+
372371 private static string RunSTM32ProgrammerCLI ( string arguments )
373372 {
374373 try
0 commit comments