diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index 0c68d09134..4235e184e2 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -151,6 +151,10 @@ if(NOT non_os_build) list(APPEND srcs "power_supply/brownout.c") endif() + if(CONFIG_ESP_VBAT_INIT_AUTO) + list(APPEND srcs "power_supply/vbat.c") + endif() + else() if(ESP_TEE_BUILD) list(APPEND srcs "esp_clk.c" "hw_random.c") diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index 2fbfad0b40..e184b5dea5 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -247,7 +247,7 @@ menu "Hardware Settings" orsource "./port/$IDF_TARGET/Kconfig.ldo" - orsource "./power_supply/port/$IDF_TARGET/Kconfig.bod" + orsource "./power_supply/port/$IDF_TARGET/Kconfig.power" # Invisible bringup bypass options for esp_hw_support component config ESP_BRINGUP_BYPASS_CPU_CLK_SETTING diff --git a/components/esp_hw_support/power_supply/brownout.c b/components/esp_hw_support/power_supply/brownout.c index aa20d8c46c..d2b73df4d8 100644 --- a/components/esp_hw_support/power_supply/brownout.c +++ b/components/esp_hw_support/power_supply/brownout.c @@ -91,7 +91,8 @@ void esp_brownout_init(void) #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 rtc_isr_register(rtc_brownout_isr_handler, NULL, RTC_CNTL_BROWN_OUT_INT_ENA_M, RTC_INTR_FLAG_IRAM); #else - esp_intr_alloc_intrstatus(power_supply_periph_signal.irq, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED, (uint32_t)brownout_ll_intr_get_status_reg(), BROWNOUT_DETECTOR_LL_INTERRUPT_MASK, &rtc_brownout_isr_handler, NULL, NULL); + intr_handle_t bod_intr; + esp_intr_alloc_intrstatus(power_supply_periph_signal.irq, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED, (uint32_t)brownout_ll_intr_get_status_reg(), BROWNOUT_DETECTOR_LL_INTERRUPT_MASK, &rtc_brownout_isr_handler, NULL, &bod_intr); #endif brownout_ll_intr_enable(true); diff --git a/components/esp_hw_support/power_supply/include/esp_private/vbat.h b/components/esp_hw_support/power_supply/include/esp_private/vbat.h new file mode 100644 index 0000000000..bfba630a2b --- /dev/null +++ b/components/esp_hw_support/power_supply/include/esp_private/vbat.h @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include "esp_err.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Initialize the VBAT (RTC Backup Battery) management system. + * + * @return + * - ESP_OK: Initialization was successful. + */ +esp_err_t esp_vbat_init(void); + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_hw_support/power_supply/port/esp32/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32/Kconfig.bod deleted file mode 100644 index b79c97eb6b..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32/Kconfig.bod +++ /dev/null @@ -1,64 +0,0 @@ -menu "Brownout Detector" - - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_0 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each ESP chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_0 - bool "2.43V +/- 0.05" - config ESP_BROWNOUT_DET_LVL_SEL_1 - bool "2.48V +/- 0.05" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "2.58V +/- 0.05" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "2.62V +/- 0.05" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.67V +/- 0.05" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.70V +/- 0.05" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.77V +/- 0.05" - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.80V +/- 0.05" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 0 if ESP_BROWNOUT_DET_LVL_SEL_0 - default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - Two occasions need to restart the chip with interrupt so far. - (1). For ESP32 version 1, brown-out reset function doesn't work (see ESP32 errata 3.4). - So that we must restart from interrupt. - (2). For special workflow, the chip needs do more things instead of restarting directly. This part - needs to be done in callback function of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32/Kconfig.power new file mode 100644 index 0000000000..628b3bfa8d --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32/Kconfig.power @@ -0,0 +1,68 @@ +menu "Power Supplier" + + menu "Brownout Detector" + + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_0 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each ESP chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_0 + bool "2.43V +/- 0.05" + config ESP_BROWNOUT_DET_LVL_SEL_1 + bool "2.48V +/- 0.05" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "2.58V +/- 0.05" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "2.62V +/- 0.05" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.67V +/- 0.05" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.70V +/- 0.05" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.77V +/- 0.05" + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.80V +/- 0.05" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 0 if ESP_BROWNOUT_DET_LVL_SEL_0 + default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + Two occasions need to restart the chip with interrupt so far. + (1). For ESP32 version 1, brown-out reset function doesn't work (see ESP32 errata 3.4). + So that we must restart from interrupt. + (2). For special workflow, the chip needs do more things instead of restarting directly. This part + needs to be done in callback function of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c2/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32c2/Kconfig.bod deleted file mode 100644 index 0d0fb822e7..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32c2/Kconfig.bod +++ /dev/null @@ -1,55 +0,0 @@ -menu "Brownout Detector" - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-C2 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_7 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.51V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.64V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.76V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.92V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "3.10V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "3.27V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c2/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32c2/Kconfig.power new file mode 100644 index 0000000000..a57499977b --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32c2/Kconfig.power @@ -0,0 +1,59 @@ +menu "Power Supplier" + + menu "Brownout Detector" + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-C2 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_7 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.51V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.64V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.76V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.92V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "3.10V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "3.27V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c3/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32c3/Kconfig.bod deleted file mode 100644 index 19eb8e94d9..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32c3/Kconfig.bod +++ /dev/null @@ -1,55 +0,0 @@ -menu "Brownout Detector" - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-C3 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_7 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.51V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.64V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.76V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.92V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "3.10V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "3.27V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c3/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32c3/Kconfig.power new file mode 100644 index 0000000000..4b0903f401 --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32c3/Kconfig.power @@ -0,0 +1,59 @@ +menu "Power Supplier" + + menu "Brownout Detector" + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-C3 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_7 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.51V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.64V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.76V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.92V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "3.10V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "3.27V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c5/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32c5/Kconfig.bod deleted file mode 100644 index 4583c6bee3..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32c5/Kconfig.bod +++ /dev/null @@ -1,55 +0,0 @@ -menu "Brownout Detector" - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA && SOC_BOD_SUPPORTED - default y - help - The ESP32-C5 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_7 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.51V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.64V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.76V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.92V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "3.10V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "3.27V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c5/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32c5/Kconfig.power new file mode 100644 index 0000000000..1bc2552c8b --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32c5/Kconfig.power @@ -0,0 +1,59 @@ +menu "Power Supplier" + + menu "Brownout Detector" + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-C5 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_7 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.51V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.64V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.76V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.92V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "3.10V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "3.27V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c6/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32c6/Kconfig.bod deleted file mode 100644 index 5c3d440e83..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32c6/Kconfig.bod +++ /dev/null @@ -1,55 +0,0 @@ -menu "Brownout Detector" - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-C6 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_7 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.51V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.64V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.76V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.92V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "3.10V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "3.27V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c6/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32c6/Kconfig.power new file mode 100644 index 0000000000..cccc749093 --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32c6/Kconfig.power @@ -0,0 +1,59 @@ +menu "Power Supplier" + + menu "Brownout Detector" + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-C6 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_7 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.51V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.64V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.76V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.92V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "3.10V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "3.27V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c61/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32c61/Kconfig.bod deleted file mode 100644 index f1b083e18a..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32c61/Kconfig.bod +++ /dev/null @@ -1,55 +0,0 @@ -menu "Brownout Detector" - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-C61 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_7 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.51V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.64V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.76V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.92V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "3.10V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "3.27V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32c61/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32c61/Kconfig.power new file mode 100644 index 0000000000..50291ad626 --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32c61/Kconfig.power @@ -0,0 +1,59 @@ +menu "Power Supplier" + + menu "Brownout Detector" + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-C61 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_7 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.51V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.64V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.76V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.92V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "3.10V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "3.27V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32h2/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32h2/Kconfig.bod deleted file mode 100644 index d0a38ee74f..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32h2/Kconfig.bod +++ /dev/null @@ -1,61 +0,0 @@ -menu "Brownout Detector" - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-H2 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_0 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.94V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.88V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.83V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.78V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "2.73V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "2.67V" - config ESP_BROWNOUT_DET_LVL_SEL_1 - bool "2.62V" - config ESP_BROWNOUT_DET_LVL_SEL_0 - bool "2.57V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 0 if ESP_BROWNOUT_DET_LVL_SEL_0 - default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32h2/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32h2/Kconfig.power new file mode 100644 index 0000000000..441d6d5683 --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32h2/Kconfig.power @@ -0,0 +1,65 @@ +menu "Power Supplier" + + menu "Brownout Detector" + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-H2 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_0 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.94V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.88V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.83V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.78V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "2.73V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "2.67V" + config ESP_BROWNOUT_DET_LVL_SEL_1 + bool "2.62V" + config ESP_BROWNOUT_DET_LVL_SEL_0 + bool "2.57V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 0 if ESP_BROWNOUT_DET_LVL_SEL_0 + default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32h21/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32h21/Kconfig.bod deleted file mode 100644 index 61eca9bba6..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32h21/Kconfig.bod +++ /dev/null @@ -1,61 +0,0 @@ -menu "Brownout Detector" - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-H21 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_0 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.94V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.88V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.83V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.78V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "2.73V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "2.67V" - config ESP_BROWNOUT_DET_LVL_SEL_1 - bool "2.62V" - config ESP_BROWNOUT_DET_LVL_SEL_0 - bool "2.57V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 0 if ESP_BROWNOUT_DET_LVL_SEL_0 - default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32h21/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32h21/Kconfig.power new file mode 100644 index 0000000000..d01bbdfe72 --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32h21/Kconfig.power @@ -0,0 +1,65 @@ +menu "Power Supplier" + + menu "Brownout Detector" + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-H21 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_0 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.94V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.88V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.83V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.78V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "2.73V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "2.67V" + config ESP_BROWNOUT_DET_LVL_SEL_1 + bool "2.62V" + config ESP_BROWNOUT_DET_LVL_SEL_0 + bool "2.57V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 0 if ESP_BROWNOUT_DET_LVL_SEL_0 + default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32p4/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32p4/Kconfig.bod deleted file mode 100644 index 14a7a2dc23..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32p4/Kconfig.bod +++ /dev/null @@ -1,49 +0,0 @@ -menu "Brownout Detector" - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-P4 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - default ESP_BROWNOUT_DET_LVL_SEL_7 - depends on ESP_BROWNOUT_DET - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each chip. - - Please note that this config is only valid when P4 SOC version is above v1.0. When you are using a - earlier P4 SOC version (v0.x), the brownout value should be fixed around 2.52V and not configurable. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.6V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.52V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.42V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32p4/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32p4/Kconfig.power new file mode 100644 index 0000000000..2e308de598 --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32p4/Kconfig.power @@ -0,0 +1,159 @@ +menu "Power Supplier" + + menu "Brownout Detector" + + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-P4 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + default ESP_BROWNOUT_DET_LVL_SEL_7 + depends on ESP_BROWNOUT_DET + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each chip. + + Please note that this config is only valid when P4 SOC version is above v1.0. When you are using a + earlier P4 SOC version (v0.x), the brownout value should be fixed around 2.52V and not configurable. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.6V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.52V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.42V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + + menu "RTC Backup Battery" + + config ESP_VBAT_INIT_AUTO + bool "Enable VBAT power supply for RTC battery" + default n + depends on SOC_VBAT_SUPPORTED + help + Enable this option to allow the use of a button cell battery to power the RTC (Real-Time Clock) domain. + When this option is enabled, the hardware will configure VBAT as the power supply source for the RTC. + + - Ensure a compatible battery (2.5V ~ 3.6V) is connected to the VBAT pin. + - The VBAT battery provides power to retain RTC state and keep low-power peripherals active + during deep sleep. + - When this option is disabled, the RTC battery input (VBAT) must not be left floating. + + config ESP_VBAT_USE_RECHARGEABLE_BATTERY + bool "The battery for RTC battery is a rechargeable battery" + default n + depends on ESP_VBAT_INIT_AUTO + help + Select this option if the RTC backup battery used in your design is a rechargeable battery. + + When enabled, the system will configure the RTC battery management circuitry to operate + in a mode suitable for charging a rechargeable battery. This includes enabling + charging current regulation via resistor and voltage monitoring to ensure safe and efficient charging. + + Use this option carefully to avoid damage to non-rechargeable batteries. + + choice ESP_VBAT_DET_LVL_LOW_SEL + prompt "VBAT start charging voltage level" + default ESP_VBAT_DET_LVL_LOW_SEL_6 + depends on ESP_VBAT_USE_RECHARGEABLE_BATTERY + help + The brownout detector will start charging when the supply voltage drops below the selected threshold. + This ensures that the power supply is maintained at a stable level. + + config ESP_VBAT_DET_LVL_LOW_SEL_7 + bool "2.6V" + config ESP_VBAT_DET_LVL_LOW_SEL_6 + bool "2.52V" + config ESP_VBAT_DET_LVL_LOW_SEL_5 + bool "2.42V" + endchoice + + choice ESP_VBAT_DET_LVL_HIGH_SEL + prompt "VBAT stop charging voltage level" + default ESP_VBAT_DET_LVL_HIGH_SEL_7 + depends on ESP_VBAT_USE_RECHARGEABLE_BATTERY + help + The brownout detector will stop charging when the supply voltage arrives the selected threshold. + + config ESP_VBAT_DET_LVL_HIGH_SEL_7 + bool "2.6V" + config ESP_VBAT_DET_LVL_HIGH_SEL_6 + bool "2.52V" + config ESP_VBAT_DET_LVL_HIGH_SEL_5 + bool "2.42V" + endchoice + + choice ESP_VBAT_BROWNOUT_DET_LVL_SEL + prompt "VBAT brownout voltage level" + default ESP_VBAT_BROWNOUT_DET_LVL_SEL_5 + depends on ESP_VBAT_INIT_AUTO + help + The brownout detector will git a brownout signal when vbat brownout detected. + + config ESP_VBAT_BROWNOUT_DET_LVL_SEL_7 + bool "2.6V" + config ESP_VBAT_BROWNOUT_DET_LVL_SEL_6 + bool "2.52V" + config ESP_VBAT_BROWNOUT_DET_LVL_SEL_5 + bool "2.42V" + endchoice + + config ESP_VBAT_DET_LVL_LOW + int + depends on ESP_VBAT_USE_RECHARGEABLE_BATTERY + default 5 if ESP_VBAT_DET_LVL_LOW_SEL_5 + default 6 if ESP_VBAT_DET_LVL_LOW_SEL_6 + default 7 if ESP_VBAT_DET_LVL_LOW_SEL_7 + + config ESP_VBAT_DET_LVL_HIGH + int + depends on ESP_VBAT_USE_RECHARGEABLE_BATTERY + default 5 if ESP_VBAT_DET_LVL_HIGH_SEL_5 + default 6 if ESP_VBAT_DET_LVL_HIGH_SEL_6 + default 7 if ESP_VBAT_DET_LVL_HIGH_SEL_7 + + config ESP_VBAT_BROWNOUT_DET_LVL + int + default 5 if ESP_VBAT_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_VBAT_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_VBAT_BROWNOUT_DET_LVL_SEL_7 + + config ESP_VBAT_CHARGER_CIRCUIT_RESISTOR_VAL + int "vbat charger circuit resistor value (ohms), should be multiple of 500" + depends on ESP_VBAT_USE_RECHARGEABLE_BATTERY + range 1000 8500 + default 1000 + help + The resistor value of charger circuit. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32s2/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32s2/Kconfig.bod deleted file mode 100644 index d7103f235c..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32s2/Kconfig.bod +++ /dev/null @@ -1,59 +0,0 @@ -menu "Brownout Detector" - - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-S2 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_7 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each ESP3-S2 chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.44V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.56V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.67V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.84V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "2.98V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "3.19V" - config ESP_BROWNOUT_DET_LVL_SEL_1 - bool "3.30V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32s2/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32s2/Kconfig.power new file mode 100644 index 0000000000..56611086c3 --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32s2/Kconfig.power @@ -0,0 +1,63 @@ +menu "Power Supplier" + + menu "Brownout Detector" + + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-S2 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_7 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each ESP3-S2 chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.44V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.56V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.67V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.84V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "2.98V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "3.19V" + config ESP_BROWNOUT_DET_LVL_SEL_1 + bool "3.30V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32s3/Kconfig.bod b/components/esp_hw_support/power_supply/port/esp32s3/Kconfig.bod deleted file mode 100644 index 6db64c1147..0000000000 --- a/components/esp_hw_support/power_supply/port/esp32s3/Kconfig.bod +++ /dev/null @@ -1,59 +0,0 @@ -menu "Brownout Detector" - - config ESP_BROWNOUT_DET - bool "Hardware brownout detect & reset" - depends on !IDF_ENV_FPGA - default y - help - The ESP32-S3 has a built-in brownout detector which can detect if the voltage is lower than - a specific value. If this happens, it will reset the chip in order to prevent unintended - behaviour. - - choice ESP_BROWNOUT_DET_LVL_SEL - prompt "Brownout voltage level" - depends on ESP_BROWNOUT_DET - default ESP_BROWNOUT_DET_LVL_SEL_7 - help - The brownout detector will reset the chip when the supply voltage is approximately - below this level. Note that there may be some variation of brownout voltage level - between each ESP3-S3 chip. - - #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages - #of the brownout threshold levels. - config ESP_BROWNOUT_DET_LVL_SEL_7 - bool "2.44V" - config ESP_BROWNOUT_DET_LVL_SEL_6 - bool "2.56V" - config ESP_BROWNOUT_DET_LVL_SEL_5 - bool "2.67V" - config ESP_BROWNOUT_DET_LVL_SEL_4 - bool "2.84V" - config ESP_BROWNOUT_DET_LVL_SEL_3 - bool "2.98V" - config ESP_BROWNOUT_DET_LVL_SEL_2 - bool "3.19V" - config ESP_BROWNOUT_DET_LVL_SEL_1 - bool "3.30V" - endchoice - - config ESP_BROWNOUT_DET_LVL - int - default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 - default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 - default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 - default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 - default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 - default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 - default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 - - config ESP_BROWNOUT_USE_INTR - bool - default n - help - This config allows to trigger an interrupt when brownout detected. Software restart will be done - at the end of the default callback. - This is because for some special workflow, the chip needs do more things when brownout happens - before restart instead of restarting directly. This part needs to be done in callback function - of interrupt. - -endmenu diff --git a/components/esp_hw_support/power_supply/port/esp32s3/Kconfig.power b/components/esp_hw_support/power_supply/port/esp32s3/Kconfig.power new file mode 100644 index 0000000000..d8a3d5ac10 --- /dev/null +++ b/components/esp_hw_support/power_supply/port/esp32s3/Kconfig.power @@ -0,0 +1,63 @@ +menu "Power Supplier" + + menu "Brownout Detector" + + config ESP_BROWNOUT_DET + bool "Hardware brownout detect & reset" + depends on !IDF_ENV_FPGA + default y + help + The ESP32-S3 has a built-in brownout detector which can detect if the voltage is lower than + a specific value. If this happens, it will reset the chip in order to prevent unintended + behaviour. + + choice ESP_BROWNOUT_DET_LVL_SEL + prompt "Brownout voltage level" + depends on ESP_BROWNOUT_DET + default ESP_BROWNOUT_DET_LVL_SEL_7 + help + The brownout detector will reset the chip when the supply voltage is approximately + below this level. Note that there may be some variation of brownout voltage level + between each ESP3-S3 chip. + + #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages + #of the brownout threshold levels. + config ESP_BROWNOUT_DET_LVL_SEL_7 + bool "2.44V" + config ESP_BROWNOUT_DET_LVL_SEL_6 + bool "2.56V" + config ESP_BROWNOUT_DET_LVL_SEL_5 + bool "2.67V" + config ESP_BROWNOUT_DET_LVL_SEL_4 + bool "2.84V" + config ESP_BROWNOUT_DET_LVL_SEL_3 + bool "2.98V" + config ESP_BROWNOUT_DET_LVL_SEL_2 + bool "3.19V" + config ESP_BROWNOUT_DET_LVL_SEL_1 + bool "3.30V" + endchoice + + config ESP_BROWNOUT_DET_LVL + int + default 1 if ESP_BROWNOUT_DET_LVL_SEL_1 + default 2 if ESP_BROWNOUT_DET_LVL_SEL_2 + default 3 if ESP_BROWNOUT_DET_LVL_SEL_3 + default 4 if ESP_BROWNOUT_DET_LVL_SEL_4 + default 5 if ESP_BROWNOUT_DET_LVL_SEL_5 + default 6 if ESP_BROWNOUT_DET_LVL_SEL_6 + default 7 if ESP_BROWNOUT_DET_LVL_SEL_7 + + config ESP_BROWNOUT_USE_INTR + bool + default n + help + This config allows to trigger an interrupt when brownout detected. Software restart will be done + at the end of the default callback. + This is because for some special workflow, the chip needs do more things when brownout happens + before restart instead of restarting directly. This part needs to be done in callback function + of interrupt. + + endmenu + +endmenu diff --git a/components/esp_hw_support/power_supply/vbat.c b/components/esp_hw_support/power_supply/vbat.c new file mode 100644 index 0000000000..6b360a58fc --- /dev/null +++ b/components/esp_hw_support/power_supply/vbat.c @@ -0,0 +1,92 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include "esp_attr.h" +#include "esp_intr_alloc.h" +#include "hal/vbat_ll.h" +#include "hal/brownout_ll.h" +#include "hal/vbat_hal.h" +#include "freertos/FreeRTOS.h" +#include "sdkconfig.h" +#include "esp_private/startup_internal.h" +#include "esp_check.h" +#include "soc/power_supply_periph.h" + +#define VBAT_BROWNOUT_DET_LVL CONFIG_ESP_VBAT_BROWNOUT_DET_LVL + +#if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY +#define VBAT_CHARGE_DET_LVL_LOW CONFIG_ESP_VBAT_DET_LVL_LOW +#define VBAT_CHARGE_DET_LVL_HIGH CONFIG_ESP_VBAT_DET_LVL_HIGH +#define VBAT_CHARGER_RESISTOR_VALUE CONFIG_ESP_VBAT_CHARGER_CIRCUIT_RESISTOR_VAL + +#if (VBAT_CHARGER_RESISTOR_VALUE < 1000 || VBAT_CHARGER_RESISTOR_VALUE > 4500 || VBAT_CHARGER_RESISTOR_VALUE % 500 != 0) +#error "vbat charger resistor (ESP_VBAT_CHARGER_CIRCUIT_RESISTOR_VAL) must be between 1000 and 4500 ohms and must be a multiple of 500." +#endif + +#if (VBAT_BROWNOUT_DET_LVL >= VBAT_CHARGE_DET_LVL_LOW) +#error "vbat charger low threshold is equal or lower than vbat brownout threshold, please put vbat brownout threshold lower than vbat charger low threshold" +#endif + +#endif + +static const char TAG[] = "VBAT"; + +IRAM_ATTR static void vbat_isr_handler(void *arg) +{ + uint32_t int_status; + vbat_ll_get_interrupt_status(&int_status); + vbat_ll_clear_intr_mask(int_status); + + if (int_status & VBAT_LL_CHARGER_UNDERVOLTAGE_INTR) { + ESP_DRAM_LOGW(TAG, "RTC battery voltage low, start charging..."); + vbat_ll_start_battery_charge(true); + } + + if (int_status & VBAT_LL_CHARGER_UPVOLTAGE_INTR) { + ESP_DRAM_LOGW(TAG, "RTC battery voltage reaches high limit , stop charging..."); + vbat_ll_start_battery_charge(false); + } + + if (int_status & VBAT_LL_BROWNOUT_INTR) { + // TODO: A callback may needed here to inform an under voltage event. + ESP_DRAM_LOGW(TAG, "RTC battery voltage low, please change battery..."); + } + +} + +esp_err_t esp_vbat_init(void) +{ + intr_handle_t vbat_intr; +#if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY + vbat_hal_config_t vbat_cfg = { + .enable_vbat_charger = true, + .charger_resistor_value = VBAT_CHARGER_RESISTOR_VALUE, + .low_threshold = VBAT_CHARGE_DET_LVL_LOW, + .high_threshold = VBAT_CHARGE_DET_LVL_HIGH, + .brownout_threshold = VBAT_BROWNOUT_DET_LVL, + .undervoltage_filter_time = 20, + .upvoltage_filter_time = 10, + .interrupt_mask = (VBAT_LL_CHARGER_MASK | VBAT_LL_DETECT_MASK), + }; + +#else + vbat_hal_config_t vbat_cfg = { + .enable_vbat_charger = false, + .brownout_threshold = VBAT_BROWNOUT_DET_LVL, + .interrupt_mask = VBAT_LL_DETECT_MASK, + }; +#endif + + vbat_hal_config(&vbat_cfg); + + ESP_RETURN_ON_ERROR(esp_intr_alloc_intrstatus(power_supply_periph_signal.irq, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_SHARED, (uint32_t)brownout_ll_intr_get_status_reg(), VBAT_LL_CHARGER_MASK | VBAT_LL_DETECT_MASK, &vbat_isr_handler, NULL, &vbat_intr), TAG, "Allocate vbat isr failed"); + + return ESP_OK; +} diff --git a/components/esp_system/startup_funcs.c b/components/esp_system/startup_funcs.c index 5c7ce44492..2855dc325a 100644 --- a/components/esp_system/startup_funcs.c +++ b/components/esp_system/startup_funcs.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -41,6 +41,7 @@ #include "esp_private/esp_clk.h" #include "esp_private/spi_flash_os.h" #include "esp_private/brownout.h" +#include "esp_private/vbat.h" #include "esp_rom_caps.h" #include "esp_rom_sys.h" @@ -78,6 +79,7 @@ ESP_SYSTEM_INIT_FN(init_brownout, CORE, BIT(0), 104) { // [refactor-todo] leads to call chain rtc_is_register (driver) -> esp_intr_alloc (esp32/esp32s2) -> // malloc (newlib) -> heap_caps_malloc (heap), so heap must be at least initialized + esp_err_t ret = ESP_OK; #if CONFIG_ESP_BROWNOUT_DET esp_brownout_init(); #else @@ -85,7 +87,12 @@ ESP_SYSTEM_INIT_FN(init_brownout, CORE, BIT(0), 104) brownout_ll_ana_reset_enable(false); #endif // SOC_CAPS_NO_RESET_BY_ANA_BOD #endif // CONFIG_ESP_BROWNOUT_DET - return ESP_OK; + +#if CONFIG_ESP_VBAT_INIT_AUTO + ret = esp_vbat_init(); +#endif + + return ret; } #endif diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 47c1d8a404..4fd7ac1757 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -217,6 +217,10 @@ if(NOT BOOTLOADER_BUILD AND NOT esp_tee_build) list(APPEND srcs "brownout_hal.c") endif() + if(CONFIG_SOC_VBAT_SUPPORTED) + list(APPEND srcs "vbat_hal.c") + endif() + if(CONFIG_SOC_JPEG_CODEC_SUPPORTED) list(APPEND srcs "jpeg_hal.c") endif() diff --git a/components/hal/esp32c5/include/hal/brownout_ll.h b/components/hal/esp32c5/include/hal/brownout_ll.h index e103d2639c..af0f6c8122 100644 --- a/components/hal/esp32c5/include/hal/brownout_ll.h +++ b/components/hal/esp32c5/include/hal/brownout_ll.h @@ -121,7 +121,7 @@ static inline void brownout_ll_ana_reset_enable(bool enable) __attribute__((always_inline)) static inline void brownout_ll_intr_clear(void) { - LP_ANA_PERI.int_clr.bod_mode0_int_clr = 1; + LP_ANA_PERI.int_clr.val = BROWNOUT_DETECTOR_LL_INTERRUPT_MASK; } /** diff --git a/components/hal/esp32c6/include/hal/brownout_ll.h b/components/hal/esp32c6/include/hal/brownout_ll.h index 61248cfe47..b70875a9fd 100644 --- a/components/hal/esp32c6/include/hal/brownout_ll.h +++ b/components/hal/esp32c6/include/hal/brownout_ll.h @@ -121,7 +121,7 @@ static inline void brownout_ll_ana_reset_enable(bool enable) __attribute__((always_inline)) static inline void brownout_ll_intr_clear(void) { - LP_ANA_PERI.int_clr.bod_mode0 = 1; + LP_ANA_PERI.int_clr.val = BROWNOUT_DETECTOR_LL_INTERRUPT_MASK; } /** diff --git a/components/hal/esp32c61/include/hal/brownout_ll.h b/components/hal/esp32c61/include/hal/brownout_ll.h index ac3b966d56..8991ec6f93 100644 --- a/components/hal/esp32c61/include/hal/brownout_ll.h +++ b/components/hal/esp32c61/include/hal/brownout_ll.h @@ -121,7 +121,7 @@ static inline void brownout_ll_ana_reset_enable(bool enable) __attribute__((always_inline)) static inline void brownout_ll_intr_clear(void) { - LP_ANA.int_clr.bod_mode0_int_clr = 1; + LP_ANA.int_clr.val = BROWNOUT_DETECTOR_LL_INTERRUPT_MASK; } /** diff --git a/components/hal/esp32h2/include/hal/brownout_ll.h b/components/hal/esp32h2/include/hal/brownout_ll.h index 9dce284ac8..8816a36a4a 100644 --- a/components/hal/esp32h2/include/hal/brownout_ll.h +++ b/components/hal/esp32h2/include/hal/brownout_ll.h @@ -122,7 +122,7 @@ static inline void brownout_ll_ana_reset_enable(bool enable) __attribute__((always_inline)) static inline void brownout_ll_intr_clear(void) { - LP_ANA_PERI.int_clr.bod_mode0_int_clr = 1; + LP_ANA_PERI.int_clr.val = BROWNOUT_DETECTOR_LL_INTERRUPT_MASK; } /** diff --git a/components/hal/esp32p4/include/hal/brownout_ll.h b/components/hal/esp32p4/include/hal/brownout_ll.h index 9f13dde6af..7f7a47de50 100644 --- a/components/hal/esp32p4/include/hal/brownout_ll.h +++ b/components/hal/esp32p4/include/hal/brownout_ll.h @@ -102,6 +102,8 @@ static inline void brownout_ll_set_intr_wait_cycles(uint8_t cycle) * @brief Enable brown out interrupt * * @param enable true: enable, false: disable + * + * @note Avoid concurrency risky with vbat_ll_enable_intr_mask */ static inline void brownout_ll_intr_enable(bool enable) { @@ -127,7 +129,7 @@ static inline void brownout_ll_ana_reset_enable(bool enable) __attribute__((always_inline)) static inline void brownout_ll_intr_clear(void) { - LP_ANA_PERI.int_clr.bod_mode0_int_clr = 1; + LP_ANA_PERI.int_clr.val = BROWNOUT_DETECTOR_LL_INTERRUPT_MASK; } /** diff --git a/components/hal/esp32p4/include/hal/vbat_ll.h b/components/hal/esp32p4/include/hal/vbat_ll.h new file mode 100644 index 0000000000..be742e38ae --- /dev/null +++ b/components/hal/esp32p4/include/hal/vbat_ll.h @@ -0,0 +1,162 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/******************************************************************************* + * NOTICE + * The ll is not public api, don't use in application code. + * See readme.md in hal/readme.md + ******************************************************************************/ + +#pragma once + +#include +#include "esp_bit_defs.h" +#include "soc/lp_analog_peri_struct.h" +#include "hal/regi2c_ctrl.h" +#include "soc/regi2c_brownout.h" + + +typedef enum { + VBAT_LL_CHARGER_UPVOLTAGE_INTR = BIT(27), + VBAT_LL_CHARGER_UNDERVOLTAGE_INTR = BIT(28), + VBAT_LL_BROWNOUT_INTR = BIT(30), +} vbat_ll_intr_t; + +#define VBAT_LL_CHARGER_MASK (BIT(27)|BIT(28)) +#define VBAT_LL_DETECT_MASK (BIT(30)) + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Set vbat brownout threshold voltage + * + * @param threshold vbat brownout threshold + */ +static inline void vbat_ll_set_brownout_threshold(uint8_t threshold) +{ + // Give same value + REGI2C_WRITE_MASK(I2C_BOD, I2C_BIAS_OR_DREF_VBAT_L, threshold); + REGI2C_WRITE_MASK(I2C_BOD, I2C_BIAS_OR_DREF_VBAT_H, threshold); +} + +/** + * @brief Set vbat charge threshold voltage + * + * @param threshold vbat charge threshold + */ +static inline void vbat_ll_set_charger_threshold(uint8_t threshold_l, uint8_t threshold_h) +{ + REGI2C_WRITE_MASK(I2C_BOD, I2C_BIAS_OR_DREF_VBAT_CHARGER_L, threshold_l); + REGI2C_WRITE_MASK(I2C_BOD, I2C_BIAS_OR_DREF_VBAT_CHARGER_H, threshold_h); +} + +/** + * @brief Enable or disable the VBAT charger comparator + * + * @param enable Set to `true` to enable the comparator, or `false` to disable it. + */ +static inline void vbat_ll_enable_charger_comparator(bool enable) +{ + REGI2C_WRITE_MASK(I2C_BOD, I2C_BIAS_OR_FORCE_PU_VBAT_CHARGER, enable); +} + +/** + * @brief Set the under voltage filter time for the charger detector + * + * @param time_tick The filter time in ticks (unit depends on the hardware implementation). + */ +static inline void vbat_ll_set_undervoltage_filter_time(uint32_t time_tick) +{ + LP_ANA_PERI.vddbat_charge_cntl.vddbat_charge_undervoltage_target = time_tick; +} + +/** + * @brief Set the upvoltage filter time for the charger detector + * + * @param time_tick The filter time in ticks (unit depends on the hardware implementation). + */ +static inline void vbat_ll_set_upvoltage_filter_time(uint32_t time_tick) +{ + LP_ANA_PERI.vddbat_charge_cntl.vddbat_charge_upvoltage_target = time_tick; +} + +/** + * @brief Set the charger resistor value for VBAT charging + * + * @param resistor Resistor value to be set (unit depends on the hardware implementation). + */ +static inline void vbat_ll_set_charger_resistor(uint32_t resistor) +{ + REGI2C_WRITE_MASK(I2C_BOD, I2C_BIAS_OR_DRES_CHARGER, resistor); +} + +/* + * @brief Start or stop the VBAT battery charging process + * + * @param start Set to true to start charging, or false to stop charging. + */ +static inline void vbat_ll_start_battery_charge(bool start) +{ + LP_ANA_PERI.vddbat_bod_cntl.vddbat_charger = start; +} + +/** + * @brief Enable the interrupt mask for vbat usage + * + * @param mask A bitmask representing the interrupts to enable. + * Each bit corresponds to a specific interrupt source. + * @param enable true for enabling the interrupt, otherwise false. + * + * @note Avoid concurrency risky with brownout_ll_intr_enable + */ +static inline void vbat_ll_enable_intr_mask(uint32_t mask, bool enable) +{ + if (enable) { + LP_ANA_PERI.int_ena.val |= mask; + } else { + LP_ANA_PERI.int_ena.val &= ~mask; + } +} + +/** + * @brief Clear the interrupt mask for vbat usage + * + * @param mask A bitmask representing the interrupts to clear. + * Each bit corresponds to a specific interrupt source. + */ +static inline void vbat_ll_clear_intr_mask(uint32_t mask) +{ + LP_ANA_PERI.int_clr.val = mask; +} + +/** + * @brief Get the current interrupt mask for vbat usage + * + * @param intr_status Pointer to a variable where the interrupt status mask will be stored. + * The function will write the current interrupt status to this variable. + */ +static inline void vbat_ll_get_interrupt_status(uint32_t *intr_status) +{ + *intr_status = LP_ANA_PERI.int_st.val; +} + +/** + * @brief Clear the VBAT count for charge detection + * + * This function clears the internal counter that tracks the number of charge events detected + * related to the VBAT power supply. It is typically used to reset the count for monitoring purposes. + */ +static inline void vbat_ll_clear_count(void) +{ + LP_ANA_PERI.vddbat_charge_cntl.vddbat_charge_cnt_clr = 1; + LP_ANA_PERI.vddbat_charge_cntl.vddbat_charge_cnt_clr = 0; +} + +#ifdef __cplusplus +} +#endif diff --git a/components/hal/include/hal/vbat_hal.h b/components/hal/include/hal/vbat_hal.h new file mode 100644 index 0000000000..e450ed7127 --- /dev/null +++ b/components/hal/include/hal/vbat_hal.h @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint32_t interrupt_mask; // interrupt mask. + uint16_t charger_resistor_value; // charger resistor value + bool enable_vbat_charger; // whether enable vbat charger comparator + uint8_t low_threshold; // low voltage threshold + uint8_t high_threshold; // high voltage threshold + uint8_t brownout_threshold; // brownout threshold + uint8_t undervoltage_filter_time; // under voltage filter time + uint8_t upvoltage_filter_time; // up voltage filter time +} vbat_hal_config_t; + +/** + * @brief Config vbat hal. + * + * @param cfg Pointer of vbat configuration structure. + */ +void vbat_hal_config(const vbat_hal_config_t *cfg); + +#ifdef __cplusplus +} +#endif diff --git a/components/hal/vbat_hal.c b/components/hal/vbat_hal.c new file mode 100644 index 0000000000..b37e1e8081 --- /dev/null +++ b/components/hal/vbat_hal.c @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "hal/vbat_ll.h" +#include "hal/vbat_hal.h" + +void vbat_hal_config(const vbat_hal_config_t *cfg) +{ + vbat_ll_clear_count(); + vbat_ll_enable_charger_comparator(cfg->enable_vbat_charger); + if (cfg->enable_vbat_charger) { + uint8_t resistor_reg = (cfg->charger_resistor_value - 1000) / 500; + vbat_ll_set_charger_resistor(resistor_reg); + vbat_ll_set_charger_threshold(cfg->low_threshold, cfg->high_threshold); + vbat_ll_set_undervoltage_filter_time(cfg->undervoltage_filter_time); + vbat_ll_set_upvoltage_filter_time(cfg->upvoltage_filter_time); + } + vbat_ll_set_brownout_threshold(cfg->brownout_threshold); + vbat_ll_enable_intr_mask(cfg->interrupt_mask, true); +} diff --git a/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in b/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in index c62bcfd0cd..c84b7e5670 100644 --- a/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in @@ -219,6 +219,10 @@ config SOC_BOD_SUPPORTED bool default y +config SOC_VBAT_SUPPORTED + bool + default y + config SOC_APM_SUPPORTED bool default y diff --git a/components/soc/esp32p4/include/soc/regi2c_brownout.h b/components/soc/esp32p4/include/soc/regi2c_brownout.h index b7297808f4..6637ae9662 100644 --- a/components/soc/esp32p4/include/soc/regi2c_brownout.h +++ b/components/soc/esp32p4/include/soc/regi2c_brownout.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,3 +23,26 @@ #define I2C_BOD_THRESHOLD_H 0x9 #define I2C_BOD_THRESHOLD_H_MSB 7 #define I2C_BOD_THRESHOLD_H_LSB 5 + +#define I2C_BIAS_OR_DREF_VBAT_L 8 +#define I2C_BIAS_OR_DREF_VBAT_L_MSB 4 +#define I2C_BIAS_OR_DREF_VBAT_L_LSB 2 +#define I2C_BIAS_OR_DREF_VBAT_H 8 +#define I2C_BIAS_OR_DREF_VBAT_H_MSB 7 +#define I2C_BIAS_OR_DREF_VBAT_H_LSB 5 + +#define I2C_BIAS_OR_DREF_VBAT_CHARGER_L 10 +#define I2C_BIAS_OR_DREF_VBAT_CHARGER_L_MSB 4 +#define I2C_BIAS_OR_DREF_VBAT_CHARGER_L_LSB 2 +#define I2C_BIAS_OR_DREF_VBAT_CHARGER_H 10 +#define I2C_BIAS_OR_DREF_VBAT_CHARGER_H_MSB 7 +#define I2C_BIAS_OR_DREF_VBAT_CHARGER_H_LSB 5 + +#define I2C_BIAS_OR_FORCE_PU_VBAT_CHARGER 10 +#define I2C_BIAS_OR_FORCE_PU_VBAT_CHARGER_MSB 0 +#define I2C_BIAS_OR_FORCE_PU_VBAT_CHARGER_LSB 0 + +/** Change the charging current by adjusting the value of the series resistor. 1kΩ + N * 0.5kΩ */ +#define I2C_BIAS_OR_DRES_CHARGER 3 +#define I2C_BIAS_OR_DRES_CHARGER_MSB 7 +#define I2C_BIAS_OR_DRES_CHARGER_LSB 4 diff --git a/components/soc/esp32p4/include/soc/soc_caps.h b/components/soc/esp32p4/include/soc/soc_caps.h index b09328f48c..e7833aec90 100644 --- a/components/soc/esp32p4/include/soc/soc_caps.h +++ b/components/soc/esp32p4/include/soc/soc_caps.h @@ -71,6 +71,7 @@ #define SOC_FLASH_ENC_SUPPORTED 1 #define SOC_SECURE_BOOT_SUPPORTED 1 #define SOC_BOD_SUPPORTED 1 +#define SOC_VBAT_SUPPORTED 1 #define SOC_APM_SUPPORTED 1 #define SOC_PMU_SUPPORTED 1 #define SOC_DCDC_SUPPORTED 1