@@ -1094,10 +1094,15 @@ const (
10941094)
10951095
10961096func flashBinUsingEsp32 (port , resetMode , tmppath string , options * compileopts.Options ) error {
1097- var opts * espflasher.FlasherOptions
1097+ opts := espflasher .DefaultOptions ()
1098+ opts .Compress = true
1099+ opts .Logger = & espflasher.StdoutLogger {W : os .Stdout }
1100+ if options .BaudRate != 0 {
1101+ opts .FlashBaudRate = options .BaudRate
1102+ }
1103+
10981104 // On Windows, we have to explicitly specify the reset mode to use USB JTAG.
10991105 if runtime .GOOS == "windows" && resetMode == jtagReset {
1100- opts = espflasher .DefaultOptions ()
11011106 opts .ResetMode = espflasher .ResetUSBJTAG
11021107 }
11031108
@@ -1108,8 +1113,6 @@ func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Op
11081113 defer flasher .Close ()
11091114
11101115 chipName := flasher .ChipName ()
1111- fmt .Printf ("Connected to %s\n " , chipName )
1112-
11131116 offset := uint32 (0x0 )
11141117 if chipName == "ESP32" {
11151118 offset = 0x1000
@@ -1121,18 +1124,26 @@ func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Op
11211124 return err
11221125 }
11231126
1127+ if err := flasher .EraseFlash (); err != nil {
1128+ return fmt .Errorf ("erase failed: %v" , err )
1129+ }
1130+
1131+ progress := func (current , total int ) {
1132+ pct := float64 (current ) / float64 (total ) * 100
1133+ bar := int (pct / 2 )
1134+ fmt .Printf ("\r [%-50s] %6.1f%%" , strings .Repeat ("#" , bar )+ strings .Repeat ("." , 50 - bar ), pct )
1135+ if current >= total {
1136+ fmt .Println ()
1137+ }
1138+ }
1139+
11241140 // Flash with progress reporting
1125- err = flasher .FlashImage (data , offset , func (current , total int ) {
1126- fmt .Printf ("\r Flashing: %d/%d bytes (%.0f%%)" , current , total ,
1127- float64 (current )/ float64 (total )* 100 )
1128- })
1141+ err = flasher .FlashImage (data , offset , progress )
11291142 if err != nil {
11301143 return err
11311144 }
11321145 fmt .Println ()
11331146
1134- time .Sleep (time .Second )
1135-
11361147 // Reset the device to run the new firmware
11371148 flasher .Reset ()
11381149
0 commit comments