ESP32 reboot loop when uploading >4MB via JTAG

I’m using an ESP32-WROVER-E with 8MB of flash. I bought the 8MB WROVER because I have a project that needs the additional flash space.

My development environment is VSCode 1.61 with PIO 5.2.1.

To make use of the full 8MB of flash, an 8MB partition table must be set in platformio.ini using board_build.partitions. For my projects, I use:

board_build.partitions = default_8MB.csv

This works fine as long as I upload code using esptool via the USB serial port on the WROVER board.

However, if I use a JTAG debugger such as the ESP-PROG or Segger J-Link, the code uploads but the ESP32 goes into the dreaded reboot loop:

rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5828 entry 0x400806a8 ets Jul 29 2019 12:21:46

The problem goes away if I comment out board_build.partitions in platformio.ini but then I’m limited to only 4MB of flash when using a JTAG debugger.

The problem is repeatable for me with both the ESP-PROG and J-Link on both Windows 10 and macOS Big Sur. This leads me to think it may be a problem with OpenOCD.

Has anyone else encountered this behavior? Any suggestions for a fix?

Here is code that will replicate the issue if you have access to an 8MB ESP32-WROVER-E:

main.cpp

#include <Arduino.h>

#define LED_BUILTIN 2

void setup() {
    log_d("Total heap: %d", ESP.getHeapSize());
    log_d("Total PSRAM: %d", ESP.getPsramSize());
    log_d("Flash Chip Size: %d", ESP.getFlashChipSize());

    pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
}

platformio.ini

; PlatformIO Project Configuration File

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

board_build.partitions = default_8MB.csv

debug_tool = esp-prog
upload_protocol = esp-prog

build_flags =
    ; Enable PSRAM
    -DBOARD_HAS_PSRAM
    -mfix-esp32-psram-cache-issue
    ; Debug level
    -DCORE_DEBUG_LEVEL=5
    -DESP32=1

If the code is working correctly after upload, it should output:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
[D][esp32-hal-psram.c:47] psramInit(): PSRAM enabled
[D][main.cpp:6] setup(): Total heap: 387412
[D][main.cpp:7] setup(): Total PSRAM: 4194252
[D][main.cpp:8] setup(): Flash Chip Size: 8388608

Thanks for looking!

Please report this a bug to Issues · platformio/platform-espressif32 · GitHub for the developers.

Thanks for the suggestion.

I’ve added an issue here: [Feature Request] Support uploading via JTAG to devices with 8MB or 16MB of flash · Issue #648 · platformio/platform-espressif32 · GitHub

With help from erhankur in another issue I filed at openocd-esp32 (ESP32 WROVER reboot loop when uploading >4MB via JTAG (OCD-421) · Issue #184 · espressif/openocd-esp32 · GitHub), I’ve realized that the real problem is that platform-espressif32 does not presently fully support uploading to 8MB and 16MB ESP32 devices via JTAG/OpenOCD.

Full details of what’s happening are in the openocd-esp32 issue linked above and my original issue post at platform-espressif32 (ESP32 WROVER reboot loop when uploading >4MB via JTAG (OCD-421) · Issue #184 · espressif/openocd-esp32 · GitHub) which I have transformed into a feature request.

Please consider voicing your support for this adding this functionality.

Thanks!