@@ -1060,10 +1060,15 @@ const (
10601060)
10611061
10621062func flashBinUsingEsp32 (port , resetMode , tmppath string , options * compileopts.Options ) error {
1063- var opts * espflasher.FlasherOptions
1063+ opts := espflasher .DefaultOptions ()
1064+ opts .Compress = true
1065+ opts .Logger = & espflasher.StdoutLogger {W : os .Stdout }
1066+ if options .BaudRate != 0 {
1067+ opts .FlashBaudRate = options .BaudRate
1068+ }
1069+
10641070 // On Windows, we have to explicitly specify the reset mode to use USB JTAG.
10651071 if runtime .GOOS == "windows" && resetMode == jtagReset {
1066- opts = espflasher .DefaultOptions ()
10671072 opts .ResetMode = espflasher .ResetUSBJTAG
10681073 }
10691074
@@ -1074,8 +1079,6 @@ func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Op
10741079 defer flasher .Close ()
10751080
10761081 chipName := flasher .ChipName ()
1077- fmt .Printf ("Connected to %s\n " , chipName )
1078-
10791082 offset := uint32 (0x0 )
10801083 if chipName == "ESP32" {
10811084 offset = 0x1000
@@ -1087,18 +1090,26 @@ func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Op
10871090 return err
10881091 }
10891092
1093+ if err := flasher .EraseFlash (); err != nil {
1094+ return fmt .Errorf ("erase failed: %v" , err )
1095+ }
1096+
1097+ progress := func (current , total int ) {
1098+ pct := float64 (current ) / float64 (total ) * 100
1099+ bar := int (pct / 2 )
1100+ fmt .Printf ("\r [%-50s] %6.1f%%" , strings .Repeat ("#" , bar )+ strings .Repeat ("." , 50 - bar ), pct )
1101+ if current >= total {
1102+ fmt .Println ()
1103+ }
1104+ }
1105+
10901106 // Flash with progress reporting
1091- err = flasher .FlashImage (data , offset , func (current , total int ) {
1092- fmt .Printf ("\r Flashing: %d/%d bytes (%.0f%%)" , current , total ,
1093- float64 (current )/ float64 (total )* 100 )
1094- })
1107+ err = flasher .FlashImage (data , offset , progress )
10951108 if err != nil {
10961109 return err
10971110 }
10981111 fmt .Println ()
10991112
1100- time .Sleep (time .Second )
1101-
11021113 // Reset the device to run the new firmware
11031114 flasher .Reset ()
11041115
0 commit comments