Merge branch 'bugfix/s31_system_chip_back' into 'master'

fix(esp32s31): fix super WDT reset and systimer hang during startup

See merge request espressif/esp-idf!46701
This commit is contained in:
Marius Vikhammer
2026-03-19 10:37:55 +08:00
14 changed files with 139 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -18,15 +18,24 @@
#include "bootloader_flash_priv.h"
#include "bootloader_soc.h"
#include "esp_private/bootloader_flash_internal.h"
#include "soc/rtc_wdt_reg.h"
#include "hal/rwdt_ll.h"
ESP_LOG_ATTR_TAG(TAG, "boot.esp32s31");
static void bootloader_super_wdt_auto_feed(void)
{
REG_WRITE(RTC_WDT_SWD_WPROTECT_REG, RTC_WDT_SWD_WKEY_VALUE);
REG_SET_BIT(RTC_WDT_SWD_CONFIG_REG, RTC_WDT_SWD_AUTO_FEED_EN);
REG_WRITE(RTC_WDT_SWD_WPROTECT_REG, 0);
}
esp_err_t bootloader_init(void)
{
esp_err_t ret = ESP_OK;
// bootloader_hardware_init(); // TODO: IDF-14696
// bootloader_super_wdt_auto_feed(); // TODO: IDF-14678
bootloader_super_wdt_auto_feed();
// In RAM_APP, memory will be initialized in `call_start_cpu0`
#if !CONFIG_APP_BUILD_TYPE_RAM
@@ -62,6 +62,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -62,6 +62,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -63,6 +63,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -63,6 +63,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -63,6 +63,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -63,6 +63,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -63,6 +63,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -63,6 +63,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -70,6 +70,23 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
HP_SYS_CLKRST.peri_clk_ctrl21.reg_systimer_clk_en = enable;
}
/// use a macro to wrap the function, force the caller to use it in a critical section
/// the critical section needs to declare the __DECLARE_RCC_RC_ATOMIC_ENV variable in advance
#define systimer_ll_enable_sys_clock(...) do { \
(void)__DECLARE_RCC_RC_ATOMIC_ENV; \
systimer_ll_enable_sys_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Reset the systimer module
*
@@ -62,6 +62,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -62,6 +62,17 @@ static inline void systimer_ll_enable_bus_clock(bool enable)
systimer_ll_enable_bus_clock(__VA_ARGS__); \
} while(0)
/**
* @brief Enable the sys clock for systimer module
* This chip does not have a separate sys clock gate, this is a no-op.
*
* @param enable true to enable, false to disable
*/
static inline void systimer_ll_enable_sys_clock(bool enable)
{
(void)enable;
}
/**
* @brief Reset the systimer module
*
@@ -29,7 +29,6 @@ extern "C" {
#define SYSTIMER_LL_INT_LEVEL 1 // Systimer peripheral uses level interrupt
#define SYSTIMER_LL_ALARM_MISS_COMPENSATE 1 // Systimer peripheral can generate interrupt immediately if t(target) > t(current)
#define SYSTIMER_LL_FIXED_DIVIDER 1 // Clock source divider is fixed: 2.5
/******************* Clock *************************/
__attribute__((always_inline)) static inline void systimer_ll_enable_clock(systimer_dev_t *dev, bool en)
@@ -153,6 +153,7 @@ esp_err_t esp_timer_impl_early_init(void)
if (ref_count == 0) {
systimer_ll_enable_bus_clock(true);
systimer_ll_reset_register();
systimer_ll_enable_sys_clock(true);
}
}
systimer_hal_tick_rate_ops_t ops = {