We begin now a series of articles about the Espressif ESP32 MCU
After having analyzed in the previous articles MicroPython for ESP8266, in this we start to treat MicroPython on ESP32.
The following shows how to generate the MicroPython image from the source code for the ESP32 board.
The operating system is Debian 9, previously encountered for the esptool and Adafruit-ampy utilities
MicroPython – Python on embedded devices
Log on with the operating system user on Debian 9, sviluppo in our case; under the home folder create the Micropython folder and inside this folder the esp32 folder
1 2 3 4 |
mkdir Micropython cd Micropython mkdir esp32 cd esp32 |
The MicroPython source code is available at the following link
Instructions to build the firmware for the ESP32 are available at the link
Clone the repository
1 |
git clone https://github.com/micropython/micropython |
Go into micropython/ports/esp32 folder
1 |
cd micropython/ports/esp32 |
Run
1 |
make |
The command releases the git hash for the supported espidf
At the time of our compilation the result is as follows
1 2 3 4 5 6 |
sviluppo@debian9:~/Micropython/esp32/micropython/ports/esp32$ make Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity. The ESPIDF variable has not been set, please set it to the root of the esp-idf repository. See README.md for installation instructions. Supported git hash: 3ede9f011b50999b0560683f9419538c066dd09e Makefile:34: *** ESPIDF not set. Stop. |
Go into /home/sviluppo/Micropython/esp32 folder and clone ESPIDF
1 2 |
git clone https://github.com/espressif/esp-idf.git cd esp-idf |
Checkout with the hash obtained above
1 |
git checkout 3ede9f011b50999b0560683f9419538c066dd09e |
Run
1 |
git submodule update --init |
We follow the instructions at the link
to install the cross compiler; install the prerequisites for building
1 |
sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial |
Download the cross compiler
1 2 |
cd /home/sviluppo/Micropython/esp32 wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz |
Create the esp folder under /home/sviluppo/Micropython/esp32
1 2 3 |
cd /home/sviluppo/Micropython/esp32 mkdir esp cd esp |
Unpack the cross compiler in esp
1 |
tar -zxvf ../xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz |
Add the binary folder of the cross compiler to the PATH envinronment variable
1 |
export PATH=/home/sviluppo/Micropython/esp32/esp/xtensa-esp32-elf/bin:$PATH |
Go into the following folder
1 |
/home/sviluppo/Micropython/esp32/micropython/ports/esp32/ |
and create the makefile file with the following code inside
1 2 3 4 5 6 7 |
ESPIDF = /home/sviluppo/Micropython/esp32/esp-idf #PORT = /dev/ttyUSB0 #FLASH_MODE = qio #FLASH_SIZE = 4MB #CROSS_COMPILE = xtensa-esp32-elf- include Makefile |
Go into the micropython folder available in /home/sviluppo/Micropython/esp32
1 |
cd micropython |
Run
1 |
git submodule update --init |
to add external dependencies.
Next step is the MicroPython cross compiler build
1 2 3 |
make -C mpy-cross git submodule init lib/berkeley-db-1.xx git submodule update |
Finally we can build the ESP32 firmware with the following commands
1 2 |
cd ports/esp32 make |
The firmware is generated under ports/esp32/build with the name firmware.bin.
Proceed to load the firmware with the commands
1 |
make erase |
In our case, the firmware upload was successful with the command
1 |
make deploy |
It is also possible to load the firmware.bin image with the commands
1 |
esptool.py --chip esp32 --port /dev/ttyXXX --baud 921600 erase_flash |
1 |
esptool.py --chip esp32 --port /dev/ttyXXX --baud 921600 write_flash -z --flash_mode "dio" --flash_freq "40m" --flash_size detect 0x1000 firmware.bin |
where /dev/ttyXXX is replaced with the actual serial port to which we connect the ESP32 board.
In the next article we’ll compile the nodemcu firmware for ESP32