Skip to content

Commit 26d6f0f

Browse files
author
sibeibei
committed
fix(pm): fix tbtt interrupt timing error when BLE RTC is configured to use MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL on C6EC01 and later version
1 parent 38628f9 commit 26d6f0f

File tree

7 files changed

+15
-26
lines changed

7 files changed

+15
-26
lines changed

components/esp_hw_support/include/esp_private/esp_pmu.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,6 @@ bool pmu_sleep_finish(bool dslp);
332332
*/
333333
void pmu_init(void);
334334

335-
/**
336-
* @brief Enable or disable system clock in PMU HP sleep state
337-
*
338-
* This API only used for fix BLE 40 MHz low power clock source issue
339-
*
340-
* @param enable true to enable, false to disable
341-
*/
342-
void pmu_sleep_enable_hp_sleep_sysclk(bool enable);
343-
344335
/**
345336
* Get the time overhead used by regdma to work on the retention link during the hardware wake-up process
346337
* @return regdma time cost during hardware wake-up stage in microseconds

components/esp_hw_support/include/esp_private/esp_sleep_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ typedef enum {
9494
ESP_SLEEP_CLOCK_UART1, //!< The clock ICG cell mapping of UART1
9595
#if SOC_UART_HP_NUM > 2
9696
ESP_SLEEP_CLOCK_UART2, //!< The clock ICG cell mapping of UART2
97+
#endif
98+
#if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND
99+
ESP_SLEEP_CLOCK_BT_USE_WIFI_PWR_CLK, //!< The clock ICG cell remapping of RETENTION
97100
#endif
98101
ESP_SLEEP_CLOCK_MAX //!< Number of ICG cells
99102
} esp_sleep_clock_t;

components/esp_hw_support/modem_clock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "soc/soc_caps.h"
1414
#include "freertos/FreeRTOS.h"
1515
#include "esp_private/esp_modem_clock.h"
16+
#include "esp_private/esp_sleep_internal.h"
1617
#include "esp_private/esp_pmu.h"
1718
#include "esp_sleep.h"
1819
#include "hal/efuse_hal.h"
@@ -408,7 +409,7 @@ void modem_clock_select_lp_clock_source(periph_module_t module, modem_clock_lpcl
408409
#if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND
409410
if (efuse_hal_chip_revision() != 0) {
410411
if (src == MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL) {
411-
pmu_sleep_enable_hp_sleep_sysclk(true);
412+
esp_sleep_clock_config(ESP_SLEEP_CLOCK_BT_USE_WIFI_PWR_CLK, ESP_SLEEP_CLOCK_OPTION_UNGATE);
412413
modem_clock_hal_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal, true);
413414
modem_clock_domain_clk_gate_disable(MODEM_CLOCK_DOMAIN_WIFIPWR, PMU_HP_ICG_MODEM_CODE_SLEEP);
414415
}
@@ -481,7 +482,7 @@ void modem_clock_deselect_lp_clock_source(periph_module_t module)
481482
#if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND && SOC_LIGHT_SLEEP_SUPPORTED // TODO: [ESP32C5] IDF-8643
482483
if (efuse_hal_chip_revision() != 0) {
483484
if (last_src == MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL) {
484-
pmu_sleep_enable_hp_sleep_sysclk(false);
485+
esp_sleep_clock_config(ESP_SLEEP_CLOCK_BT_USE_WIFI_PWR_CLK, ESP_SLEEP_CLOCK_OPTION_GATE);
485486
modem_clock_hal_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal, false);
486487
modem_clock_domain_clk_gate_enable(MODEM_CLOCK_DOMAIN_WIFIPWR, PMU_HP_ICG_MODEM_CODE_SLEEP);
487488
}

components/esp_hw_support/port/esp32c5/pmu_sleep.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,6 @@ bool pmu_sleep_finish(bool dslp)
328328
return pmu_ll_hp_is_sleep_reject(PMU_instance()->hal->dev);
329329
}
330330

331-
void pmu_sleep_enable_hp_sleep_sysclk(bool enable)
332-
{
333-
pmu_ll_hp_set_icg_sysclk_enable(PMU_instance()->hal->dev, HP(SLEEP), enable);
334-
}
335-
336331
uint32_t pmu_sleep_get_wakup_retention_cost(void)
337332
{
338333
const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc;

components/esp_hw_support/port/esp32c6/pmu_sleep.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,6 @@ bool pmu_sleep_finish(bool dslp)
391391
return pmu_ll_hp_is_sleep_reject(PMU_instance()->hal->dev);
392392
}
393393

394-
void pmu_sleep_enable_hp_sleep_sysclk(bool enable)
395-
{
396-
pmu_ll_hp_set_icg_sysclk_enable(PMU_instance()->hal->dev, HP(SLEEP), enable);
397-
}
398-
399394
uint32_t pmu_sleep_get_wakup_retention_cost(void)
400395
{
401396
const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc;

components/esp_hw_support/port/esp32c61/pmu_sleep.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,6 @@ bool pmu_sleep_finish(bool dslp)
327327
return pmu_ll_hp_is_sleep_reject(PMU_instance()->hal->dev);
328328
}
329329

330-
void pmu_sleep_enable_hp_sleep_sysclk(bool enable)
331-
{
332-
pmu_ll_hp_set_icg_sysclk_enable(PMU_instance()->hal->dev, HP(SLEEP), enable);
333-
}
334-
335330
uint32_t pmu_sleep_get_wakup_retention_cost(void)
336331
{
337332
const pmu_sleep_machine_constant_t *mc = (pmu_sleep_machine_constant_t *)PMU_instance()->mc;

components/esp_hw_support/sleep_modes.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,15 @@ static SLEEP_FN_ATTR uint32_t get_sleep_clock_icg_flags(void)
26462646
clk_flags |= BIT(PMU_ICG_FUNC_ENA_UART2);
26472647
}
26482648
#endif
2649+
#if SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND
2650+
/* Starting from C6ECO1 and later versions, when BLE RTC is configured to use
2651+
* MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL,the actual slow clock source is the WiFi power clock.
2652+
* As all 32 bits of ICG_FUNC are occupied, the ESP_SLEEP_CLOCK_BT_USE_WIFI_PWR_CLK
2653+
* has been remapped to PMU_ICG_FUNC_ENA_RETENTION.*/
2654+
if (s_config.clock_icg_refs[ESP_SLEEP_CLOCK_BT_USE_WIFI_PWR_CLK] > 0) {
2655+
clk_flags |= BIT(PMU_ICG_FUNC_ENA_RETENTION);
2656+
}
2657+
#endif
26492658
#endif /* SOC_PM_SUPPORT_PMU_CLK_ICG */
26502659
return clk_flags;
26512660
}

0 commit comments

Comments
 (0)