diff --git a/components/esp_system/port/brownout.c b/components/esp_system/port/brownout.c index cb1e823221..568e1044dd 100644 --- a/components/esp_system/port/brownout.c +++ b/components/esp_system/port/brownout.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,7 +11,7 @@ #include "esp_private/system_internal.h" #include "esp_private/rtc_ctrl.h" #include "esp_private/spi_flash_os.h" -#include "esp_rom_sys.h" +#include "esp_log.h" #include "esp_cpu.h" #include "soc/soc.h" #include "soc/rtc_periph.h" @@ -28,6 +28,8 @@ #define BROWNOUT_DET_LVL 0 #endif +static __attribute__((unused)) DRAM_ATTR const char *TAG = "BOD"; + #if CONFIG_ESP_SYSTEM_BROWNOUT_INTR IRAM_ATTR static void rtc_brownout_isr_handler(void *arg) { @@ -51,7 +53,7 @@ IRAM_ATTR static void rtc_brownout_isr_handler(void *arg) } else #endif // CONFIG_SPI_FLASH_BROWNOUT_RESET { - esp_rom_printf("\r\nBrownout detector was triggered\r\n\r\n"); + ESP_DRAM_LOGI(TAG, "Brownout detector was triggered\r\n\r\n"); } esp_restart_noos(); diff --git a/components/hal/brownout_hal.c b/components/hal/brownout_hal.c index c46dd2e091..b755bdb4fc 100644 --- a/components/hal/brownout_hal.c +++ b/components/hal/brownout_hal.c @@ -15,6 +15,7 @@ void brownout_hal_config(const brownout_hal_config_t *cfg) brownout_ll_set_intr_wait_cycles(2); brownout_ll_enable_flash_power_down(cfg->flash_power_down); brownout_ll_enable_rf_power_down(cfg->rf_power_down); + brownout_ll_clear_count(); brownout_ll_reset_config(cfg->reset_enabled, 0x3ff, 1); brownout_ll_set_threshold(cfg->threshold); brownout_ll_bod_enable(cfg->enabled); diff --git a/components/hal/esp32/include/hal/brownout_ll.h b/components/hal/esp32/include/hal/brownout_ll.h index d18fcfd245..3ebdd8ec8e 100644 --- a/components/hal/esp32/include/hal/brownout_ll.h +++ b/components/hal/esp32/include/hal/brownout_ll.h @@ -112,6 +112,15 @@ static inline void brownout_ll_intr_clear(void) RTCCNTL.int_clr.rtc_brown_out = 1; } +/** + * @brief Clear BOD internal count. + */ +static inline void brownout_ll_clear_count(void) +{ + // Not supported on esp32 +} + + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32c2/include/hal/brownout_ll.h b/components/hal/esp32c2/include/hal/brownout_ll.h index f44f5228c7..77b77a6968 100644 --- a/components/hal/esp32c2/include/hal/brownout_ll.h +++ b/components/hal/esp32c2/include/hal/brownout_ll.h @@ -115,6 +115,16 @@ static inline void brownout_ll_intr_clear(void) RTCCNTL.int_clr.rtc_brown_out = 1; } +/** + * @brief Clear BOD internal count. + */ +static inline void brownout_ll_clear_count(void) +{ + RTCCNTL.brown_out.cnt_clr = 1; + RTCCNTL.brown_out.cnt_clr = 0; +} + + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32c3/include/hal/brownout_ll.h b/components/hal/esp32c3/include/hal/brownout_ll.h index d415ebed53..4a60eb4424 100644 --- a/components/hal/esp32c3/include/hal/brownout_ll.h +++ b/components/hal/esp32c3/include/hal/brownout_ll.h @@ -115,6 +115,15 @@ static inline void brownout_ll_intr_clear(void) RTCCNTL.int_clr.rtc_brown_out = 1; } +/** + * @brief Clear BOD internal count. + */ +static inline void brownout_ll_clear_count(void) +{ + RTCCNTL.brown_out.cnt_clr = 1; + RTCCNTL.brown_out.cnt_clr = 0; +} + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32c6/include/hal/brownout_ll.h b/components/hal/esp32c6/include/hal/brownout_ll.h index e0614583a4..913f99ff0b 100644 --- a/components/hal/esp32c6/include/hal/brownout_ll.h +++ b/components/hal/esp32c6/include/hal/brownout_ll.h @@ -115,6 +115,15 @@ static inline void brownout_ll_intr_clear(void) LP_ANA_PERI.int_clr.bod_mode0 = 1; } +/** + * @brief Clear BOD internal count. + */ +static inline void brownout_ll_clear_count(void) +{ + LP_ANA_PERI.bod_mode0_cntl.bod_mode0_cnt_clr = 1; + LP_ANA_PERI.bod_mode0_cntl.bod_mode0_cnt_clr = 0; +} + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32h2/include/hal/brownout_ll.h b/components/hal/esp32h2/include/hal/brownout_ll.h index 7885decbfd..f0b3d63263 100644 --- a/components/hal/esp32h2/include/hal/brownout_ll.h +++ b/components/hal/esp32h2/include/hal/brownout_ll.h @@ -115,6 +115,15 @@ static inline void brownout_ll_intr_clear(void) LP_ANA_PERI.int_clr.bod_mode0_int_clr = 1; } +/** + * @brief Clear BOD internal count. + */ +static inline void brownout_ll_clear_count(void) +{ + LP_ANA_PERI.bod_mode0_cntl.bod_mode0_cnt_clr = 1; + LP_ANA_PERI.bod_mode0_cntl.bod_mode0_cnt_clr = 0; +} + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32s2/include/hal/brownout_ll.h b/components/hal/esp32s2/include/hal/brownout_ll.h index 6a8b7cfe57..fc13a382e9 100644 --- a/components/hal/esp32s2/include/hal/brownout_ll.h +++ b/components/hal/esp32s2/include/hal/brownout_ll.h @@ -116,6 +116,16 @@ static inline void brownout_ll_intr_clear(void) RTCCNTL.int_clr.rtc_brown_out = 1; } +/** + * @brief Clear BOD internal count. + */ +static inline void brownout_ll_clear_count(void) +{ + RTCCNTL.brown_out.cnt_clr = 1; + RTCCNTL.brown_out.cnt_clr = 0; +} + + #ifdef __cplusplus } #endif diff --git a/components/hal/esp32s3/include/hal/brownout_ll.h b/components/hal/esp32s3/include/hal/brownout_ll.h index 37a2020c12..4cc8d95f67 100644 --- a/components/hal/esp32s3/include/hal/brownout_ll.h +++ b/components/hal/esp32s3/include/hal/brownout_ll.h @@ -115,6 +115,15 @@ static inline void brownout_ll_intr_clear(void) RTCCNTL.int_clr.rtc_brown_out = 1; } +/** + * @brief Clear BOD internal count. + */ +static inline void brownout_ll_clear_count(void) +{ + RTCCNTL.brown_out.cnt_clr = 1; + RTCCNTL.brown_out.cnt_clr = 0; +} + #ifdef __cplusplus } #endif