Skip to content

Commit

Permalink
WAMR in Zephyr
Browse files Browse the repository at this point in the history
  • Loading branch information
oubotong committed Sep 9, 2020
0 parents commit fa983a4
Show file tree
Hide file tree
Showing 699 changed files with 124,796 additions and 0 deletions.
52 changes: 52 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.8.2)

#set(CMAKE_C_COMPILER "/home/dafran/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-gcc")
#set(CMAKE_CXX_COMPILER "/home/dafran/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-g++")
#find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

enable_language (ASM)

set (WAMR_BUILD_PLATFORM "zephyr")

# Build as X86_32 by default, change to "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS" or "XTENSA"
# if we want to support arm, thumb, mips or xtensa
if (NOT DEFINED WAMR_BUILD_TARGET)
set (WAMR_BUILD_TARGET "X86_32")
endif ()

if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()

if (NOT DEFINED WAMR_BUILD_AOT)
# Enable AOT by default.
set (WAMR_BUILD_AOT 1)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
# Enable libc builtin support by default
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
# Disable libc wasi support by default
set (WAMR_BUILD_LIBC_WASI 0)
endif ()

set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wamr)

include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)

#add_executable (app src/main.c src/native_impl.c ${UNCOMMON_SHARED_SOURCE})
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE
${WAMR_RUNTIME_LIB_SOURCE}
${app_sources})
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/net/ip)

26 changes: 26 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2020, Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

config LOG
default y

config LOG_PRINTK
default y

config SENSOR_LOG_LEVEL
default 4

# Workaround for not being able to have commas in macro arguments
DT_COMPAT_BOSCH_BME280 := bosch,bme280

# Enable SPI support by default if there are any BME280 sensors
# on a SPI bus.
config SPI
default $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BME280),spi)

# Enable I2C support by default if there are any BME280 sensors
# on an I2C bus.
config I2C
default $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BME280),i2c)

source "Kconfig.zephyr"
43 changes: 43 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.. _bme280:

BME280 Humidity and Pressure Sensor
###################################

Overview
********

This sample application periodically reads temperature, pressure and humidity data from
the first available device that implements SENSOR_CHAN_AMBIENT_TEMP, SENSOR_CHAN_PRESS,
and SENSOR_CHAN_HUMIDITY. This sample checks the sensor in polling mode (without
interrupt trigger).

Building and Running
********************

This sample application uses an BME280 sensor connected to a board via I2C.
Connect the sensor pins according to the connection diagram given in the `bme280 datasheet`_
at page 38.


.. zephyr-app-commands::
:zephyr-app: samples/sensor/bme280
:board: nrf52840dk_nrf52840
:goals: flash
:compact:

Sample Output
=============
To check output of this sample , any serial console program can be used.
This example uses ``picocom`` on the serial port ``/dev/ttyACM0``:

.. code-block:: console
$ sudo picocom -D /dev/ttyUSB0
.. code-block:: console
temp: 27.950000; press: 100.571027; humidity: 61.014648
temp: 27.940000; press: 100.570269; humidity: 61.012695
temp: 27.950000; press: 100.570695; humidity: 61.002929
.. _bme280 datasheet: https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280-DS002.pdf
13 changes: 13 additions & 0 deletions boards/nrf52840dk_nrf52840.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2020, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

&i2c0 {
bme280@76 {
compatible = "bosch,bme280";
reg = <0x76>;
label = "BME280";
};
};
86 changes: 86 additions & 0 deletions build_and_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

X86_TARGET="x86"
STM32_TARGET="stm32"
QEMU_CORTEX_A53="qemu_cortex_a53"
XTENSA_QEMU_TARGET="xtensa-qemu"
ESP32_TARGET="esp32"
NRF52840_DK="nrf52840dk_nrf52840"

usage ()
{
echo "USAGE:"
echo "$0 $X86_TARGET|$STM32_TARGET|$QEMU_CORTEX_A53|$XTENSA_QEMU_TARGET|$ESP32_TARGET|$NRF52840_DK"
echo "Example:"
echo " $0 $X86_TARGET"
echo " $0 $STM32_TARGET"
echo " $0 $QEMU_CORTEX_A53"
echo " $0 $XTENSA_QEMU_TARGET"
echo " $0 $ESP32_TARGET"
echo " $0 $NRF52840_DK"
exit 1
}

if [ $# != 1 ] ; then
usage
fi

TARGET=$1

case $TARGET in
$X86_TARGET)
west build -b qemu_x86_nommu \
. -p always -- \
-DCONF_FILE=prj_qemu_x86_nommu.conf \
-DWAMR_BUILD_TARGET=X86_32
west build -t run
;;
$STM32_TARGET)
west build -b nucleo_f767zi \
. -p always -- \
-DCONF_FILE=prj_nucleo767zi.conf \
-DWAMR_BUILD_TARGET=THUMBV7
west flash
;;
$XTENSA_QEMU_TARGET)
west build -b qemu_xtensa \
. -p always -- \
-DCONF_FILE=prj_qemu_xtensa.conf \
-DWAMR_BUILD_TARGET=XTENSA
west build -t run
;;
$ESP32_TARGET)
# suppose you have set environment variable ESP_IDF_PATH
west build -b esp32 \
. -p always -- \
-DESP_IDF_PATH=$ESP_IDF_PATH \
-DCONF_FILE=prj_esp32.conf \
-DWAMR_BUILD_TARGET=XTENSA
# suppose the serial port is /dev/ttyUSB1 and you should change to
# the real name accordingly
west flash --esp-device /dev/ttyUSB1
;;
$QEMU_CORTEX_A53)
west build -b qemu_cortex_a53 \
. -p always -- \
-DCONF_FILE=prj_qemu_cortex_a53.conf \
-DWAMR_BUILD_TARGET=AARCH64
west build -t run
;;
$NRF52840_DK)
west build -b nrf52840dk_nrf52840 \
. -p always -- \
-DCONF_FILE=prf_nrf52840_dk.conf \
-DWAMR_BUILD_TARGET=ARM
west build -t run
;;
*)
echo "unsupported target: $TARGET"
usage
exit 1
;;
esac

Loading

0 comments on commit fa983a4

Please sign in to comment.