From 84d16f970e093a94e978cfc6021276bcb3b92440 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 9 Apr 2019 13:25:24 +0800 Subject: [PATCH] pm: prevent interrupt nesting during esp_pm_impl_isr_hook Follows the approach proposed in https://github.com/espressif/esp-idf/pull/3110, but masks the interrupts during the entire ISR hook, not only during leave_idle. Interrupt nesting during update_ccompare may also cause issues. Closes https://github.com/espressif/esp-idf/issues/3057 --- components/esp32/pm_esp32.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/esp32/pm_esp32.c b/components/esp32/pm_esp32.c index f75b3fe811..218afc1327 100644 --- a/components/esp32/pm_esp32.c +++ b/components/esp32/pm_esp32.c @@ -453,6 +453,10 @@ void IRAM_ATTR esp_pm_impl_isr_hook() { int core_id = xPortGetCoreID(); ESP_PM_TRACE_ENTER(ISR_HOOK, core_id); + /* Prevent higher level interrupts (than the one this function was called from) + * from happening in this section, since they will also call into esp_pm_impl_isr_hook. + */ + uint32_t state = portENTER_CRITICAL_NESTED(); #if portNUM_PROCESSORS == 2 if (s_need_update_ccompare[core_id]) { update_ccompare(); @@ -463,6 +467,7 @@ void IRAM_ATTR esp_pm_impl_isr_hook() #else leave_idle(); #endif // portNUM_PROCESSORS == 2 + portEXIT_CRITICAL_NESTED(state); ESP_PM_TRACE_EXIT(ISR_HOOK, core_id); }