Milkv duo 交叉编译LVGL并运行

首先,感谢大佬们的教程,开始之前需要先点亮你的屏幕并搞定交叉编译环境

参考下面的教程设置好教程编译的工具链环境

参考下面的教程点亮你的spi屏幕

然后我们就可以开始了

克隆lvgl fb的模板工程

克隆项目并初始化子模块

git clone https://github.com/lvgl/lv_port_linux_frame_buffer.git
cd lv_port_linux_frame_buffer/
git submodule update --init --recursive

修改lv_conf.h,

//根据你的屏幕设置对应的色深,只支持标出来的这几种
/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH 16
//...省略中间部分,打开警告级别的日志输出,方便调试
/*Enable the log module*/
#define LV_USE_LOG 1
#if LV_USE_LOG

    /*How important log should be added:
    *LV_LOG_LEVEL_TRACE       A lot of logs to give detailed information
    *LV_LOG_LEVEL_INFO        Log important events
    *LV_LOG_LEVEL_WARN        Log if something unwanted happened but didn't cause a problem
    *LV_LOG_LEVEL_ERROR       Only critical issue, when the system may fail
    *LV_LOG_LEVEL_USER        Only logs added by the user
    *LV_LOG_LEVEL_NONE        Do not log anything*/
    #define LV_LOG_LEVEL LV_LOG_LEVEL_WARN

    /*1: Print the log with 'printf';
    *0: User need to register a callback with `lv_log_register_print_cb()`*/
    #define LV_LOG_PRINTF 1

    /*Enable/disable LV_LOG_TRACE in modules that produces a huge number of logs*/
    #define LV_LOG_TRACE_MEM        1
    #define LV_LOG_TRACE_TIMER      1
    #define LV_LOG_TRACE_INDEV      1
    #define LV_LOG_TRACE_DISP_REFR  1
    #define LV_LOG_TRACE_EVENT      1
    #define LV_LOG_TRACE_OBJ_CREATE 1
    #define LV_LOG_TRACE_LAYOUT     1
    #define LV_LOG_TRACE_ANIM       1

#endif  /*LV_USE_LOG*/
//...省略中间部分,下面打开一些帧数内存信息的覆盖显示
/*-------------
 * Others
 *-----------*/

/*1: Show CPU usage and FPS count*/
#define LV_USE_PERF_MONITOR 1
#if LV_USE_PERF_MONITOR
    #define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
#endif

/*1: Show the used memory and the memory fragmentation
 * Requires LV_MEM_CUSTOM = 0*/
#define LV_USE_MEM_MONITOR 1
#if LV_USE_MEM_MONITOR
    #define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
#endif
//...打开部分demo需要的字体
/*==================
 *   FONT USAGE
 *===================*/

/*Montserrat fonts with ASCII range and some symbols using bpp = 4
 *https://fonts.google.com/specimen/Montserrat*/
#define LV_FONT_MONTSERRAT_8  0
#define LV_FONT_MONTSERRAT_10 0
#define LV_FONT_MONTSERRAT_12 1
#define LV_FONT_MONTSERRAT_14 1
#define LV_FONT_MONTSERRAT_16 1
#define LV_FONT_MONTSERRAT_18 1
#define LV_FONT_MONTSERRAT_20 0
#define LV_FONT_MONTSERRAT_22 1
#define LV_FONT_MONTSERRAT_24 1
#define LV_FONT_MONTSERRAT_26 0
#define LV_FONT_MONTSERRAT_28 0
#define LV_FONT_MONTSERRAT_30 0
#define LV_FONT_MONTSERRAT_32 0
#define LV_FONT_MONTSERRAT_34 0
#define LV_FONT_MONTSERRAT_36 0
#define LV_FONT_MONTSERRAT_38 0
#define LV_FONT_MONTSERRAT_40 0
#define LV_FONT_MONTSERRAT_42 0
#define LV_FONT_MONTSERRAT_44 0
#define LV_FONT_MONTSERRAT_46 0
#define LV_FONT_MONTSERRAT_48 0
...benchmark所依赖的选项
/*Enables/disables support for compressed fonts.*/
#define LV_USE_FONT_COMPRESSED 1
//...打开你需要的demo
/*===================
 * DEMO USAGE
 ====================*/

/*Show some widget. It might be required to increase `LV_MEM_SIZE` */
#define LV_USE_DEMO_WIDGETS 1
#if LV_USE_DEMO_WIDGETS
#define LV_DEMO_WIDGETS_SLIDESHOW 0
#endif

/*Demonstrate the usage of encoder and keyboard*/
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0

/*Benchmark your system*/
#define LV_USE_DEMO_BENCHMARK 1
#if LV_USE_DEMO_BENCHMARK
/*Use RGB565A8 images with 16 bit color depth instead of ARGB8565*/
#define LV_DEMO_BENCHMARK_RGB565A8 0
#endif

/*Stress test for LVGL*/
#define LV_USE_DEMO_STRESS 1

/*Music player demo*/
#define LV_USE_DEMO_MUSIC 1
#if LV_USE_DEMO_MUSIC
    #define LV_DEMO_MUSIC_SQUARE    1
    #define LV_DEMO_MUSIC_LANDSCAPE 1
    #define LV_DEMO_MUSIC_ROUND     1
    #define LV_DEMO_MUSIC_LARGE     0
    #define LV_DEMO_MUSIC_AUTO_PLAY 1
#endif

修改最外层的Makefile

#指定编译器如果不适用脚本设置环境变量请在下面写死路径
CC = riscv64-unknown-linux-musl-gcc

#CC = /root/host-tools/gcc/riscv64-linux-musl-arm64/bin/riscv64-unknown-linux-musl-gcc
#添加编译选项
CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/ -march=rv64imafdcvxthead -mcpu=c906fdv -mcmodel=medany -mabi=lp64d -Wall -Wshadow#后面省略了只在前面做修改

修改main.c

#define DISP_BUF_SIZE (256 * 1024)

//...省略中间代码,根据自己的屏幕去设置分辨率
    disp_drv.hor_res    = 800;
    disp_drv.ver_res    = 480;

修改完后直接make进行编译,会在当前目录下生成一个名为demo的可执行文件
使用File查看一下信息,发现教程编译成功了,是riscv架构的可执行文件,才有动态库链接,库路径位于

/lib/ld-musl-riscv64xthead.so.1

root@rock-5b:/mnt/nvme/lv_port_linux_frame_buffer# file _demo
demo: ELF 64-bit LSB executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-riscv64xthead.so.1, with debug_info, not stripped

我们查看一下库文件夹,发现并没有这个动态库,但是有一个文件名类似的

[root@milkv]~# ls /lib/
ld-musl-riscv64v0p7_xthead.so.1  libstdc++.so.6.0.28
libatomic.so.1                   libstdc++.so.6.0.28-gdb.py
libatomic.so.1.2.0               libuuid.so.1
libblkid.so.1                    libuuid.so.1.3.0
libblkid.so.1.1.0                lp64d
libgcc_s.so.1                    udev
libstdc++.so.6

所以需要软连接一下,修改

milkv/overlay/mnt/system/rndis.sh

在文件开头添加下面两行代码,在启动的时候就帮我们软连接了

#!/bin/sh

date -s "2023-07-11 12:00:00"

ln -s /lib/ld-musl-riscv64v0p7_xthead.so.1 /lib/ld-musl-riscv64xthead.so.1

可以使用SCP将可执行文件上传到板子,也可以直接读卡器在linux挂载rootfs分区直接复制进root文件夹
使用下面的命令执行文件,因为没有输入设备可能会有一些输入设备的报错,可以直接在main.c里面将输入设备的初始化注释掉
./demo
lvgl即使将spi max clk修改为80M刷屏依然很卡,自身运行也很卡,不清楚是哪里遇到瓶颈了
显示效果还是挺不错的

3 Likes

大佬,很强,先马了。
请问有没有尝试过st7735s?
我现在还没驱动起来。

dts配置好了,开了config
设备中查找st7735的配置,dt节点也都有。
不过尝试花屏,提示内存不足,请问有没有遇到过这个问题?

image

cat random报error是正常的,这个应该是会花屏的