External LVGL Example
Source code path: example/multimedia/lvgl/lvgl_external
This example shows how to use an upstream LVGL checkout outside the SDK (lvgl/lvgl, already containing the upstream SiFli EPIC renderer). The project owns the build, the display/input port and the configuration. The SDK LVGL integration (PKG_USING_LITTLEVGL2RTT) stays disabled and is not compiled, so no SDK source or Python build script has to be changed for external mode.
What this example demonstrates:
How to build an upstream LVGL tree with the SiFli-SDK build system (source collection, object relocation);
How to register
lv_display/lv_indevon the RT-Threadlcdandtouchdevices;Why such a project should configure LVGL with the native
lv_conf.hinstead of SDK Kconfig-generated macros.
Usage
Initialize the toolchain first, as described in SiFli-SDK Getting Started.
Supported Boards
sf32lb58-lcd_a128r32n1_qspi: build, flash and on-hardware verified (CO5300 390x450, upstream EPIC + partial rendering, the label and the upstream benchmark both render).
sf32lb52-lcd_n16r8: build and link verified, not yet verified on hardware.
sf32lb52-lchspi-ulp: not re-verified yet.
Hardware Required
The board, an LCD with touch panel, and the download connection.
LVGL Checkout Location
The example targets the upstream LVGL release/v9.6 branch. That branch (checked out as v9.6.0-24-gd8a4e1dfb during testing) has been built, flashed and integration-tested with this example: both the label and the upstream benchmark render. Other branches/versions are not verified – upstream releases before 9.6 do not carry the SiFli EPIC renderer, and the 9.6 Kconfig collides with the SiFli configuration tool (see below), so switching versions means re-checking port/lv_conf.h.
The example refers to the upstream LVGL tree through LVGL_ROOT in project/SConscript. The checkout normally sits beside the SDK checkout; the script walks up from SIFLI_SDK for at most three levels, so both a normal checkout (<parent>/lvgl) and a git worktree one level deeper are found. Other layouts can name it with LVGL_ROOT in the environment:
LVGL_ROOT = find_lvgl_checkout(SIFLI_SDK) # or export LVGL_ROOT=...
The path only exists in the project repository; the SDK needs no “external LVGL path” configuration option.
Configure the Project
source "./export.sh"
cd "example/multimedia/lvgl/lvgl_external/project"
sdk.py menuconfig --board=sf32lb52-lcd_n16r8
menuconfig only configures the SDK and the project’s own switches. LVGL options are not there (see the next section).
Why lv_conf.h Instead of Kconfig-Generated Macros
LVGL supports two configuration modes:
Kconfig mode |
|
|
|---|---|---|
Source of settings |
|
|
Typical users |
Zephyr, NuttX, the SDK bundled LVGL |
upstream default |
Version coupling |
Kconfig tree must track the LVGL version |
config file is maintained with the source tree |
The SDK bundled lvgl_v9 uses Kconfig mode, but the upstream 9.6 Kconfig cannot be reused as-is. The SiFli Kconfig tool writes symbols into rtconfig.h without a CONFIG_ prefix, while the upstream 9.6 Kconfig contains many symbols whose names are also LVGL C identifiers:
# Upstream Kconfig (source of include/lvgl/config/lv_conf_kconfig.h)
choice LV_COLOR_FORMAT_DEFAULT
config LV_COLOR_FORMAT_RGB565
bool "RGB565"
/* LVGL header lv_color.h */
typedef enum {
LV_COLOR_FORMAT_RGB565 = 0x12,
...
} lv_color_format_t;
Sourcing that Kconfig would make rtconfig.h contain:
#define LV_COLOR_FORMAT_RGB565 1
rtconfig.h reaches every translation unit through rtthread.h, so the enum declaration becomes 1 = 0x12 and the build fails. LV_OS_NONE, LV_TXT_ENC_* and friends carry the same risk.
The bundled lvgl_v9 is unaffected because the Kconfig shipped with the SDK (9.2/9.4 era) uses LV_COLOR_DEPTH_16/24/32 and never defines LV_COLOR_FORMAT_*. The collision is new in upstream 9.6.
This example therefore uses LVGL’s native configuration mechanism:
port/lv_conf.hcarries the whole LVGL configuration. The build definesLV_CONF_INCLUDE_SIMPLEglobally, solv_conf_internal.hincludes it directly;lv_conf.honly includesrtconfig.hto read project switches such asEXAMPLE_LVGL_BENCHMARK. The configuration tree contains no LVGL symbols, so no same-name macros appear;Rule: inside
lv_conf.h, reference LVGL identifiers but never define a macro with the same name as an LVGL identifier. This is safe:
#define LV_COLOR_FORMAT_DEFAULT LV_COLOR_FORMAT_RGB565
LV_COLOR_FORMAT_RGB565 only appears in the replacement text and expands to the enum value where LV_COLOR_FORMAT_DEFAULT is used.
Key Configuration Items
port/lv_conf.h:
Option |
Purpose |
|---|---|
|
Default color format, RGB565 here; must match the LCD |
|
|
|
Use RT-Thread |
|
CLIB, because this RT-Thread port does not provide |
|
Enable the upstream SiFli EPIC renderer. |
|
Draw buffer alignment: both the buffer’s start address and its allocation size follow it, matching the LCD/EPIC DMA path (see “Display and Input”). |
|
Controlled by |
project/proj.conf / Kconfig:
Option |
Purpose |
|---|---|
|
Must stay disabled; the SDK compiles no LVGL integration. |
|
Consumed by the upstream SConscript to build the external sources. |
|
Build upstream demos; required by the benchmark. |
|
Run the upstream benchmark; otherwise a label is shown. |
|
Use two partial draw buffers. |
|
Lines per draw buffer. |
|
Must stay disabled so the SDK EPIC driver and the upstream EPIC never own the hardware or interrupts at the same time. |
|
Disabled in this example; the upstream EPIC does not participate in SDK suspend/resume coordination yet. |
Example Output
The console reports the external LVGL version and the screen runs the upstream benchmark:
LVGL 9.6.0
With CONFIG_EXAMPLE_LVGL_BENCHMARK disabled, the screen shows the LVGL external source example label.
Example Breakdown
Build
project/SConscript invokes the upstream root SConscript (which forwards to env_support/rt-thread/SConscript) to collect lvgl/src/**/*.c, with three project-side adaptations:
VariantDirplus aDefineGroupwrapper relocate object files intobuild_<board>/lvgl/source/, keeping the LVGL checkout clean;the upstream
LVGL-portgroup is skipped: that file is entirely under#ifdef __RTTHREAD__, the SDK does not define it, and this example driveslv_timer_handler()itself;demos/lv_demos.cis added explicitly, because the upstream RT-Thread script only walks the subdirectories ofdemos/and misses it.
Display and Input
port/lv_port_disp.c: opens thelcddevice, creates thelv_displaywith two 100-line partial buffers; the allocation isLV_ROUND_UP(PORT_BUF_SIZE, LV_DRAW_BUF_ALIGN)and the arrays areALIGN(LV_DRAW_BUF_ALIGN), becauselv_draw_buf_reshape()compares the shape against the aligned size – allocating exactlystride * linesmakes the full-strip reshape fail. Each flush is sent withset_window+draw_rect_async, andlv_display_flush_ready()is called from the transfer-complete callback.port/lv_port_indev.c: opens thetouchdevice and registers it as anLV_INDEV_TYPE_POINTERinput device.src/main.c:lv_init()→ register tick → initialize display/input → create the UI → loop overlv_timer_handler().
Troubleshooting
LVGL checkout not found:project/SConscriptfound nolvgl/SConscriptbeside the SDK checkout (up to three levels); set theLVGL_ROOTenvironment variable to the actual checkout.rt_strcpyundefined:LV_STDLIB_RTTHREADis used for string/sprintf, but this SDK’s RT-Thread does not provide that wrapper. UseLV_STDLIB_CLIB.undefined reference to lv_demo_args_init:demos/lv_demos.cwas not compiled; check adaptation 3 above.Syntax error in an enum declaration: the upstream Kconfig was sourced into the configuration tree and
rtconfig.hnow contains macros named like LVGL identifiers. Configure LVGL withlv_conf.hinstead.Nothing is displayed: make sure
BSP_USING_EPIC=nand the LCD/touch device names arelcdandtouch.The benchmark dies under PARTIAL: an EPIC assertion
total_width >= width(bf0_hal_epic.c) or a softwaremem manage fault(lv_draw_sw_blend_color_to_rgb565): the draw buffer is allocated as exactlystride * lineswithout rounding toLV_DRAW_BUF_ALIGN.lv_draw_buf_reshape()sizes a shape asLV_ROUND_UP(stride * h, LV_DRAW_BUF_ALIGN), so the full-strip reshape fails on a slightly-too-small buffer and the header keeps the previous, smaller area whilebuf_areahas moved to the strip: EPIC turns the stale stride intototal_widthand asserts, the software renderer computes its destination frombuf_areaand writes through NULL. AllocatePORT_BUF_ALLOC_SIZE = LV_ROUND_UP(PORT_BUF_SIZE, LV_DRAW_BUF_ALIGN)and declare the arraysALIGN(LV_DRAW_BUF_ALIGN). FULL/DIRECT mode does not expose it, because the initial header is already the whole screen.Assertion failed at function:output_lock/fatal error on thread: main: the upstream EPIC backend logs at WARN from its completion interrupt, and withLV_USE_OS=LV_OS_NONEthat interrupt never callsrt_interrupt_enter(). ulog therefore treats the log as thread context and takes its mutex recursively on top of the render thread’s log. The example drops LVGL logs from exception context (VECTACTIVEinSCB->ICSR) to avoid it; the proper fix is for the upstream EPIC backend to register its interrupt with the OS.
Reference
Bundled-version example: …/lvgl_v9_demos