From 8e56ecc656bececa908013d840e2f742469182c2 Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Fri, 9 Jul 2021 12:18:41 +0800 Subject: [PATCH] openthread: enable ot_cli on esp32h2 --- components/esp32h2/ld/esp32h2.peripherals.ld | 1 + components/esp_phy/lib | 2 +- components/ieee802154/lib | 2 +- components/openthread/CMakeLists.txt | 2 +- components/openthread/Kconfig | 19 +++++ .../openthread/include/esp_openthread_types.h | 4 +- components/openthread/lib | 2 +- examples/openthread/ot_br/main/esp_ot_br.c | 6 +- .../openthread/ot_br/main/esp_ot_config.h | 8 +-- examples/openthread/ot_cli/main/esp_ot_cli.c | 9 +-- .../openthread/ot_cli/main/esp_ot_config.h | 72 +++++++++++++++++++ .../ot_cli/sdkconfig.defaults.esp32h2 | 21 ++++++ 12 files changed, 132 insertions(+), 16 deletions(-) rename components/openthread/include/esp_openthread_defaults.h => examples/openthread/ot_br/main/esp_ot_config.h (92%) create mode 100644 examples/openthread/ot_cli/main/esp_ot_config.h create mode 100644 examples/openthread/ot_cli/sdkconfig.defaults.esp32h2 diff --git a/components/esp32h2/ld/esp32h2.peripherals.ld b/components/esp32h2/ld/esp32h2.peripherals.ld index 49a57408c3..38e6b58258 100644 --- a/components/esp32h2/ld/esp32h2.peripherals.ld +++ b/components/esp32h2/ld/esp32h2.peripherals.ld @@ -28,3 +28,4 @@ PROVIDE ( GPSPI4 = 0x60037000 ); PROVIDE ( APB_SARADC = 0x60040000 ); PROVIDE ( USB_SERIAL_JTAG = 0x60043000 ); PROVIDE ( GDMA = 0x6003F000 ); +PROVIDE ( IEEE802154 = 0x60047000 ); diff --git a/components/esp_phy/lib b/components/esp_phy/lib index 6def308291..8b1137c35c 160000 --- a/components/esp_phy/lib +++ b/components/esp_phy/lib @@ -1 +1 @@ -Subproject commit 6def308291aaba24a2baaa27fe2a4d50c79420cc +Subproject commit 8b1137c35cc3d2b1085e7f857c2530efb115d3a3 diff --git a/components/ieee802154/lib b/components/ieee802154/lib index f4cdc78bb1..46396c46bd 160000 --- a/components/ieee802154/lib +++ b/components/ieee802154/lib @@ -1 +1 @@ -Subproject commit f4cdc78bb198414ad1e1962b3c044305bbcf62a8 +Subproject commit 46396c46bd3c4d459b194e0e9273ff004158b993 diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt index c521ae5327..e10d0300bd 100644 --- a/components/openthread/CMakeLists.txt +++ b/components/openthread/CMakeLists.txt @@ -69,7 +69,7 @@ idf_component_register(SRC_DIRS "${src_dirs}" EXCLUDE_SRCS "${exclude_srcs}" INCLUDE_DIRS "${public_include_dirs}" PRIV_INCLUDE_DIRS "${private_include_dirs}" - REQUIRES mbedtls) + REQUIRES mbedtls ieee802154) if(CONFIG_OPENTHREAD_ENABLED) target_compile_definitions( diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index 3318a0b0ee..7803240730 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -6,6 +6,25 @@ menu "OpenThread" help Select this option to enable OpenThread and show the submenu with OpenThread configuration choices. + choice OPENTHREAD_RADIO_TYPE + prompt "Config the Thread radio type" + depends on OPENTHREAD_ENABLED + default OPENTHREAD_RADIO_NATIVE if IDF_TARGET_ESP32H2 + default OPENTHREAD_RADIO_SPINEL_UART + help + Configure how OpenThread connects to the 15.4 radio + + config OPENTHREAD_RADIO_NATIVE + bool "Native 15.4 radio" + help + Select this to use the native 15.4 radio. + + config OPENTHREAD_RADIO_SPINEL_UART + bool "Connect via UART" + help + Select this to connect to a Radio Co-Processor via UART. + endchoice + choice OPENTHREAD_DEVICE_TYPE prompt "Config the Thread device type" depends on OPENTHREAD_ENABLED diff --git a/components/openthread/include/esp_openthread_types.h b/components/openthread/include/esp_openthread_types.h index eaa6528852..a3fb31ed41 100644 --- a/components/openthread/include/esp_openthread_types.h +++ b/components/openthread/include/esp_openthread_types.h @@ -72,7 +72,9 @@ typedef struct { * */ typedef enum { - RADIO_MODE_UART_RCP = 0x0, /*!< UART connection to a 15.4 capable radio co-processor(RCP)*/ + RADIO_MODE_NATIVE = 0x0, /*!< Use the native 15.4 radio*/ + RADIO_MODE_UART_RCP = 0x1, /*!< UART connection to a 15.4 capable radio co-processor (RCP)*/ + RADIO_MODE_SPI_RCP = 0x2, /*!< SPI connection to a 15.4 capable radio co-processor (RCP)*/ } esp_openthread_radio_mode_t; /** diff --git a/components/openthread/lib b/components/openthread/lib index 3a3009e7a1..d84f8967f8 160000 --- a/components/openthread/lib +++ b/components/openthread/lib @@ -1 +1 @@ -Subproject commit 3a3009e7a1d9a89f2a06453eb299d6c1a9ee7cad +Subproject commit d84f8967f8ce14490e19433b85c8c363d424f4c1 diff --git a/examples/openthread/ot_br/main/esp_ot_br.c b/examples/openthread/ot_br/main/esp_ot_br.c index 4cceb4a1b8..6d98c9909d 100644 --- a/examples/openthread/ot_br/main/esp_ot_br.c +++ b/examples/openthread/ot_br/main/esp_ot_br.c @@ -24,10 +24,10 @@ #include "esp_netif_net_stack.h" #include "esp_openthread.h" #include "esp_openthread_border_router.h" -#include "esp_openthread_defaults.h" #include "esp_openthread_lock.h" #include "esp_openthread_netif_glue.h" #include "esp_openthread_types.h" +#include "esp_ot_config.h" #include "esp_vfs_eventfd.h" #include "esp_wifi.h" #include "nvs_flash.h" @@ -143,8 +143,8 @@ static void create_config_network(otInstance *instance) static void ot_task_worker(void *aContext) { esp_openthread_platform_config_t config = { - .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_UART_RCP_CONFIG(4, 5), - .host_config = ESP_OPENTHREAD_DEFAULT_UART_HOST_CONFIG(), + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), }; diff --git a/components/openthread/include/esp_openthread_defaults.h b/examples/openthread/ot_br/main/esp_ot_config.h similarity index 92% rename from components/openthread/include/esp_openthread_defaults.h rename to examples/openthread/ot_br/main/esp_ot_config.h index 07ae0f67e5..e2ed326eac 100644 --- a/components/openthread/include/esp_openthread_defaults.h +++ b/examples/openthread/ot_br/main/esp_ot_config.h @@ -16,7 +16,7 @@ #include "esp_openthread_types.h" -#define ESP_OPENTHREAD_DEFAULT_RADIO_UART_RCP_CONFIG(pin_rx, pin_tx) \ +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ { \ .radio_mode = RADIO_MODE_UART_RCP, \ .radio_uart_config = { \ @@ -31,12 +31,12 @@ .rx_flow_ctrl_thresh = 0, \ .source_clk = UART_SCLK_APB, \ }, \ - .rx_pin = pin_rx, \ - .tx_pin = pin_tx, \ + .rx_pin = 4, \ + .tx_pin = 5, \ }, \ } -#define ESP_OPENTHREAD_DEFAULT_UART_HOST_CONFIG() \ +#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \ { \ .host_connection_mode = HOST_CONNECTION_MODE_UART, \ .host_uart_config = { \ diff --git a/examples/openthread/ot_cli/main/esp_ot_cli.c b/examples/openthread/ot_cli/main/esp_ot_cli.c index 3fe51b4317..7eefe0ed20 100644 --- a/examples/openthread/ot_cli/main/esp_ot_cli.c +++ b/examples/openthread/ot_cli/main/esp_ot_cli.c @@ -21,10 +21,10 @@ #include "esp_netif.h" #include "esp_netif_types.h" #include "esp_openthread.h" -#include "esp_openthread_defaults.h" #include "esp_openthread_lock.h" #include "esp_openthread_netif_glue.h" #include "esp_openthread_types.h" +#include "esp_ot_config.h" #include "esp_vfs_eventfd.h" #include "driver/uart.h" #include "freertos/FreeRTOS.h" @@ -56,8 +56,8 @@ static esp_netif_t *init_openthread_netif(const esp_openthread_platform_config_t static void ot_task_worker(void *aContext) { esp_openthread_platform_config_t config = { - .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_UART_RCP_CONFIG(4, 5), - .host_config = ESP_OPENTHREAD_DEFAULT_UART_HOST_CONFIG(), + .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), + .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), }; esp_netif_t *openthread_netif; @@ -89,9 +89,10 @@ void app_main(void) { // Used eventfds: // * netif + // * ot task queue // * radio driver esp_vfs_eventfd_config_t eventfd_config = { - .max_fds = 2, + .max_fds = 3, }; ESP_ERROR_CHECK(esp_event_loop_create_default()); diff --git a/examples/openthread/ot_cli/main/esp_ot_config.h b/examples/openthread/ot_cli/main/esp_ot_config.h new file mode 100644 index 0000000000..bd6371728b --- /dev/null +++ b/examples/openthread/ot_cli/main/esp_ot_config.h @@ -0,0 +1,72 @@ +// Copyright 2021 Espressif Systems (Shanghai) CO LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +#pragma once + +#include "esp_openthread_types.h" + +#if CONFIG_IDF_TARGET_ESP32H2 +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_NATIVE, \ + } + +#else +#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \ + { \ + .radio_mode = RADIO_MODE_UART_RCP, \ + .radio_uart_config = { \ + .port = 1, \ + .uart_config = \ + { \ + .baud_rate = 115200, \ + .data_bits = UART_DATA_8_BITS, \ + .parity = UART_PARITY_DISABLE, \ + .stop_bits = UART_STOP_BITS_1, \ + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, \ + .rx_flow_ctrl_thresh = 0, \ + .source_clk = UART_SCLK_APB, \ + }, \ + .rx_pin = 4, \ + .tx_pin = 5, \ + }, \ + } +#endif + +#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \ + { \ + .host_connection_mode = HOST_CONNECTION_MODE_UART, \ + .host_uart_config = { \ + .port = 0, \ + .uart_config = \ + { \ + .baud_rate = 115200, \ + .data_bits = UART_DATA_8_BITS, \ + .parity = UART_PARITY_DISABLE, \ + .stop_bits = UART_STOP_BITS_1, \ + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, \ + .rx_flow_ctrl_thresh = 0, \ + .source_clk = UART_SCLK_APB, \ + }, \ + .rx_pin = UART_PIN_NO_CHANGE, \ + .tx_pin = UART_PIN_NO_CHANGE, \ + }, \ + } + +#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \ + { \ + .storage_partition_name = "ot_storage", \ + .netif_queue_size = 10, \ + .task_queue_size = 10, \ + } diff --git a/examples/openthread/ot_cli/sdkconfig.defaults.esp32h2 b/examples/openthread/ot_cli/sdkconfig.defaults.esp32h2 new file mode 100644 index 0000000000..28d6db482c --- /dev/null +++ b/examples/openthread/ot_cli/sdkconfig.defaults.esp32h2 @@ -0,0 +1,21 @@ +# +# mbedTLS +# + +# ESP32H2-TODO: enable HW acceleration +CONFIG_MBEDTLS_HARDWARE_AES=n +CONFIG_MBEDTLS_HARDWARE_MPI=n +CONFIG_MBEDTLS_HARDWARE_SHA=n +# end of mbedTLS + +# +# OpenThread +# +CONFIG_OPENTHREAD_BORDER_ROUTER=n +# end of OpenThread + +# +# IEEE 802.15.4 +# +CONFIG_IEEE802154_ENABLED=y +# end of IEEE 802.15.4