diff --git a/samples/net/openthread/ncp/CMakeLists.txt b/samples/net/openthread/ncp/CMakeLists.txt new file mode 100644 index 00000000000..b180cf43ff7 --- /dev/null +++ b/samples/net/openthread/ncp/CMakeLists.txt @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(ncp) + +target_sources( app + PRIVATE + src/main.c +) + +include($ENV{ZEPHYR_BASE}/samples/net/common/common.cmake) + +set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/) diff --git a/samples/net/openthread/ncp/Kconfig b/samples/net/openthread/ncp/Kconfig new file mode 100644 index 00000000000..72be8f20ea3 --- /dev/null +++ b/samples/net/openthread/ncp/Kconfig @@ -0,0 +1,16 @@ +# Config options for OpenThread Border Router sample app + +# Copyright (c) 2020 Tridonic GmbH & Co KG +# SPDX-License-Identifier: Apache-2.0 + +mainmenu "OpenThread NCP" + +menu "Application configuration" + +config NET_SAMPLE_APPLICATION_VERSION + string "Version number for the application" + default "v0.0.0" + +endmenu + +source "Kconfig.zephyr" diff --git a/samples/net/openthread/ncp/README.rst b/samples/net/openthread/ncp/README.rst new file mode 100644 index 00000000000..15a4b142935 --- /dev/null +++ b/samples/net/openthread/ncp/README.rst @@ -0,0 +1,41 @@ +.. _ncp-sample: + +OpenThread NCP +############## + +Overview +******** + +OpenThread NCP allows building a Thread Border Router. The code in this +sample is only the MCU target part of a complete Thread Border Router. +The Linux tools from https://openthread.io/guides/border-router +(especially wpantund and wpanctl) are required to get a complete Thread +Border Router. + +The source code for this sample application can be found at: +:zephyr_file:`samples/net/openthread/ncp`. + +Building and Running +******************** + +Build the OpenThread NCP sample application like this: + +.. zephyr-app-commands:: + :zephyr-app: samples/net/openthread/ncp + :board: + :conf: + :goals: build + :compact: + +There are configuration files for different boards and setups in the +ncp directory: + +- :file:`prj.conf` + Generic config file, normally you should use this. + +- :file:`overlay-tri-n4m-br.conf` + This is an overlay for the dedicated Thread Border Router hardware + https://www.tridonic.com/com/en/products/net4more-borderROUTER-PoE-Thread.asp. + The board support is not part of the Zephyr repositories, but the + product is based on NXP K64 and AT86RF233. This file can be used as an + example for a development set-up based on development boards. diff --git a/samples/net/openthread/ncp/overlay-tri-n4m-br.conf b/samples/net/openthread/ncp/overlay-tri-n4m-br.conf new file mode 100644 index 00000000000..4d014343a1c --- /dev/null +++ b/samples/net/openthread/ncp/overlay-tri-n4m-br.conf @@ -0,0 +1,34 @@ +# TRI n4m BR +# Use UART_0 for Shell/Console +CONFIG_UART_SHELL_ON_DEV_NAME="UART_0" +CONFIG_UART_CONSOLE_ON_DEV_NAME="UART_0" +CONFIG_SHELL_PROMPT_UART="ncp-uart:~$ " + +# Use UART_1 for NCP +CONFIG_UART_MCUX_1=y +CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_DEV_NAME="UART_1" + +# Use USB-CDC-ACM for NCP +CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_ACM=y +CONFIG_OPENTHREAD_NCP_SPINEL_ON_UART_DEV_NAME="CDC_ACM_0" +CONFIG_STDOUT_CONSOLE=y +CONFIG_GPIO=y +CONFIG_USB=y +CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_PRODUCT="OT BorderRouter K64" +CONFIG_LOG=y +CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y +CONFIG_USB_CDC_ACM=y +CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_UART_LINE_CTRL=y +CONFIG_USB_REQUEST_BUFFER_SIZE=2048 + +# disable ethernet on K64 +CONFIG_NET_L2_ETHERNET=n +CONFIG_ETH_MCUX_0=n + +CONFIG_IEEE802154_RF2XX=y +CONFIG_NET_CONFIG_IEEE802154_DEV_NAME="RF2XX_0" +CONFIG_ISR_STACK_SIZE=4096 diff --git a/samples/net/openthread/ncp/prj.conf b/samples/net/openthread/ncp/prj.conf new file mode 100644 index 00000000000..6707cc00fd6 --- /dev/null +++ b/samples/net/openthread/ncp/prj.conf @@ -0,0 +1,95 @@ +# Generic networking options +CONFIG_NETWORKING=y +CONFIG_NET_UDP=y +CONFIG_NET_TCP=n +CONFIG_NET_IPV6=y +CONFIG_NET_IPV4=n + +CONFIG_NET_CONFIG_NEED_IPV6=y +CONFIG_NET_CONFIG_NEED_IPV4=n + +# disable certain parts of Zephyr IPv6 stack +CONFIG_NET_IPV6_NBR_CACHE=n +CONFIG_NET_IPV6_MLD=n + +# Kernel options +CONFIG_MAIN_STACK_SIZE=4096 +CONFIG_ENTROPY_GENERATOR=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_INIT_STACKS=y +#CONFIG_DEBUG_OPTIMIZATIONS=y + +# Logging +CONFIG_NET_LOG=y +CONFIG_LOG=y +CONFIG_NET_STATISTICS=y +CONFIG_PRINTK=y + +# Network buffers +CONFIG_NET_PKT_RX_COUNT=16 +CONFIG_NET_PKT_TX_COUNT=16 +CONFIG_NET_BUF_RX_COUNT=80 +CONFIG_NET_BUF_TX_COUNT=80 +CONFIG_NET_CONTEXT_NET_PKT_POOL=y + +# Thread by default registers quite a lot addresses. +CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=6 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=8 +CONFIG_NET_MAX_CONTEXTS=10 + +# OpenThread NCP needs to be able to reboot +CONFIG_REBOOT=y + +# Allow monitoring of stacks +# CONFIG_KERNEL_SHELL=y + +# make sure that Bluetooth is off +CONFIG_BT=n + +# OpenThread is using C++ +CONFIG_CPLUSPLUS=y + +# Other OpenThread dependencies +CONFIG_FLASH=y +CONFIG_FLASH_PAGE_LAYOUT=y +CONFIG_FLASH_MAP=y +CONFIG_MPU_ALLOW_FLASH_WRITE=y +CONFIG_NVS=y +CONFIG_SETTINGS=y + +# mbedTLS tweaks +CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=768 +CONFIG_MBEDTLS_HEAP_SIZE=8192 +# CONFIG_MBEDTLS_DEBUG=y +# CONFIG_MBEDTLS_DEBUG_LEVEL=4 + +# Enable OpenThread +CONFIG_NET_L2_OPENTHREAD=y + +# Configure OpenThread +CONFIG_OPENTHREAD_CHANNEL=26 +# Use PANID 0xffff to be able to commission +CONFIG_OPENTHREAD_PANID=65535 + +# Increase a few stack and other sizes for OpenThread +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 +CONFIG_NET_TX_STACK_SIZE=2048 +CONFIG_NET_RX_STACK_SIZE=5120 +CONFIG_SHELL_STACK_SIZE=3072 +CONFIG_OPENTHREAD_THREAD_STACK_SIZE=8192 +CONFIG_OPENTHREAD_PKT_LIST_SIZE=20 + +# Settings for the Border Router +# from https://openthread.io/guides/border-router/build#build-and-flash-ncp + +# CONFIG_OPENTHREAD_DHCP6_CLIENT is not set +CONFIG_OPENTHREAD_DHCP6_SERVER=y +CONFIG_OPENTHREAD_COMMISSIONER=y +CONFIG_OPENTHREAD_BORDER_AGENT=y +CONFIG_OPENTHREAD_BORDER_ROUTER=y +CONFIG_OPENTHREAD_UDP_FORWARD=y +CONFIG_OPENTHREAD_NCP=y +CONFIG_OPENTHREAD_ENABLE_SERVICE=y + +# OpenThread shell interferes with Zephyr shell +CONFIG_OPENTHREAD_SHELL=n diff --git a/samples/net/openthread/ncp/sample.yaml b/samples/net/openthread/ncp/sample.yaml new file mode 100644 index 00000000000..72a0a44c077 --- /dev/null +++ b/samples/net/openthread/ncp/sample.yaml @@ -0,0 +1,8 @@ +common: + harness: net + tags: net + depends_on: netif + min_flash: 140 +sample: + description: Runs the OpenThread stack as NCP BR + name: OpenThread Network Co-Processor diff --git a/samples/net/openthread/ncp/src/main.c b/samples/net/openthread/ncp/src/main.c new file mode 100644 index 00000000000..34436f619ec --- /dev/null +++ b/samples/net/openthread/ncp/src/main.c @@ -0,0 +1,19 @@ +/* main.c - OpenThread NCP */ + +/* + * Copyright (c) 2020 Tridonic GmbH & Co KG + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +LOG_MODULE_REGISTER(ot_br, LOG_LEVEL_DBG); + +#include + +#define APP_BANNER "***** OpenThread NCP on Zephyr %s *****" + +void main(void) +{ + LOG_INF(APP_BANNER, CONFIG_NET_SAMPLE_APPLICATION_VERSION); +}