wasm-micro-runtime/samples/littlevgl
Stephen Berard df83aef101
Corrects Zephyr include files for current versions of Zephyr (#2881)
This fixes bug #2880.  Zephyr 3.2 made changes to how headers are reference (see [release notes](https://docs.zephyrproject.org/latest/releases/release-notes-3.2.html)).  Work item [49578](https://github.com/zephyrproject-rtos/zephyr/issues/49578) deprecated the old headers names.
The current WAMR codebase references these old headers, thus causing compile errors with
current versions of Zephyr.

This update adds #ifdefs around the header names.  With this change, compiling with Zephyr 3.2.0
and above will use the new header files.  Prior versions will use the existing code.
2023-12-08 17:16:16 +08:00
..
lv_config Enable AoT and wamr-sdk, and change arguments of call wasm API (#157) 2020-01-21 13:26:14 +08:00
vgl-native-ui-app Enhance cmake makefiles (#1390) 2022-08-18 16:27:01 +08:00
vgl-wasm-runtime Corrects Zephyr include files for current versions of Zephyr (#2881) 2023-12-08 17:16:16 +08:00
wasm-apps Apply clang format for samples files (#833) 2021-11-15 12:48:35 +08:00
build.sh Fix littlevgl link error issues (#1006) 2022-02-15 08:41:36 +08:00
LICENCE.txt Import app manager, samples and test-tools 2019-05-17 17:15:25 +08:00
README.md Enable mpu stack for latest zephyr to enable app manager (#673) 2021-07-27 12:22:22 +08:00
wamr_config_littlevgl.cmake littlevgl sample update (#235) 2020-04-22 11:02:55 +08:00

"littlevgl" sample introduction

This sample demonstrates that a graphic user interface application in WebAssembly by compiling the LittlevGL v5.3, an open-source embedded 2d graphic library into the WASM bytecode.

In this sample, the whole LittlevGL v5.3 source code is built into the WebAssembly code with the user application. The platform interfaces defined by LittlevGL is implemented in the runtime and registered for WASM application through calling wasm_runtime_full_init().

static NativeSymbol native_symbols[] = {
    EXPORT_WASM_API_WITH_SIG(display_input_read, "(*)i"),
    EXPORT_WASM_API_WITH_SIG(display_flush, "(iiii*)"),
    EXPORT_WASM_API_WITH_SIG(display_fill, "(iiii*)"),
    EXPORT_WASM_API_WITH_SIG(display_vdb_write, "(*iii*i)"),
    EXPORT_WASM_API_WITH_SIG(display_map, "(iiii*)"),
    EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i")
};

The runtime component supports building target for Linux and Zephyr/STM Nucleo board. The beauty of this sample is the WebAssembly application can have identical display and behavior when running from both runtime environments. That implies we can do majority of application validation from desktop environment as long as two runtime distributions support the same set of application interface.

Below pictures show the WASM application is running on an STM board with an LCD touch panel.

WAMR UI SAMPLE

WAMR UI SAMPLE

The number on top will plus one each second, and the number on the bottom will plus one when clicked. When users click the blue button, the WASM application increases the counter, and the latest counter value is displayed on the top banner of the touch panel.

The sample also provides the native Linux version of application without the runtime under folder "vgl-native-ui-app". It can help to check differences between the implementations in native and WebAssembly.

Test on Linux

Install required SDK and libraries

  • 32 bit SDL(simple directmedia layer) (Note: only necessary when WAMR_BUILD_TARGET is set to X86_32 when building WAMR runtime) Use apt-get:
    sudo apt-get install libsdl2-dev:i386
    

Or download source from www.libsdl.org:

./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32
make
sudo make install
  • 64 bit SDL(simple directmedia layer) (Note: only necessary when WAMR_BUILD_TARGET is set to X86_64 when building WAMR runtime) Use apt-get:
    sudo apt-get install libsdl2-dev
    

Or download source from www.libsdl.org:

./configure
make
sudo make install

Build and Run

  • Build

    ./build.sh
    

    All binaries are in "out", which contains "host_tool", "vgl_native_ui_app", "ui_app.wasm" "ui_app_no_wasi.wasm "and "vgl_wasm_runtime".

  • Run the native Linux build of the lvgl sample (no wasm)

    ./vgl_native_ui_app
    
  • Run WASM VM Linux applicaton & install WASM APP First start vgl_wasm_runtime in server mode.

    ./vgl_wasm_runtime -s
    

Then install and uninstall wasm APPs by using host tool.

./host_tool -i ui_wasi -f ui_app_wasi.wasm
./host_tool -q
./host_tool -u ui_wasi
./host_tool -i ui_no_wasi -f ui_app_builtin_libc.wasm
./host_tool -q
./host_tool -u ui_no_wasi

Test on Zephyr

We can use a STM32 NUCLEO_F767ZI board with ILI9341 display and XPT2046 touch screen to run the test. Then use host_tool to remotely install wasm app into STM32.

  • Build WASM VM into Zephyr system a. clone zephyr source code Refer to Zephyr getting started.

    west init zephyrproject
    cd zephyrproject/zephyr
    git checkout zephyr-v2.3.0
    cd ..
    west update
    

    b. copy samples

    cd zephyr/samples/
    cp -a <wamr_root>/samples/littlevgl/vgl-wasm-runtime vgl-wasm-runtime
    cd vgl-wasm-runtime/zephyr_build
    

    c. create a link to wamr root dir

    ln -s <wamr_root> wamr
    

d. build source code Since ui_app incorporated LittlevGL source code, so it needs more RAM on the device to install the application. It is recommended that RAM SIZE not less than 380KB. In our test use nucleo_f767zi, which is supported by Zephyr. Since the littlevgl wasm app is quite big (~100KB in wasm format and ~200KB in AOT format ), there isn't enough SRAM to build interpreter and AOT together. You can only choose one of them:

  • Interpreter
mkdir build && cd build
source ../../../../zephyr-env.sh
cmake -GNinja -DBOARD=nucleo_f767zi -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_AOT=0 ..
ninja flash
  • AOT
mkdir build && cd build
source ../../../../zephyr-env.sh
cmake -GNinja -DBOARD=nucleo_f767zi -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_AOT=1 ..
ninja flash
  • Hardware Connections
+-------------------+-+------------------+
|NUCLEO-F767ZI       | ILI9341  Display  |
+-------------------+-+------------------+
| CN7.10             |         CLK       |
+-------------------+-+------------------+
| CN7.12             |         MISO      |
+-------------------+-+------------------+
| CN7.14             |         MOSI      |
+-------------------+-+------------------+
| CN11.1             | CS1 for ILI9341   |
+-------------------+-+------------------+
| CN11.2             |         D/C       |
+-------------------+-+------------------+
| CN11.3             |         RESET     |
+-------------------+-+------------------+
| CN9.25             |    PEN interrupt  |
+-------------------+-+------------------+
| CN9.27             |  CS2 for XPT2046  |
+-------------------+-+------------------+
| CN10.14            |    PC UART RX     |
+-------------------+-+------------------+
| CN11.16            |    PC UART RX     |
+-------------------+-+------------------+
  • Install WASM application to Zephyr using host_tool First, connect PC and STM32 with UART. Then install to use host_tool.
    sudo ./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app_builtin_libc.wasm
    # /dev/ttyUSBXXX is the UART device, e.g. /dev/ttyUSB0
    

Note: WASI is unavailable on zephyr currently, so you have to use the ui_app_builtin_libc.wasm which doesn't depend on WASI.

  • Install AOT version WASM application
    wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app_no_wasi.aot ui_app_builtin_libc.wasm
    ./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app_no_wasi.aot