From 37f8afd777a7a0403e1c779f32fcbb836907c592 Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Sun, 5 Jan 2025 17:54:22 +1030 Subject: [PATCH 1/4] Fix M5Stack Core power off. Disable dynamic frequency scaling and most of the power management. The M5Stack Core does not actually power off, the underlying code actually results in a deep sleep. For some reason the power options were causing the M5Stack Core to immediately wake up. Only the M5Stack Core was affected, weird. --- platformio.ini | 2 +- sdkconfig.m5stack-core | 8 ++------ src/main.cpp | 5 +++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/platformio.ini b/platformio.ini index 37e8e7b..4fde13a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,7 +34,7 @@ build_flags = ${furble.build_flags} -DFURBLE_M5STICKC_PLUS [env:m5stack-core] board = m5stack-core-esp32 -build_flags = ${furble.build_flags} -DFURBLE_GROVE_CORE -DFURBLE_M5COREX +build_flags = ${furble.build_flags} -DFURBLE_GROVE_CORE -DFURBLE_M5COREX -DPM_DISABLE [env:m5stack-core2] board = m5stack-core2 diff --git a/sdkconfig.m5stack-core b/sdkconfig.m5stack-core index 3b54095..3b4dc29 100644 --- a/sdkconfig.m5stack-core +++ b/sdkconfig.m5stack-core @@ -604,12 +604,9 @@ CONFIG_ESP_PHY_CALIBRATION_MODE=0 # Power Management # CONFIG_PM_ENABLE=y -CONFIG_PM_DFS_INIT_AUTO=y +# CONFIG_PM_DFS_INIT_AUTO is not set # CONFIG_PM_PROFILING is not set # CONFIG_PM_TRACE is not set -CONFIG_PM_SLP_IRAM_OPT=y -CONFIG_PM_RTOS_IDLE_OPT=y -# CONFIG_PM_SLP_DISABLE_GPIO is not set CONFIG_PM_UPDATE_CCOMPARE_HLI_WORKAROUND=y # end of Power Management @@ -817,8 +814,7 @@ CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 # CONFIG_FREERTOS_USE_TRACE_FACILITY is not set # CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set -CONFIG_FREERTOS_USE_TICKLESS_IDLE=y -CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3 +# CONFIG_FREERTOS_USE_TICKLESS_IDLE is not set CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y # CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set # CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set diff --git a/src/main.cpp b/src/main.cpp index 48cf51b..a26c2a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,8 +25,13 @@ void app_main() { esp_pm_config_esp32_t pm_config = { .max_freq_mhz = 80, +#if defined(PM_DISABLE) + .min_freq_mhz = 80, + .light_sleep_enable = false, +#else .min_freq_mhz = 10, .light_sleep_enable = true, +#endif }; ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); From a03f2d1176453ac8ccf471533a8364056449b756 Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Sun, 5 Jan 2025 18:11:26 +1030 Subject: [PATCH 2/4] Revert "Fix M5Stack Core power off." This reverts commit 37f8afd777a7a0403e1c779f32fcbb836907c592. --- platformio.ini | 2 +- sdkconfig.m5stack-core | 8 ++++++-- src/main.cpp | 5 ----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/platformio.ini b/platformio.ini index 4fde13a..37e8e7b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,7 +34,7 @@ build_flags = ${furble.build_flags} -DFURBLE_M5STICKC_PLUS [env:m5stack-core] board = m5stack-core-esp32 -build_flags = ${furble.build_flags} -DFURBLE_GROVE_CORE -DFURBLE_M5COREX -DPM_DISABLE +build_flags = ${furble.build_flags} -DFURBLE_GROVE_CORE -DFURBLE_M5COREX [env:m5stack-core2] board = m5stack-core2 diff --git a/sdkconfig.m5stack-core b/sdkconfig.m5stack-core index 3b4dc29..3b54095 100644 --- a/sdkconfig.m5stack-core +++ b/sdkconfig.m5stack-core @@ -604,9 +604,12 @@ CONFIG_ESP_PHY_CALIBRATION_MODE=0 # Power Management # CONFIG_PM_ENABLE=y -# CONFIG_PM_DFS_INIT_AUTO is not set +CONFIG_PM_DFS_INIT_AUTO=y # CONFIG_PM_PROFILING is not set # CONFIG_PM_TRACE is not set +CONFIG_PM_SLP_IRAM_OPT=y +CONFIG_PM_RTOS_IDLE_OPT=y +# CONFIG_PM_SLP_DISABLE_GPIO is not set CONFIG_PM_UPDATE_CCOMPARE_HLI_WORKAROUND=y # end of Power Management @@ -814,7 +817,8 @@ CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 # CONFIG_FREERTOS_USE_TRACE_FACILITY is not set # CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set -# CONFIG_FREERTOS_USE_TICKLESS_IDLE is not set +CONFIG_FREERTOS_USE_TICKLESS_IDLE=y +CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3 CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y # CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set # CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set diff --git a/src/main.cpp b/src/main.cpp index a26c2a5..48cf51b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,13 +25,8 @@ void app_main() { esp_pm_config_esp32_t pm_config = { .max_freq_mhz = 80, -#if defined(PM_DISABLE) - .min_freq_mhz = 80, - .light_sleep_enable = false, -#else .min_freq_mhz = 10, .light_sleep_enable = true, -#endif }; ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); From 8dfea6fda75b2a7b0f3c9420696345bbc19a0160 Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Sun, 5 Jan 2025 18:14:17 +1030 Subject: [PATCH 3/4] Fix M5Stack Core power off. Fix it a different way. The wakeup cause was a timer, so disable timer wakeups only on for this device. All other power management settings can now be retained. --- platformio.ini | 2 +- src/FurbleUI.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 37e8e7b..e1bc632 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,7 +34,7 @@ build_flags = ${furble.build_flags} -DFURBLE_M5STICKC_PLUS [env:m5stack-core] board = m5stack-core-esp32 -build_flags = ${furble.build_flags} -DFURBLE_GROVE_CORE -DFURBLE_M5COREX +build_flags = ${furble.build_flags} -DFURBLE_GROVE_CORE -DFURBLE_M5COREX -DFURBLE_M5STACK_CORE [env:m5stack-core2] board = m5stack-core2 diff --git a/src/FurbleUI.cpp b/src/FurbleUI.cpp index 84e7a10..3c0820e 100644 --- a/src/FurbleUI.cpp +++ b/src/FurbleUI.cpp @@ -790,7 +790,11 @@ void UI::addMainMenu(void) { m_PowerOff = addMenuItem(m_MainMenu, LV_SYMBOL_POWER, "Power Off"); lv_obj_add_event_cb( - m_PowerOff, [](lv_event_t *e) { M5.Power.powerOff(); }, LV_EVENT_CLICKED, NULL); + m_PowerOff, [](lv_event_t *e) { +#if defined(FURBLE_M5STACK_CORE) + esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER); +#endif + M5.Power.powerOff(); }, LV_EVENT_CLICKED, NULL); lv_obj_add_event_cb( m_MainMenu.main, From e27c92cda45ff670854e2a514acc97f320548b9b Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Sun, 5 Jan 2025 18:17:03 +1030 Subject: [PATCH 4/4] clang-format --- src/FurbleUI.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/FurbleUI.cpp b/src/FurbleUI.cpp index 3c0820e..f47107b 100644 --- a/src/FurbleUI.cpp +++ b/src/FurbleUI.cpp @@ -790,11 +790,14 @@ void UI::addMainMenu(void) { m_PowerOff = addMenuItem(m_MainMenu, LV_SYMBOL_POWER, "Power Off"); lv_obj_add_event_cb( - m_PowerOff, [](lv_event_t *e) { + m_PowerOff, + [](lv_event_t *e) { #if defined(FURBLE_M5STACK_CORE) - esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER); + esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER); #endif - M5.Power.powerOff(); }, LV_EVENT_CLICKED, NULL); + M5.Power.powerOff(); + }, + LV_EVENT_CLICKED, NULL); lv_obj_add_event_cb( m_MainMenu.main,