This repository provides a sample code implementation for flashing firmware from one ESP32 (master) to another ESP32 (target). It includes a detailed implementation of the firmware uploading process using SPIFFS and a custom flasher class. The provided .ino
file demonstrates the essential wiring and flashing workflow, along with the key functions needed to test and execute the firmware upload.
To set up the connections between the master and target ESP32 devices:
Master ESP32 Pin | Target ESP32 Pin |
---|---|
RX2 (GPIO 16) | TX0 |
TX2 (GPIO 17) | RX0 |
GND | GND |
VIN | VIN |
GPIO 25 | GPIO 0 (BOOT) |
GPIO 26 | EN |
Ensure all connections are secure before proceeding.
-
setup()
This function initializes the master ESP32 and starts the firmware upload process:- Begins Serial communication for monitoring the process.
- Initializes SPIFFS to access the firmware binary file (
firmware.bin
). - Sets up the flasher class (
ESP32Flasher
) and attempts to connect to the target ESP32. - Initiates the flashing of the firmware stored in SPIFFS to the target ESP32.
-
espFlasher::espFlasherInit()
Configures the master ESP32 to communicate with the target ESP32:- Sets up Serial communication using
Serial2
. - Configures GPIO pins to control the target ESP32 (GPIO 25 for BOOT and GPIO 26 for EN).
- Sets up Serial communication using
-
espFlasher::espFlashBinFile(const char* bin_file_name)
Handles the flashing process:- Locates the binary firmware file (
firmware.bin
) in the SPIFFS. - Verifies the file size and starts the flashing process using the
flashBinary()
function. - Ensures the target ESP32 is reset after successful flashing.
- Locates the binary firmware file (
-
Prepare the Firmware:
- Compile your test firmware code and generate the
.bin
file. - Copy the
.bin
file into thedata
folder of the master ESP32's code directory.
- Compile your test firmware code and generate the
-
Upload the Binary to SPIFFS:
- Use the ESP32 File System Uploader to upload the
.bin
file to the master ESP32's SPIFFS. - If the tool is not available, follow the installation guide here.
- Use the ESP32 File System Uploader to upload the
-
Connect the Master and Target ESP32 Devices:
- Wire the devices as specified in the wiring table above.
-
Run the Master Code:
- Upload the
master_code.ino
to the master ESP32. - Monitor the Serial output to ensure the firmware is flashed successfully.
- Upload the
This repository demonstrates a straightforward approach for ESP32-to-ESP32 firmware flashing, making it ideal for testing and development purposes.