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.