diff --git a/components/esp_hw_support/esp_key_mgr.c b/components/esp_hw_support/esp_key_mgr.c index 6b67decd90..c1009c89d4 100644 --- a/components/esp_hw_support/esp_key_mgr.c +++ b/components/esp_hw_support/esp_key_mgr.c @@ -74,6 +74,7 @@ static void esp_key_mgr_acquire_hardware(void) // Reset the Key Manager Clock KEY_MANAGER_RCC_ATOMIC() { key_mgr_ll_enable_bus_clock(true); + key_mgr_ll_enable_peripheral_clock(true); key_mgr_ll_reset_register(); } } @@ -83,6 +84,7 @@ static void esp_key_mgr_release_hardware(void) esp_crypto_key_manager_lock_release(); // Reset the Key Manager Clock KEY_MANAGER_RCC_ATOMIC() { + key_mgr_ll_enable_peripheral_clock(false); key_mgr_ll_enable_bus_clock(false); key_mgr_ll_reset_register(); } diff --git a/components/hal/esp32p4/include/hal/key_mgr_ll.h b/components/hal/esp32p4/include/hal/key_mgr_ll.h index 1bcd5402bf..bcf68a199f 100644 --- a/components/hal/esp32p4/include/hal/key_mgr_ll.h +++ b/components/hal/esp32p4/include/hal/key_mgr_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -41,12 +41,24 @@ static inline void key_mgr_ll_enable_bus_clock(bool enable) /// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance #define key_mgr_ll_enable_bus_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; key_mgr_ll_enable_bus_clock(__VA_ARGS__) +/** + * @brief Enable the peripheral clock for Key Manager + * + * @param true to enable, false to disable + */ +static inline void key_mgr_ll_enable_peripheral_clock(bool enable) +{ + HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_km_clk_en = enable; +} + +#define key_mgr_ll_enable_peripheral_clock(...) (void)__DECLARE_RCC_ATOMIC_ENV; key_mgr_ll_enable_bus_clock(__VA_ARGS__) + /** * @brief Reset the Key Manager peripheral */ static inline void key_mgr_ll_reset_register(void) { - HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_km_clk_en = 1; - HP_SYS_CLKRST.peri_clk_ctrl25.reg_crypto_km_clk_en = 0; + HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_km = 1; + HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_km = 0; HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 1; HP_SYS_CLKRST.hp_rst_en2.reg_rst_en_crypto = 0; }