我做了大量的测试,发现
电源管理锁在ESP32中不生效,但是在ESP32S3中可以正常工作,我测试了IDF最新的代码(release/v5.1, release/v4.4)都是这样的情况。
我希望这不是IDF的Bug,但是我实在无法解决,请大佬们帮我看下,下面是我的代码:
// 启动时
```cpp
void app_main() {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
#if CONFIG_PM_ENABLE
# if CONFIG_IDF_TARGET_ESP32
esp_pm_config_esp32_t pm_config = {
# elif CONFIG_IDF_TARGET_ESP32S2
esp_pm_config_esp32s2_t pm_config = {
# elif CONFIG_IDF_TARGET_ESP32C3
esp_pm_config_esp32c3_t pm_config = {
# elif CONFIG_IDF_TARGET_ESP32S3
esp_pm_config_esp32s3_t pm_config = {
# endif
.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
.min_freq_mhz = 80,
# if CONFIG_FREERTOS_USE_
tiCKLESS_IDLE
.light_sleep_enable = false
# endif
};
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
#endif
}
```
业务中加锁:
```
void somewhere(void) {
static esp_pm_lock_handle_t rmt_send_task_pm_lock;
ESP_ERROR_CHECK(esp_pm_lock_create(ESP_PM_CPU_FREQ_MAX, 0, "rmt_send_task",
&rmt_send_task_pm_lock));
ESP_ERROR_CHECK(esp_pm_lock_acquire(rmt_send_task_pm_lock));
// ... 业务代码
ESP_ERROR_CHECK(esp_pm_lock_release(rmt_send_task_pm_lock));
}
```