espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.37k stars 7.21k forks source link

ESP32: dynamic frequency scaling affects RTC accuracy (IDFGH-7771) #9297

Open Andste82 opened 2 years ago

Andste82 commented 2 years ago

Environment

Problem Description

If dynamic frequency scaling is active, the RTC runs too fast. An external oscillator is not available, so only the internal ones can be used.

In both configurations the clock runs too fast.

No sleep functions are used.

Expected Behavior

DFS should not affect RTC.

Actual Behavior

If DFS is active and CPU + APB clock are reduced, the RTC becomes faster. If the APB clock is locked via power-management 'ESP_PM_APB_FREQ_MAX', the accuracy of the RTC remains within limits.

Steps to reproduce

  1. activate DFS
  2. print time in a cyclic manner

Code snippets

DFS setup:

esp_pm_config_esp32_t pm_config =
{
    .max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ,
    .min_freq_mhz = (REF_CLK_FREQ * 10) / MHZ,
    .light_sleep_enable = false
};

ESP_ERROR_CHECK(esp_pm_configure(&pm_config));

Lock APB clock:

static esp_pm_lock_handle_t pm_lock_apb;
esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "lock_apb", &pm_lock_apb);
esp_pm_lock_acquire(pm_lock_apb);
FanhuaCloud commented 2 years ago

I have also encountered the same problem, and currently use an external low-speed 32.768k crystal oscillator to solve the problem