diff --git a/main.go b/main.go index 4df12695e..425d12574 100644 --- a/main.go +++ b/main.go @@ -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?") @@ -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: @@ -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 } diff --git a/targets/esp32c3.json b/targets/esp32c3.json index 3336f3c18..96af15d51 100644 --- a/targets/esp32c3.json +++ b/targets/esp32c3.json @@ -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", diff --git a/targets/esp32s3.json b/targets/esp32s3.json index 8f534e289..1b9159230 100644 --- a/targets/esp32s3.json +++ b/targets/esp32s3.json @@ -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"] }