一、概述
之前通过修改lv_bindings的代码使编译通过了,但是在执行lvgl相关代码时出错了。目前国外一个大佬开源了一个lvgl_micropython项目,他改了模块的绑定关系,之前LVGL是作为Micropython的依赖项,现在Micro python是作为LVGL的依赖项。通过这样做,简化了更新MicroPython版本的过程。尝试编译这个项目,希望能解决之前lvgl不能用的问题。
源码链接:GitHub - kdschlosser/lvgl_micropython: LVGL module for MicroPython
二、开发环境
由于国内访问github受限的问题,速度比较慢,也可能出错。这次使用了一个香港的云服务器来搭建开发环境。服务器是一个2核4G的弹性云服务器,带宽1Mb,服务器安装Ubuntu-22.04-x64系统。
基于ubuntu系统编译时,需要安装以下4个工具:
- build-essential
- cmake
- ninja-build
- python
ubuntu22系统自带了build-essential和python,只需要安装cmake和ninja-build。
1、安装cmake
执行以下命令:
sudo apt install cmake
执行成功之后查看版本号:
# cmake --version
cmake version 3.22.1
2、安装ninja-build
执行以下命令:
sudo apt install ninja-build
执行成功之后查看版本号:
# ninja --version
1.10.1
三、克隆代码
由于国内访问github受限的问题,速度比较慢,也可能出错。这次使用了一个香港的云服务器来克隆代码,服务器安装Ubuntu-22.04-x64系统。服务器是一个2核4G的弹性云服务器,带宽1Mb。
1、克隆代码
源码存在在home路径下,执行以下指令克隆代码:
cd /home
git clone https://github.com/kdschlosser/lvgl_micropython.git
路径/home可以自定义任意路径。
2、更新模块
克隆仓库之后,不要执行更新submodules的命令,编译时会自动更新。
三、编译ESP32C3固件
1、开始编译
执行命令:
python3 make.py esp32 submodules clean mpy_cross BOARD=ESP32_GENERIC_C3 DISPLAY=st7789 INDEV=ft6x36
处理器ESP32C3,Display IC:st7789,Touch IC:ft6x36,适配立创实战派开发板。
2、更新模块
执行编译命令后后自动下载MicroPython 1.23.0、LVGL、pycparser、ESP-IDF v5.2.0。
Collecting build requirements....
collecting MicroPython 1.23.0
Submodule 'lib/micropython' (https://github.com/micropython/micropython) registered for path 'lib/micropython'
Cloning into '/home/lvgl_micropython/lib/micropython'...
collecting LVGL
this might take a while...
Submodule 'lib/lvgl' (https://github.com/lvgl/lvgl) registered for path 'lib/lvgl'
Cloning into '/home/lvgl_micropython/lib/lvgl'...
collecting pycparser
Submodule 'lib/pycparser' (https://github.com/eliben/pycparser) registered for path 'lib/pycparser'
Cloning into '/home/lvgl_micropython/lib/pycparser'...
collecting ESP-IDF v5.2.0
this might take a while...
Submodule 'lib/esp-idf' (https://github.com/espressif/esp-idf) registered for path 'lib/esp-idf'
Cloning into '/home/lvgl_micropython/lib/esp-idf'...
3、编译完成
编译完成提示:
Project build complete. To flash, run:
idf.py flash
or
idf.py -p PORT flash
or
python -m esptool --chip esp32c3 -b 460800 --before default_reset --after no_reset --no-stub write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m 0x0 build-ESP32_GENERIC_C3/bootloader/bootloader.bin 0x8000 build-ESP32_GENERIC_C3/partition_table/partition-table.bin 0x10000 build-ESP32_GENERIC_C3/micropython.bin
or from the "/home/lvgl_micropython/lib/micropython/ports/esp32/build-ESP32_GENERIC_C3" directory
python -m esptool --chip esp32c3 -b 460800 --before default_reset --after no_reset --no-stub write_flash "@flash_args"
bootloader @0x000000 17200 ( 15568 remaining)
partitions @0x008000 3072 ( 1024 remaining)
application @0x010000 2789808 ( 3664 remaining)
total 2855344
make: Leaving directory '/home/lvgl_micropython/lib/micropython/ports/esp32'
esptool.py v4.7.0
Wrote 0x2b91b0 bytes to file /home/lvgl_micropython/build/lvgl_micropy_ESP32_GENERIC_C3-4.bin, ready to flash to offset 0x0
To flash firmware:
Replace "(PORT)" with the serial port for your esp32
and run the commands.
/root/.espressif/python_env/idf5.2_py3.10_env/bin/python -m esptool -p (PORT) -b 460800 erase_flash
/root/.espressif/python_env/idf5.2_py3.10_env/bin/python -m esptool --chip esp32c3 -p (PORT) -b 921600 --before default_reset --after no_reset --no-stub write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m 0x0 "/home/lvgl_micropython/build/lvgl_micropy_ESP32_GENERIC_C3-4.bin"
将lvgl_micropy_ESP32_GENERIC_C3-4.bin烧写到目标板即可,烧写地址0x0。
四、遇到错误
/root/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20230928/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/13.2.0/../../../../riscv32-esp-elf/bin/ld: /home/lvgl_micropython/lib/micropython/extmod/modbluetooth.c:662:(.text.bluetooth_ble_gap_connect+0xae): undefined reference to `mp_bluetooth_gap_peripheral_connect'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the /home/lvgl_micropython/lib/micropython/ports/esp32/build-ESP32_GENERIC_C3/log/idf_py_stderr_output_219318 and /home/lvgl_micropython/lib/micropython/ports/esp32/build-ESP32_GENERIC_C3/log/idf_py_stdout_output_219318
-e See https://github.com/micropython/micropython/wiki/Build-Troubleshooting
make: *** [Makefile:66: all] Error 1
make: Leaving directory '/home/lvgl_micropython/lib/micropython/ports/esp32'
这是由于Micropython导致,克隆最新的仓库已解决,问题的详细原因。