@@ -57,6 +57,11 @@ def main():
5757 print ("Unsupported firmware type!" )
5858 sys .exit (1 )
5959
60+ # Erase the flash memory of the selected board
61+ erase_flash (flasher_tool_executable_path ,
62+ arduino_tools_dir ,
63+ selected_board_config ['flasher_tool' ])
64+
6065 # Flash the bootloader binary file for the selected board
6166 flash_binary (flasher_tool_executable_path ,
6267 selected_board_config ['bootloader_binary' ],
@@ -72,6 +77,27 @@ def main():
7277 print ("Finished successfully" )
7378
7479
80+ def erase_flash (flasher_tool_executable_path , arduino_tools_dir , flasher_tool ):
81+ print ("" )
82+ print ("Erasing flash memory..." )
83+ if flasher_tool == 'openocd' :
84+ flasher_process = subprocess .Popen (
85+ [flasher_tool_executable_path , "-d2" , "-s" , arduino_tools_dir + "/openocd/0.12.0-arduino1-static/share/openocd/scripts/" , "-f" , "interface/cmsis-dap.cfg" , "-f" , "target/efm32s2_g23.cfg" , "-c" , "init; reset_config srst_nogate; reset halt; flash erase_sector 0 1 last; exit" ]
86+ )
87+ flasher_process .communicate (timeout = 30 )
88+ elif flasher_tool == 'simplicitycommander' :
89+ flasher_process = subprocess .Popen (
90+ [flasher_tool_executable_path , "device" , "masserase" ]
91+ )
92+ flasher_process .communicate (timeout = 30 )
93+ else :
94+ print ("Unsupported flasher tool" )
95+ sys .exit (1 )
96+
97+ if flasher_process .returncode != 0 :
98+ print (f"Error: Flash erase failed with return code '{ flasher_process .returncode } '" )
99+ sys .exit (flasher_process .returncode )
100+
75101def flash_binary (flasher_tool_executable_path , binary_file , arduino_tools_dir , flasher_tool ):
76102 print ("" )
77103 print ("Flashing binary file: {}" .format (binary_file ))
0 commit comments