Skip to content

Commit 186f2a8

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'bugfix/idf-11425' into 'master'
power management module memory (iram or flash) usage optimization Closes IDF-11425 See merge request espressif/esp-idf!37550
2 parents 0f6e067 + 0cb2114 commit 186f2a8

File tree

29 files changed

+396
-216
lines changed

29 files changed

+396
-216
lines changed

components/esp_adc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ menu "ADC and ADC Calibration"
22

33
config ADC_ONESHOT_CTRL_FUNC_IN_IRAM
44
bool "Place ISR version ADC oneshot mode read function into IRAM"
5+
select ESP_PERIPH_CTRL_FUNC_IN_IRAM
56
default n
67
help
78
Place ISR version ADC oneshot mode read function into IRAM.

components/esp_driver_parlio/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ menu "ESP-Driver:Parallel IO Configurations"
66
default y
77
select PARLIO_OBJ_CACHE_SAFE
88
select GDMA_CTRL_FUNC_IN_IRAM
9+
select ESP_PERIPH_CTRL_FUNC_IN_IRAM
910
help
1011
Place Parallel IO TX ISR handler in IRAM to reduce latency caused by cache miss.
1112

components/esp_driver_spi/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ menu "ESP-Driver:SPI Configurations"
2323
bool "Place SPI master ISR function into IRAM"
2424
default y
2525
depends on !HEAP_PLACE_FUNCTION_INTO_FLASH
26+
select ESP_PERIPH_CTRL_FUNC_IN_IRAM
2627
select ESP_SPI_BUS_LOCK_ISR_FUNCS_IN_IRAM
2728
select GDMA_CTRL_FUNC_IN_IRAM if SOC_GDMA_SUPPORTED
2829
help
@@ -51,6 +52,7 @@ menu "ESP-Driver:SPI Configurations"
5152
config SPI_SLAVE_ISR_IN_IRAM
5253
bool "Place SPI slave ISR function into IRAM"
5354
default y
55+
select ESP_PERIPH_CTRL_FUNC_IN_IRAM
5456
select GDMA_CTRL_FUNC_IN_IRAM if SOC_GDMA_SUPPORTED
5557
help
5658
Place the SPI slave ISR in to IRAM to avoid possible cache miss.

components/esp_hw_support/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ menu "Hardware Settings"
7070
# regardless of power management configuration.
7171
config ESP_SLEEP_POWER_DOWN_FLASH
7272
bool "Power down flash in light sleep when there is no SPIRAM or SPIRAM has independent power supply"
73+
# TODO: PM-383
74+
select PM_SLP_IRAM_OPT if (!IDF_TARGET_ESP32H21 && !IDF_TARGET_ESP32H4)
75+
select ESP_PERIPH_CTRL_FUNC_IN_IRAM
76+
select ESP_REGI2C_CTRL_FUNC_IN_IRAM
7377
depends on !SPIRAM || ESP_LDO_RESERVE_PSRAM
7478
depends on !(IDF_TARGET_ESP32P4 && (ESP32P4_REV_MIN_FULL < 100))
7579
default n
@@ -219,12 +223,19 @@ menu "Hardware Settings"
219223
endmenu
220224

221225
menu "Peripheral Control"
222-
config PERIPH_CTRL_FUNC_IN_IRAM
226+
config ESP_PERIPH_CTRL_FUNC_IN_IRAM
223227
bool "Place peripheral control functions into IRAM"
224228
default n
225229
help
226230
Place peripheral control functions (e.g. periph_module_reset) into IRAM,
227231
so that these functions can be IRAM-safe and able to be called in the other IRAM interrupt context.
232+
233+
config ESP_REGI2C_CTRL_FUNC_IN_IRAM
234+
bool "Place regi2c control functions into IRAM"
235+
default y
236+
help
237+
Place analog i2c master control functions (e.g. regi2c_ctrl_read_reg, regi2c_ctrl_write_reg) into IRAM,
238+
so that these functions can be IRAM-safe and able to be called in the other IRAM interrupt context.
228239
endmenu
229240

230241
menu "ETM Configuration"

components/esp_hw_support/esp_clk.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626

2727
#define MHZ (1000000)
2828

29+
#if CONFIG_PM_SLP_IRAM_OPT
30+
# define ESP_CLK_FN_ATTR IRAM_ATTR
31+
#else
32+
# define ESP_CLK_FN_ATTR
33+
#endif
34+
2935
// g_ticks_us defined in ROMs for PRO and APP CPU
3036
extern uint32_t g_ticks_per_us_pro;
3137

@@ -48,7 +54,7 @@ _Static_assert(offsetof(retain_mem_t, checksum) == sizeof(retain_mem_t) - sizeof
4854
#if !NON_OS_BUILD
4955
static __attribute__((section(".rtc_timer_data_in_rtc_mem"))) retain_mem_t s_rtc_timer_retain_mem;
5056

51-
static uint32_t calc_checksum(void)
57+
static ESP_CLK_FN_ATTR uint32_t calc_checksum(void)
5258
{
5359
uint32_t checksum = 0;
5460
uint32_t *data = (uint32_t*) &s_rtc_timer_retain_mem;

components/esp_hw_support/linker.lf

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,61 @@ entries:
1212
cpu: esp_cpu_clear_watchpoint (noflash)
1313
cpu: esp_cpu_compare_and_set (noflash)
1414
esp_memory_utils (noflash)
15-
rtc_clk (noflash)
1615
clk_utils (noflash)
16+
if PM_SLP_IRAM_OPT = y:
17+
rtc_clk (noflash)
18+
rtc_time (noflash_text)
1719
if SOC_CONFIGURABLE_VDDSDIO_SUPPORTED = y:
1820
rtc_init:rtc_vddsdio_get_config (noflash)
1921
rtc_init:rtc_vddsdio_set_config (noflash)
2022
if IDF_TARGET_ESP32 = y || IDF_TARGET_ESP32S2 = y || IDF_TARGET_ESP32S3 = y || IDF_TARGET_ESP32C2 = y || IDF_TARGET_ESP32C3 = y:
21-
rtc_sleep (noflash_text)
22-
rtc_time (noflash_text)
23+
rtc_sleep:rtc_sleep_start (noflash)
24+
if PM_SLP_IRAM_OPT = y:
25+
rtc_sleep:rtc_sleep_get_default_config (noflash)
26+
rtc_sleep:rtc_sleep_init (noflash)
27+
rtc_sleep:rtc_sleep_low_init (noflash)
28+
if IDF_TARGET_ESP32 = y || IDF_TARGET_ESP32S2 = y:
29+
rtc_sleep:rtc_sleep_pd (noflash)
30+
if IDF_TARGET_ESP32S3 = y || IDF_TARGET_ESP32C2 = y || IDF_TARGET_ESP32C3 = y:
31+
rtc_sleep:rtc_sleep_pu (noflash)
2332
if SOC_PMU_SUPPORTED = y && SOC_LIGHT_SLEEP_SUPPORTED = y:
2433
pmu_sleep (noflash)
25-
if SPIRAM_FLASH_LOAD_TO_PSRAM = y:
26-
pmu_init (noflash)
27-
pmu_param (noflash)
28-
if SOC_USB_SERIAL_JTAG_SUPPORTED = y:
34+
if SPIRAM_FLASH_LOAD_TO_PSRAM = y:
35+
pmu_init (noflash)
36+
pmu_param (noflash)
37+
elif PM_SLP_IRAM_OPT = y && IDF_TARGET_ESP32P4 != y:
38+
pmu_param:get_act_hp_dbias (noflash)
39+
pmu_param:get_act_lp_dbias (noflash)
40+
if PM_SLP_IRAM_OPT = y && SOC_USB_SERIAL_JTAG_SUPPORTED = y:
2941
sleep_console (noflash)
30-
if SOC_USB_OTG_SUPPORTED && SOC_PM_SUPPORT_CNNT_PD = y:
42+
if PM_SLP_IRAM_OPT = y && SOC_USB_OTG_SUPPORTED && SOC_PM_SUPPORT_CNNT_PD = y:
3143
sleep_usb (noflash)
3244
if IDF_TARGET_ESP32 = y || IDF_TARGET_ESP32S2 = y:
3345
rtc_wdt (noflash_text)
34-
if PERIPH_CTRL_FUNC_IN_IRAM = y:
35-
periph_ctrl: periph_module_reset (noflash)
36-
if PERIPH_CTRL_FUNC_IN_IRAM = y && ESP_WIFI_ENABLED = y:
46+
if ESP_PERIPH_CTRL_FUNC_IN_IRAM = y:
47+
periph_ctrl:periph_module_reset (noflash)
48+
periph_ctrl:periph_rcc_enter (noflash)
49+
periph_ctrl:periph_rcc_exit (noflash)
50+
periph_ctrl:periph_rcc_acquire_enter (noflash)
51+
periph_ctrl:periph_rcc_acquire_exit (noflash)
52+
periph_ctrl:periph_rcc_release_enter (noflash)
53+
periph_ctrl:periph_rcc_release_exit (noflash)
54+
if ESP_PERIPH_CTRL_FUNC_IN_IRAM = y && ESP_WIFI_ENABLED = y:
3755
periph_ctrl: wifi_module_enable (noflash)
3856
periph_ctrl: wifi_module_disable (noflash)
57+
if ESP_REGI2C_CTRL_FUNC_IN_IRAM = y:
58+
regi2c_ctrl:regi2c_ctrl_read_reg (noflash)
59+
regi2c_ctrl:regi2c_ctrl_read_reg_mask (noflash)
60+
regi2c_ctrl:regi2c_ctrl_write_reg (noflash)
61+
regi2c_ctrl:regi2c_ctrl_write_reg_mask (noflash)
62+
regi2c_ctrl:regi2c_enter_critical (noflash)
63+
regi2c_ctrl:regi2c_exit_critical (noflash)
3964
if SOC_SYSTIMER_SUPPORTED = y:
4065
systimer (noflash)
4166
if SOC_ADC_SHARED_POWER = y:
4267
if ADC_ONESHOT_CTRL_FUNC_IN_IRAM = y:
4368
sar_periph_ctrl (noflash)
44-
else:
69+
elif PM_SLP_IRAM_OPT = y:
4570
sar_periph_ctrl: sar_periph_ctrl_power_enable (noflash)
4671

4772
[mapping:soc_pm]

components/esp_hw_support/periph_ctrl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@ static portMUX_TYPE periph_spinlock = portMUX_INITIALIZER_UNLOCKED;
2121

2222
static uint8_t ref_counts[PERIPH_MODULE_MAX] = {0};
2323

24-
IRAM_ATTR void periph_rcc_enter(void)
24+
void periph_rcc_enter(void)
2525
{
2626
portENTER_CRITICAL_SAFE(&periph_spinlock);
2727
}
2828

29-
IRAM_ATTR void periph_rcc_exit(void)
29+
void periph_rcc_exit(void)
3030
{
3131
portEXIT_CRITICAL_SAFE(&periph_spinlock);
3232
}
3333

34-
IRAM_ATTR uint8_t periph_rcc_acquire_enter(periph_module_t periph)
34+
uint8_t periph_rcc_acquire_enter(periph_module_t periph)
3535
{
3636
periph_rcc_enter();
3737
return ref_counts[periph];
3838
}
3939

40-
IRAM_ATTR void periph_rcc_acquire_exit(periph_module_t periph, uint8_t ref_count)
40+
void periph_rcc_acquire_exit(periph_module_t periph, uint8_t ref_count)
4141
{
4242
ref_counts[periph] = ++ref_count;
4343
periph_rcc_exit();
4444
}
4545

46-
IRAM_ATTR uint8_t periph_rcc_release_enter(periph_module_t periph)
46+
uint8_t periph_rcc_release_enter(periph_module_t periph)
4747
{
4848
periph_rcc_enter();
4949
return ref_counts[periph] - 1;
5050
}
5151

52-
IRAM_ATTR void periph_rcc_release_exit(periph_module_t periph, uint8_t ref_count)
52+
void periph_rcc_release_exit(periph_module_t periph, uint8_t ref_count)
5353
{
5454
ref_counts[periph] = ref_count;
5555
periph_rcc_exit();

components/esp_hw_support/port/esp32/rtc_sleep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef struct {
6565
* Configure whether certain peripherals are powered down in deep sleep
6666
* @param cfg power down flags as rtc_sleep_pd_config_t structure
6767
*/
68-
static void rtc_sleep_pd(rtc_sleep_pd_config_t cfg)
68+
void rtc_sleep_pd(rtc_sleep_pd_config_t cfg)
6969
{
7070
REG_SET_FIELD(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_LSLP_MEM_FORCE_PU, ~cfg.dig_pd);
7171
REG_SET_FIELD(RTC_CNTL_PWC_REG, RTC_CNTL_SLOWMEM_FORCE_LPU, ~cfg.rtc_pd);
@@ -345,7 +345,7 @@ uint32_t rtc_deep_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt)
345345
return rtc_sleep_finish();
346346
}
347347

348-
static uint32_t rtc_sleep_finish(void)
348+
static IRAM_ATTR uint32_t rtc_sleep_finish(void)
349349
{
350350
/* In deep sleep mode, we never get here */
351351
uint32_t reject = REG_GET_FIELD(RTC_CNTL_INT_RAW_REG, RTC_CNTL_SLP_REJECT_INT_RAW);

components/esp_hw_support/port/esp32c2/rtc_sleep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ uint32_t rtc_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp
222222
return rtc_sleep_finish(lslp_mem_inf_fpu);
223223
}
224224

225-
static uint32_t rtc_sleep_finish(uint32_t lslp_mem_inf_fpu)
225+
static IRAM_ATTR uint32_t rtc_sleep_finish(uint32_t lslp_mem_inf_fpu)
226226
{
227227
/* In deep sleep mode, we never get here */
228228
uint32_t reject = REG_GET_FIELD(RTC_CNTL_INT_RAW_REG, RTC_CNTL_SLP_REJECT_INT_RAW);

components/esp_hw_support/port/esp32c3/rtc_sleep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ uint32_t rtc_deep_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt)
352352
return rtc_sleep_finish(0);
353353
}
354354

355-
static uint32_t rtc_sleep_finish(uint32_t lslp_mem_inf_fpu)
355+
static IRAM_ATTR uint32_t rtc_sleep_finish(uint32_t lslp_mem_inf_fpu)
356356
{
357357
/* In deep sleep mode, we never get here */
358358
uint32_t reject = REG_GET_FIELD(RTC_CNTL_INT_RAW_REG, RTC_CNTL_SLP_REJECT_INT_RAW);

0 commit comments

Comments
 (0)