From dc707d593398a05b3578d5938e4e31463f9522c7 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 20 Dec 2021 17:25:56 +0100 Subject: [PATCH] freertos: ensure interrupts are disabled before enabling tick timer xPortStartScheduler calls vPortSetupTimer -> _frxt_tick_timer_init, which enables tick timer interrupt and sets up the first timeout. From that point on, the interrupt can fire. If the interrupt happens while _frxt_dispatch is running, the scheduler will enter an infinite loop. This is because _frxt_dispatch isn't supposed to be preemptable, and the tick interrupt will overwrite some of the registers used by _frxt_dispatch. Note that this situation doesn't practically occur on the real hardware, where the execution of vPortSetupTimer and _frxt_dispatch happens quickly enough. However it can be reproduced on an emulator if the tick period is set to 1ms. Add an explicit call to portDISABLE_INTERRUPTS in xPortStartScheduler to guarantee that _frxt_dispatch doesn't run with interrupts enabled. This is similar to the esprv_intc_int_set_threshold(1); call in RISC-V version of port.c. --- components/freertos/port/xtensa/port.c | 1 + 1 file changed, 1 insertion(+) diff --git a/components/freertos/port/xtensa/port.c b/components/freertos/port/xtensa/port.c index 3508653730..84d8d99f41 100644 --- a/components/freertos/port/xtensa/port.c +++ b/components/freertos/port/xtensa/port.c @@ -92,6 +92,7 @@ extern void _xt_coproc_init(void); BaseType_t xPortStartScheduler( void ) { + portDISABLE_INTERRUPTS(); // Interrupts are disabled at this point and stack contains PS with enabled interrupts when task context is restored #if XCHAL_CP_NUM > 0