This tutorial shows you how to get started with MicroPython and LVGL on the STM32F746 Discovery board. You'll learn how to build the firmware, flash it to the board, and initialize the display and touch screen.
Get MicroPython#
The fork of the original MicroPython repository with LVGL is available at https://github.com/lvgl/lv_micropython.
Simply clone it with git:
git clone --recurse-submodules https://github.com/micropython/micropython.gitshThese libraries also need to be installed:
sudo apt-get install build-essential libreadline-dev libffi-dev git pkg-config pythonshBuild for STM32F746 Discovery#
Prepare MicroPython for cross-compiling:
cd lv_micropython
make -C mpy-crossshBuild the STM32 port and flash the board:
cd ports/stm32
make -j8 BOARD=STM32F7DISC MICROPY_PY_LVGL=1 deploy-stlinkshWhen flashed, reset the board and connect to the board's serial port. Here picocom is used but other applications work as well.
picocom /dev/ttyACM0 -b 115200shInitialize the Display and Touch Screen#
When the terminal is active, test if MicroPython is really running. For example, type 3 + 4 and it should print the result.
If all is good, copy this line by line:
import lvgl as lv
lv.init()
import lvstm32 as st
st.lvstm32()
import rk043fn48h as rk
rk.init()
disp_buf1 = lv.disp_buf_t()
buf1_1 = bytes(480 * 80)
disp_buf1.init(buf1_1, None, len(buf1_1) // 4)
disp_drv = lv.disp_drv_t()
disp_drv.init()
disp_drv.buffer = disp_buf1
disp_drv.flush_cb = rk.flush
disp_drv.hor_res = 480
disp_drv.ver_res = 272
disp_drv.register()
indev_drv = lv.indev_drv_t()
indev_drv.init()
indev_drv.type = lv.INDEV_TYPE.POINTER
indev_drv.read_cb = rk.ts_read
indev_drv.register()pythonTest LVGL#
Just create a button to see the display and touch is working:
btn1 = lv.btn.create(lv.scr_act())python