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] ESP-IDF v5.0 support in reamining apps #24983

Merged
merged 6 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
1 change: 0 additions & 1 deletion examples/chef/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/../../common/cmake/idf_flashing.cmake)
set(EXTRA_COMPONENT_DIRS
"${CMAKE_CURRENT_LIST_DIR}/third_party/connectedhomeip/config/esp32/components"
"${CMAKE_CURRENT_LIST_DIR}/../../common/QRCode"
"${IDF_PATH}/examples/common_components/led_strip"
)

if(${IDF_TARGET} STREQUAL "esp32")
Expand Down
8 changes: 7 additions & 1 deletion examples/chef/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ set(PRIV_INCLUDE_DIRS_LIST "${PRIV_INCLUDE_DIRS_LIST}"
"${CMAKE_SOURCE_DIR}/../../common/pigweed/esp32"
"${CMAKE_SOURCE_DIR}/../../common/screen-framework/include/"
"${CMAKE_SOURCE_DIR}/../../../src/lib/support"
"${IDF_PATH}/components/freertos/include/freertos"
)

if (${IDF_VERSION_MAJOR} LESS 5)
list(APPEND PRIV_INCLUDE_DIRS_LIST "${IDF_PATH}/components/freertos/include/freertos")
else()
list(APPEND PRIV_INCLUDE_DIRS_LIST "${IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos")
endif()

set(SRC_DIRS_LIST "${SRC_DIRS_LIST}"
"${CMAKE_SOURCE_DIR}/../../platform/esp32"
"${CMAKE_SOURCE_DIR}/../../common/pigweed"
Expand Down
2 changes: 2 additions & 0 deletions examples/chef/esp32/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dependencies:
espressif/led_strip: "^1.0.0-alpha"
4 changes: 2 additions & 2 deletions examples/lock-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ idf_component_register(INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/door-lock-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/identify-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server"
PRIV_REQUIRES bt chip QRCode)
PRIV_REQUIRES bt chip QRCode nvs_flash driver)
add_dependencies(${COMPONENT_LIB} app-codegen)

set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo")
Expand Down Expand Up @@ -185,7 +185,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/identify-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/lock"
PRIV_REQUIRES chip QRCode bt)
PRIV_REQUIRES chip QRCode bt nvs_flash driver)

add_dependencies(${COMPONENT_LIB} app-codegen)

Expand Down
9 changes: 5 additions & 4 deletions examples/lock-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ using namespace ::chip::DeviceLayer;
void AppDeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId,
uint8_t type, uint16_t size, uint8_t * value)
{
ESP_LOGI(TAG, "PostAttributeChangeCallback - Cluster ID: '0x%04x', EndPoint ID: '0x%02x', Attribute ID: '0x%04x'", clusterId,
endpointId, attributeId);
ESP_LOGI(TAG,
"PostAttributeChangeCallback - Cluster ID: '0x%04" PRIx32 "', EndPoint ID: '0x%02x', Attribute ID: '0x%04" PRIx32 "'",
shubhamdp marked this conversation as resolved.
Show resolved Hide resolved
clusterId, endpointId, attributeId);

switch (clusterId)
{
Expand All @@ -49,7 +50,7 @@ void AppDeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Clus
break;

default:
ESP_LOGI(TAG, "Unhandled cluster ID: %d", clusterId);
ESP_LOGI(TAG, "Unhandled cluster ID: %" PRIu32, clusterId);
break;
}

Expand All @@ -59,7 +60,7 @@ void AppDeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Clus
void AppDeviceCallbacks::OnOnOffPostAttributeChangeCallback(EndpointId endpointId, AttributeId attributeId, uint8_t * value)
{
VerifyOrExit(attributeId == app::Clusters::OnOff::Attributes::OnOff::Id,
ESP_LOGI(TAG, "Unhandled Attribute ID: '0x%04x", attributeId));
ESP_LOGI(TAG, "Unhandled Attribute ID: '0x%04" PRIx32, attributeId));
shubhamdp marked this conversation as resolved.
Show resolved Hide resolved
VerifyOrExit(endpointId == 1 || endpointId == 2, ESP_LOGE(TAG, "Unexpected EndPoint ID: `0x%02x'", endpointId));
if (*value)
{
Expand Down
7 changes: 2 additions & 5 deletions examples/lock-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "esp_heap_caps_init.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_spi_flash.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
Expand All @@ -37,8 +36,6 @@
#include <string>
#include <vector>

#include <lib/support/ErrorStr.h>

#if CONFIG_ENABLE_PW_RPC
#include "PigweedLogger.h"
#include "Rpc.h"
Expand Down Expand Up @@ -82,7 +79,7 @@ static void InitServer(intptr_t context)
CHIP_ERROR error = GetAppTask().StartAppTask();
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "GetAppTask().StartAppTask() failed: %s", ErrorStr(error));
ESP_LOGE(TAG, "GetAppTask().StartAppTask() failed: %" CHIP_ERROR_FORMAT, error.Format());
}
}

Expand Down Expand Up @@ -114,7 +111,7 @@ extern "C" void app_main()
CHIP_ERROR error = deviceMgr.Init(&EchoCallbacks);
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "device.Init() failed: %s", ErrorStr(error));
ESP_LOGE(TAG, "device.Init() failed: %" CHIP_ERROR_FORMAT, error.Format());
return;
}

Expand Down
8 changes: 4 additions & 4 deletions examples/ota-provider-app/esp32/main/BdxOtaSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
acceptData.StartOffset = mTransfer.GetStartOffset();
acceptData.Length = mTransfer.GetTransferLength();
VerifyOrReturn(mTransfer.AcceptTransfer(acceptData) == CHIP_NO_ERROR,
ChipLogError(BDX, "%s: %s", __FUNCTION__, chip::ErrorStr(err)));
ChipLogError(BDX, "AcceptTransfter failed error:%" CHIP_ERROR_FORMAT, err.Format()));

// Store the file designator, used during block query
uint16_t fdl = 0;
const uint8_t * fd = mTransfer.GetFileDesignator(fdl);
VerifyOrReturn(fdl < sizeof(mFileDesignator), ChipLogError(BDX, "Cannot store file designator with length = %d", fdl));
VerifyOrReturn(fdl < sizeof(mFileDesignator), ChipLogError(BDX, "Cannot store file designator with length = %u", fdl));
memcpy(mFileDesignator, fd, fdl);
mFileDesignator[fdl] = 0;

Expand Down Expand Up @@ -157,7 +157,7 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev

if (CHIP_NO_ERROR != mTransfer.PrepareBlock(blockData))
{
ChipLogError(BDX, "%s: PrepareBlock failed: %s", __FUNCTION__, chip::ErrorStr(err));
ChipLogError(BDX, "PrepareBlock failed: %" CHIP_ERROR_FORMAT, err.Format());
mTransfer.AbortTransfer(StatusCode::kUnknown);
}
break;
Expand Down Expand Up @@ -215,7 +215,7 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
case TransferSession::OutputEventType::kBlockReceived:
default:
// TransferSession should prevent this case from happening.
ChipLogError(BDX, "%s: unsupported event type", __FUNCTION__);
ChipLogError(BDX, "unsupported event type");
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/ota-provider-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
EXCLUDE_SRCS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/ota-provider-app/ota-provider-common/BdxOtaSender.cpp"
PRIV_REQUIRES chip QRCode bt console spiffs)
PRIV_REQUIRES chip QRCode bt console spiffs spi_flash nvs_flash)

get_filename_component(CHIP_ROOT ${CMAKE_SOURCE_DIR}/third_party/connectedhomeip REALPATH)
include("${CHIP_ROOT}/build/chip/esp32/esp32_codegen.cmake")
Expand Down
13 changes: 6 additions & 7 deletions examples/ota-provider-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <common/Esp32AppServer.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/ErrorStr.h>
#include <lib/support/logging/CHIPLogging.h>

#include <OTAProviderCommands.h>
Expand Down Expand Up @@ -89,7 +88,7 @@ static void InitServer(intptr_t context)
chip::Protocols::BDX::Id, bdxOtaSender);
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "RegisterUnsolicitedMessageHandler failed: %s", chip::ErrorStr(error));
ESP_LOGE(TAG, "RegisterUnsolicitedMessageHandler failed: %" CHIP_ERROR_FORMAT, error.Format());
return;
}

Expand All @@ -114,7 +113,7 @@ static void InitServer(intptr_t context)
}
size_t total = 0, used = 0;
err = esp_spiffs_info(NULL, &total, &used);
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
ESP_LOGI(TAG, "Partition size: total: %u, used: %u", total, used);
char otaImagePath[kMaxImagePathlen];
memset(otaImagePath, 0, sizeof(otaImagePath));
snprintf(otaImagePath, sizeof(otaImagePath), "/fs/%s", otaFilename);
Expand All @@ -129,7 +128,7 @@ static void InitServer(intptr_t context)
fseek(otaImageFile, 0, SEEK_END);
otaImageLen = ftell(otaImageFile);
rewind(otaImageFile);
ESP_LOGI(TAG, "The OTA image size: %d", otaImageLen);
ESP_LOGI(TAG, "The OTA image size: %" PRIu32, otaImageLen);
if (otaImageLen > 0)
{
otaProvider.SetQueryImageStatus(OTAQueryStatus::kUpdateAvailable);
Expand Down Expand Up @@ -203,12 +202,12 @@ CHIP_ERROR OnBlockQuery(void * context, chip::System::PacketBufferHandle & block
size_t size_read = fread(blockBuf->Start(), 1, size, otaImageFile);
if (size_read != size)
{
ESP_LOGE(TAG, "Failed to read %d bytes from %s", size, otaFilename);
ESP_LOGE(TAG, "Failed to read %u bytes from %s", size, otaFilename);
size = 0;
isEof = false;
return CHIP_ERROR_READ_FAILED;
}
ESP_LOGI(TAG, "Read %d bytes from %s", size, otaFilename);
ESP_LOGI(TAG, "Read %u bytes from %s", size, otaFilename);
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -253,7 +252,7 @@ extern "C" void app_main()
CHIP_ERROR error = deviceMgr.Init(&EchoCallbacks);
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "device.Init() failed: %s", ErrorStr(error));
ESP_LOGE(TAG, "device.Init() failed: %" CHIP_ERROR_FORMAT, error.Format());
return;
}

Expand Down
8 changes: 4 additions & 4 deletions examples/ota-provider-app/esp32/partitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, , 0x6000,
phy_init, data, phy, , 0x1000,
# Factory partition size about 1.5MB
factory, app, factory, , 1500K,
# spiffs partition to storage the image file size about 1.5MB
img_storage, data, spiffs, , 1500K,
# Factory partition size about 1.6MB
factory, app, factory, , 1600K,
# spiffs partition to storage the image file size about 1.6MB
img_storage, data, spiffs, , 1600K,
2 changes: 1 addition & 1 deletion examples/ota-requestor-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
)

set(PRIV_REQUIRES_LIST chip QRCode bt console app_update)
set(PRIV_REQUIRES_LIST chip QRCode bt console app_update nvs_flash)

if (CONFIG_ENABLE_PW_RPC)
# Append additional directories for RPC build
Expand Down
15 changes: 1 addition & 14 deletions examples/ota-requestor-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "esp_heap_caps_init.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_spi_flash.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
Expand All @@ -32,7 +31,6 @@
#include <common/Esp32AppServer.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <lib/support/ErrorStr.h>
#include <ota/OTAHelper.h>
#include <shell_extension/launch.h>

Expand Down Expand Up @@ -128,17 +126,6 @@ extern "C" void app_main()

ESP_LOGI(TAG, "OTA Requester!");

/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
ESP_LOGI(TAG, "This is ESP32 chip with %d CPU cores, WiFi%s%s, ", chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");

ESP_LOGI(TAG, "silicon revision %d, ", chip_info.revision);

ESP_LOGI(TAG, "%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

// Initialize the ESP NVS layer.
esp_err_t err = nvs_flash_init();
if (err != ESP_OK)
Expand All @@ -159,7 +146,7 @@ extern "C" void app_main()
CHIP_ERROR error = deviceMgr.Init(&EchoCallbacks);
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "device.Init() failed: %s", ErrorStr(error));
ESP_LOGE(TAG, "device.Init() failed: %" CHIP_ERROR_FORMAT, error.Format());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
)

set(PRIV_REQUIRES_LIST chip QRCode bt)
set(PRIV_REQUIRES_LIST chip QRCode bt nvs_flash)

if (CONFIG_ENABLE_PW_RPC)
# Append additional directories for RPC build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ using namespace ::chip::System;
void AppDeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId,
uint8_t type, uint16_t size, uint8_t * value)
{
ESP_LOGI(TAG, "PostAttributeChangeCallback - Cluster ID: '0x%04x', EndPoint ID: '0x%02x', Attribute ID: '0x%04x'", clusterId,
endpointId, attributeId);
ESP_LOGI(TAG,
"PostAttributeChangeCallback - Cluster ID: '0x%04" PRIx32 "', EndPoint ID: '0x%02x', Attribute ID: '0x%04" PRIx32 "'",
clusterId, endpointId, attributeId);

// TODO handle this callback in switch statement
ESP_LOGI(TAG, "Unhandled cluster ID: %d", clusterId);
ESP_LOGI(TAG, "Unhandled cluster ID: %" PRIu32, clusterId);

ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
17 changes: 1 addition & 16 deletions examples/temperature-measurement-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "esp_heap_caps_init.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_spi_flash.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "freertos/FreeRTOS.h"
Expand All @@ -36,8 +35,6 @@
#include <string>
#include <vector>

#include <lib/support/ErrorStr.h>

#if CONFIG_ENABLE_PW_RPC
#include "Rpc.h"
#endif
Expand Down Expand Up @@ -85,18 +82,6 @@ extern "C" void app_main()

ESP_LOGI(TAG, "Temperature sensor!");

/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);

ESP_LOGI(TAG, "This is ESP32 chip with %d CPU cores, WiFi%s%s, ", chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");

ESP_LOGI(TAG, "silicon revision %d, ", chip_info.revision);

ESP_LOGI(TAG, "%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

// Initialize the ESP NVS layer.
esp_err_t err = nvs_flash_init();
if (err != ESP_OK)
Expand All @@ -112,7 +97,7 @@ extern "C" void app_main()
CHIP_ERROR error = deviceMgr.Init(&EchoCallbacks);
if (error != CHIP_NO_ERROR)
{
ESP_LOGE(TAG, "device.Init() failed: %s", ErrorStr(error));
ESP_LOGE(TAG, "device.Init() failed: %" CHIP_ERROR_FORMAT, error.Format());
return;
}

Expand Down