Firmware burning under Linux
Overview
In this tutorial, 1Z Lab mainly explains in detail the specific process of flashing MicroPython firmware to ESP32 under Linux.
before the start
Before starting, you should read the previous chapters in this tutorial series carefully:
MicroPython Firmware Burning Guide
After reading, you need to:
-
Download the MicroPython firmware to the local
-
Learn about the tools needed to burn MicroPython firmware
-
Connect your ESP32 device to your computer with a proper cable
Get tools¶
In the MicroPython firmware burning guide , the author mentioned:
Tools needed to flash MicroPython firmware for ESP32:
Python3
pip
Python package manager for downloadingesptool
modules
esptool
A Python tool module for flashing firmware to ESP32
Next we focus on how to get these tools on Linux.
Linux comes with Python¶
It is very convenient to burn firmware under linux, thanks to the fact that linux distributions usually come with Python. Many distributions even come with two versions of Python2 and Python3 at the same time. In the following examples, we only take Python3 as an example. .
Although we don't have to install Python ourselves under linux, we need to install a package manager for Pythonpip
get pip¶
Open a terminal program in your lovely Linux, check in with your distribution, and enter the following command
-
Arch Linux
-
sudo pacman -S python3-pip
-
Ubuntu
-
sudo apt-get install python3-pip
The rest of the distributions are Baidu, so I won't list them all here.
Get esptool¶
We need to use Python's package manager pip
to get esptool, and enter the following command in the command line window to install it:
sudo pip3 install esptool
So far, the tools under linux have been prepared.
Flash the firmware with esptool¶
Now that you're all set, let's start flashing the MicroPython firmware.
Check the port number under linux¶
Before you start, you need to know the port number of the ESP32 device you plugged into your computer, in Linux. Different from Windows, Linux adheres to the idea that everything is a file. USB serial devices /dev/
can be found in the directory in the Linux file system. Linux usually ttyUSB
names these devices with a + number number. You can use the following command to view:
ls -l /dev/ttyUSB*
As shown in the picture above, the port number of the author's ESP32 under linux is the part in the red frame, which is very different from that of Windows.
Note: ttyUSB
The number that follows may also depend on your specific situation, not necessarily 0. If there are multiple USB serial devices, you need to identify which one is your ESP32 device.
Erase flash¶
Similarly, in order to ensure the success rate of firmware flashing, we need to clear the flash of ESP32 first.
sudo esptool.py --port <your port number> erase_flash
On my borrowed Mac, the port number is /dev/ttyUSB0
, so the command I should enter is
sudo esptool.py --port /dev/ttyUSB0 erase_flash
Note: Be sure to replace <your port number> with your own port number
Flash the firmware with esptool¶
Find the full path of the firmware you downloaded before, usually the firmware downloaded by the browser is stored in the ~/Downloads
directory
Follow the following command template to start flashing:
sudo esptool.py --chip esp32 --port <your port number> write_flash -z 0x1000 <full path to your firmware>
Note: Be sure to replace <your port number> and <full path to your firmware> to ensure they are correct
The author's port number is /dev/ttyUSB0
, and the firmware path is~/Dowloads/esp32-20180411-v1.9.3-534-g59dda710.bin
So my input should be
sudo esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 ~/Dowloads/esp32-20180411-v1.9.3-534-g59dda710.bin
The following is the complete output of the command execution, which took 53.5s:
➜ ~ sudo esptool.py --chip esp32 --port /dev/ttyUSB1 write_flash -z 0x1000 ~/Dowloads/esp32-20180411-v1.9.3-534-g59dda710.bin esptool.py v2.3.1 Connecting........_ Chip is ESP32D0WDQ6 (revision 1) Features: WiFi, BT, Dual Core Uploading stub... Running stub... Stub running... Configuring flash size... Auto-detected Flash size: 4MB Compressed 973584 bytes to 604211... Wrote 973584 bytes (604211 compressed) at 0x00001000 in 53.5 seconds (effective 145.5 kbit/s)... Hash of data verified.
Leaving... Hard resetting via RTS pin...
So far, the firmware burning process of linux is over.