Skip to content

Commit 50cd05c

Browse files
committed
Merge branch 'refactor/move_bod_to_hw_support' into 'master'
refactor(bod): Move brownout handling file from esp_system to esp_hw_support See merge request espressif/esp-idf!36191
2 parents e73f27f + 5e4fd8e commit 50cd05c

File tree

48 files changed

+433
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+433
-185
lines changed

components/esp_hw_support/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ if(NOT non_os_build)
146146
if(CONFIG_SOC_GPIO_CLOCKOUT_BY_GPIO_MATRIX OR CONFIG_SOC_GPIO_CLOCKOUT_BY_IO_MUX)
147147
list(APPEND srcs "esp_clock_output.c")
148148
endif()
149+
150+
if(CONFIG_SOC_BOD_SUPPORTED)
151+
list(APPEND srcs "power_supply/brownout.c")
152+
endif()
153+
149154
else()
150155
if(ESP_TEE_BUILD)
151156
list(APPEND srcs "esp_clk.c" "hw_random.c")
@@ -156,7 +161,7 @@ endif()
156161

157162
set(public_include_dirs "include" "include/soc" "include/soc/${target}"
158163
"dma/include" "ldo/include" "debug_probe/include"
159-
"mspi_timing_tuning/include")
164+
"mspi_timing_tuning/include" "power_supply/include")
160165

161166
if(CONFIG_IDF_TARGET_ESP32H21)
162167
list(REMOVE_ITEM srcs

components/esp_hw_support/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ menu "Hardware Settings"
247247

248248
orsource "./port/$IDF_TARGET/Kconfig.ldo"
249249

250+
orsource "./power_supply/port/$IDF_TARGET/Kconfig.bod"
251+
250252
# Invisible bringup bypass options for esp_hw_support component
251253
config ESP_BRINGUP_BYPASS_CPU_CLK_SETTING
252254
bool

components/esp_hw_support/port/esp32/Kconfig.hw_support

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ choice ESP32_REV_MIN
1212
config ESP32_REV_MIN_0
1313
bool "Rev v0.0 (ECO0)"
1414
# Brownout on Rev 0 is bugged, must use interrupt
15-
select ESP_SYSTEM_BROWNOUT_INTR
15+
select ESP_BROWNOUT_USE_INTR
1616
config ESP32_REV_MIN_1
1717
bool "Rev v1.0 (ECO1)"
1818
config ESP32_REV_MIN_1_1

components/esp_system/port/brownout.c renamed to components/esp_hw_support/power_supply/brownout.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -25,6 +25,7 @@
2525
#include "sdkconfig.h"
2626
#include "esp_rom_uart.h"
2727
#include "hal/uart_ll.h"
28+
#include "soc/power_supply_periph.h"
2829

2930
#if defined(CONFIG_ESP_BROWNOUT_DET_LVL)
3031
#define BROWNOUT_DET_LVL CONFIG_ESP_BROWNOUT_DET_LVL
@@ -34,7 +35,7 @@
3435

3536
static __attribute__((unused)) DRAM_ATTR const char TAG[] = "BOD";
3637

37-
#if CONFIG_ESP_SYSTEM_BROWNOUT_INTR
38+
#if CONFIG_ESP_BROWNOUT_USE_INTR
3839
IRAM_ATTR static void rtc_brownout_isr_handler(void *arg)
3940
{
4041
/* Normally RTC ISR clears the interrupt flag after the application-supplied
@@ -71,11 +72,11 @@ IRAM_ATTR static void rtc_brownout_isr_handler(void *arg)
7172

7273
ESP_INFINITE_LOOP();
7374
}
74-
#endif // CONFIG_ESP_SYSTEM_BROWNOUT_INTR
75+
#endif // CONFIG_ESP_BROWNOUT_USE_INTR
7576

7677
void esp_brownout_init(void)
7778
{
78-
#if CONFIG_ESP_SYSTEM_BROWNOUT_INTR
79+
#if CONFIG_ESP_BROWNOUT_USE_INTR
7980
brownout_hal_config_t cfg = {
8081
.threshold = BROWNOUT_DET_LVL,
8182
.enabled = true,
@@ -87,15 +88,12 @@ void esp_brownout_init(void)
8788
brownout_hal_config(&cfg);
8889
brownout_ll_intr_clear();
8990

90-
#if SOC_LP_TIMER_BOD_SHARE_INTR_SOURCE
91-
// TODO IDF-6606: LP_RTC_TIMER interrupt source is shared by lp_timer and brownout detector, but lp_timer interrupt
92-
// is not used now. An interrupt allocator is needed when lp_timer intr gets supported.
93-
esp_intr_alloc_intrstatus(ETS_LP_RTC_TIMER_INTR_SOURCE, 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);
94-
#elif CONFIG_IDF_TARGET_ESP32P4
95-
esp_intr_alloc(ETS_LP_ANAPERI_INTR_SOURCE, ESP_INTR_FLAG_IRAM, &rtc_brownout_isr_handler, NULL, NULL);
96-
#else
91+
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2
9792
rtc_isr_register(rtc_brownout_isr_handler, NULL, RTC_CNTL_BROWN_OUT_INT_ENA_M, RTC_INTR_FLAG_IRAM);
93+
#else
94+
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);
9895
#endif
96+
9997
brownout_ll_intr_enable(true);
10098

10199
#else // brownout without interrupt
@@ -119,8 +117,8 @@ void esp_brownout_disable(void)
119117
};
120118

121119
brownout_hal_config(&cfg);
122-
#if CONFIG_ESP_SYSTEM_BROWNOUT_INTR
120+
#if CONFIG_ESP_BROWNOUT_USE_INTR
123121
brownout_ll_intr_enable(false);
124122
rtc_isr_deregister(rtc_brownout_isr_handler, NULL);
125-
#endif // CONFIG_ESP_SYSTEM_BROWNOUT_INTR
123+
#endif // CONFIG_ESP_BROWNOUT_USE_INTR
126124
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
/**
14+
* @brief Initialize the brownout detection system
15+
*
16+
* This function configures and enables the brownout detection hardware, which monitors
17+
* the power supply voltage and triggers appropriate system actions if the voltage
18+
* drops below a predefined threshold. Brownout detection helps ensure the stability
19+
* and reliability of the system under low-voltage conditions.
20+
*/
21+
void esp_brownout_init(void);
22+
23+
/**
24+
* @brief Disable the brownout detection system
25+
*
26+
* This function disables the brownout detection hardware, stopping voltage monitoring
27+
* and associated system actions. Use this function with caution, as disabling brownout
28+
* detection may increase the risk of system instability or malfunction under low-voltage
29+
* conditions.
30+
*/
31+
void esp_brownout_disable(void);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
menu "Brownout Detector"
2+
3+
config ESP_BROWNOUT_DET
4+
bool "Hardware brownout detect & reset"
5+
depends on !IDF_ENV_FPGA
6+
default y
7+
help
8+
The ESP has a built-in brownout detector which can detect if the voltage is lower than
9+
a specific value. If this happens, it will reset the chip in order to prevent unintended
10+
behaviour.
11+
12+
choice ESP_BROWNOUT_DET_LVL_SEL
13+
prompt "Brownout voltage level"
14+
depends on ESP_BROWNOUT_DET
15+
default ESP_BROWNOUT_DET_LVL_SEL_0
16+
help
17+
The brownout detector will reset the chip when the supply voltage is approximately
18+
below this level. Note that there may be some variation of brownout voltage level
19+
between each ESP chip.
20+
21+
#The voltage levels here are estimates, more work needs to be done to figure out the exact voltages
22+
#of the brownout threshold levels.
23+
config ESP_BROWNOUT_DET_LVL_SEL_0
24+
bool "2.43V +/- 0.05"
25+
config ESP_BROWNOUT_DET_LVL_SEL_1
26+
bool "2.48V +/- 0.05"
27+
config ESP_BROWNOUT_DET_LVL_SEL_2
28+
bool "2.58V +/- 0.05"
29+
config ESP_BROWNOUT_DET_LVL_SEL_3
30+
bool "2.62V +/- 0.05"
31+
config ESP_BROWNOUT_DET_LVL_SEL_4
32+
bool "2.67V +/- 0.05"
33+
config ESP_BROWNOUT_DET_LVL_SEL_5
34+
bool "2.70V +/- 0.05"
35+
config ESP_BROWNOUT_DET_LVL_SEL_6
36+
bool "2.77V +/- 0.05"
37+
config ESP_BROWNOUT_DET_LVL_SEL_7
38+
bool "2.80V +/- 0.05"
39+
endchoice
40+
41+
config ESP_BROWNOUT_DET_LVL
42+
int
43+
default 0 if ESP_BROWNOUT_DET_LVL_SEL_0
44+
default 1 if ESP_BROWNOUT_DET_LVL_SEL_1
45+
default 2 if ESP_BROWNOUT_DET_LVL_SEL_2
46+
default 3 if ESP_BROWNOUT_DET_LVL_SEL_3
47+
default 4 if ESP_BROWNOUT_DET_LVL_SEL_4
48+
default 5 if ESP_BROWNOUT_DET_LVL_SEL_5
49+
default 6 if ESP_BROWNOUT_DET_LVL_SEL_6
50+
default 7 if ESP_BROWNOUT_DET_LVL_SEL_7
51+
52+
config ESP_BROWNOUT_USE_INTR
53+
bool
54+
default n
55+
help
56+
This config allows to trigger an interrupt when brownout detected. Software restart will be done
57+
at the end of the default callback.
58+
Two occasions need to restart the chip with interrupt so far.
59+
(1). For ESP32 version 1, brown-out reset function doesn't work (see ESP32 errata 3.4).
60+
So that we must restart from interrupt.
61+
(2). For special workflow, the chip needs do more things instead of restarting directly. This part
62+
needs to be done in callback function of interrupt.
63+
64+
endmenu

components/esp_system/port/soc/esp32c2/Kconfig.system renamed to components/esp_hw_support/power_supply/port/esp32c2/Kconfig.bod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ menu "Brownout Detector"
4242
default 6 if ESP_BROWNOUT_DET_LVL_SEL_6
4343
default 7 if ESP_BROWNOUT_DET_LVL_SEL_7
4444

45+
config ESP_BROWNOUT_USE_INTR
46+
bool
47+
default n
48+
help
49+
This config allows to trigger an interrupt when brownout detected. Software restart will be done
50+
at the end of the default callback.
51+
This is because for some special workflow, the chip needs do more things when brownout happens
52+
before restart instead of restarting directly. This part needs to be done in callback function
53+
of interrupt.
54+
4555
endmenu

components/esp_system/port/soc/esp32c3/Kconfig.system renamed to components/esp_hw_support/power_supply/port/esp32c3/Kconfig.bod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ menu "Brownout Detector"
4242
default 6 if ESP_BROWNOUT_DET_LVL_SEL_6
4343
default 7 if ESP_BROWNOUT_DET_LVL_SEL_7
4444

45+
config ESP_BROWNOUT_USE_INTR
46+
bool
47+
default n
48+
help
49+
This config allows to trigger an interrupt when brownout detected. Software restart will be done
50+
at the end of the default callback.
51+
This is because for some special workflow, the chip needs do more things when brownout happens
52+
before restart instead of restarting directly. This part needs to be done in callback function
53+
of interrupt.
54+
4555
endmenu

components/esp_system/port/soc/esp32c5/Kconfig.system renamed to components/esp_hw_support/power_supply/port/esp32c5/Kconfig.bod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ menu "Brownout Detector"
4242
default 6 if ESP_BROWNOUT_DET_LVL_SEL_6
4343
default 7 if ESP_BROWNOUT_DET_LVL_SEL_7
4444

45+
config ESP_BROWNOUT_USE_INTR
46+
bool
47+
default n
48+
help
49+
This config allows to trigger an interrupt when brownout detected. Software restart will be done
50+
at the end of the default callback.
51+
This is because for some special workflow, the chip needs do more things when brownout happens
52+
before restart instead of restarting directly. This part needs to be done in callback function
53+
of interrupt.
54+
4555
endmenu

components/esp_system/port/soc/esp32c6/Kconfig.system renamed to components/esp_hw_support/power_supply/port/esp32c6/Kconfig.bod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,14 @@ menu "Brownout Detector"
4242
default 6 if ESP_BROWNOUT_DET_LVL_SEL_6
4343
default 7 if ESP_BROWNOUT_DET_LVL_SEL_7
4444

45+
config ESP_BROWNOUT_USE_INTR
46+
bool
47+
default n
48+
help
49+
This config allows to trigger an interrupt when brownout detected. Software restart will be done
50+
at the end of the default callback.
51+
This is because for some special workflow, the chip needs do more things when brownout happens
52+
before restart instead of restarting directly. This part needs to be done in callback function
53+
of interrupt.
54+
4555
endmenu

0 commit comments

Comments
 (0)