Skip to content

Commit 6a0fb7f

Browse files
committed
main: update espflasher and auto-use best available flashing options on esp32
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 709349e commit 6a0fb7f

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
golang.org/x/sys v0.30.0
1919
golang.org/x/tools v0.30.0
2020
gopkg.in/yaml.v2 v2.4.0
21-
tinygo.org/x/espflasher v0.4.0
21+
tinygo.org/x/espflasher v0.5.0
2222
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74
2323
)
2424

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
5858
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
5959
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
6060
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
61-
tinygo.org/x/espflasher v0.4.0 h1:0N+Ei+0qT/wGkGIoMaY2g+oI519VA5G4kUVUYHedTv8=
62-
tinygo.org/x/espflasher v0.4.0/go.mod h1:a3hRV9EETPUkfPE6P14p4A6jKKth+oD5gtQz3nmij+8=
61+
tinygo.org/x/espflasher v0.5.0 h1:aLYv6ldFw/Bxj36e4DaEqjGMUwx+LvI7xdapqz49LQ8=
62+
tinygo.org/x/espflasher v0.5.0/go.mod h1:a3hRV9EETPUkfPE6P14p4A6jKKth+oD5gtQz3nmij+8=
6363
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74 h1:ovavgTdIBWCH8YWlcfq9gkpoyT1+IxMKSn+Df27QwE8=
6464
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=

main.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,15 @@ const (
10601060
)
10611061

10621062
func 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("\rFlashing: %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

Comments
 (0)