Skip to content

Commit be54b4c

Browse files
authored
Fix sample littlevgl/gui build issues on zephyr platform (#588)
Fix sample littlevgl/guil build issues on zephyr platform, modify code of zephyr platform by adding some macros to control some apis to fit different zephyr version, and align to zephyr-v2.3.0 for sample littlevgl/gui as the latest zephyr version (>=v2.4.0) requires that the thread stack for the thread to create must be defined by macro but not allocating stack memory dynamically. Signed-off-by: Wenyong Huang <[email protected]>
1 parent 02d27e1 commit be54b4c

File tree

9 files changed

+229
-133
lines changed

9 files changed

+229
-133
lines changed

core/shared/platform/zephyr/platform_internal.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
#include <autoconf.h>
1010
#include <zephyr.h>
1111
#include <kernel.h>
12+
#include <version.h>
13+
#if KERNEL_VERSION_NUMBER >= 0x020200 /* version 2.2.0 */
1214
#include <sys/printk.h>
15+
#else
16+
#include <misc/printk.h>
17+
#endif
1318
#include <inttypes.h>
1419
#include <stdarg.h>
1520
#include <ctype.h>
@@ -53,7 +58,13 @@ typedef struct korp_cond {
5358
os_thread_wait_list thread_wait_list;
5459
} korp_cond;
5560

56-
#define os_printf printf
61+
#ifndef Z_TIMEOUT_MS
62+
#define Z_TIMEOUT_MS(ms) ms
63+
#endif
64+
65+
void abort(void);
66+
size_t strspn(const char *s, const char *accept);
67+
size_t strcspn(const char *s, const char *reject);
5768

5869
/* math functions which are not provided by os */
5970
double sqrt(double x);

core/shared/platform/zephyr/zephyr_platform.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ char_out(int c, void *ctx)
101101
out_ctx->count++;
102102
return _stdout_hook_iwasm(c);
103103
}
104-
#endif
105104

106105
int
107106
os_vprintf(const char *fmt, va_list ap)
@@ -115,6 +114,59 @@ os_vprintf(const char *fmt, va_list ap)
115114
return 0;
116115
#endif
117116
}
117+
#endif
118+
119+
int
120+
os_printf(const char *format, ...)
121+
{
122+
int ret = 0;
123+
va_list ap;
124+
125+
va_start(ap, format);
126+
#ifndef BH_VPRINTF
127+
ret += vprintf(format, ap);
128+
#else
129+
ret += BH_VPRINTF(format, ap);
130+
#endif
131+
va_end(ap);
132+
133+
return ret;
134+
}
135+
136+
int
137+
os_vprintf(const char *format, va_list ap)
138+
{
139+
#ifndef BH_VPRINTF
140+
return vprintf(format, ap);
141+
#else
142+
return BH_VPRINTF(format, ap);
143+
#endif
144+
}
145+
146+
#if KERNEL_VERSION_NUMBER <= 0x020400 /* version 2.4.0 */
147+
void
148+
abort(void)
149+
{
150+
int i = 0;
151+
os_printf("%d\n", 1 / i);
152+
}
153+
#endif
154+
155+
#if KERNEL_VERSION_NUMBER <= 0x010E01 /* version 1.14.1 */
156+
size_t
157+
strspn(const char *s, const char *accept)
158+
{
159+
os_printf("## unimplemented function %s called", __FUNCTION__);
160+
return 0;
161+
}
162+
163+
size_t
164+
strcspn(const char *s, const char *reject)
165+
{
166+
os_printf("## unimplemented function %s called", __FUNCTION__);
167+
return 0;
168+
}
169+
#endif
118170

119171
void *
120172
os_mmap(void *hint, size_t size, int prot, int flags)

core/shared/platform/zephyr/zephyr_thread.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,12 @@ int os_mutex_lock(korp_mutex *mutex)
353353

354354
int os_mutex_unlock(korp_mutex *mutex)
355355
{
356+
#if KERNEL_VERSION_NUMBER >= 0x020200 /* version 2.2.0 */
356357
return k_mutex_unlock(mutex);
358+
#else
359+
k_mutex_unlock(mutex);
360+
return 0;
361+
#endif
357362
}
358363

359364
int os_cond_init(korp_cond *cond)

product-mini/platforms/zephyr/simple/build_and_run.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55

66
X86_TARGET="x86"
77
STM32_TARGET="stm32"
8-
QEMU_CORTEX_A53="qemu_cortex_a53"
9-
XTENSA_QEMU_TARGET="xtensa-qemu"
108
ESP32_TARGET="esp32"
9+
QEMU_CORTEX_A53="qemu_cortex_a53"
10+
QEMU_XTENSA_TARGET="qemu_xtensa"
1111
QEMU_RISCV64_TARGET="qemu_riscv64"
1212
QEMU_RISCV32_TARGET="qemu_riscv32"
1313

1414
usage ()
1515
{
1616
echo "USAGE:"
17-
echo "$0 $X86_TARGET|$STM32_TARGET|$QEMU_CORTEX_A53|$XTENSA_QEMU_TARGET|$ESP32_TARGET|$QEMU_RISCV64_TARGET|$QEMU_RISCV32_TARGET"
17+
echo "$0 $X86_TARGET|$STM32_TARGET|$ESP32_TARGET|$QEMU_CORTEX_A53|$QEMU_XTENSA_TARGET|$QEMU_RISCV64_TARGET|$QEMU_RISCV32_TARGET"
1818
echo "Example:"
1919
echo " $0 $X86_TARGET"
2020
echo " $0 $STM32_TARGET"
21-
echo " $0 $QEMU_CORTEX_A53"
22-
echo " $0 $XTENSA_QEMU_TARGET"
2321
echo " $0 $ESP32_TARGET"
22+
echo " $0 $QEMU_CORTEX_A53"
23+
echo " $0 $QEMU_XTENSA_TARGET"
2424
echo " $0 $QEMU_RISCV64_TARGET"
2525
echo " $0 $QEMU_RISCV32_TARGET"
2626
exit 1
@@ -47,13 +47,6 @@ case $TARGET in
4747
-DWAMR_BUILD_TARGET=THUMBV7
4848
west flash
4949
;;
50-
$XTENSA_QEMU_TARGET)
51-
west build -b qemu_xtensa \
52-
. -p always -- \
53-
-DCONF_FILE=prj_qemu_xtensa.conf \
54-
-DWAMR_BUILD_TARGET=XTENSA
55-
west build -t run
56-
;;
5750
$ESP32_TARGET)
5851
# suppose you have set environment variable ESP_IDF_PATH
5952
west build -b esp32 \
@@ -65,6 +58,13 @@ case $TARGET in
6558
# the real name accordingly
6659
west flash --esp-device /dev/ttyUSB1
6760
;;
61+
$QEMU_XTENSA_TARGET)
62+
west build -b qemu_xtensa \
63+
. -p always -- \
64+
-DCONF_FILE=prj_qemu_xtensa.conf \
65+
-DWAMR_BUILD_TARGET=XTENSA
66+
west build -t run
67+
;;
6868
$QEMU_CORTEX_A53)
6969
west build -b qemu_cortex_a53 \
7070
. -p always -- \

samples/gui/README.md

Lines changed: 72 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,96 @@
11
"gui" sample introduction
22
==============
3-
This sample demonstrates that a graphic user interface application in WebAssembly programming with WAMR graphic library(WGL) which is part of WAMR app-framework.
3+
This sample demonstrates that a graphic user interface application in WebAssembly programming with WAMR graphic library(WGL) which is part of WAMR app-framework.
44

55
Compared with the [littlevgl](../littlevgl) sample, WGL compiles LittlevGL source code into the WAMR runtime and defines a set of wrapper API's for exporting to Webassembly application.
66

7-
87
Below picture shows the WASM application is running on an STM board with an LCD touch panel.
98

10-
119
![WAMR UI SAMPLE](../../doc/pics/vgl_demo2.png "WAMR UI DEMO")
1210

13-
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.
11+
When user clicks 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.
1412

1513
# Test on Linux
1614

1715
Install required SDK and libraries
1816
--------------
1917
- 32 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_32` when building WAMR runtime)
2018
Use apt-get:
21-
`sudo apt-get install libsdl2-dev:i386`
19+
```bash
20+
sudo apt-get install libsdl2-dev:i386
21+
```
2222
Or download source from www.libsdl.org:
23-
```
24-
./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32
25-
make
26-
sudo make install
27-
```
23+
```bash
24+
./configure C_FLAGS=-m32 CXX_FLAGS=-m32 LD_FLAGS=-m32
25+
make
26+
sudo make install
27+
```
2828
- 64 bit SDL(simple directmedia layer) (Note: only necessary when `WAMR_BUILD_TARGET` is set to `X86_64` when building WAMR runtime)
2929
Use apt-get:
30-
`sudo apt-get install libsdl2-dev`
31-
Or download source from www.libsdl.org:
32-
```
33-
./configure
34-
make
35-
sudo make install
36-
```
30+
31+
```bash
32+
sudo apt-get install libsdl2-dev
33+
```
34+
Or download source from www.libsdl.org:
35+
```bash
36+
./configure
37+
make
38+
sudo make install
39+
```
3740

3841
Build and Run
3942
--------------
4043

41-
- Build</br>
42-
`./build.sh`</br>
44+
- Build
45+
```bash
46+
./build.sh
47+
```
4348
All binaries are in "out", which contains "host_tool", "ui_decrease.wasm", "ui_increase.wasm" and "wasm_runtime_wgl".
4449

45-
- Run WASM VM Linux applicaton & install WASM APP</br>
46-
First start wasm_runtime_wgl in server mode.</br>
47-
`./wasm_runtime_wgl -s`</br>
48-
Then install wasm APP use host tool.</br>
49-
`./host_tool -i inc -f ui_increase.wasm`</br>
50-
`./host_tool -i dec -f ui_decrease.wasm`</br>
51-
52-
50+
- Run WASM VM Linux applicaton & install WASM APP
51+
First start wasm_runtime_wgl in server mode.
52+
```bash
53+
./wasm_runtime_wgl -s
54+
```
55+
Then install wasm APP by using host tool.
56+
```bash
57+
./host_tool -i inc -f ui_increase.wasm
58+
# or
59+
./host_tool -i dec -f ui_decrease.wasm
60+
```
5361

5462
Test on Zephyr
5563
================================
5664

5765
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.
58-
- Build WASM VM into Zephyr system</br>
59-
a. clone zephyr source code</br>
60-
Refer to Zephyr getting started.</br>
61-
https://docs.zephyrproject.org/latest/getting_started/index.html</br>
62-
`west init zephyrproject`</br>
63-
`cd zephyrproject`</br>
64-
`west update`</br>
65-
b. copy samples</br>
66-
`cd zephyr/samples/`</br>
67-
`cp -a <wamr_root>samples/gui/wasm-runtime-wgl wasm-runtime-wgl`</br>
68-
`cd wasm-runtime-wgl/zephyr_build`</br>
69-
c. create a link to wamr root dir</br>
70-
` ln -s <wamr_root> wamr`</br>
71-
d. build source code</br>
72-
`mkdir build && cd build`</br>
73-
`source ../../../../zephyr-env.sh`</br>
74-
`cmake -GNinja -DBOARD=nucleo_f767zi ..`</br>
75-
` ninja flash`</br>
66+
- Build WASM VM into Zephyr system
67+
a. clone zephyr source code
68+
Refer to [Zephyr getting started](https://docs.zephyrproject.org/latest/getting_started/index.html).
69+
70+
```bash
71+
west init zephyrproject
72+
cd zephyrproject/zephyr
73+
git checkout zephyr-v2.3.0
74+
cd ..
75+
west update
76+
```
77+
b. copy samples
78+
```bash
79+
cd zephyr/samples
80+
cp -a <wamr_root>samples/gui/wasm-runtime-wgl wasm-runtime-wgl
81+
cd wasm-runtime-wgl/zephyr_build
82+
```
83+
c. create a link to wamr root dir
84+
```bash
85+
ln -s <wamr_root> wamr
86+
```
87+
d. build source code
88+
```bash
89+
mkdir build && cd build
90+
source ../../../../zephyr-env.sh
91+
cmake -GNinja -DBOARD=nucleo_f767zi ..
92+
ninja flash
93+
```
7694

7795
- Hardware Connections
7896

@@ -102,16 +120,17 @@ https://docs.zephyrproject.org/latest/getting_started/index.html</br>
102120
+-------------------+-+------------------+
103121
```
104122

105-
106-
- Install WASM application to Zephyr using host_tool</br>
107-
First, connect PC and STM32 with UART. Then install to use host_tool.</br>
108-
`./host_tool -D /dev/ttyUSBXXX -i inc -f ui_increase.wasm`
123+
- Install WASM application to Zephyr using host_tool
124+
First, connect PC and STM32 with UART. Then install to use host_tool.
125+
```bash
126+
./host_tool -D /dev/ttyUSBXXX -i inc -f ui_increase.wasm
127+
```
109128

110129
- Install AOT version WASM application
111-
`wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app.aot ui_increase.wasm`
112-
`./host_tool -D /dev/ttyUSBXXX -i inc -f ui_app.aot`
113-
114-
130+
```bash
131+
wamrc --target=thumbv7 --target-abi=eabi --cpu=cortex-m7 -o ui_app.aot ui_increase.wasm
132+
./host_tool -D /dev/ttyUSBXXX -i inc -f ui_app.aot
133+
```
115134

116135
The graphic user interface demo photo:
117136

0 commit comments

Comments
 (0)