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_indev on the RT-Thread lcd and touch devices;

  • Why such a project should configure LVGL with the native lv_conf.h instead 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

lv_conf.h mode

Source of settings

CONFIG_LV_* / LV_* macros generated by the platform Kconfig

lv_conf.h in the project

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.h carries the whole LVGL configuration. The build defines LV_CONF_INCLUDE_SIMPLE globally, so lv_conf_internal.h includes it directly;

  • lv_conf.h only includes rtconfig.h to read project switches such as EXAMPLE_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

LV_COLOR_FORMAT_DEFAULT

Default color format, RGB565 here; must match the LCD bits_per_pixel.

LV_USE_OS

LV_OS_NONE: the application thread drives LVGL, no second OSAL.

LV_USE_STDLIB_MALLOC

Use RT-Thread rt_malloc.

LV_USE_STDLIB_STRING/SPRINTF

CLIB, because this RT-Thread port does not provide rt_strcpy and friends.

LV_USE_SIFLI_EPIC

Enable the upstream SiFli EPIC renderer.

LV_DRAW_BUF_ALIGN

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”).

LV_USE_DEMO_BENCHMARK

Controlled by EXAMPLE_LVGL_BENCHMARK, together with the fonts and sysmon it needs.

project/proj.conf / Kconfig:

Option

Purpose

CONFIG_PKG_USING_LITTLEVGL2RTT

Must stay disabled; the SDK compiles no LVGL integration.

CONFIG_PKG_USING_LVGL

Consumed by the upstream SConscript to build the external sources.

CONFIG_PKG_LVGL_USING_DEMOS

Build upstream demos; required by the benchmark.

CONFIG_EXAMPLE_LVGL_BENCHMARK

Run the upstream benchmark; otherwise a label is shown.

CONFIG_LV_EXT_FB_TWO_PARTIAL

Use two partial draw buffers.

CONFIG_LV_EXT_FB_LINE_NUM

Lines per draw buffer.

CONFIG_BSP_USING_EPIC

Must stay disabled so the SDK EPIC driver and the upstream EPIC never own the hardware or interrupts at the same time.

CONFIG_BSP_USING_PM

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:

  1. VariantDir plus a DefineGroup wrapper relocate object files into build_<board>/lvgl/source/, keeping the LVGL checkout clean;

  2. the upstream LVGL-port group is skipped: that file is entirely under #ifdef __RTTHREAD__, the SDK does not define it, and this example drives lv_timer_handler() itself;

  3. demos/lv_demos.c is added explicitly, because the upstream RT-Thread script only walks the subdirectories of demos/ and misses it.

Display and Input

  • port/lv_port_disp.c: opens the lcd device, creates the lv_display with two 100-line partial buffers; the allocation is LV_ROUND_UP(PORT_BUF_SIZE, LV_DRAW_BUF_ALIGN) and the arrays are ALIGN(LV_DRAW_BUF_ALIGN), because lv_draw_buf_reshape() compares the shape against the aligned size – allocating exactly stride * lines makes the full-strip reshape fail. Each flush is sent with set_window + draw_rect_async, and lv_display_flush_ready() is called from the transfer-complete callback.

  • port/lv_port_indev.c: opens the touch device and registers it as an LV_INDEV_TYPE_POINTER input device.

  • src/main.c: lv_init() → register tick → initialize display/input → create the UI → loop over lv_timer_handler().

Troubleshooting

  • LVGL checkout not found: project/SConscript found no lvgl/SConscript beside the SDK checkout (up to three levels); set the LVGL_ROOT environment variable to the actual checkout.

  • rt_strcpy undefined: LV_STDLIB_RTTHREAD is used for string/sprintf, but this SDK’s RT-Thread does not provide that wrapper. Use LV_STDLIB_CLIB.

  • undefined reference to lv_demo_args_init: demos/lv_demos.c was not compiled; check adaptation 3 above.

  • Syntax error in an enum declaration: the upstream Kconfig was sourced into the configuration tree and rtconfig.h now contains macros named like LVGL identifiers. Configure LVGL with lv_conf.h instead.

  • Nothing is displayed: make sure BSP_USING_EPIC=n and the LCD/touch device names are lcd and touch.

  • The benchmark dies under PARTIAL: an EPIC assertion total_width >= width (bf0_hal_epic.c) or a software mem manage fault (lv_draw_sw_blend_color_to_rgb565): the draw buffer is allocated as exactly stride * lines without rounding to LV_DRAW_BUF_ALIGN. lv_draw_buf_reshape() sizes a shape as LV_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 while buf_area has moved to the strip: EPIC turns the stale stride into total_width and asserts, the software renderer computes its destination from buf_area and writes through NULL. Allocate PORT_BUF_ALLOC_SIZE = LV_ROUND_UP(PORT_BUF_SIZE, LV_DRAW_BUF_ALIGN) and declare the arrays ALIGN(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 with LV_USE_OS=LV_OS_NONE that interrupt never calls rt_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 (VECTACTIVE in SCB->ICSR) to avoid it; the proper fix is for the upstream EPIC backend to register its interrupt with the OS.

Reference