Page 1 of 1

ESP32 ROM Loader: Write to flash does not work

Posted: Mon Jan 13, 2025 11:29 pm
by Ivan32
We are trying to upload binaries to ESP32-U4WDH using Serial Protocol found at:

https://docs.espressif.com/projects/esp ... tocol.html

but it does not work.

We cannot use esptool.py in the production because the device we are making does not have space for external connections. So we have to use on-board MCU (STM32 in our case) to upload all project binaries (bootloader, partition table and the app) using our C program in STM32.

We are using ROM loader directly, without the stub. The upload process stops when we send FLASH_BEGIN command. ESP32 ROM Loader returns an error:

0x05 "Received message is invalid" (parameters or length field is invalid).

This error happens when we use documentation's suggested block size of 16k. If we use a smaller block, such as 4k, the ROM Loader hangs and does not reply at all.

Here is the sequence of the commands that we send:
-------------

Code: Untitled.txt Select all


Send: SYNC( 36 bytes );
Wait 50 ms;
Send: SYNC( 36 bytes );
Receive: SYNC OK, SYNC OK, SYNC OK, ..., SYNC OK; - 8 replies
Wait 50 ms;

Send: SPI_ATTACH( 0x00000000, 0x00000000 );
Wait 1.2 ms;
Receive: SPI_ATTACH OK;

Send: SPI_SET_PARAMS( 0x00000000, 0x400000, 64*1024, 4*1024, 256, 0xffff );
Wait 1.2 ms;
Receive: SPI_SET_PARAMS OK;

Send: FLASH_BEGIN( 0x00008000, 0x00000002, 0x00004000, 0x00001000 );
Wait 1.2 ms;
Receive: FLASH_BEGIN Error: 0x05;
-------------

If however we reduce block size in the FLASH_BEGIN command from 0x00004000 to 0x00001000, the ROM Loader never sends the reply.

Our Question:
Does ESP32 ROM Loader support FLASH_BEGIN command at all? If it does, what we are doing wrong in the above sequence?
Should we provide custom parameters somewhere, such as write to some registers first?

We tried to use esptool.py with extra parameters --no-stub --trace:

Code: Select all

python -m esptool --no-stub --trace --chip esp32 --before default_reset --after hard_reset  --port COM5 write_flash --flash_mode dio --flash_size 4MB --flash_freq 40m 0x1000 bootloader\bootloader.bin
on several ESP32 development boards of different versions (such as ESP32-PICO-MINI-02), but esptool also hangs on FLASH_BEGIN command. This is the last fragment from the trace (command op=0x02 is FLASH_BEGIN):

-------------

Code: Untitled.txt Select all

Flash will be erased from 0x00001000 to 0x00007fff...
Erasing flash...
TRACE +0.000 command op=0x02 data len=16 wait_response=1 timeout=3.000 data=106700001a0000000004000000100000
TRACE +0.000 Write 26 bytes:
c000021000000000 00106700001a0000 | ..........g.....
0000040000001000 00c0 | ..........
TRACE +3.001 Serial data stream stopped: Possible serial noise or corruption.
-------------

The same esptool command but without "--no-stub" argument works OK (when it bypasses ROM loader). ESP-IDF v5.0.2.

Thank You.

Re: ESP32 ROM Loader: Write to flash does not work

Posted: Mon May 12, 2025 6:03 am
by Robomilk
Can confirm this is also happening to me on newly acquired chips.

I have a very similar setup with an independent MCU which needs to flash and verify the ESP32 flash memory.

Sync process for entering ROM bootloader on an ESP32-U4WDH chip is completed without issues, and most functionalities seem to work fine until either entering the FLASH_BEGIN or the SPI_FLASH_MD5 commands, at which points the bootloader stops responding/crashes. This is disappointing from the point of view of the ease of use, since now a stub process will be needed, which needlesly complicates the verification process on the MCU side.

The same process on a ESP32-S3 chip seems to work fine.

Re: ESP32 ROM Loader: Write to flash does not work

Posted: Wed May 21, 2025 2:47 am
by Mary
Can confirm this is also happening to me on newly acquired chips.

I have a very similar setup with an independent MCU which needs to flash and verify the ESP32 flash memory.

Sync process for entering ROM bootloader on an ESP32-U4WDH chip is completed without issues, and most functionalities seem to work fine until either entering the FLASH_BEGIN or the SPI_FLASH_MD5 commands, at which points the bootloader stops responding/crashes. This is disappointing from the point of view of the ease of use, since now a stub process will be needed, which needlesly complicates the verification process on the MCU side.

The same process on a ESP32-S3 chip seems to work fine.
"Can confirm this is also happening to me on newly acquired chips." what were the chips you were using before (also ESP32-U4WDH or ESP32-S3?) where everything worked.

Re: ESP32 ROM Loader: Write to flash does not work

Posted: Wed Jul 02, 2025 6:06 am
by Robomilk
Can confirm this is also happening to me on newly acquired chips.

I have a very similar setup with an independent MCU which needs to flash and verify the ESP32 flash memory.

Sync process for entering ROM bootloader on an ESP32-U4WDH chip is completed without issues, and most functionalities seem to work fine until either entering the FLASH_BEGIN or the SPI_FLASH_MD5 commands, at which points the bootloader stops responding/crashes. This is disappointing from the point of view of the ease of use, since now a stub process will be needed, which needlesly complicates the verification process on the MCU side.

The same process on a ESP32-S3 chip seems to work fine.
"Can confirm this is also happening to me on newly acquired chips." what were the chips you were using before (also ESP32-U4WDH or ESP32-S3?) where everything worked.
Actually, I might have not expressed myself correctly. Newly acquired ESP32-U4WDH chips are running into this problem, but I have no past reference regarding older chips, other than the ESP32-S3 which have always worked fine