Skip to content

Commit 3114935

Browse files
committed
fix(esp_hw_support): update systimer step immediately when XTAL changes on esp32s2
1 parent 833df30 commit 3114935

File tree

5 files changed

+8
-37
lines changed

5 files changed

+8
-37
lines changed

components/esp_hw_support/port/esp32s2/rtc_clk.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include "esp_hw_log.h"
2222
#include "sdkconfig.h"
2323
#include "hal/clk_tree_ll.h"
24+
#ifndef BOOTLOADER_BUILD
25+
#include "esp_private/systimer.h"
26+
#include "hal/systimer_ll.h"
27+
#endif
2428

2529
static const char *TAG = "rtc_clk";
2630

@@ -468,6 +472,9 @@ static void rtc_clk_cpu_freq_to_xtal(int cpu_freq, int div)
468472
/* no need to adjust the REF_TICK, default register value already set it to 1MHz with any cpu clock source */
469473
/* switch clock source */
470474
clk_ll_cpu_set_src(SOC_CPU_CLK_SRC_XTAL);
475+
#ifndef BOOTLOADER_BUILD
476+
systimer_ll_set_step_for_xtal(&SYSTIMER, systimer_us_to_ticks(1) / cpu_freq);
477+
#endif
471478
rtc_clk_apb_freq_update(cpu_freq * MHZ);
472479

473480
/* lower the voltage

components/esp_pm/pm_impl.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,15 +572,6 @@ void IRAM_ATTR esp_pm_impl_switch_mode(pm_mode_t mode,
572572
*/
573573
static void IRAM_ATTR on_freq_update(uint32_t old_ticks_per_us, uint32_t ticks_per_us)
574574
{
575-
#if !CONFIG_IDF_TARGET_ESP32
576-
uint32_t old_apb_ticks_per_us = MIN(old_ticks_per_us, 80);
577-
uint32_t apb_ticks_per_us = MIN(ticks_per_us, 80);
578-
/* Update APB frequency value used by the timer */
579-
if (old_apb_ticks_per_us != apb_ticks_per_us) {
580-
esp_timer_private_update_apb_freq(apb_ticks_per_us);
581-
}
582-
#endif
583-
584575
#ifdef CONFIG_FREERTOS_SYSTICK_USES_CCOUNT
585576
#ifdef XT_RTOS_TIMER_INT
586577
/* Calculate new tick divisor */

components/esp_timer/include/esp_private/esp_timer_private.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -24,16 +24,6 @@
2424
#ifdef __cplusplus
2525
extern "C" {
2626
#endif
27-
28-
/**
29-
* @brief Notify esp_timer implementation that APB frequency has changed
30-
*
31-
* Called by the frequency switching code.
32-
*
33-
* @param apb_ticks_per_us new number of APB clock ticks per microsecond
34-
*/
35-
void esp_timer_private_update_apb_freq(uint32_t apb_ticks_per_us);
36-
3727
/**
3828
* @brief Set esp_timer time to a certain value
3929
*

components/esp_timer/private_include/esp_timer_impl.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ void esp_timer_impl_set_alarm(uint64_t timestamp);
7676
*/
7777
void esp_timer_impl_set_alarm_id(uint64_t timestamp, unsigned alarm_id);
7878

79-
/**
80-
* @brief Notify esp_timer implementation that APB frequency has changed
81-
*
82-
* Called by the frequency switching code.
83-
*
84-
* @param apb_ticks_per_us new number of APB clock ticks per microsecond
85-
*/
86-
void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us);
87-
8879
/**
8980
* @brief Adjust current esp_timer time by a certain value
9081
*

components/esp_timer/src/esp_timer_impl_systimer.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,6 @@ static void ESP_TIMER_IRAM_ATTR timer_alarm_isr(void *arg)
129129
#endif // ISR_HANDLERS != 1
130130
}
131131

132-
void ESP_TIMER_IRAM_ATTR esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us)
133-
{
134-
#if !SOC_SYSTIMER_FIXED_DIVIDER
135-
systimer_hal_on_apb_freq_update(&systimer_hal, apb_ticks_per_us);
136-
#endif
137-
}
138-
139132
void esp_timer_impl_set(uint64_t new_us)
140133
{
141134
portENTER_CRITICAL_SAFE(&s_time_update_lock);
@@ -253,6 +246,5 @@ uint64_t esp_timer_impl_get_alarm_reg(void)
253246
return val;
254247
}
255248

256-
void esp_timer_private_update_apb_freq(uint32_t apb_ticks_per_us) __attribute__((alias("esp_timer_impl_update_apb_freq")));
257249
void esp_timer_private_set(uint64_t new_us) __attribute__((alias("esp_timer_impl_set")));
258250
void esp_timer_private_advance(int64_t time_diff_us) __attribute__((alias("esp_timer_impl_advance")));

0 commit comments

Comments
 (0)