XIAO ESP32C3, unable to upload sketch or re-write bootloader

I am having problems uploading sketches and need help.
I can upload sketches to two XIAOs without any problem, but I can’t upload to one of them. So I am trying to write the bootloader according to “Q3: I want to reflash the bootloader with factory firmware” on the Wiki, but it looks like the screenshot below and I can’t write it. It seems that the connection is made but the write timeout has occurred.

I have already confirmed the following

Connect to USB while holding down the boot switch
Remove the com port and reconnect it
Update the driver for the com port

Is there anything else I can try?

Hi there,
They don’t like any other programs open or using the ports , so check that, No arduino IDE windows open or connected same port.
HTH
GL :slight_smile: PJ

PJ, thanks for the reply.
ArduinoIDE is closed. No other devices are using this port. The connection to the port seems to succeed, but the write times out.
I have over 20 XIAOs and have unbricked many times, but this is a tough problem.

Hi there,
I agree, the connection looks ok, What about speed, Try lower baud rate
or flash with esptool.py ```
I was able to read a ESP32C6 with this command line below, you can flash that way also, I had to drop the speed to get a successful read to 230400
“esptool.py -p com4 -b 921600 read_flash 0 0x400000 flash_dump.bin”
so try esptool.py
HTH
GL :slight_smile: PJ :v:

I tried reducing the baud rate, but still cannot write.
I will try esptool.py. Where can I get it?

I found it.

I tried using esptool.py, but it still doesn’t work. I am going in circles.

PS C:\ESP_TOOLS\EspRFTestTool_v3.6_Manual\tool\esptool> python esptool.py -p com5 -b 9600 flash_id
esptool.py v4.5-dev
Serial port com5
Connecting...
Failed to get PID of a device on com5, using standard reset sequence.
.

A serial exception error occurred: Write timeout
Note: This error originates from pySerial. It is likely not a problem with esptool, but with the hardware connection or drivers.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
PS C:\ESP_TOOLS\EspRFTestTool_v3.6_Manual\tool\esptool>

lower baud rate, what is the command line?
took me a couple tries also.
GL :slight_smile: PJ

python esptool.py -p com5 -b 9600 flash_id

The flash ID can be read from 2 normal ESPC3s.

I’m doing this right now, takes longer but works well.

HTH
GL :slight_smile: PJ

I’m using ESP_IDF command prompt. installed the latest one ver.3.0 , fyi

I used this video as a guideline.

also this thread here,are other tools too.

GL :slight_smile: PJ :v:

I also tried ESP-IDF, but the result is the same. It does not seem to be able to access Flash. The Blink sketch I uploaded just before the problem occurred is working, so it appears the device is not dead.
It doesn’t look like an easy solution.

Hi @msfujino
Have you tried reflashing the firmware in EspRSTestTool for other XIAO ESP32C3? Is the result still the same?

I tried to re-flash my XIAO ESP32C3 following the Wiki steps and it was working.

BTW, did you do anything else before turning it into a brick?

Hi Seeed_Seraphine,
The screenshot in post 1/12 is the result of trying to write using EspRSTestTool.

I changed BSP to 3.0.0-rc1 and checked with a simple sketch with just blink and Serial.print(). However, there is a problem that the sketch does not work on battery power. I changed the sketch several times and uploaded it, but when I noticed it was bricked.
I changed BSP back to 2.1.1 and the problem persisted. I did the same with two other XIAOs as well, and these two uploaded without any problems.

Could this be caused by the code containing while(!serial) not being removed?
Do you remember roughly how many times you uploaded the code before it bricked? I’d like to see if I can reproduce this situation :face_with_hand_over_mouth:

There is no While(!Serial) in the sketch.
(I found that using printf() instead of Serial.print() works on battery power.)
Just before bricking, the following sketch was written. It was written at most a few times.

#define LED D10
void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT); // LED
//  Serial.println("END of SETUP"); 
  printf("END of SETUP\n");
}

void loop() {
  digitalWrite(LED, LOW);
//  Serial.println("serial print");
  printf("serial print\n");
  delay(100);
  digitalWrite(LED, HIGH);
  delay(500);
}

The day before, the following sketch was used to measure the sleep current.
Comparison of Sleep Currents for XIAO ESP32C6, S3, and C3

// Board Library : esp32 by Espressif 3.0.0-rc1
// Board Select  : XIAO_ESP32C6, XIAO_ESP32S3, XIAO_ESP32C3
// ArduinoIDE compile options left at default
// Vbat = 3.8V

void setup() {
  esp_deep_sleep_start();
}

void loop() {
}

Ok I got it. I’ll see if I can try to reproduce your situation

From the serial monitor it prints out, so I think the port is normal.
I await the results.

A0/D0(GPIO2) was connected to resistors for battery voltage divider as shown in the following link posted previously.
Battery voltage monitor and AD conversion for XIAO_ESP32C

The battery or the charging circuit will give a voltage of about 2V on A0/D0(GPIO2).
It seems that the level of A0/D0(GPIO2), which is Strapping Pin, was determined to be HIGH and did not enter boot mode. When the resistors for voltage divider was removed, writing to Flash became possible.
Since the threshold voltage that is judged as HIGH is subtle, it seems to have been just barely working so far; A0/D0(GPIO2) is not suitable as a battery voltage measurement port. This method is also described in the ESP32C3 Wiki, and should be noted when using Strapping Pins (A0/D0,A1/D1,D8,D9).

On the other hand, the following documents states that GPIO2 must be set to 1 when writing code to Flash.
1.“ESP32-C3 Series Datasheet Version, 2.4 Strapping Pins, able 4: Strapping Pins” 2.“Technical Reference Manual 7.2, Boot Mode Control, Table 7-2. Boot Mode Control”
However, as a result of experiments, it is possible to write to Flash when GPIO2 is LOW, but not when GPIO2 is HIGH.
Note that the document description and the experimental results do not match.

Thanks to those who helped me.

1 Like