ESP32 ROM Loader: Write to flash does not work
Posted: Mon Jan 13, 2025 11:29 pm
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:
-------------
-------------
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:
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):
-------------
-------------
The same esptool command but without "--no-stub" argument works OK (when it bypasses ROM loader). ESP-IDF v5.0.2.
Thank You.
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:
-------------
- 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
-------------
- 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.