fix(esp_system): limit CPU clock to 160MHz in ESP32-C5 for flash encryption

Encrypted flash write operation sometimes result in random corruption in
certain bytes. Root cause points to sudden current surge due to involvement of
encryption block overwhelming LDO supply. More details will be provided
in the ESP32-C5 SoC Errata document.

This fix limits the CPU clock to 160MHz for flash encryption enabled
case. Failing encrypted flash write tests could successfully pass in
this configuration. Going ahead, a dynamic clock adjustment in flash
driver will be considered to mitigate this issue.
This commit is contained in:
Mahavir Jain
2025-11-12 17:50:18 +05:30
parent 3154f66e89
commit 3fd00b4d80
2 changed files with 17 additions and 1 deletions
+10
View File
@@ -55,6 +55,16 @@ static void esp_key_mgr_init(void)
ESP_SYSTEM_INIT_FN(esp_security_init, SECONDARY, BIT(0), 103)
{
#if CONFIG_IDF_TARGET_ESP32C5
// Check for unsupported configuration: flash encryption with CPU frequency > 160MHz
// Manual encrypted flash writes are not stable at higher CPU clock.
// Please refer to the ESP32-C5 SoC Errata document for more details.
if (efuse_hal_flash_encryption_enabled() && CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ > 160) {
ESP_EARLY_LOGE(TAG, "Flash encryption with CPU frequency > 160MHz is not supported. Please reconfigure the CPU frequency.");
return ESP_ERR_NOT_SUPPORTED;
}
#endif
esp_crypto_clk_init();
esp_key_mgr_init();
#if CONFIG_ESP_CRYPTO_DPA_PROTECTION_AT_STARTUP