fix(bod): Reset brownout in configuration to avoid RF cannot be enabled again

This commit is contained in:
Cao Sen Miao
2023-11-22 18:35:56 +08:00
parent 5bdcaef8c9
commit 9dd90e2d9b
9 changed files with 71 additions and 3 deletions

View File

@ -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 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -11,7 +11,7 @@
#include "esp_private/system_internal.h" #include "esp_private/system_internal.h"
#include "esp_private/rtc_ctrl.h" #include "esp_private/rtc_ctrl.h"
#include "esp_private/spi_flash_os.h" #include "esp_private/spi_flash_os.h"
#include "esp_rom_sys.h" #include "esp_log.h"
#include "esp_cpu.h" #include "esp_cpu.h"
#include "soc/soc.h" #include "soc/soc.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
@ -28,6 +28,8 @@
#define BROWNOUT_DET_LVL 0 #define BROWNOUT_DET_LVL 0
#endif #endif
static __attribute__((unused)) DRAM_ATTR const char *TAG = "BOD";
#if CONFIG_ESP_SYSTEM_BROWNOUT_INTR #if CONFIG_ESP_SYSTEM_BROWNOUT_INTR
IRAM_ATTR static void rtc_brownout_isr_handler(void *arg) 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 } else
#endif // CONFIG_SPI_FLASH_BROWNOUT_RESET #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(); esp_restart_noos();

View File

@ -15,6 +15,7 @@ void brownout_hal_config(const brownout_hal_config_t *cfg)
brownout_ll_set_intr_wait_cycles(2); brownout_ll_set_intr_wait_cycles(2);
brownout_ll_enable_flash_power_down(cfg->flash_power_down); brownout_ll_enable_flash_power_down(cfg->flash_power_down);
brownout_ll_enable_rf_power_down(cfg->rf_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_reset_config(cfg->reset_enabled, 0x3ff, 1);
brownout_ll_set_threshold(cfg->threshold); brownout_ll_set_threshold(cfg->threshold);
brownout_ll_bod_enable(cfg->enabled); brownout_ll_bod_enable(cfg->enabled);

View File

@ -112,6 +112,15 @@ static inline void brownout_ll_intr_clear(void)
RTCCNTL.int_clr.rtc_brown_out = 1; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -115,6 +115,16 @@ static inline void brownout_ll_intr_clear(void)
RTCCNTL.int_clr.rtc_brown_out = 1; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -115,6 +115,15 @@ static inline void brownout_ll_intr_clear(void)
RTCCNTL.int_clr.rtc_brown_out = 1; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -115,6 +115,15 @@ static inline void brownout_ll_intr_clear(void)
LP_ANA_PERI.int_clr.bod_mode0 = 1; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -115,6 +115,15 @@ static inline void brownout_ll_intr_clear(void)
LP_ANA_PERI.int_clr.bod_mode0_int_clr = 1; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -116,6 +116,16 @@ static inline void brownout_ll_intr_clear(void)
RTCCNTL.int_clr.rtc_brown_out = 1; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -115,6 +115,15 @@ static inline void brownout_ll_intr_clear(void)
RTCCNTL.int_clr.rtc_brown_out = 1; 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 #ifdef __cplusplus
} }
#endif #endif