Skip to content

Commit

Permalink
[ESP32] esp-idf v5.0 support changes, fixed format specifiers and fixed
Browse files Browse the repository at this point in the history
the error codes where it would have been uninitialized
  • Loading branch information
shubhamdp committed Jan 23, 2023
1 parent 63527d4 commit 2955b0a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/platform/esp32/lock/BoltLockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void BoltLockManager::ActuatorMovementTimerEventHandler(AppEvent * aEvent)

lock->mAutoLockTimerArmed = true;

ESP_LOGI(TAG, "Auto Re-lock enabled. Will be triggered in %u seconds", lock->mAutoLockDuration);
ESP_LOGI(TAG, "Auto Re-lock enabled. Will be triggered in %" PRIu32 " seconds", lock->mAutoLockDuration);
}
}
}
Expand Down
48 changes: 32 additions & 16 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,22 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
{
ChipLogError(DeviceLayer,
"CONFIG_NVS_ENCRYPTION is enabled, but no partition with subtype nvs_keys found in the partition table.");
SuccessOrExit(MapConfigError(esp_err));
err = MapConfigError(esp_err);
SuccessOrExit(err);
}

esp_err = nvs_flash_read_security_cfg(key_part, &cfg);
if (esp_err == ESP_ERR_NVS_KEYS_NOT_INITIALIZED)
{
ChipLogError(DeviceLayer, "NVS key partition empty");
SuccessOrExit(MapConfigError(esp_err));
err = MapConfigError(esp_err);
SuccessOrExit(err);
}
else if (esp_err != ESP_OK)
{
ChipLogError(DeviceLayer, "Failed to read NVS security cfg, err:0x%02x", esp_err);
SuccessOrExit(MapConfigError(esp_err));
err = MapConfigError(esp_err);
SuccessOrExit(err);
}

// Securely initialize the nvs partitions,
Expand All @@ -93,35 +96,41 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
{
ChipLogError(DeviceLayer, "Failed to initialize NVS partition %s err:0x%02x",
CHIP_DEVICE_CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION, esp_err);
SuccessOrExit(MapConfigError(esp_err));
err = MapConfigError(esp_err);
SuccessOrExit(err);
}

esp_err = nvs_flash_secure_init_partition(CHIP_DEVICE_CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION, &cfg);
if (esp_err == ESP_ERR_NVS_NO_FREE_PAGES || esp_err == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ChipLogError(DeviceLayer, "Failed to initialize NVS partition %s err:0x%02x",
CHIP_DEVICE_CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION, esp_err);
SuccessOrExit(MapConfigError(esp_err));
err = MapConfigError(esp_err);
SuccessOrExit(err);
}

esp_err = nvs_flash_secure_init_partition(CHIP_DEVICE_CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION, &cfg);
if (esp_err == ESP_ERR_NVS_NO_FREE_PAGES || esp_err == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ChipLogError(DeviceLayer, "Failed to initialize NVS partition %s err:0x%02x",
CHIP_DEVICE_CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION, esp_err);
SuccessOrExit(MapConfigError(esp_err));
err = MapConfigError(esp_err);
SuccessOrExit(err);
}
#else
// Initialize the nvs partitions,
// nvs_flash_init_partition() will initialize the partition only if it is not already initialized.
esp_err_t esp_err = nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION);
SuccessOrExit(MapConfigError(esp_err));
esp_err = nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION);
SuccessOrExit(MapConfigError(esp_err));
esp_err = nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION);
SuccessOrExit(MapConfigError(esp_err));
esp_err = nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION);
SuccessOrExit(MapConfigError(esp_err));
err = MapConfigError(nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION));
SuccessOrExit(err);

err = MapConfigError(nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION));
SuccessOrExit(err);

err = MapConfigError(nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION));
SuccessOrExit(err);

err = MapConfigError(nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION));
SuccessOrExit(err);
#endif

// Force initialization of NVS namespaces if they doesn't already exist.
Expand Down Expand Up @@ -188,7 +197,14 @@ CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOp
CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t bufSize)
{
memset(buf, 0, bufSize);
const esp_app_desc_t * appDescription = esp_ota_get_app_description();
const esp_app_desc_t * appDescription = NULL;

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
appDescription = esp_app_get_description();
#else
appDescription = esp_ota_get_app_description();
#endif

ReturnErrorCodeIf(bufSize < sizeof(appDescription->version), CHIP_ERROR_BUFFER_TOO_SMALL);
ReturnErrorCodeIf(sizeof(appDescription->version) > ConfigurationManager::kMaxSoftwareVersionStringLength, CHIP_ERROR_INTERNAL);
strcpy(buf, appDescription->version);
Expand All @@ -215,7 +231,7 @@ CHIP_ERROR ConfigurationManagerImpl::GetLocationCapability(uint8_t & location)

return err;
#else
location = static_cast<uint8_t>(chip::app::Clusters::GeneralCommissioning::RegulatoryLocationType::kIndoor);
location = static_cast<uint8_t>(chip::app::Clusters::GeneralCommissioning::RegulatoryLocationType::kIndoor);
return CHIP_NO_ERROR;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/ESP32Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ CHIP_ERROR ESP32Config::WriteConfigValueBin(Key key, const uint8_t * data, size_
// Commit the value to the persistent store.
ReturnMappedErrorOnFailure(nvs_commit(handle));

ChipLogProgress(DeviceLayer, "NVS set: %s/%s = (blob length %" PRId32 ")", StringOrNullMarker(key.Namespace),
ChipLogProgress(DeviceLayer, "NVS set: %s/%s = (blob length %u)", StringOrNullMarker(key.Namespace),
StringOrNullMarker(key.Name), dataLen);
return CHIP_NO_ERROR;
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ESP32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
return;
}
imageProcessor->ReleaseBlock();
ChipLogProgress(SoftwareUpdate, "OTA image downloaded to offset 0x%x", imageProcessor->mOTAUpdatePartition->address);
ChipLogProgress(SoftwareUpdate, "OTA image downloaded to offset 0x%" PRIx32, imageProcessor->mOTAUpdatePartition->address);
PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadComplete);
}

Expand Down Expand Up @@ -241,7 +241,7 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
PostOTAStateChangeEvent(DeviceLayer::kOtaApplyFailed);
return;
}
ESP_LOGI(TAG, "Applying, Boot partition set offset:0x%x", imageProcessor->mOTAUpdatePartition->address);
ESP_LOGI(TAG, "Applying, Boot partition set offset:0x%" PRIx32, imageProcessor->mOTAUpdatePartition->address);

PostOTAStateChangeEvent(DeviceLayer::kOtaApplyComplete);

Expand Down
5 changes: 3 additions & 2 deletions src/platform/ESP32/SystemTimeSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ CHIP_ERROR ClockImpl::SetClock_RealTime(Microseconds64 aNewCurTime)
const time_t timep = tv.tv_sec;
struct tm calendar;
localtime_r(&timep, &calendar);
ChipLogProgress(DeviceLayer, "Real time clock set to %ld (%04d/%02d/%02d %02d:%02d:%02d UTC)", tv.tv_sec, calendar.tm_year,
calendar.tm_mon, calendar.tm_mday, calendar.tm_hour, calendar.tm_min, calendar.tm_sec);
ChipLogProgress(DeviceLayer, "Real time clock set to %lld (%04d/%02d/%02d %02d:%02d:%02d UTC)",
static_cast<long long>(tv.tv_sec), calendar.tm_year, calendar.tm_mon, calendar.tm_mday, calendar.tm_hour,
calendar.tm_min, calendar.tm_sec);
}
#endif // CHIP_PROGRESS_LOGGING
return CHIP_NO_ERROR;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ESP32/route_hook/ESP32RouteHook.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ static void ra_recv_handler(struct netif * netif, const uint8_t * icmp_payload,
route.prefix = prefix;
route.preference = preference;
route.lifetime_seconds = lwip_ntohl(rio_header.route_lifetime);
ESP_LOGI(TAG, "prefix %s lifetime %u\n", ip6addr_ntoa(&prefix), route.lifetime_seconds);
ESP_LOGI(TAG, "prefix %s lifetime %" PRIu32, ip6addr_ntoa(&prefix), route.lifetime_seconds);
if (esp_route_table_add_route_entry(&route) == NULL)
{
ESP_LOGI(TAG, "Failed to add route table entry\n");
ESP_LOGI(TAG, "Failed to add route table entry");
}
}
}
Expand Down

0 comments on commit 2955b0a

Please sign in to comment.