ESP32 flashing
Flashing the ESP32-S3 using the Espressif Flash Download Tool
Summary
Using the Espressif Flash Download Tool allows us to write binary firmware files to the Espressif ESP32-S3. We need to know which memory location to write the binary files to. I found these memory locations by examining the output of Visual Studio Code (VSCode). I use VSCode with the PlatformIO plugin to create and write binary file to my ESP32-S3 based devices.
The problem
I use Visual Studio Code with the PlatformIO plugin to prepare code for some ESP32-S3 based devices that I am using for this project. The devices are the Lilygo T-Watch S3 and T-Embed. The same PlatformIO plugin then create the binary file that is written to the ESP32. How do I enable somebody else to flash any new and improved binary files that I create to these devices without having to return the device to me?
The solution
Download the Flash Download Tool from the Espressif website here. There was only a version of the software available for Windows when I last looked.
The PlatformIO plugin creates three binary files from the source code. These binary files end with the suffix ‘.bin’ and can be found in the directory:
.pio/build/<project_name>
The three .bin files that need to be written to the ESP32-S3 are:
bootloader.bin
firmware.bin
partitions.bin
The memory location and other settings that I used to load each of these is shown in the screenshot below:
Note that the COM port you use will probably be different from mine. To see what the COM port that is connected to your device is, unplug your device from the USB port and see what COM port disappears from the drop down menu. There may be more than one COM port to choose from.
After loading the binary files restart the device. Otherwise the new code will not run. This is different behaviour from using VSCode, which automagically resets the device so that the new code runs on it.
I downloaded some example code made by the manufacturer of one of the devices that I am using. There was only a single file called ‘firmware.bin’. In this case, I loaded the single file to address 0x0000. This was successful and the code loaded and ran correctly. For whatever reason, PlatformIO creates three separate .bin files that need to be loaded to different parts of the memory of the ESP32-S3 shown in the screenshot. Please note that these memory values are valid for the ESP32-S3. Other variations of the ESP32 and other microcontrollers may well use different memory locations.
Background
How did I figure this out? When I ran the PlatformIO build tool in VSCode I found three .bin files created in the build subdirectory of .pio:
-rw-r--r-- 1 ash ash 15040 Sep 12 16:24 bootloader.bin
-rw-r--r-- 1 ash ash 879568 Sep 19 15:50 firmware.bin
-rw-r--r-- 1 ash ash 3072 Sep 12 16:24 partitions.bin
Note the file sizes. The file sizes of some of the .bin files will change each time that the code used to create the .bin files changes. When I ran the upload tool to write these files to the ESP32-S3 on the board that I’m using, I got this output. I put ‘**’ around some of the values to draw attention to them and replaced several lines with ‘…’:
Changing baud rate to **460800**
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00003fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x000e6fff...
Compressed **15040** bytes to 10333...
Writing at **0x00000000**... (100 %)
Wrote 15040 bytes (10333 compressed) at 0x00000000 in 0.3 seconds (effective 461.1 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 137...
Writing at **0x00008000**... (100 %)
Wrote 3072 bytes (137 compressed) at 0x00008000 in 0.0 seconds (effective 528.6 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 713.3 kbit/s)...
Hash of data verified.
Compressed **879568** bytes to 564833...
Writing at **0x00010000**... (2 %)
...
Writing at 0x000e3ec9... (100 %)
Wrote **879568 bytes** (564833 compressed) at **0x00010000** in 6.4 seconds (effective 1107.7 kbit/s)...
Hash of data verified.
We can see that a file of the same size as the bootloader.bin file was written to 0x000. We can see that a file of the same size as partitions.bin was written to 0x8000. We can see that a file of the same size as firmware.bin was written to 0x10000 (note the four 0s).
If we look closely, we can see that 8192 bytes were written starting at 0xe000. I suspect that these are padding 0 values.
The baud rate is changed in the first line to be 460800 baud. I used this value in the Espressif Flash Download Tool, as shown in the screenshot above.