XIAO ESP32C3 Can't erase flash

I was trying to get the HardwareTest app for the Seeed Round Display running on my XIAO ESP32C3 and have run into a problem:

ELF file SHA256: 27130e8b14f58bba
11:11:15.012 -> 
11:11:15.012 -> Rebooting...
11:11:15.012 -> ESP-ROM:esp32c3-api1-20210207
11:11:15.012 -> Build:Feb  7 2021
11:11:15.012 -> rst:0x3 (RTC_SW_SYS_RST),boot:0x9 (SPI_FAST_FLASH_BOOT)
11:11:15.012 -> Saved PC:0x40381cc8
11:11:15.012 -> SPIWP:0xee
11:11:15.012 -> mode:DIO, clock div:1
11:11:15.012 -> load:0x3fcd5810,len:0x438
11:11:15.044 -> load:0x403cc710,len:0x90c
11:11:15.044 -> load:0x403ce710,len:0x2624
11:11:15.044 -> entry 0x403cc710
11:11:15.143 -> XIAO round screen - LVGL_Arduino
11:11:15.143 -> Guru Meditation Error: Core  0 panic'ed (Store access fault). Exception was unhandled.
11:11:15.143 -> 
11:11:15.143 -> Core  0 register dump:
11:11:15.143 -> MEPC    : 0x4202bd74  RA      : 0x4202bd66  SP      : 0x3fca3510  GP      : 0x3fc8c200  
11:11:15.143 -> TP      : 0x3fc8f850  T0      : 0xffffffff  T1      : 0xffc3ffff  T2      : 0x00000001  
11:11:15.143 -> S0/FP   : 0x60004000  S1      : 0x3fc8eb4c  A0      : 0x00000001  A1      : 0xffffffff  
11:11:15.175 -> A2      : 0x00000000  A3      : 0xfdffffff  A4      : 0x08000000  A5      : 0x00000010  
11:11:15.175 -> A6      : 0x00000000  A7      : 0x04c4b400  S2      : 0x00000001  S3      : 0x00000000  
11:11:15.175 -> S4      : 0x00000000  S5      : 0x00000000  S6      : 0x00000000  S7      : 0x00000000  
11:11:15.175 -> S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
11:11:15.207 -> T3      : 0x00000000  T4      : 0x0000000f  T5      : 0x003c0000  T6      : 0x00000003  
11:11:15.207 -> MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000007  MTVAL   : 0x00000010  
11:11:15.207 -> MHARTID : 0x00000000  
11:11:15.207 -> 
11:11:15.207 -> Stack memory:

Which would normally mean just re-flashing and going on, or, at worst, erasing the flash and starting over.

But that’s the problem. With this running, I can’t erase the flash.

 % /Users/davidgs/Library/Arduino15/packages/esp32/tools/esptool_py/4.5.1/esptool --chip esp32c3 --port /dev/cu.usbmodem83201  erase_flash
esptool.py v4.5.1
Serial port /dev/cu.usbmodem83201
Connecting...
Chip is ESP32-C3 (revision v0.4)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 64:e8:33:8b:87:8c
Uploading stub...
Running stub...
Stub running...

A fatal error occurred: Unable to verify flash chip connection (No serial data received.).

I’ve tried unplugging it, holding down the boot button and plugging it back in, etc. Nothing seems to help.

How can I recover this device?

I have managed to finally erase the flash, but now, when I upload a program, i get an endless stream of:

17:09:00.058 -> invalid header: 0xffffffff

This was the program:

void setup() {
  Serial.begin(115200);
  delay(50);
  Serial.println("starting ..");
  delay(1000);
  // put your setup code here, to run once:
}

void loop() {
  Serial.println("Running");
  delay(3000);
  // put your main code here, to run repeatedly:
}

were you using Arduino IDE

Yes. I did have to use esptool.py from the command line to erase the flash though.

i dont think you need to erase the flash… why did you think you had to do that? I think you erased the bootloader

It was the only way to get it out of the first crash-loop.

I have since gone and downloaded the Bootloader according to this: (How to reflash the bootloader with factory firmware | Seeed Studio Wiki) but of course that’s Windows-only, so I just downloaded the boot loader, and used esptool.py --chip esp32c3 --before no_reset --port /dev/cu.usbmodem83201 write_flash --flash_mode dio --flash_freq 80m --flash_size 8MB 0x0 ~/Downloads/ESP32-C3_RFTest_108_2b9b157_20211014.bin

That has not been helpful either.