Skip to content

Commit deed35c

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'fix/fix_coverity_defects_in_sleep_code_v5.3' into 'release/v5.3'
fix(esp_hw_support): fix coverity defects in sleep code (v5.3) See merge request espressif/esp-idf!34108
2 parents 3eef7a1 + 55ff232 commit deed35c

File tree

7 files changed

+33
-26
lines changed

7 files changed

+33
-26
lines changed

components/esp_hw_support/include/esp_private/io_mux.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ esp_err_t io_mux_set_clock_source(soc_module_clk_t clk_src);
3232

3333
#if SOC_LP_IO_CLOCK_IS_INDEPENDENT
3434
typedef struct {
35-
uint8_t rtc_io_enabled_cnt[MAX_RTC_GPIO_NUM];
35+
uint8_t rtc_io_enabled_cnt[MAX_RTC_GPIO_NUM + 1];
3636
uint32_t rtc_io_using_mask;
3737
} rtc_io_status_t;
3838

components/esp_hw_support/sleep_modes.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
968968
#endif // SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY
969969
#endif
970970

971+
#if SOC_DCDC_SUPPORTED
972+
uint64_t ldo_increased_us = rtc_time_slowclk_to_us(rtc_time_get() - s_config.rtc_ticks_at_ldo_prepare, s_config.rtc_clk_cal_period);
973+
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
974+
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
975+
}
976+
pmu_sleep_shutdown_dcdc();
977+
#endif
978+
971979
// Enter Deep Sleep
972980
#if!ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB || SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY || !CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
973981
#if SOC_PMU_SUPPORTED
@@ -994,19 +1002,12 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
9941002
#endif
9951003
#endif
9961004

997-
#if SOC_DCDC_SUPPORTED
998-
#if CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
999-
if (!deep_sleep) {
1000-
// Keep DCDC always on during light sleep, no need to adjust LDO voltage.
1001-
} else
1002-
#endif
1003-
{
1004-
uint64_t ldo_increased_us = rtc_time_slowclk_to_us(rtc_time_get() - s_config.rtc_ticks_at_ldo_prepare, s_config.rtc_clk_cal_period);
1005-
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
1006-
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
1007-
}
1008-
pmu_sleep_shutdown_dcdc();
1005+
#if SOC_DCDC_SUPPORTED && !CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
1006+
uint64_t ldo_increased_us = rtc_time_slowclk_to_us(rtc_time_get() - s_config.rtc_ticks_at_ldo_prepare, s_config.rtc_clk_cal_period);
1007+
if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US) {
1008+
esp_rom_delay_us(LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us);
10091009
}
1010+
pmu_sleep_shutdown_dcdc();
10101011
#endif
10111012

10121013
#if SOC_PMU_SUPPORTED
@@ -1924,8 +1925,9 @@ uint64_t esp_sleep_get_gpio_wakeup_status(void)
19241925

19251926
static void gpio_deep_sleep_wakeup_prepare(void)
19261927
{
1927-
for (gpio_num_t gpio_idx = GPIO_NUM_0; gpio_idx < GPIO_NUM_MAX; gpio_idx++) {
1928-
if (((1ULL << gpio_idx) & s_config.gpio_wakeup_mask) == 0) {
1928+
uint32_t valid_wake_io_mask = SOC_GPIO_DEEP_SLEEP_WAKE_VALID_GPIO_MASK;
1929+
for (gpio_num_t gpio_idx = __builtin_ctz(valid_wake_io_mask); valid_wake_io_mask >> gpio_idx; gpio_idx++) {
1930+
if ((s_config.gpio_wakeup_mask & BIT64(gpio_idx)) == 0) {
19291931
continue;
19301932
}
19311933
#if CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS
@@ -1951,13 +1953,18 @@ esp_err_t esp_deep_sleep_enable_gpio_wakeup(uint64_t gpio_pin_mask, esp_deepslee
19511953
}
19521954
gpio_int_type_t intr_type = ((mode == ESP_GPIO_WAKEUP_GPIO_LOW) ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL);
19531955
esp_err_t err = ESP_OK;
1954-
for (gpio_num_t gpio_idx = GPIO_NUM_0; gpio_idx < GPIO_NUM_MAX; gpio_idx++, gpio_pin_mask >>= 1) {
1955-
if ((gpio_pin_mask & 1) == 0) {
1956-
continue;
1956+
uint64_t invalid_io_mask = gpio_pin_mask & ~SOC_GPIO_DEEP_SLEEP_WAKE_VALID_GPIO_MASK;
1957+
if (invalid_io_mask != 0) {
1958+
for (gpio_num_t gpio_idx = __builtin_ctzll(invalid_io_mask); invalid_io_mask >> gpio_idx; gpio_idx++) {
1959+
if (invalid_io_mask & BIT64(gpio_idx)) {
1960+
ESP_LOGE(TAG, "gpio %d is an invalid deep sleep wakeup IO", gpio_idx);
1961+
return ESP_ERR_INVALID_ARG;
1962+
}
19571963
}
1958-
if (!esp_sleep_is_valid_wakeup_gpio(gpio_idx)) {
1959-
ESP_LOGE(TAG, "gpio %d is an invalid deep sleep wakeup IO", gpio_idx);
1960-
return ESP_ERR_INVALID_ARG;
1964+
}
1965+
for (gpio_num_t gpio_idx = __builtin_ctzll(gpio_pin_mask); gpio_pin_mask >> gpio_idx; gpio_idx++) {
1966+
if ((gpio_pin_mask & BIT64(gpio_idx)) == 0) {
1967+
continue;
19611968
}
19621969
err = gpio_deep_sleep_wakeup_enable(gpio_idx, intr_type);
19631970

components/soc/esp32c5/beta3/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ extern "C" {
147147

148148
#define EXT_OSC_SLOW_GPIO_NUM 0
149149

150-
#define MAX_RTC_GPIO_NUM 8
150+
#define MAX_RTC_GPIO_NUM 7
151151
#define MAX_PAD_GPIO_NUM 26
152152
#define MAX_GPIO_NUM 30
153153
#define DIG_IO_HOLD_BIT_SHIFT 32

components/soc/esp32c5/mp/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ extern "C" {
144144

145145
#define EXT_OSC_SLOW_GPIO_NUM 0
146146

147-
#define MAX_RTC_GPIO_NUM 8
147+
#define MAX_RTC_GPIO_NUM 7
148148
#define MAX_PAD_GPIO_NUM 28
149149
#define MAX_GPIO_NUM 32
150150
#define DIG_IO_HOLD_BIT_SHIFT 32

components/soc/esp32c6/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148

149149
#define EXT_OSC_SLOW_GPIO_NUM 0
150150

151-
#define MAX_RTC_GPIO_NUM 8
151+
#define MAX_RTC_GPIO_NUM 7
152152
#define MAX_PAD_GPIO_NUM 30
153153
#define MAX_GPIO_NUM 34
154154
#define DIG_IO_HOLD_BIT_SHIFT 32

components/soc/esp32c61/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ extern "C" {
137137
#define SPI_D_GPIO_NUM 21
138138
#define SPI_Q_GPIO_NUM 16
139139

140-
#define MAX_RTC_GPIO_NUM 7
140+
#define MAX_RTC_GPIO_NUM 6
141141
#define MAX_PAD_GPIO_NUM 30
142142
#define MAX_GPIO_NUM 34
143143
#define HIGH_IO_HOLD_BIT_SHIFT 32

components/soc/esp32p4/include/soc/io_mux_reg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194

195195
#define EXT_OSC_SLOW_GPIO_NUM 0 // XTAL_32K_N
196196

197-
#define MAX_RTC_GPIO_NUM 16
197+
#define MAX_RTC_GPIO_NUM 15
198198
#define MAX_PAD_GPIO_NUM 54
199199
#define MAX_GPIO_NUM 56
200200
#define HIGH_IO_HOLD_BIT_SHIFT 32

0 commit comments

Comments
 (0)