ESP32-C3 boot loop 2MB flash

Hi there!

Setup: ESPHome v2022.9.1 docker

I’ve recently bought an ESP32-C3 board thinking it would be as easy to connect as my other ESP boards but I’ve ran into some problems getting it to run.
I’ve already googled multiple topics and angles during the past few days, and I did came further with the boot process, but I still get stuck on:
spi_flash: Detected size(2048k) smaller than the size in the binary image header(4096k). Probe failed.

Normally I install the binary through the ESPHome web installer, not sure if that influences anything. I’ve also tried Espressif own flash tool which didn’t seem to do much on Windows.

Anyway, this is my config. I know that for most people selecting dio did the trick. Sure, it does more than in qio, but still get’s stuck.

esphome:
  name: ESP32C3
  platformio_options:
    board_build.flash_mode: dio
    board_build.f_flash: 40000000L
    board_build.flash_size: 4MB

esp32:
  board: esp32-c3-devkitm-1
  variant: ESP32C3
  framework:
    type: esp-idf
    version: latest
    # Custom sdkconfig options
    sdkconfig_options:
      CONFIG_COMPILER_OPTIMIZATION_SIZE: y
    # Advanced tweaking options
    advanced:
      ignore_efuse_mac_crc: false
    
# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key

ota:
  password: !secret ota_key

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

And my log:

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x40380978
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fcd6100,len:0x19c0
load:0x403ce000,len:0x8d4
load:0x403d0000,len:0x2dc0
entry 0x403ce000
I (35) boot: ESP-IDF 4.3.2 2nd stage bootloader
I (35) boot: compile time 09:01:47
I (35) boot: chip revision: 3
I (37) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (44) boot.esp32c3: SPI Speed      : 40MHz
I (48) boot.esp32c3: SPI Mode       : DIO
I (53) boot.esp32c3: SPI Flash Size : 4MB
I (58) boot: Enabling RNG early entropy source...
I (63) boot: Partition Table:
I (67) boot: ## Label            Usage          Type ST Offset   Length
I (74) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (82) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (89) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (97) boot:  3 app0             OTA app          00 10 00010000 001c0000
I (104) boot:  4 app1             OTA app          00 11 001d0000 001c0000
I (112) boot: End of partition table
I (116) boot_comm: chip revision: 3, min. application chip revision: 0
I (123) esp_image: segment 0: paddr=00010020 vaddr=3c090020 size=23918h (145688) map
I (162) esp_image: segment 1: paddr=00033940 vaddr=3fc8de00 size=03280h ( 12928) load
I (165) esp_image: segment 2: paddr=00036bc8 vaddr=40380000 size=09450h ( 37968) load
I (177) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=8a21ch (565788) map
I (296) esp_image: segment 4: paddr=000ca244 vaddr=40389450 size=04824h ( 18468) load
I (300) esp_image: segment 5: paddr=000cea70 vaddr=50000000 size=00010h (    16) load
I (306) boot: Loaded app from partition at offset 0x10000
I (308) boot: Disabling RNG early entropy source...
I (324) cpu_start: Pro cpu up.
I (885) cpu_start: Pro cpu start user code
I (885) cpu_start: cpu freq: 160000000
I (885) cpu_start: Application information:
I (888) cpu_start: Project name:     lemon-tree-v2
I (893) cpu_start: App version:      2022.9.1
I (898) cpu_start: Compile time:     Sep 28 2022 09:01:33
I (905) cpu_start: ELF file SHA256:  735015a1611afff0...
I (911) cpu_start: ESP-IDF:          4.3.2
I (915) heap_init: Initializing. RAM available for dynamic allocation:
I (923) heap_init: At 3FC95910 len 0002A6F0 (169 KiB): DRAM
I (929) heap_init: At 3FCC0000 len 0001F060 (124 KiB): STACK/DRAM
I (936) heap_init: At 50000010 len 00001FF0 (7 KiB): RTCRAM
I (942) spi_flash: detected chip: generic
I (947) spi_flash: flash io: dio
E (950) spi_flash: Detected size(2048k) smaller than the size in the binary image header(4096k). Probe failed.

assert failed: do_core_init startup.c:339 (flash_ret == ESP_OK)
Core  0 register dump:
MEPC    : 0x4038094c  RA      : 0x403870a0  SP      : 0x3fcde1a0  GP      : 0x3fc8e600  
TP      : 0x00000000  T0      : 0x37363534  T1      : 0x7271706f  T2      : 0x33323130  
S0/FP   : 0x3fcde2ff  S1      : 0x00000088  A0      : 0x3fcde1f8  A1      : 0x3fc8f5c9  
A2      : 0x00000001  A3      : 0x00000029  A4      : 0x00000001  A5      : 0x3fc95000  
A6      : 0x7a797877  A7      : 0x76757473  S2      : 0x3fcde1f8  S3      : 0x00000001  
S4      : 0x3fcde1f8  S5      : 0x00040020  S6      : 0x00000000  S7      : 0x3fcd7000  
S8      : 0x3c090020  S9      : 0x00010020  S10     : 0x00000006  S11     : 0x3fcde3cc  
T3      : 0x6e6d6c6b  T4      : 0x6a696867  T5      : 0x66656463  T6      : 0x62613938  
MSTATUS : 0x00001801  MTVEC   : 0x40380001  MCAUSE  : 0x00000007  MTVAL   : 0x00000000  
MHARTID : 0x00000000  

Stack memory:
3fcde1a0: 0x3c0a6ec4 0x00040020 0x3c09f1ec 0x4038c52c 0x00000000 0x00000079 0x0000000a 0x3fc8f5c8
3fcde1c0: 0x00393333 0x00000079 0x00000000 0x00000000 0xff000000 0x3fc90640 0x3c09f1ec 0x3fc9092c
3fcde1e0: 0x3c09f3f1 0x3fc90650 0x3fcde1c0 0x3fc90654 0x3c09f3fc 0x3fc8f5c8 0x65737361 0x66207472
3fcde200: 0x656c6961 0x64203a64 0x6f635f6f 0x695f6572 0x2074696e 0x72617473 0x2e707574 0x33333a63
3fcde220: 0x66282039 0x6873616c 0x7465725f 0x203d3d20 0x5f505345 0x00294b4f 0x42000020 0x3fc8f340
3fcde240: 0x3fcdf5c0 0x00000000 0x3fc8f340 0x40048722 0x00000006 0x00040020 0x42000020 0x00000000
3fcde260: 0x3fc8f318 0x00000000 0x3fc8f340 0x3fcde284 0x00000000 0x00000000 0x005e6015 0x4203eb88
3fcde280: 0x00000000 0x000003b6 0x3c0a7084 0x00000800 0x00001000 0x000003e8 0xa0000000 0x0000000a
3fcde2a0: 0x00000000 0x00000000 0x00000000 0x00000001 0x00000000 0x00000005 0x00000000 0x00000001
3fcde2c0: 0x00000000 0x3fc95844 0x42000020 0x3fc92e30 0x3c0a9000 0x3c09f000 0x3fc92e30 0x42021a08
3fcde2e0: 0x400391e6 0x00000000 0x00000002 0x09896800 0x00000001 0x000001e0 0x00000006 0x30353337
3fcde300: 0x31613531 0x61313136 0x30666666 0x4207a700 0x0000003e 0x0000003e 0x3c09f000 0x403809b0
3fcde320: 0xffff0000 0x0009a21b 0x0009a23b 0x403d0f1a 0x00000000 0x00000000 0x00000000 0x00000000
3fcde340: 0x00000000 0x00000000 0x00000000 0x3fcdf000 0x00005084 0x3ff1c14c 0x0000ffff 0xffffffff
3fcde360: 0x00000000 0x3fcde4b0 0x00000000 0x403d15a6 0x00000000 0x0000000a 0x00010000 0x001c0000
3fcde380: 0x00010000 0x200206e9 0x403809b0 0x000000ee 0x00000005 0x00000000 0x01000000 0x3c090020
3fcde3a0: 0x00023918 0x3fc8de00 0x00003280 0x40380000 0x00009450 0x42000020 0x0008a21c 0x40389450
3fcde3c0: 0x00004824 0x50000000 0x00000010 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fcde3e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fcde400: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00010020
3fcde420: 0x00033940 0x00036bc8 0x00040020 0x000ca244 0x000cea70 0x00000000 0x00000000 0x00000000
3fcde440: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x000beab0
3fcde460: 0x4a0a3f78 0x660ed264 0x20417774 0xe3b157b7 0xa8807273 0xa7ddd6a2 0x8a87b1fa 0xe07a6620
3fcde480: 0xffffffff 0xffffffff 0xffffffff 0x3fce0000 0x00000000 0x00000024 0x00005090 0x403ce060
3fcde4a0: 0x2bca1a3c 0x5b2428c6 0x00000000 0x00000000 0x0000d000 0x00002000 0x00000000 0x00000000
3fcde4c0: 0x00000000 0x00000000 0x00010000 0x001c0000 0x001d0000 0x001c0000 0x00000000 0x00000000
3fcde4e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fcde500: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fcde520: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
3fcde540: 0x00000000 0x00000000 0x00000002 0x00000000 0x600c5200 0x600c5200 0x00000000 0x4004a296
3fcde560: 0x89174a77 0xbc07b8ce 0x3fcde668 0x00000000 0x30393738 0x00000000 0x00010000 0x200203e9
3fcde580: 0x403ce000 0x403d0000 0x00002dc0 0x000000ee 0x00000005 0x00000000 0x01000000 0x3c005090



ELF file SHA256: 735015a1611afff0

Rebooting...

Anyone an idea what else I can try to do?

Well the error message should have helped you :wink: it indicates you have done a binary for 4Mb flash size (confirmed by sketch you shared) but ESP itself has only 2M so correct your sketch and try again :smiley:

@vincen okay so I need to adjust the flash_size right? I digged a bit deeper for the platformio options, seems I should have wrote it like this board_upload.flash_size: 2MB but then during the compilation step the partitions don’t match:

Partitions defined in 'partitions.csv' occupy 3.6MB of flash (3735552 bytes) which does not fit in configured flash size 2MB. Change the flash size in menuconfig under the 'Serial Flasher Config' menu.

Any other configuration I found here: platform-espressif32/boards at develop · platformio/platform-espressif32 · GitHub doesn’t seem to have a 2MB flash either.

So I went into the build directory and added my own minimal.csv for a partition, where I simply halved app0 and app1 in size:

# Name,   Type, SubType, Offset,   Size, Flags
nvs,      data, nvs,     ,        0x4000,
otadata,  data, ota,     ,        0x2000,
phy_init, data, phy,     ,        0x1000,
app0,     app,  ota_0,   ,        0xE0000,
app1,     app,  ota_1,   ,        0xE0000,

Then I set the top part of the config like so:

esphome:
  name: ESP32C3
  platformio_options:
    board_upload.flash_size: 2MB
    board_upload.maximum_size: 2097152
    board_build.partitions: "minimal.csv"
    board_build.flash_mode: dio

This seems to work, I have a proper boot now! But, this seems not ideal to get it to work with a custom partition file. After all, it doesn’t get generated with the config. Is there a nicer way?

2 Likes

Be a little patient :wink: that chipset is very recent and as stated on esphome website on page about ESP32:

Support for the ESP32-S2 and ESP32-C3 is currently in development.

1 Like

@vincen Okay, I’ll wait patiently and see :stuck_out_tongue_winking_eye:
For now I can tinker with it, that’s nice.
I’ve updated the title so other people with the same silly 2MB board can find it

2 Likes

:+1: good idea

Are there any updates on the topic, since there are now a bunch of ESP C3 Modules available that are sold with only 2MB flash directly from Espressif? All the ESP8685-Wroom modules are available in 2MB and 4MB versions.

At the moment I still use my custom configuration in the latest ESP Home (2023.7.1)
I don’t see any other board_build.partitions configurations so far yet.

I did maximise my 2mb partition a bit better though:

# Name,   Type, SubType, Offset,   Size, Flags
nvs,      data, nvs,     ,        0x4000,
otadata,  data, ota,     ,        0x2000,
phy_init, data, phy,     ,        0x1000,
app0,     app,  ota_0,   ,        0xEA640,
app1,     app,  ota_1,   ,        0xEA640,

Are you able to use my suggestions?

1 Like

Hi, so you’re able to run esphome with your own modification on the 2mb chip?
Any issues so far?

Hi there,

Yes, I’ve been running it for a while. I use it to control the remote of my AJAX alarm system. It has been working perfectly, even though it’s a snug fit when it comes to flash size.
It’s actually the one esphome device that gives me the least amount of trouble.

I do think the flash size is a bit of a let down. Using the bluetooth proxy option can’t be flashed, it’s about ~140% of the available space. Unless you disable OTA and flash it through USB I guess.