Porting MicroPython’s LVGL Bindings to ESP32
I am not sure why nobody provides ready-made ESP32 firmware with MicroPython’s LVGL bindings, so I compiled one and recorded the steps.
Steps
All the steps below were done on a Linux system; other systems are similar, so I will not elaborate.
Switch the ESP-IDF version
The official LVGL bindings support up to v4.4; see Setting up ESP-IDF and the build environment.
The ESP-IDF changes quickly and MicroPython only supports certain versions. Currently MicroPython supports v4.0.2, v4.1.1, v4.2.2, v4.3.2 and v4.4, although other IDF v4 versions may also work.
If you have already installed the IDF, there is no need to download it again. Enter esp/esp-idf — it is a Git repository — and run the following command to switch to the version branch:
| |
After switching branches, you need to re-initialize the Git submodules:
| |
Once that is done, running git status will show some files with changes — these are usually leftovers from the previous version. Remove those changes.
Here is what I ran:
| |
Check git status again to make sure there are no changes.
Reinstall the IDF:
| |
Build lv_micropython
First clone the repository:
| |
Enter the repository and activate the IDF environment:
| |
Run the following commands to compile for the ESP32:
| |
When using IL9341 driver, the color depth need to be set to match ILI9341. This can be done from the command line.
LV_CFLAGSare used to override color depth, for ILI9341 compatibility.
LV_COLOR_DEPTH=16is needed if you plan to use the ILI9341 driver.
BOARD- I use WROVER board with SPIRAM. You can choose other boards fromports/esp32/boards/directory.
deploy- make command will create ESP32 port of Micropython, and will try to deploy it through USB-UART bridge.
The compilation will report errors because some Git submodules are missing; initialize them:
| |
If it still reports another one missing, initialize that one as well. In my case these two were the ones that errored.
Compile again — this time it fails with a static assertion error in lv_micropython/ports/esp32/network_common.c:
| |
Looking at esp-idf/components/esp_wifi/include/esp_wifi_types.h, it turns out to be an enum:
| |
I counted and WIFI_AUTH_MAX equals 10, so I changed TEST_WIFI_AUTH_MAX to 10 everywhere, and it compiles.
Now the build succeeds, and it auto-flashes after compiling.
Customize the ESP32 board
The default board has only 4MB of flash, but the board I have on hand uses 16MB, so I needed a custom board configuration.
For the specific steps, refer to Defining a custom ESP32 board.
Straight to the commands — copy a board configuration template as GENERIC_16M:
| |
Copy an sdkconfig.board from the SIL_WESP32 board into the GENERIC_16M folder.
Modify its contents as follows:
| |
Edit mpconfigboard.cmake, modifying its contents as follows:
| |
Recompile:
| |