Skip to content

Commit f011456

Browse files
committed
flashing: introduce flash method 'esp32jtag' for esp32c3/esp32s3 targets
This adds a new flash method 'esp32jtag' to explicitly define when this reset method is needed. When flashing esp32c3/esp32s3 boards on Windows this method of board reset is required, otherwise the reset does not take place and the board cannot be flashed. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent eca45bc commit f011456

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

main.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
386386
fileExt = ".hex"
387387
case "bmp":
388388
fileExt = ".elf"
389-
case "esp32flash":
389+
case "esp32flash", "esp32jtag":
390390
fileExt = ".bin"
391391
case "native":
392392
return errors.New("unknown flash method \"native\" - did you miss a -target flag?")
@@ -528,7 +528,16 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
528528
return &commandError{"failed to find port", port, err}
529529
}
530530

531-
if err := flashBinUsingEsp32(port, result.Binary, config.Options); err != nil {
531+
if err := flashBinUsingEsp32(port, classicReset, result.Binary, config.Options); err != nil {
532+
return &commandError{"failed to flash", result.Binary, err}
533+
}
534+
case "esp32jtag":
535+
port, err := getDefaultPort(port, config.Target.SerialPort)
536+
if err != nil {
537+
return &commandError{"failed to find port", port, err}
538+
}
539+
540+
if err := flashBinUsingEsp32(port, jtagReset, result.Binary, config.Options); err != nil {
532541
return &commandError{"failed to flash", result.Binary, err}
533542
}
534543
default:
@@ -1031,8 +1040,20 @@ func flashHexUsingMSD(volumes []string, tmppath string, options *compileopts.Opt
10311040
return errors.New("unable to locate any volume: [" + strings.Join(volumes, ",") + "]")
10321041
}
10331042

1034-
func flashBinUsingEsp32(port, tmppath string, options *compileopts.Options) error {
1035-
flasher, err := espflash.NewFlasher(port, nil)
1043+
const (
1044+
classicReset = "classic"
1045+
jtagReset = "jtag"
1046+
)
1047+
1048+
func flashBinUsingEsp32(port, resetMode, tmppath string, options *compileopts.Options) error {
1049+
var opts *espflash.FlasherOptions
1050+
// On Windows, we have to explicitly specify the reset mode to use USB JTAG.
1051+
if runtime.GOOS == "windows" && resetMode == jtagReset {
1052+
opts = espflash.DefaultOptions()
1053+
opts.ResetMode = espflash.ResetUSBJTAG
1054+
}
1055+
1056+
flasher, err := espflash.NewFlasher(port, opts)
10361057
if err != nil {
10371058
return err
10381059
}

targets/esp32c3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"src/device/esp/esp32c3.S"
1414
],
1515
"binary-format": "esp32c3",
16-
"flash-method": "esp32flash",
16+
"flash-method": "esp32jtag",
1717
"serial-port": ["303a:1001"],
1818
"openocd-interface": "esp_usb_jtag",
1919
"openocd-target": "esp32c3",

targets/esp32s3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"src/internal/task/task_stack_esp32.S"
1616
],
1717
"binary-format": "esp32s3",
18-
"flash-method": "esp32flash",
18+
"flash-method": "esp32jtag",
1919
"emulator": "qemu-system-xtensa -machine esp32 -nographic -drive file={img},if=mtd,format=raw",
2020
"gdb": ["xtensa-esp32-elf-gdb"]
2121
}

0 commit comments

Comments
 (0)