Merge branch 'feature/esp32c3_support_brownout' into 'master'

esp32c3: Adds support BROWNOUT reset

Closes IDF-2397

See merge request espressif/esp-idf!11910
This commit is contained in:
Angus Gratton 2021-01-20 12:19:56 +08:00
commit 55970fe3a2
7 changed files with 34 additions and 19 deletions

View File

@ -78,9 +78,8 @@ menu "ESP32C3-Specific"
e.g. GCOV data dump. e.g. GCOV data dump.
config ESP32C3_BROWNOUT_DET config ESP32C3_BROWNOUT_DET
# TODO ESP32-C3 IDF-2397
bool bool
default n default y
help help
The ESP32-S3 has a built-in brownout detector which can detect if the voltage is lower than 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 a specific value. If this happens, it will reset the chip in order to prevent unintended
@ -93,29 +92,26 @@ menu "ESP32C3-Specific"
help help
The brownout detector will reset the chip when the supply voltage is approximately 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 below this level. Note that there may be some variation of brownout voltage level
between each ESP3-S3 chip. between each chip.
#The voltage levels here are estimates, more work needs to be done to figure out the exact voltages #The voltage levels here are estimates, more work needs to be done to figure out the exact voltages
#of the brownout threshold levels. #of the brownout threshold levels.
config ESP32C3_BROWNOUT_DET_LVL_SEL_7 config ESP32C3_BROWNOUT_DET_LVL_SEL_7
bool "2.44V" bool "2.51V"
config ESP32C3_BROWNOUT_DET_LVL_SEL_6 config ESP32C3_BROWNOUT_DET_LVL_SEL_6
bool "2.56V" bool "2.64V"
config ESP32C3_BROWNOUT_DET_LVL_SEL_5 config ESP32C3_BROWNOUT_DET_LVL_SEL_5
bool "2.67V" bool "2.76V"
config ESP32C3_BROWNOUT_DET_LVL_SEL_4 config ESP32C3_BROWNOUT_DET_LVL_SEL_4
bool "2.84V" bool "2.92V"
config ESP32C3_BROWNOUT_DET_LVL_SEL_3 config ESP32C3_BROWNOUT_DET_LVL_SEL_3
bool "2.98V" bool "3.10V"
config ESP32C3_BROWNOUT_DET_LVL_SEL_2 config ESP32C3_BROWNOUT_DET_LVL_SEL_2
bool "3.19V" bool "3.27V"
config ESP32C3_BROWNOUT_DET_LVL_SEL_1
bool "3.30V"
endchoice endchoice
config ESP32C3_BROWNOUT_DET_LVL config ESP32C3_BROWNOUT_DET_LVL
int int
default 1 if ESP32C3_BROWNOUT_DET_LVL_SEL_1
default 2 if ESP32C3_BROWNOUT_DET_LVL_SEL_2 default 2 if ESP32C3_BROWNOUT_DET_LVL_SEL_2
default 3 if ESP32C3_BROWNOUT_DET_LVL_SEL_3 default 3 if ESP32C3_BROWNOUT_DET_LVL_SEL_3
default 4 if ESP32C3_BROWNOUT_DET_LVL_SEL_4 default 4 if ESP32C3_BROWNOUT_DET_LVL_SEL_4

View File

@ -35,6 +35,10 @@
#define BROWNOUT_DET_LVL CONFIG_ESP32_BROWNOUT_DET_LVL #define BROWNOUT_DET_LVL CONFIG_ESP32_BROWNOUT_DET_LVL
#elif defined(CONFIG_ESP32S2_BROWNOUT_DET_LVL) #elif defined(CONFIG_ESP32S2_BROWNOUT_DET_LVL)
#define BROWNOUT_DET_LVL CONFIG_ESP32S2_BROWNOUT_DET_LVL #define BROWNOUT_DET_LVL CONFIG_ESP32S2_BROWNOUT_DET_LVL
#elif defined(CONFIG_ESP32S3_BROWNOUT_DET_LVL)
#define BROWNOUT_DET_LVL CONFIG_ESP32S3_BROWNOUT_DET_LVL
#elif defined(CONFIG_ESP32C3_BROWNOUT_DET_LVL)
#define BROWNOUT_DET_LVL CONFIG_ESP32C3_BROWNOUT_DET_LVL
#else #else
#define BROWNOUT_DET_LVL 0 #define BROWNOUT_DET_LVL 0
#endif #endif
@ -45,7 +49,7 @@
#define BROWNOUT_RESET_EN false #define BROWNOUT_RESET_EN false
#endif // SOC_BROWNOUT_RESET_SUPPORTED #endif // SOC_BROWNOUT_RESET_SUPPORTED
#ifndef SOC_BROWNOUT_RESET_SUPPORTED
static void rtc_brownout_isr_handler(void *arg) static void rtc_brownout_isr_handler(void *arg)
{ {
/* Normally RTC ISR clears the interrupt flag after the application-supplied /* Normally RTC ISR clears the interrupt flag after the application-supplied
@ -61,6 +65,7 @@ static void rtc_brownout_isr_handler(void *arg)
esp_rom_printf("\r\nBrownout detector was triggered\r\n\r\n"); esp_rom_printf("\r\nBrownout detector was triggered\r\n\r\n");
esp_restart_noos(); esp_restart_noos();
} }
#endif // not SOC_BROWNOUT_RESET_SUPPORTED
void esp_brownout_init(void) void esp_brownout_init(void)
{ {
@ -74,7 +79,9 @@ void esp_brownout_init(void)
brownout_hal_config(&cfg); brownout_hal_config(&cfg);
#ifndef SOC_BROWNOUT_RESET_SUPPORTED
rtc_isr_register(rtc_brownout_isr_handler, NULL, RTC_CNTL_BROWN_OUT_INT_ENA_M); rtc_isr_register(rtc_brownout_isr_handler, NULL, RTC_CNTL_BROWN_OUT_INT_ENA_M);
brownout_hal_intr_enable(true); brownout_hal_intr_enable(true);
#endif // not SOC_BROWNOUT_RESET_SUPPORTED
} }

View File

@ -242,7 +242,10 @@ static void do_core_init(void)
#endif #endif
} }
#if CONFIG_ESP32_BROWNOUT_DET || CONFIG_ESP32S2_BROWNOUT_DET #if CONFIG_ESP32_BROWNOUT_DET || \
CONFIG_ESP32S2_BROWNOUT_DET || \
CONFIG_ESP32S3_BROWNOUT_DET || \
CONFIG_ESP32C3_BROWNOUT_DET
// [refactor-todo] leads to call chain rtc_is_register (driver) -> esp_intr_alloc (esp32/esp32s2) -> // [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 // malloc (newlib) -> heap_caps_malloc (heap), so heap must be at least initialized
esp_brownout_init(); esp_brownout_init();

View File

@ -264,7 +264,6 @@ TEST_CASE_MULTIPLE_STAGES("reset reason ESP_RST_WDT after RTC watchdog",
check_reset_reason_any_wdt); check_reset_reason_any_wdt);
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3) // TODO ESP32-C3 IDF-2397
static void do_brownout(void) static void do_brownout(void)
{ {
setup_values(); setup_values();
@ -289,7 +288,6 @@ TEST_CASE_MULTIPLE_STAGES("reset reason ESP_RST_BROWNOUT after brownout event",
"[reset_reason][ignore][reset="BROWNOUT"]", "[reset_reason][ignore][reset="BROWNOUT"]",
do_brownout, do_brownout,
check_reset_reason_brownout); check_reset_reason_brownout);
#endif // TODO ESP32-C3 IDF-2397
#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY #ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY

View File

@ -22,15 +22,24 @@
void brownout_hal_config(const brownout_hal_config_t *cfg) void brownout_hal_config(const brownout_hal_config_t *cfg)
{ {
// TODO ESP32-C3 IDF-2397 REGI2C_WRITE_MASK(I2C_BOD, I2C_BOD_THRESHOLD, cfg->threshold);
typeof(RTCCNTL.brown_out) brown_out_reg = {
.close_flash_ena = cfg->flash_power_down,
.pd_rf_ena = cfg->rf_power_down,
.rst_wait = 0x3ff,
.rst_ena = cfg->reset_enabled,
.ena = cfg->enabled,
.rst_sel = 1,
};
RTCCNTL.brown_out = brown_out_reg;
} }
void brownout_hal_intr_enable(bool enable) void brownout_hal_intr_enable(bool enable)
{ {
// TODO ESP32-C3 IDF-2397 RTCCNTL.int_ena.rtc_brown_out = enable;
} }
void brownout_hal_intr_clear(void) void brownout_hal_intr_clear(void)
{ {
// TODO ESP32-C3 IDF-2397 RTCCNTL.int_clr.rtc_brown_out = 1;
} }

View File

@ -31,6 +31,7 @@ void brownout_hal_config(const brownout_hal_config_t *cfg)
.rst_wait = 0x3ff, .rst_wait = 0x3ff,
.rst_ena = cfg->reset_enabled, .rst_ena = cfg->reset_enabled,
.ena = cfg->enabled, .ena = cfg->enabled,
.rst_sel = 1,
}; };
RTCCNTL.brown_out = brown_out_reg; RTCCNTL.brown_out = brown_out_reg;
} }

View File

@ -30,6 +30,7 @@ void brownout_hal_config(const brownout_hal_config_t *cfg)
.rst_wait = 0x3ff, .rst_wait = 0x3ff,
.rst_ena = cfg->reset_enabled, .rst_ena = cfg->reset_enabled,
.ena = cfg->enabled, .ena = cfg->enabled,
.rst_sel = 1,
}; };
RTCCNTL.brown_out = brown_out_reg; RTCCNTL.brown_out = brown_out_reg;
} }