Skip to content

Commit 936206f

Browse files
authored
Update Zephyr document, add esp32c3 and particle_argon support(#920)
Update the Zephyr document to provide more detailed instructions, and add info about espressif toolchain too. Add ESP32C3 (RISC-V) and Particle Argon boards support to the zephyr platform sample. More boards are possible, but the script doesn't scale well and is to be improved in future. Add Dockerfile to kickstart a Zephyr development environment as it can be rather confusing for new users.
1 parent 98bacfe commit 936206f

File tree

4 files changed

+103
-10
lines changed

4 files changed

+103
-10
lines changed

doc/build_wamr.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,25 @@ WAMR provides some features which can be easily configured by passing options to
306306
307307
Zephyr
308308
-------------------------
309-
You need to download the Zephyr source code first and embed WAMR into it.
309+
You need to prepare Zephyr first as described here https://docs.zephyrproject.org/latest/getting_started/index.html#get-zephyr-and-install-python-dependencies).
310+
311+
After that you need to point the `ZEPHYR_BASE` variable to e.g. `~/zephyrproject/zephyr`. Also, it is important that you have `west` available for subsequent actions.
312+
310313
``` Bash
311-
git clone https://github.com/zephyrproject-rtos/zephyr.git
312-
source zephyr/zephyr-env.sh
313314
cd <wamr_root_dir>/product-mini/platforms/zephyr/simple
314315
# Execute the ./build_and_run.sh script with board name as parameter. Here take x86 as example:
315316
./build_and_run.sh x86
317+
```
316318
319+
If you want to use the Espressif toolchain (esp32 or esp32c3), you can most conveniently install it with `west`:
320+
321+
``` Bash
322+
cd $ZEPHYR_BASE
323+
west espressif install
317324
```
318325
326+
After that set `ESPRESSIF_TOOLCHAIN_PATH` according to the output, for example `~/.espressif/tools/zephyr`.
327+
319328
Note:
320329
WAMR provides some features which can be easily configured by passing options to cmake, please see [WAMR vmcore cmake building configurations](./build_wamr.md#wamr-vmcore-cmake-building-configurations) for details. Currently in Zephyr, interpreter, AoT and builtin libc are enabled by default.
321330
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM ubuntu:20.04
2+
3+
ARG DOCKER_UID=1000
4+
5+
ENV DEBIAN_FRONTEND noninteractive
6+
7+
RUN apt-get -qq update && apt-get -qq dist-upgrade && apt install -qq -y python3-pip git wget ninja-build
8+
9+
WORKDIR /tmp
10+
11+
RUN mkdir /opt/cmake && wget -q https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1-linux-x86_64.sh && sh cmake-3.22.1-linux-x86_64.sh --skip-license --prefix=/opt/cmake && rm cmake-3.22.1-linux-x86_64.sh
12+
13+
ENV PATH="/opt/cmake/bin:$PATH"
14+
15+
RUN useradd -m wamr -u ${DOCKER_UID} -G dialout
16+
17+
USER wamr
18+
19+
ENV PATH="/home/wamr/.local/bin:$PATH"
20+
21+
RUN pip3 install --user west
22+
23+
RUN west init ~/zephyrproject && cd ~/zephyrproject && west update && west zephyr-export
24+
25+
RUN pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt
26+
27+
WORKDIR /home/wamr/zephyrproject
28+
29+
RUN west espressif install
30+
31+
ENV ZEPHYR_BASE=/home/wamr/zephyrproject/zephyr
32+
ENV ESPRESSIF_TOOLCHAIN_PATH=/home/wamr/.espressif/tools/zephyr
33+
34+
WORKDIR /home/wamr/source/product-mini/platforms/zephyr/simple
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Build with Docker
2+
3+
To have a quicker start, a Docker container of the Zephyr setup can be generated.
4+
5+
## Build Docker container
6+
7+
``` Bash
8+
docker build --build-arg DOCKER_UID=$(id -u) . -t wamr-zephyr
9+
```
10+
11+
## Run Docker container to build images
12+
13+
Enter the docker container (maps the toplevel wasm-micro-runtime repo as volume):
14+
15+
``` Bash
16+
docker run -ti -v $PWD/../../../..:/home/wamr/source --device=/dev/ttyUSB0 wamr-zephyr
17+
```
18+
19+
Adopt the device or remove if not needed.
20+
21+
And then in the docker container:
22+
23+
``` Bash
24+
./build_and_run.sh esp32c3
25+
```

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
X86_TARGET="x86"
77
STM32_TARGET="stm32"
88
ESP32_TARGET="esp32"
9+
ESP32C3_TARGET="esp32c3"
10+
PARTICLE_ARGON_TARGET="particle_argon"
911
QEMU_CORTEX_A53="qemu_cortex_a53"
1012
QEMU_XTENSA_TARGET="qemu_xtensa"
1113
QEMU_RISCV64_TARGET="qemu_riscv64"
@@ -15,11 +17,13 @@ QEMU_ARC_TARGET="qemu_arc"
1517
usage ()
1618
{
1719
echo "USAGE:"
18-
echo "$0 $X86_TARGET|$STM32_TARGET|$ESP32_TARGET|$QEMU_CORTEX_A53|$QEMU_XTENSA_TARGET|$QEMU_RISCV64_TARGET|$QEMU_RISCV32_TARGET|$QEMU_ARC_TARGET"
20+
echo "$0 $X86_TARGET|$STM32_TARGET|$ESP32_TARGET|$ESP32C3_TARGET|$PARTICLE_ARGON_TARGET|$QEMU_CORTEX_A53|$QEMU_XTENSA_TARGET|$QEMU_RISCV64_TARGET|$QEMU_RISCV32_TARGET|$QEMU_ARC_TARGET"
1921
echo "Example:"
2022
echo " $0 $X86_TARGET"
2123
echo " $0 $STM32_TARGET"
2224
echo " $0 $ESP32_TARGET"
25+
echo " $0 $ESP32C3_TARGET"
26+
echo " $0 $PARTICLE_ARGON_TARGET"
2327
echo " $0 $QEMU_CORTEX_A53"
2428
echo " $0 $QEMU_XTENSA_TARGET"
2529
echo " $0 $QEMU_RISCV64_TARGET"
@@ -47,14 +51,35 @@ case $TARGET in
4751
west flash
4852
;;
4953
$ESP32_TARGET)
50-
# suppose you have set environment variable ESP_IDF_PATH
54+
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
55+
if [[ -z "${ESPRESSIF_TOOLCHAIN_PATH}" ]]; then
56+
echo "Set ESPRESSIF_TOOLCHAIN_PATH to your espressif toolchain"
57+
exit 1
58+
fi
5159
west build -b esp32 \
5260
. -p always -- \
53-
-DESP_IDF_PATH=$ESP_IDF_PATH \
54-
-DWAMR_BUILD_TARGET=XTENSA
55-
# suppose the serial port is /dev/ttyUSB1 and you should change to
56-
# the real name accordingly
57-
west flash --esp-device /dev/ttyUSB1
61+
-DWAMR_BUILD_TARGET=XTENSA
62+
# west flash will discover the device
63+
west flash
64+
;;
65+
$ESP32C3_TARGET)
66+
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
67+
if [[ -z "${ESPRESSIF_TOOLCHAIN_PATH}" ]]; then
68+
echo "Set ESPRESSIF_TOOLCHAIN_PATH to your espressif toolchain"
69+
exit 1
70+
fi
71+
west build -b esp32c3_devkitm \
72+
. -p always -- \
73+
-DWAMR_BUILD_TARGET=RISCV32_ILP32
74+
# west flash will discover the device
75+
west flash
76+
;;
77+
$PARTICLE_ARGON_TARGET)
78+
west build -b particle_argon \
79+
. -p always -- \
80+
-DWAMR_BUILD_TARGET=THUMBV7
81+
# west flash will discover the device
82+
west flash
5883
;;
5984
$QEMU_XTENSA_TARGET)
6085
west build -b qemu_xtensa \

0 commit comments

Comments
 (0)