Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ require (
github.com/mattn/go-tty v0.0.4
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3
github.com/tetratelabs/wazero v1.6.0
go.bug.st/serial v1.6.2
go.bug.st/serial v1.6.4
golang.org/x/net v0.35.0
golang.org/x/sys v0.30.0
golang.org/x/tools v0.30.0
gopkg.in/yaml.v2 v2.4.0
tinygo.org/x/espflash v0.2.0
tinygo.org/x/espflash v0.3.0
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74
)

require (
github.com/creack/goselect v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/text v0.22.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g=
github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
go.bug.st/serial v1.6.2 h1:kn9LRX3sdm+WxWKufMlIRndwGfPWsH1/9lCWXQCasq8=
go.bug.st/serial v1.6.2/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE=
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
go.bug.st/serial v1.6.4/go.mod h1:nofMJxTeNVny/m6+KaafC6vJGj3miwQZ6vW4BZUGJPI=
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
Expand All @@ -58,7 +58,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
tinygo.org/x/espflash v0.2.0 h1:sHDeMVaiJ0kEosCYgkiAHjSCV9+/mgQZMKy7nOXWVoQ=
tinygo.org/x/espflash v0.2.0/go.mod h1:n4sWxsjN4wjHN1lKfEYjXke6/eSeLTq/lRRLJS5FNfg=
tinygo.org/x/espflash v0.3.0 h1:uhTOWZb1FyQ4MZTZWORh/bOLFQfaFr2nuM9t3pJExRM=
tinygo.org/x/espflash v0.3.0/go.mod h1:n4sWxsjN4wjHN1lKfEYjXke6/eSeLTq/lRRLJS5FNfg=
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74 h1:ovavgTdIBWCH8YWlcfq9gkpoyT1+IxMKSn+Df27QwE8=
tinygo.org/x/go-llvm v0.0.0-20250422114502-b8f170971e74/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0=
31 changes: 26 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/tinygo-org/tinygo/goenv"
"github.com/tinygo-org/tinygo/loader"
"golang.org/x/tools/go/buildutil"
"tinygo.org/x/espflash"
"tinygo.org/x/espflash/pkg/espflash"
"tinygo.org/x/go-llvm"

"go.bug.st/serial"
Expand Down Expand Up @@ -386,7 +386,7 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
fileExt = ".hex"
case "bmp":
fileExt = ".elf"
case "esp32flash":
case "esp32flash", "esp32jtag":
fileExt = ".bin"
case "native":
return errors.New("unknown flash method \"native\" - did you miss a -target flag?")
Expand Down Expand Up @@ -528,7 +528,16 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
return &commandError{"failed to find port", port, err}
}

if err := flashBinUsingEsp32(port, result.Binary, config.Options); err != nil {
if err := flashBinUsingEsp32(port, classicReset, result.Binary, config.Options); err != nil {
return &commandError{"failed to flash", result.Binary, err}
}
case "esp32jtag":
port, err := getDefaultPort(port, config.Target.SerialPort)
if err != nil {
return &commandError{"failed to find port", port, err}
}

if err := flashBinUsingEsp32(port, jtagReset, result.Binary, config.Options); err != nil {
return &commandError{"failed to flash", result.Binary, err}
}
default:
Expand Down Expand Up @@ -1031,8 +1040,20 @@ func flashHexUsingMSD(volumes []string, tmppath string, options *compileopts.Opt
return errors.New("unable to locate any volume: [" + strings.Join(volumes, ",") + "]")
}

func flashBinUsingEsp32(port, tmppath string, options *compileopts.Options) error {
flasher, err := espflash.NewFlasher(port, nil)
const (
classicReset = "classic"
jtagReset = "jtag"
)

func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Options) error {
var opts *espflash.FlasherOptions
// On Windows, we have to explicitly specify the reset mode to use USB JTAG.
if runtime.GOOS == "windows" && resetMode == jtagReset {
opts = espflash.DefaultOptions()
opts.ResetMode = espflash.ResetUSBJTAG
}

flasher, err := espflash.NewFlasher(port, opts)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion targets/esp32c3.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"src/device/esp/esp32c3.S"
],
"binary-format": "esp32c3",
"flash-method": "esp32flash",
"flash-method": "esp32jtag",
"serial-port": ["303a:1001"],
"openocd-interface": "esp_usb_jtag",
"openocd-target": "esp32c3",
Expand Down
2 changes: 1 addition & 1 deletion targets/esp32s3.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"src/internal/task/task_stack_esp32.S"
],
"binary-format": "esp32s3",
"flash-method": "esp32flash",
"flash-method": "esp32jtag",
"emulator": "qemu-system-xtensa -machine esp32 -nographic -drive file={img},if=mtd,format=raw",
"gdb": ["xtensa-esp32-elf-gdb"]
}
Loading