Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32-H2: Add support for ESP-IDF v5.0 #22064

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ endif()

include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake)

set(CHIP_REQURIE_COMPONENTS freertos lwip bt mdns mbedtls fatfs app_update console openthread)
set(CHIP_REQURIE_COMPONENTS freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash)

if(NOT "${IDF_TARGET}" STREQUAL "esp32h2")
list(APPEND CHIP_REQURIE_COMPONENTS mdns)
endif()

if (NOT CMAKE_BUILD_EARLY_EXPANSION)
if (CONFIG_COMPILER_OPTIMIZATION_DEFAULT OR CONFIG_COMPILER_OPTIMIZATION_NONE)
Expand Down Expand Up @@ -270,7 +274,9 @@ if(CONFIG_BT_ENABLED)
idf_component_get_property(bt_lib bt COMPONENT_LIB)
idf_component_get_property(bt_dir bt COMPONENT_DIR)
list(APPEND chip_libraries $<TARGET_FILE:${bt_lib}>)
list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/libcontroller_5p0_seq.a)
if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2)
list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/beta2/libble_app.a)
endif()
else()
idf_component_get_property(bt_lib bt COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${bt_lib}> -lbtdm_app)
Expand All @@ -287,7 +293,7 @@ if(CONFIG_OPENTHREAD_ENABLED)
list(APPEND chip_libraries $<TARGET_FILE:${openthread_lib}>)
endif()

if(NOT CONFIG_USE_MINIMAL_MDNS)
if(NOT CONFIG_USE_MINIMAL_MDNS AND NOT CONFIG_IDF_TARGET_ESP32H2)
idf_component_get_property(mdns_lib mdns COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${mdns_lib}>)
endif()
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/esp32/setup_idf_chip.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ step.
$ ./install.sh
```

- For ESP32H2, please checkout commit id
[10f3aba770](https://github.com/espressif/esp-idf/tree/10f3aba770),
- For ESP32H2, please checkout tag
[v5.0-beta1](https://github.com/espressif/esp-idf/tree/v5.0-beta1),
currently only lighting-app is supported on H2

```
$ cd esp-idf
$ git checkout 10f3aba770
$ git checkout v5.0-beta1
$ git submodule update --init
$ ./install.sh
```
Expand Down
18 changes: 18 additions & 0 deletions examples/lighting-app/esp32/main/Button.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
*
* 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.
*/

#include "Button.h"
#include "esp_attr.h"

#define GPIO_INPUT_IO_0 9
#define GPIO_INPUT_PIN_SEL (1ULL << GPIO_INPUT_IO_0)
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/group-key-mgmt-server"
PRIV_REQUIRES chip QRCode bt led_strip app_update openthread)
PRIV_REQUIRES chip QRCode bt led_strip app_update openthread driver nvs_flash)

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H")
Expand Down
18 changes: 16 additions & 2 deletions examples/lighting-app/esp32/main/LEDWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "LEDWidget.h"
#include "ColorFormat.h"
#include "led_strip.h"

static const char * TAG = "LEDWidget";

Expand All @@ -26,14 +27,23 @@ void LEDWidget::Init(void)
mBrightness = UINT8_MAX;

#if CONFIG_LED_TYPE_RMT
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
led_strip_config_t strip_config = {
.strip_gpio_num = CONFIG_LED_GPIO,
.max_leds = 1,
};

led_strip_new_rmt_device(&strip_config, &mStrip);
#else
rmt_config_t config = RMT_DEFAULT_CONFIG_TX((gpio_num_t) CONFIG_LED_GPIO, (rmt_channel_t) CONFIG_LED_RMT_CHANNEL);
led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t) config.channel);

config.clk_div = 2;
rmt_config(&config);
rmt_driver_install(config.channel, 0, 0);

mStrip = led_strip_new_rmt_ws2812(&strip_config);
mStrip = led_strip_new_rmt_ws2812(&strip_config);
#endif
mHue = 0;
mSaturation = 0;
#else
Expand Down Expand Up @@ -121,9 +131,13 @@ void LEDWidget::DoSet(void)
{
HsvColor_t hsv = { mHue, mSaturation, brightness };
RgbColor_t rgb = HsvToRgb(hsv);

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
led_strip_set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b);
led_strip_refresh(mStrip);
#else
mStrip->set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b);
mStrip->refresh(mStrip, 100);
#endif
}
#else
ESP_LOGI(TAG, "DoSet to GPIO number %d", mGPIONum);
Expand Down
4 changes: 4 additions & 0 deletions examples/lighting-app/esp32/main/include/LEDWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class LEDWidget
#if CONFIG_LED_TYPE_RMT
uint8_t mHue;
uint8_t mSaturation;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
led_strip_handle_t mStrip;
#else
led_strip_t * mStrip;
#endif
#else
gpio_num_t mGPIONum;
#endif
Expand Down
24 changes: 10 additions & 14 deletions examples/lighting-app/esp32/sdkconfig.defaults.esp32h2
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CONFIG_IDF_TARGET="esp32h2"
CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2=y

# Default to 921600 baud when flashing and monitoring device
CONFIG_ESPTOOLPY_BAUD_921600B=y
Expand All @@ -16,14 +17,9 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y

# NIMBLE
CONFIG_BT_ENABLED=y
CONFIG_BT_BLUEDROID_ENABLED=n
CONFIG_BT_NIMBLE_ENABLED=y
CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y
CONFIG_BT_NIMBLE_EXT_ADV=n
CONFIG_BT_NIMBLE_USE_ESP_TIMER=n
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70
CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n

# Enable OpenThread
Expand All @@ -45,22 +41,19 @@ CONFIG_LWIP_MULTICAST_PING=y
CONFIG_MBEDTLS_HARDWARE_AES=n
CONFIG_MBEDTLS_HARDWARE_MPI=n
CONFIG_MBEDTLS_HARDWARE_SHA=n
CONFIG_MBEDTLS_HARDWARE_ECC=y
CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN=n
CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY=n
CONFIG_MBEDTLS_CMAC_C=y
CONFIG_MBEDTLS_SSL_PROTO_DTLS=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y

# rtc clk for ble
# CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y

# MDNS platform
CONFIG_USE_MINIMAL_MDNS=n

# Increase stacks size
CONFIG_NIMBLE_CONTROLLER_TASK_STACK_SIZE=5120
CONFIG_NIMBLE_HOST_TASK_STACK_SIZE=5120

# ESP32H2 BLE using a ext 32k crystal
CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y
CONFIG_ESP32H2_RTC_CLK_CAL_CYCLES=576
CONFIG_ENABLE_EXTENDED_DISCOVERY=y

# FreeRTOS should use legacy API
CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y
Expand All @@ -71,3 +64,6 @@ CONFIG_ENABLE_WIFI_AP=n

# Enable OTA Requestor
CONFIG_ENABLE_OTA_REQUESTOR=y

# Enable chip shell
CONFIG_ENABLE_CHIP_SHELL=y
25 changes: 20 additions & 5 deletions examples/platform/esp32/common/CommonDeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#if CONFIG_BT_ENABLED
#include "esp_bt.h"
#if CONFIG_BT_NIMBLE_ENABLED
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
#include "esp_nimble_hci.h"
#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
#include "nimble/nimble_port.h"
#endif // CONFIG_BT_NIMBLE_ENABLED
#endif // CONFIG_BT_ENABLED
Expand All @@ -45,6 +47,9 @@ using namespace chip::DeviceLayer;
using namespace chip::System;

DeviceCallbacksDelegate * appDelegate = nullptr;
#if CONFIG_ENABLE_OTA_REQUESTOR
static bool isOTAInitialized = false;
#endif

void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg)
{
Expand All @@ -62,17 +67,30 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i
ESP_LOGI(TAG, "CHIPoBLE disconnected");
break;

case DeviceEventType::kThreadConnectivityChange:
#if CONFIG_ENABLE_OTA_REQUESTOR
if (event->ThreadConnectivityChange.Result == kConnectivity_Established && !isOTAInitialized)
{
OTAHelpers::Instance().InitOTARequestor();
isOTAInitialized = true;
}
#endif
break;

case DeviceEventType::kCommissioningComplete: {
ESP_LOGI(TAG, "Commissioning complete");
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE

if (ble_hs_is_enabled())
{
int ret = nimble_port_stop();
int ret = nimble_port_stop();
esp_err_t err = ESP_OK;
if (ret == 0)
{
nimble_port_deinit();
esp_err_t err = esp_nimble_hci_and_controller_deinit();
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
err = esp_nimble_hci_and_controller_deinit();
#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
err += esp_bt_mem_release(ESP_BT_MODE_BLE);
if (err == ESP_OK)
{
Expand Down Expand Up @@ -114,9 +132,6 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i

void CommonDeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event)
{
#if CONFIG_ENABLE_OTA_REQUESTOR
static bool isOTAInitialized = false;
#endif
appDelegate = DeviceCallbacksDelegate::Instance().GetAppDelegate();
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
Expand Down
6 changes: 5 additions & 1 deletion src/lib/shell/streamer_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ int streamer_esp32_init(streamer_t * streamer)
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.rx_flow_ctrl_thresh = 0,
.source_clk = UART_SCLK_APB,
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
.source_clk = UART_SCLK_DEFAULT,
#else
.source_clk = UART_SCLK_APB,
#endif
};
ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
esp_vfs_dev_uart_use_driver(0);
Expand Down
6 changes: 6 additions & 0 deletions src/platform/ESP32/ESP32Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,14 @@ CHIP_ERROR ESP32Config::ClearConfigValue(Key key)

bool ESP32Config::ConfigValueExists(Key key)
{
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
nvs_iterator_t iterator = NULL;
esp_err_t err = nvs_entry_find(NVS_DEFAULT_PART_NAME, key.Namespace, NVS_TYPE_ANY, &iterator);
for (; iterator && err == ESP_OK; err = nvs_entry_next(&iterator))
#else
nvs_iterator_t iterator = nvs_entry_find(NVS_DEFAULT_PART_NAME, key.Namespace, NVS_TYPE_ANY);
for (; iterator; iterator = nvs_entry_next(iterator))
#endif
{
nvs_entry_info_t info;
nvs_entry_info(iterator, &info);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/OpenthreadLauncher.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void ot_task_worker(void * context)
// Initialize the OpenThread stack
ESP_ERROR_CHECK(esp_openthread_init(&config));
// The OpenThread log level directly matches ESP log level
(void) otLoggingSetLevel(OT_LOG_LEVEL_INFO);
(void) otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL);
// Initialize the esp_netif bindings
openthread_netif = init_openthread_netif(&config);

Expand Down
7 changes: 5 additions & 2 deletions src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include <system/SystemTimer.h>

#include "esp_log.h"
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
#include "esp_nimble_hci.h"
#endif
#include "host/ble_hs.h"
#include "host/ble_hs_pvcy.h"
#include "host/ble_uuid.h"
Expand Down Expand Up @@ -152,7 +154,7 @@ CHIP_ERROR BLEManagerImpl::_Init()
mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
mNumGAPCons = 0;
memset(mCons, 0, sizeof(mCons));
memset(reinterpret_cast<void *>(mCons), 0, sizeof(mCons));
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled;
memset(mDeviceName, 0, sizeof(mDeviceName));

Expand Down Expand Up @@ -613,9 +615,10 @@ CHIP_ERROR BLEManagerImpl::InitESPBleLayer(void)
{
mSubscribedConIds[i] = BLE_CONNECTION_UNINITIALIZED;
}

#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
err = MapBLEError(esp_nimble_hci_and_controller_init());
SuccessOrExit(err);
#endif

nimble_port_init();

Expand Down