openthread: enable ot_cli on esp32h2

This commit is contained in:
Shu Chen
2021-07-09 12:18:41 +08:00
parent bdaeeb3169
commit 8e56ecc656
12 changed files with 132 additions and 16 deletions

View File

@@ -28,3 +28,4 @@ PROVIDE ( GPSPI4 = 0x60037000 );
PROVIDE ( APB_SARADC = 0x60040000 ); PROVIDE ( APB_SARADC = 0x60040000 );
PROVIDE ( USB_SERIAL_JTAG = 0x60043000 ); PROVIDE ( USB_SERIAL_JTAG = 0x60043000 );
PROVIDE ( GDMA = 0x6003F000 ); PROVIDE ( GDMA = 0x6003F000 );
PROVIDE ( IEEE802154 = 0x60047000 );

View File

@@ -69,7 +69,7 @@ idf_component_register(SRC_DIRS "${src_dirs}"
EXCLUDE_SRCS "${exclude_srcs}" EXCLUDE_SRCS "${exclude_srcs}"
INCLUDE_DIRS "${public_include_dirs}" INCLUDE_DIRS "${public_include_dirs}"
PRIV_INCLUDE_DIRS "${private_include_dirs}" PRIV_INCLUDE_DIRS "${private_include_dirs}"
REQUIRES mbedtls) REQUIRES mbedtls ieee802154)
if(CONFIG_OPENTHREAD_ENABLED) if(CONFIG_OPENTHREAD_ENABLED)
target_compile_definitions( target_compile_definitions(

View File

@@ -6,6 +6,25 @@ menu "OpenThread"
help help
Select this option to enable OpenThread and show the submenu with OpenThread configuration choices. 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 choice OPENTHREAD_DEVICE_TYPE
prompt "Config the Thread device type" prompt "Config the Thread device type"
depends on OPENTHREAD_ENABLED depends on OPENTHREAD_ENABLED

View File

@@ -72,7 +72,9 @@ typedef struct {
* *
*/ */
typedef enum { 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; } esp_openthread_radio_mode_t;
/** /**

View File

@@ -24,10 +24,10 @@
#include "esp_netif_net_stack.h" #include "esp_netif_net_stack.h"
#include "esp_openthread.h" #include "esp_openthread.h"
#include "esp_openthread_border_router.h" #include "esp_openthread_border_router.h"
#include "esp_openthread_defaults.h"
#include "esp_openthread_lock.h" #include "esp_openthread_lock.h"
#include "esp_openthread_netif_glue.h" #include "esp_openthread_netif_glue.h"
#include "esp_openthread_types.h" #include "esp_openthread_types.h"
#include "esp_ot_config.h"
#include "esp_vfs_eventfd.h" #include "esp_vfs_eventfd.h"
#include "esp_wifi.h" #include "esp_wifi.h"
#include "nvs_flash.h" #include "nvs_flash.h"
@@ -143,8 +143,8 @@ static void create_config_network(otInstance *instance)
static void ot_task_worker(void *aContext) static void ot_task_worker(void *aContext)
{ {
esp_openthread_platform_config_t config = { esp_openthread_platform_config_t config = {
.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_UART_RCP_CONFIG(4, 5), .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(),
.host_config = ESP_OPENTHREAD_DEFAULT_UART_HOST_CONFIG(), .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(),
.port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),
}; };

View File

@@ -16,7 +16,7 @@
#include "esp_openthread_types.h" #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_mode = RADIO_MODE_UART_RCP, \
.radio_uart_config = { \ .radio_uart_config = { \
@@ -31,12 +31,12 @@
.rx_flow_ctrl_thresh = 0, \ .rx_flow_ctrl_thresh = 0, \
.source_clk = UART_SCLK_APB, \ .source_clk = UART_SCLK_APB, \
}, \ }, \
.rx_pin = pin_rx, \ .rx_pin = 4, \
.tx_pin = pin_tx, \ .tx_pin = 5, \
}, \ }, \
} }
#define ESP_OPENTHREAD_DEFAULT_UART_HOST_CONFIG() \ #define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \
{ \ { \
.host_connection_mode = HOST_CONNECTION_MODE_UART, \ .host_connection_mode = HOST_CONNECTION_MODE_UART, \
.host_uart_config = { \ .host_uart_config = { \

View File

@@ -21,10 +21,10 @@
#include "esp_netif.h" #include "esp_netif.h"
#include "esp_netif_types.h" #include "esp_netif_types.h"
#include "esp_openthread.h" #include "esp_openthread.h"
#include "esp_openthread_defaults.h"
#include "esp_openthread_lock.h" #include "esp_openthread_lock.h"
#include "esp_openthread_netif_glue.h" #include "esp_openthread_netif_glue.h"
#include "esp_openthread_types.h" #include "esp_openthread_types.h"
#include "esp_ot_config.h"
#include "esp_vfs_eventfd.h" #include "esp_vfs_eventfd.h"
#include "driver/uart.h" #include "driver/uart.h"
#include "freertos/FreeRTOS.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) static void ot_task_worker(void *aContext)
{ {
esp_openthread_platform_config_t config = { esp_openthread_platform_config_t config = {
.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_UART_RCP_CONFIG(4, 5), .radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(),
.host_config = ESP_OPENTHREAD_DEFAULT_UART_HOST_CONFIG(), .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(),
.port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),
}; };
esp_netif_t *openthread_netif; esp_netif_t *openthread_netif;
@@ -89,9 +89,10 @@ void app_main(void)
{ {
// Used eventfds: // Used eventfds:
// * netif // * netif
// * ot task queue
// * radio driver // * radio driver
esp_vfs_eventfd_config_t eventfd_config = { esp_vfs_eventfd_config_t eventfd_config = {
.max_fds = 2, .max_fds = 3,
}; };
ESP_ERROR_CHECK(esp_event_loop_create_default()); ESP_ERROR_CHECK(esp_event_loop_create_default());

View File

@@ -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, \
}

View File

@@ -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