After using in some examples the MicroPython firmware on the ESP8266 board
MicroPython – Nodes examples with DHT11, Relay and MQTT
this article shows how to generate the MicroPython firmware for the ESP8266 board.
The operating system used for this task is Debian 9, already encountered when we analyzed the esptool utility
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 esp8266 folder
1 2 3 4 |
mkdir Micropython cd Micropython mkdir esp8266 cd esp8266 |
The MicroPython source code is available at the following link
Instructions to build the firmware for the ESP8266 are available at the link
Clone the repository
1 |
git clone https://github.com/micropython/micropython |
Download the cross compiler, as described here
As indicated in the link above, download the source of the cross compiler always from the folder esp8266
1 |
git clone --recursive https://github.com/pfalcon/esp-open-sdk |
Install the prerequisites for building
1 |
sudo apt-get install make unrar-free autoconf automake libtool gcc g++ gperf flex bison texinfo gawk ncurses-dev libexpat-dev python-dev python python-serial sed git unzip bash help2man wget bzip2 libtool-bin |
Proceed to the build of the cross compiler with the following commands
1 2 |
cd esp-open-sdk make STANDALONE=y |& tee make0.log |
At the end of the build add the binary folder of the cross compiler to the PATH envinronment variable
1 |
export PATH=/home/sviluppo/Micropython/esp8266/esp-open-sdk/xtensa-lx106-elf/bin:$PATH |
Go into the micropython folder available under ~/Micropython/esp8266
1 |
cd ~/Micropython/esp8266/micropython |
Run
1 |
git submodule update --init |
to add external dependencies.
Next step is the MicroPython cross compiler build
1 |
make -C mpy-cross |
Finally we can build the ESP8266 firmware with the following commands
1 2 3 |
cd ports/esp8266 make axtls make |
The firmware is generated under ports/esp8266/build folder with the name firmware_combined.bin.
Proceed to load the firmware with the command
1 |
esptool.py --port /dev/ttyXXX erase_flash |
where /dev/ttyXXX is repalced with the actual serial port to which we connect the ESP8266 board.
In our case, the firmware upload was successful with the command
1 |
make PORT=/dev/ttyUSB0 deploy |
It is also possible to load the firmware_combined.bin image with the command
1 |
esptool.py --port /dev/ttyUSBX --baud 460800 write_flash --flash_size=detect 0 firmware-combined.bin |
In the next article we’ll analyze how to build the MicroPython firmware adding into the image additional MicroPython modules
MicroPython – MicroPython compiling for ESP8266 with additional modules