Skip to content

Commit d91dfe3

Browse files
committed
change(esp_hw_support/sleep): improve esp32c3 systimer stall bug workaround
1 parent 8805685 commit d91dfe3

File tree

7 files changed

+29
-48
lines changed

7 files changed

+29
-48
lines changed

components/esp_hw_support/Kconfig

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,6 @@ menu "Hardware Settings"
214214
callback and hence it is highly recommended to keep them as short as possible.
215215
endmenu
216216

217-
menu "ESP_SLEEP_WORKAROUND"
218-
# No visible menu/configs for workaround
219-
visible if 0
220-
config ESP_SLEEP_SYSTIMER_STALL_WORKAROUND
221-
bool "ESP32C3 SYSTIMER Stall Issue Workaround"
222-
depends on IDF_TARGET_ESP32C3
223-
help
224-
Its not able to stall ESP32C3 systimer in sleep.
225-
To fix related RTOS TICK issue, select it to disable related systimer during sleep.
226-
TODO: IDF-7036
227-
endmenu
228-
229217
menu "RTC Clock Config"
230218
orsource "./port/$IDF_TARGET/Kconfig.rtc"
231219
endmenu

components/esp_hw_support/port/esp32c3/include/soc/rtc.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -646,18 +646,6 @@ void rtc_sleep_init(rtc_sleep_config_t cfg);
646646
*/
647647
void rtc_sleep_low_init(uint32_t slowclk_period);
648648

649-
#if CONFIG_ESP_SLEEP_SYSTIMER_STALL_WORKAROUND
650-
/**
651-
* @brief Configure systimer for esp32c3 systimer stall issue workaround
652-
*
653-
* This function configures related systimer for esp32c3 systimer stall issue.
654-
* Only apply workaround when xtal powered up.
655-
*
656-
* @param en enable systimer or not
657-
*/
658-
void rtc_sleep_systimer_enable(bool en);
659-
#endif
660-
661649
#define RTC_GPIO_TRIG_EN BIT(2) //!< GPIO wakeup
662650
#define RTC_TIMER_TRIG_EN BIT(3) //!< Timer wakeup
663651
#define RTC_WIFI_TRIG_EN BIT(5) //!< WIFI wakeup (light sleep only)

components/esp_hw_support/port/esp32c3/rtc_sleep.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "soc/regi2c_dig_reg.h"
2525
#include "soc/regi2c_lp_bias.h"
2626
#include "hal/efuse_hal.h"
27-
#if CONFIG_ESP_SLEEP_SYSTIMER_STALL_WORKAROUND
27+
#if SOC_SLEEP_SYSTIMER_STALL_WORKAROUND
2828
#include "soc/systimer_reg.h"
2929
#endif
3030

@@ -252,17 +252,6 @@ void rtc_sleep_low_init(uint32_t slowclk_period)
252252
REG_SET_FIELD(RTC_CNTL_TIMER1_REG, RTC_CNTL_CK8M_WAIT, RTC_CNTL_CK8M_WAIT_SLP_CYCLES);
253253
}
254254

255-
#if CONFIG_ESP_SLEEP_SYSTIMER_STALL_WORKAROUND
256-
void rtc_sleep_systimer_enable(bool en)
257-
{
258-
if (en) {
259-
REG_SET_BIT(SYSTIMER_CONF_REG, SYSTIMER_TIMER_UNIT1_WORK_EN);
260-
} else {
261-
REG_CLR_BIT(SYSTIMER_CONF_REG, SYSTIMER_TIMER_UNIT1_WORK_EN);
262-
}
263-
}
264-
#endif
265-
266255
static uint32_t rtc_sleep_finish(uint32_t lslp_mem_inf_fpu);
267256

268257
uint32_t rtc_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu)

components/esp_hw_support/sleep_modes.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include "hal/rtc_io_hal.h"
3131
#include "hal/clk_tree_hal.h"
3232

33+
#if SOC_SLEEP_SYSTIMER_STALL_WORKAROUND
34+
#include "hal/systimer_ll.h"
35+
#endif
36+
3337
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
3438
#include "esp_private/pm_impl.h"
3539
#endif
@@ -870,11 +874,6 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
870874
}
871875
}
872876

873-
#if CONFIG_ESP_SLEEP_SYSTIMER_STALL_WORKAROUND
874-
if (!(pd_flags & RTC_SLEEP_PD_XTAL)) {
875-
rtc_sleep_systimer_enable(false);
876-
}
877-
#endif
878877

879878
if (should_skip_sleep) {
880879
result = ESP_ERR_SLEEP_REJECT;
@@ -883,9 +882,9 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
883882
#endif
884883
} else {
885884
#if CONFIG_ESP_SLEEP_DEBUG
886-
if (s_sleep_ctx != NULL) {
887-
s_sleep_ctx->wakeup_triggers = s_config.wakeup_triggers;
888-
}
885+
if (s_sleep_ctx != NULL) {
886+
s_sleep_ctx->wakeup_triggers = s_config.wakeup_triggers;
887+
}
889888
#endif
890889
if (deep_sleep) {
891890
#if !SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP
@@ -913,6 +912,13 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
913912
result = rtc_deep_sleep_start(s_config.wakeup_triggers, reject_triggers);
914913
#endif
915914
} else {
915+
#if SOC_SLEEP_SYSTIMER_STALL_WORKAROUND
916+
if (!(pd_flags & RTC_SLEEP_PD_XTAL)) {
917+
for (uint32_t counter_id = 0; counter_id < SOC_SYSTIMER_COUNTER_NUM; ++counter_id) {
918+
systimer_ll_enable_counter(&SYSTIMER, counter_id, false);
919+
}
920+
}
921+
#endif
916922
/* Cache Suspend 1: will wait cache idle in cache suspend */
917923
suspend_cache();
918924
/* On esp32c6, only the lp_aon pad hold function can only hold the GPIO state in the active mode.
@@ -977,13 +983,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
977983
#endif
978984
/* Cache Resume 1: Resume cache for continue running*/
979985
resume_cache();
980-
}
981-
982-
#if CONFIG_ESP_SLEEP_SYSTIMER_STALL_WORKAROUND
986+
#if SOC_SLEEP_SYSTIMER_STALL_WORKAROUND
983987
if (!(pd_flags & RTC_SLEEP_PD_XTAL)) {
984-
rtc_sleep_systimer_enable(true);
988+
for (uint32_t counter_id = 0; counter_id < SOC_SYSTIMER_COUNTER_NUM; ++counter_id) {
989+
systimer_ll_enable_counter(&SYSTIMER, counter_id, true);
990+
}
985991
}
986992
#endif
993+
}
987994
}
988995
#if CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION
989996
if (pd_flags & RTC_SLEEP_PD_VDDSDIO) {

components/esp_timer/src/esp_timer_impl_systimer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ esp_err_t esp_timer_impl_early_init(void)
180180
systimer_hal_select_alarm_mode(&systimer_hal, SYSTIMER_ALARM_ESPTIMER, SYSTIMER_ALARM_MODE_ONESHOT);
181181
systimer_hal_connect_alarm_counter(&systimer_hal, SYSTIMER_ALARM_ESPTIMER, SYSTIMER_COUNTER_ESPTIMER);
182182

183+
for (unsigned cpuid = 0; cpuid < SOC_CPU_CORES_NUM; ++cpuid) {
184+
systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_ESPTIMER, cpuid, (cpuid < portNUM_PROCESSORS) ? true : false);
185+
}
186+
183187
return ESP_OK;
184188
}
185189

components/soc/esp32c3/include/soc/Kconfig.soc_caps.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ config SOC_RTC_CNTL_CPU_PD_REG_FILE_NUM
619619
int
620620
default 108
621621

622+
config SOC_SLEEP_SYSTIMER_STALL_WORKAROUND
623+
bool
624+
default y
625+
622626
config SOC_RTCIO_PIN_COUNT
623627
int
624628
default 0

components/soc/esp32c3/include/soc/soc_caps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257

258258
#define SOC_RTC_CNTL_CPU_PD_RETENTION_MEM_SIZE (SOC_RTC_CNTL_CPU_PD_REG_FILE_NUM * (SOC_RTC_CNTL_CPU_PD_DMA_BUS_WIDTH >> 3))
259259

260+
#define SOC_SLEEP_SYSTIMER_STALL_WORKAROUND 1
260261
/*-------------------------- RTCIO CAPS --------------------------------------*/
261262
/* No dedicated RTCIO subsystem on ESP32-C3. RTC functions are still supported
262263
* for hold, wake & 32kHz crystal functions - via rtc_cntl_reg */

0 commit comments

Comments
 (0)