Skip to content

Commit

Permalink
Merge branch 'bugfix/bod_reset_c6_h2_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
fix(bod): Reset brownout in configuration to avoid RF cannot be enabled again(backport v5.1)

See merge request espressif/esp-idf!27723
  • Loading branch information
suda-morris committed Dec 14, 2023
2 parents e3ca11c + 9dd90e2 commit 1b78d57
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 3 deletions.
8 changes: 5 additions & 3 deletions 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
*/
Expand All @@ -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"
Expand All @@ -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)
{
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions components/hal/brownout_hal.c
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions components/hal/esp32/include/hal/brownout_ll.h
Expand Up @@ -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
10 changes: 10 additions & 0 deletions components/hal/esp32c2/include/hal/brownout_ll.h
Expand Up @@ -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
9 changes: 9 additions & 0 deletions components/hal/esp32c3/include/hal/brownout_ll.h
Expand Up @@ -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
9 changes: 9 additions & 0 deletions components/hal/esp32c6/include/hal/brownout_ll.h
Expand Up @@ -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
9 changes: 9 additions & 0 deletions components/hal/esp32h2/include/hal/brownout_ll.h
Expand Up @@ -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
10 changes: 10 additions & 0 deletions components/hal/esp32s2/include/hal/brownout_ll.h
Expand Up @@ -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
9 changes: 9 additions & 0 deletions components/hal/esp32s3/include/hal/brownout_ll.h
Expand Up @@ -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

0 comments on commit 1b78d57

Please sign in to comment.