From bb6d154f11a3dafa146960c1dae5c706336bfb4d Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Mon, 19 Jun 2023 21:57:02 +0800 Subject: [PATCH] freertos: Fix Systick stuck when systimer was not reset Relates to OTA update for C3/S3 chips from IDF version 4.3 to v5.0 and above --- components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c | 3 +++ components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c | 3 +++ components/freertos/FreeRTOS-Kernel/portable/port_systick.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c index 686fd0dc59..bfd68f8af4 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/port.c @@ -153,7 +153,10 @@ void vPortSetupTimer(void) systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK); for (cpuid = 0; cpuid < SOC_CPU_CORES_NUM; cpuid++) { + // Set stall option and alarm mode to default state. Below they will be set to a required state. systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, false); + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; + systimer_hal_select_alarm_mode(&systimer_hal, alarm_id, SYSTIMER_ALARM_MODE_ONESHOT); } for (cpuid = 0; cpuid < portNUM_PROCESSORS; ++cpuid) { diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c index a019d823d5..567e19fc57 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c @@ -243,7 +243,10 @@ void vPortSetupTimer(void) systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK); for (cpuid = 0; cpuid < SOC_CPU_CORES_NUM; cpuid++) { + // Set stall option and alarm mode to default state. Below they will be set to a required state. systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, false); + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; + systimer_hal_select_alarm_mode(&systimer_hal, alarm_id, SYSTIMER_ALARM_MODE_ONESHOT); } for (cpuid = 0; cpuid < portNUM_PROCESSORS; ++cpuid) { diff --git a/components/freertos/FreeRTOS-Kernel/portable/port_systick.c b/components/freertos/FreeRTOS-Kernel/portable/port_systick.c index 810f0b535d..c1594c7e92 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/port_systick.c +++ b/components/freertos/FreeRTOS-Kernel/portable/port_systick.c @@ -92,7 +92,10 @@ void vPortSetupTimer(void) systimer_ll_apply_counter_value(systimer_hal.dev, SYSTIMER_COUNTER_OS_TICK); for (cpuid = 0; cpuid < SOC_CPU_CORES_NUM; cpuid++) { + // Set stall option and alarm mode to default state. Below they will be set to a required state. systimer_hal_counter_can_stall_by_cpu(&systimer_hal, SYSTIMER_COUNTER_OS_TICK, cpuid, false); + uint32_t alarm_id = SYSTIMER_ALARM_OS_TICK_CORE0 + cpuid; + systimer_hal_select_alarm_mode(&systimer_hal, alarm_id, SYSTIMER_ALARM_MODE_ONESHOT); } for (cpuid = 0; cpuid < portNUM_PROCESSORS; ++cpuid) {