B4R Code Snippet [ESP32] .bin merging and flashing

It's all was for old B4R versions supporting only Arduino 1.x. For Arduino 2.x - see posts below.

Merging 3 .bin files from B4R Object\bin folder into a single firmware file "merged-flash.bin":

Flashing "merged-flash.bin" file into the board via COM-port and esptool.exe:

Merging:
esptool.py v4.5.1
Wrote 0x115300 bytes to file ..\Objects\bin\merged-flash.bin, ready to flash to offset 0x0
Completed. Exit code: 0

Forgotten to plug USB-cable from the board:
esptool.py v4.5.1
Found 0 serial ports
A fatal error occurred: Could not connect to an Espressif device on any of the 0 available serial ports.
Completed. Exit code: 2

Flashing: do not forget
  1. disconnect log of B4R from COM-port
  2. set the flash-mode by the board buttons (usually holding BOOT press and release EN and next release BOOT) of ESP32 module just after the IDE link clicked !

Commands for B4R IDE:
B4X:
'Ctrl + click to merge binaries into merged-flash.bin: ide://run?file=%USERPROFILE%\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.5.1\esptool.exe&args=--chip&args=ESP32&args=merge_bin&args=-o&args=..\Objects\bin\merged-flash.bin&args=--flash_mode&args=dio&args=--flash_size&args=4MB&args=0x1000&args=..\Objects\bin\src.ino.bootloader.bin&args=0x8000&args=..\Objects\bin\src.ino.partitions.bin&args=0x10000&args=..\Objects\bin\src.ino.bin
'Ctrl + click to flash into ESP32 board: ide://run?file=%USERPROFILE%\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.5.1\esptool.exe&args=--chip&args=ESP32&args=--baud&args=921600&args=write_flash&args=0x0&args=..\Objects\bin\merged-flash.bin
where "%USERPROFILE%....." is your path to "esptool.exe" installed in Arduino IDE v.1.x.

These 2 links are useful for re-flashing the board if the B4R sketch was already compiled.
 
Last edited:

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
You mentioned one benefit of this is remote update, How can you update/replace app bin remotely inside IC?
 

peacemaker

Expert
Licensed User
Longtime User

peacemaker

Expert
Licensed User
Longtime User
Addition for Arduino 2.x - copying all the generated files during compilation into B4R Objects\bin folder:

Command for B4R IDE v.4.0+:

B4X:
'Ctrl + click to copy FW file of Arduino 2.x: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=%USERPROFILE%\AppData\Local\Temp\arduino\sketches\613611983B1DC48F5240C428509155C2&args=..\Objects\bin&FilesSync=True

, where "613611983B1DC48F5240C428509155C2" is the unique subfolder created by Arduino 2.x automatically for your sketch.
This folder can be found in the B4R log after compilation is complete.


Merging ESP32 partitions after Arduino 2.x:
'Ctrl + click to merge binaries into merged-flash.bin: ide://run?file=%USERPROFILE%\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.5.1\esptool.exe&args=--chip&args=ESP32&args=merge_bin&args=-o&args=..\Objects\bin\merged-flash.bin&args=--flash_mode&args=dio&args=--flash_size&args=4MB&args=0x1000&args=%USERPROFILE%\AppData\Local\Temp\arduino\sketches\5F246370AC91E228B24A8A187BD6F440\src.ino.bootloader.bin&args=0x8000&args=%USERPROFILE%\AppData\Local\Temp\arduino\sketches\5F246370AC91E228B24A8A187BD6F440\src.ino.partitions.bin&args=0x10000&args=%USERPROFILE%\AppData\Local\Temp\arduino\sketches\5F246370AC91E228B24A8A187BD6F440\src.ino.bin
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
For Arduino 2.x and esptool v4.6 (ESP32 SDK 3+) - it's not needed to merge the fw partitions into a single file for flashing, it's done during compilation (file "src.ino.merged.bin"), so, for ex. these are 2 commands for ESP32C3 MCU:

B4X:
'Ctrl + click to copy FW files of Arduino 2.x: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=%USERPROFILE%\AppData\Local\Temp\arduino\sketches\6195A4ABF2E9C4E65FF5516D3B1B3D11&args=..\Objects\bin&FilesSync=True
'Ctrl + click to flash into ESP32C3 board: ide://run?file=%USERPROFILE%\AppData\Local\Arduino15\packages\esp32\tools\esptool_py\4.6\esptool.exe&args=--chip&args=ESP32C3&args=--baud&args=921600&args=write_flash&args=0x0&args=..\Objects\bin\src.ino.merged.bin

, where 6195A4ABF2E9C4E65FF5516D3B1B3D11 is the unique subfolder created by Arduino 2.x automatically for your sketch.
This folder can be found in the B4R log after compilation is complete.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…