Skip to content

Commit

Permalink
ESP32: Add ESP32H2 target for lighting app (#16599)
Browse files Browse the repository at this point in the history
* platform and CHIPCryptoPALmbedTLS changes for idf v5.0-dev(10f3aba770)

* Add esp32h2 target for lighting-app

* Restyled by prettier-markdown

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Jan 18, 2024
1 parent 2d3b93f commit 1204591
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 56 deletions.
2 changes: 1 addition & 1 deletion config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ 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/esp32h2beta/libcontroller_5p0_seq.a)
list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/libcontroller_5p0_seq.a)
else()
idf_component_get_property(bt_lib bt COMPONENT_LIB)
list(APPEND chip_libraries $<TARGET_FILE:${bt_lib}> -lbtdm_app)
Expand Down
12 changes: 12 additions & 0 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,18 @@ menu "CHIP Device Layer"

endmenu

menu "CHIP Thread Options"
visible if OPENTHREAD_ENABLED

config THREAD_TASK_STACK_SIZE
int "Thread task stack size"
default 5120
depends on OPENTHREAD_ENABLED
help
Stack size of Thread task.

endmenu

menu "CHIP Trait Manager"

config ENABLE_TRAIT_MANAGER
Expand Down
9 changes: 7 additions & 2 deletions config/esp32/components/esp32_mbedtls/mbedtls/esp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
#ifndef ESP_CONFIG_H
#define ESP_CONFIG_H

#include "mbedtls/config.h"
#include "esp_idf_version.h"
#include "sdkconfig.h"

// For ESP32H2, we use idf v5.0. Its "mbedtls/config.h" was replaced by "mbedtls/build_info.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#include "mbedtls/build_info.h"
#else
#include "mbedtls/config.h"
#endif
/**
* \name SECTION: System support
*
Expand Down
3 changes: 3 additions & 0 deletions examples/lighting-app/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-secur
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
idf_build_set_property(COMPILE_OPTIONS "-Wno-error=maybe-uninitialized" APPEND)

#For the H2, -Werror=uninitialized will cause an error in "src/lib/support/LambdaBridge.h"
idf_build_set_property(COMPILE_OPTIONS "-Wno-error=uninitialized" APPEND)

flashing_script()
29 changes: 26 additions & 3 deletions examples/lighting-app/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ devices:

- [ESP32-DevKitC](https://www.espressif.com/en/products/hardware/esp32-devkitc/overview)
- [ESP32-WROVER-KIT_V4.1](https://www.espressif.com/en/products/hardware/esp-wrover-kit/overview)
- [ESP32C3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html).
- [ESP32S3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitm-1.html).
- [ESP32C3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/hw-reference/esp32c3/user-guide-devkitm-1.html)
- [ESP32S3-DevKitM](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitm-1.html)
- [ESP32-H2](https://www.espressif.com/en/news/ESP32_H2).

## Building the Example Application

Expand All @@ -42,6 +43,14 @@ step. To install these components manually, follow these steps:
$ git submodule update --init
$ ./install.sh

- For ESP32H2, you can checkout commit id
[10f3aba770](https://github.com/espressif/esp-idf/tree/10f3aba770)

$ cd esp-idf
$ git checkout 10f3aba770
$ git submodule update --init
$ ./install.sh

- Install ninja-build

$ sudo apt-get install ninja-build
Expand Down Expand Up @@ -72,6 +81,8 @@ make sure the IDF_PATH has been exported(See the manual setup steps above).
$ idf.py set-target esp32c3
or
$ idf.py set-target esp32s3
or
$ idf.py --preview set-target esp32h2

- To build the demo application.

Expand Down Expand Up @@ -103,10 +114,22 @@ make sure the IDF_PATH has been exported(See the manual setup steps above).
## Commissioning over BLE using chip-tool

- Please build the standalone chip-tool as described [here](../../chip-tool)
- Commissioning the Lighting device
- Commissioning the WiFi Lighting devices(ESP32, ESP32C3, ESP32S3)

$ ./out/debug/chip-tool pairing ble-wifi 12345 <ssid> <passphrase> 20202021 3840

- For ESP32-H2, firstly start OpenThread Border Router, you can either use
[Raspberry Pi OpenThread Border Router](https://github.com/project-chip/connectedhomeip/blob/master/docs/guides/openthread_border_router_pi.md)
OR
[ESP32 OpenThread Border Router](https://github.com/espressif/esp-idf/tree/master/examples/openthread/ot_br)
- Get the active operational dataset.

$ ot-ctl> dataset active -x

- Commissioning the Thread Lighting device(ESP32H2)

$ ./out/debug/chip-tool pairing ble-thread 12345 hex:<operational-dataset> 20202021 3840

## Cluster Control

- After successful commissioning, use the OnOff cluster command to control the
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 @@ -60,7 +60,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)
PRIV_REQUIRES chip QRCode bt led_strip app_update openthread)

set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17)
target_compile_options(${COMPONENT_LIB} PRIVATE "-DLWIP_IPV6_SCOPES=0" "-DCHIP_HAVE_CONFIG_H")
Expand Down
7 changes: 5 additions & 2 deletions examples/lighting-app/esp32/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ menu "Demo"
config DEVICE_TYPE_ESP32_S3_DEVKITM
bool "ESP32S3-DevKitM"
depends on IDF_TARGET_ESP32S3
config DEVICE_TYPE_ESP32H2_DEVKITC
bool "ESP32H2-DevKitC"
depends on IDF_TARGET_ESP32H2
endchoice

choice LED_TYPE
prompt "LED type"
default LED_TYPE_RMT if DEVICE_TYPE_ESP32_C3_DEVKITM || DEVICE_TYPE_ESP32_S3_DEVKITM
default LED_TYPE_RMT if DEVICE_TYPE_ESP32_C3_DEVKITM || DEVICE_TYPE_ESP32_S3_DEVKITM || DEVICE_TYPE_ESP32H2_DEVKITC
default LED_TYPE_GPIO
help
Defines the default LED type used in the example
Expand All @@ -73,7 +76,7 @@ menu "Demo"
int "LED GPIO number"
range 0 48
default 26 if DEVICE_TYPE_ESP32_WROVER_KIT
default 8 if DEVICE_TYPE_ESP32_C3_DEVKITM
default 8 if DEVICE_TYPE_ESP32_C3_DEVKITM || DEVICE_TYPE_ESP32H2_DEVKITC
default 48 if DEVICE_TYPE_ESP32_S3_DEVKITM
default 5
help
Expand Down
28 changes: 25 additions & 3 deletions examples/lighting-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
#include <app/clusters/ota-requestor/GenericOTARequestorDriver.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <credentials/DeviceAttestationCredsProvider.h>
Expand All @@ -56,10 +57,11 @@ LEDWidget AppLED;
static const char * TAG = "light-app";

static DeviceCallbacks EchoCallbacks;

namespace {
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPWiFiDriver::GetInstance()));
#endif
} // namespace

static void InitOTARequestor(void)
Expand All @@ -83,8 +85,17 @@ static void InitServer(intptr_t context)

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider());

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
sWiFiNetworkCommissioningInstance.Init();
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() &&
(chip::Server::GetInstance().GetFabricTable().FabricCount() != 0))
{
ESP_LOGI(TAG, "Thread has been provisioned, publish the dns service now");
chip::app::DnssdServer::Instance().StartServer();
}
#endif
}

extern "C" void app_main()
Expand Down Expand Up @@ -113,7 +124,18 @@ extern "C" void app_main()
ESP_LOGE(TAG, "device.Init() failed: %s", ErrorStr(error));
return;
}

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (ThreadStackMgr().InitThreadStack() != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "Failed to initialize Thread stack");
return;
}
if (ThreadStackMgr().StartThreadTask() != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "Failed to launch Thread task");
return;
}
#endif
AppLED.Init();

InitOTARequestor();
Expand Down
9 changes: 9 additions & 0 deletions examples/lighting-app/esp32/partitions_h2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, , 0x6000,
otadata, data, ota, , 0x2000,
phy_init, data, phy, , 0x1000,
ota_0, app, ota_0, , 1500K,
ota_1, app, ota_1, , 1500K,
fctry, data, nvs, , 0x6000,
ot_storage,data, fat, , 0x6000,
69 changes: 69 additions & 0 deletions examples/lighting-app/esp32/sdkconfig.defaults.esp32h2
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
CONFIG_IDF_TARGET="esp32h2"

# Default to 921600 baud when flashing and monitoring device
CONFIG_ESPTOOLPY_BAUD_921600B=y
CONFIG_ESPTOOLPY_BAUD=921600
CONFIG_ESPTOOLPY_COMPRESSED=y
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
CONFIG_ESPTOOLPY_FLASHFREQ="40m"
CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y
CONFIG_ESPTOOLPY_MONITOR_BAUD=115200

# libsodium
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_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n

# Enable OpenThread
CONFIG_OPENTHREAD_ENABLED=y
CONFIG_OPENTHREAD_SRP_CLIENT=y

# Disable lwip ipv6 autoconfig
CONFIG_LWIP_IPV6_AUTOCONFIG=n

# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_h2.csv"

# LwIP config for OpenThread
CONFIG_LWIP_IPV6_NUM_ADDRESSES=8
CONFIG_LWIP_MULTICAST_PING=y

# mbedTLS
CONFIG_MBEDTLS_HARDWARE_AES=n
CONFIG_MBEDTLS_HARDWARE_MPI=n
CONFIG_MBEDTLS_HARDWARE_SHA=n
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

# 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

# FreeRTOS should use legacy API
CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y

# Enable OTA Requestor
CONFIG_ENABLE_OTA_REQUESTOR=y
Loading

0 comments on commit 1204591

Please sign in to comment.