From 16cdbd9f5cfd82b20d4e6a3bcacc3c25f6e07c54 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 22 Sep 2025 13:53:28 +0800 Subject: [PATCH] change(esp_timer): esp_timer_init_os now returns ESP_OK if already initialized Previously it would return ESP_ERR_INVALID_STATE, which meant that if called from user-code before the system tries to initialize the timer then esp-idf would fail to boot. This could happen if a user wanted to use esp-timer from a cpp constructor. Closes https://github.com/espressif/esp-idf/issues/9679 --- components/esp_timer/src/esp_timer.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/esp_timer/src/esp_timer.c b/components/esp_timer/src/esp_timer.c index 8c59fbe40d..c362d69ddc 100644 --- a/components/esp_timer/src/esp_timer.c +++ b/components/esp_timer/src/esp_timer.c @@ -564,7 +564,13 @@ esp_err_t esp_timer_init(void) */ ESP_SYSTEM_INIT_FN(esp_timer_init_os, SECONDARY, ESP_TIMER_INIT_MASK, 100) { - return esp_timer_init(); + esp_err_t err = ESP_OK; + if (is_initialized()) { + err = ESP_OK; + } else { + err = esp_timer_init(); + } + return err; } esp_err_t esp_timer_deinit(void)