f8f61dc898
* Implement memory profiler, optimize memory usage, modify code indent * Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default * Add a new extension library: connection * Fix bug of reading magic number and version in big endian platform * Re-org platform APIs: move most platform APIs from iwasm to shared-lib * Enhance wasm loader to fix some security issues * Fix issue about illegal load of EXC_RETURN into PC on stm32 board * Updates that let a restricted version of the interpreter run in SGX * Enable native/app address validation and conversion for wasm app * Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused * Refine binary size and fix several minor issues Optimize interpreter LOAD/STORE opcodes to decrease the binary size Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper Add macros of global heap size, stack size, heap size for Zephyr main.c Clear compile warning of wasm_application.c * Add more strict security checks for libc wrapper API's * Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files * Enhance security of libc strcpy/sprintf wrapper function * Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions * Remove get_module_inst() and fix issue of call native * Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate * Refine interpreter call native process, refine memory boudary check * Fix issues of invokeNative function of arm/mips/general version * Add a switch to build simple sample without gui support |
||
---|---|---|
.. | ||
lvgl-native-ui-app | ||
wasm-apps | ||
wasm-runtime-wgl | ||
build.sh | ||
README.md |
Introduction
This sample demonstrates that a graphic user interface application in WebAssembly programming with WAMR graphic library(WGL) extension. WGL defined a WASM application API set for programming the UI applications.
WGL implemention is based on LittlevGL, an open-source embedded 2d graphic library. Comparing the building the LittlevGL into WASM bytecode in the littlevgl sample, WGL compiled LittlevGL source code into the WAMR runtime and defined a wrapper API for exporting to Webassembly application. These extension API's are listed in: <wamr_root>/core/iwasm/lib/app-libs/extension/gui/wgl.h
. Currently only a small set of API's are provided and that would be extended in future.
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. 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 number on top will plus one each second, and the number on the bottom will plus one when clicked.
Configure 32 bit or 64 bit build
On 64 bit operating system, there is an option to build 32 bit or 64 bit binaries. In file ./lvgl-native-ui-app/CMakeLists.txt
and/or ./wasm-runtime-wgl/linux-build/CMakeLists.txt
, modify the line:
set (BUILD_AS_64BIT_SUPPORT "YES")
where YES
means 64 bit build while NO
means 32 bit build.
Install required SDK and libraries
- 32 bit SDL(simple directmedia layer) (Note: only necessary when
BUILD_AS_64BIT_SUPPORT
is set toNO
) 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
BUILD_AS_64BIT_SUPPORT
is set toYES
) Use apt-get:sudo apt-get install libsdl2-dev
Or download source from www.libsdl.org:
./configure
make
sudo make install
- Install EMSDK
https://emscripten.org/docs/tools_reference/emsdk.html
Build and Run
Linux
-
Build
./build.sh
All binaries are in "out", which contains "host_tool", "lvgl_native_ui_app", "ui_app.wasm", "ui_app_lvgl_compatible.wasm" and "wasm_runtime_wgl". -
Run native Linux application
./lvgl_native_ui_app
-
Run WASM VM Linux applicaton & install WASM APP
First start wasm_runtime_wgl in server mode.
./wasm_runtime_wgl -s
Then install wasm APP use host tool.
./host_tool -i ui_app -f ui_app.wasm
./host_tool -i ui_app -f ui_app_lvgl_compatible.wasm
Zephyr
WASM VM and native extension method can be built into Zephyr, Then we can install wasm app into STM32.
-
Build WASM VM into Zephyr system
a. clone zephyr source code
Refer to Zephyr getting started.
https://docs.zephyrproject.org/latest/getting_started/index.html
west init zephyrproject
cd zephyrproject
west update
b. copy samples
cd zephyr/samples/
cp -a <wamr_root>samples/gui/wasm-runtime-wgl wasm-runtime-wgl
cd wasm-runtime-wgl/zephyr_build
c. create a link to wamr core
ln -s <wamr_root>/core core
d. build source code
mkdir build && cd build
source ../../../../zephyr-env.sh
cmake -GNinja -DBOARD=nucleo_f746zg ..
ninja flash
-
Test on STM32 NUCLEO_F767ZI with ILI9341 Display with XPT2046 touch
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.
./host_tool -D /dev/ttyUSBXXX -i ui_app -f ui_app.wasm