platform-espressif32 icon indicating copy to clipboard operation
platform-espressif32 copied to clipboard

ESP32-S3-WROOM-1, espressif32 < 6.0: wrong flash size used for bootloader image

Open rgov opened this issue 8 months ago • 10 comments

I can successfully program my board, an ESP32-S3-WROOM-1U-N16, with espressif32 @ 6.4.0 (or 6.0.1) but not espressif32 @ 5.4.0.

As a test case, I made a basic project like this:

$ cat platformio.ini
[env:test]
platform = espressif32 @ 6.4.0
framework = espidf

# Settings for ESP32-S3-WROOM-1U-N16
board = esp32-s3-devkitc-1
board_build.partitions = partitions.csv
board_upload.flash_size = 16MB
board_upload.before_reset = no_reset
board_upload.after_reset = no_reset
Contents of other source files.
$ cat src/main.cpp
extern "C" void app_main() {
    while (1) { }
}

$ cat partitions.csv
# This is a based on default_16MB.csv from
# https://registry.platformio.org/tools/platformio/framework-arduinoespressif32

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x640000,
app1,     app,  ota_1,   0x650000,0x640000,
data,     data, spiffs,  0xc90000,0x360000,
coredump, data, coredump,0xFF0000,0x10000,

Everything seems to go well when flashing and I can tell from serial output that my app_main() is being called.

esptool output for flashing with espressif32 @ 6.4.0 (successful case)
"/opt/homebrew/Cellar/platformio/6.1.11/libexec/bin/python" "/Users/rzg/.platformio/packages/tool-esptoolpy/esptool.py" --chip esp32s3 --port "/dev/cu.usbmodem1102" --baud 460800 --before no_reset --after no_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 16MB 0x0 /private/tmp/blinky/.pio/build/test/bootloader.bin 0x8000 /private/tmp/blinky/.pio/build/test/partitions.bin 0xe000 /private/tmp/blinky/.pio/build/test/ota_data_initial.bin 0x10000 .pio/build/test/firmware.bin
esptool.py v4.5.1
Serial port /dev/cu.usbmodem1102
WARNING: Pre-connection option "no_reset" was selected. Connection may fail if the chip is not in bootloader or flasher stub mode.
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 70:04:1d:be:bd:58
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00041fff...
Compressed 20976 bytes to 13326...
Writing at 0x00000000... (100 %)
Wrote 20976 bytes (13326 compressed) at 0x00000000 in 0.6 seconds (effective 283.0 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 142...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (142 compressed) at 0x00008000 in 0.1 seconds (effective 341.2 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 31...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (31 compressed) at 0x0000e000 in 0.1 seconds (effective 612.9 kbit/s)...
Hash of data verified.
Compressed 201168 bytes to 109151...
Writing at 0x00010000... (14 %)
Writing at 0x0001cc99... (28 %)
Writing at 0x000226a3... (42 %)
Writing at 0x00028b5b... (57 %)
Writing at 0x0002f315... (71 %)
Writing at 0x00037128... (85 %)
Writing at 0x0003cd63... (100 %)
Wrote 201168 bytes (109151 compressed) at 0x00010000 in 2.8 seconds (effective 579.5 kbit/s)...
Hash of data verified.

Leaving...
Staying in bootloader.

On the other hand, if I drop back to espressif32 @ 5.4.0, clean, and reflash, the microcontroller just goes into a crash loop where the board is just constantly reset.

esptool output for flashing with espressif32 @ 5.4.0 (unsuccessful case)
"/opt/homebrew/Cellar/platformio/6.1.11/libexec/bin/python" "/Users/rzg/.platformio/packages/[email protected]/esptool.py" --chip esp32s3 --port "/dev/cu.usbmodem1102" --baud 460800 --before no_reset --after no_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 16MB 0x0 /private/tmp/blinky/.pio/build/test/bootloader.bin 0x8000 /private/tmp/blinky/.pio/build/test/partitions.bin 0xe000 /private/tmp/blinky/.pio/build/test/ota_data_initial.bin 0x10000 .pio/build/test/firmware.bin
esptool.py v4.4
Serial port /dev/cu.usbmodem1102
WARNING: Pre-connection option "no_reset" was selected. Connection may fail if the chip is not in bootloader or flasher stub mode.
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 70:04:1d:be:bd:58
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x0003ffff...
Warning: Image file at 0x0 is protected with a hash checksum, so not changing the flash mode setting. Use the --flash_mode=keep option instead of --flash_mode=dio in order to remove this warning, or use the --dont-append-digest option for the elf2image command in order to generate an image file without a hash checksum
Compressed 21104 bytes to 13244...
Writing at 0x00000000... (100 %)
Wrote 21104 bytes (13244 compressed) at 0x00000000 in 0.6 seconds (effective 285.7 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 142...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (142 compressed) at 0x00008000 in 0.1 seconds (effective 345.9 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 31...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (31 compressed) at 0x0000e000 in 0.1 seconds (effective 618.8 kbit/s)...
Hash of data verified.
Compressed 193296 bytes to 101571...
Writing at 0x00010000... (14 %)
Writing at 0x0001bae2... (28 %)
Writing at 0x00021483... (42 %)
Writing at 0x00027335... (57 %)
Writing at 0x0002fb61... (71 %)
Writing at 0x00037b63... (85 %)
Writing at 0x0003db0d... (100 %)
Wrote 193296 bytes (101571 compressed) at 0x00010000 in 2.6 seconds (effective 590.0 kbit/s)...
Hash of data verified.

Leaving...
Staying in bootloader.
Crash loop with espressif32 @ 5.4.0
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:QIO, clock div:1
load:0x3fce3808,len:0x162c
ets_loader.c 78 
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x7 (TG0WDT_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x400454d5
SPIWP:0xee
mode:QIO, clock div:1
load:0x3fce3808,len:0x162c
ets_loader.c 78 

Lastly, if I switch to platform = espressif32 @ 5.4.0 but framework = arduino (and change my main.cpp to void setup() { } void loop() { }), the microcontroller seems to execute my code successfully.

esptool output for flashing with espressif32 @ 5.4.0, framework = arduino (successful case)
"/opt/homebrew/Cellar/platformio/6.1.11/libexec/bin/python" "/Users/rzg/.platformio/packages/[email protected]/esptool.py" --chip esp32s3 --port "/dev/cu.usbmodem1102" --baud 460800 --before no_reset --after no_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 16MB 0x0000 /private/tmp/blinky/.pio/build/test/bootloader.bin 0x8000 /private/tmp/blinky/.pio/build/test/partitions.bin 0xe000 /Users/rzg/.platformio/packages/framework-arduinoespressif32-3.20006.221224/tools/partitions/boot_app0.bin 0x10000 .pio/build/test/firmware.bin
esptool.py v4.4
Serial port /dev/cu.usbmodem1102
WARNING: Pre-connection option "no_reset" was selected. Connection may fail if the chip is not in bootloader or flasher stub mode.
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 70:04:1d:be:bd:58
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00003fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00047fff...
Compressed 14768 bytes to 10148...
Writing at 0x00000000... (100 %)
Wrote 14768 bytes (10148 compressed) at 0x00000000 in 0.4 seconds (effective 271.5 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 142...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (142 compressed) at 0x00008000 in 0.1 seconds (effective 332.3 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 618.7 kbit/s)...
Hash of data verified.
Compressed 227792 bytes to 126741...
Writing at 0x00010000... (12 %)
Writing at 0x0001cef2... (25 %)
Writing at 0x00022979... (37 %)
Writing at 0x00027c80... (50 %)
Writing at 0x0002d24e... (62 %)
Writing at 0x00033ab7... (75 %)
Writing at 0x0003dc3b... (87 %)
Writing at 0x000433a9... (100 %)
Wrote 227792 bytes (126741 compressed) at 0x00010000 in 3.2 seconds (effective 572.5 kbit/s)...
Hash of data verified.

Leaving...
Staying in bootloader.

A telling sign is that this message only appears with espressif32 @ 5.4.0 and platform = espidf:

Warning: Image file at 0x0 is protected with a hash checksum, so not changing the flash mode setting. Use the --flash_mode=keep option instead of --flash_mode=dio in order to remove this warning, or use the --dont-append-digest option for the elf2image command in order to generate an image file without a hash checksum

rgov avatar Nov 13 '23 02:11 rgov