# Task stuck in ready state on cortex-M33

**URL:** <https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m33/19696>\
**Category:** Kernel\
**Tags:** debug\
**Created:** [April 2, 2024, 1:54am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m33/19696 "2024-04-02T01:54:05Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![zexalistic](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/zexalistic/32/4397_2.png) [@zexalistic](https://forums.freertos.org/u/zexalistic)\
**Post date:** [April 10, 2024, 6:25pm UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m33/19696/19 "2024-04-10T18:25:57Z")

</div>

Hi,

The cause of problem is exactly the same with

> [@Quetions about the task scheduler](https://forums.freertos.org/t/quetions-about-the-task-scheduler/13339/14):
>
> Hi Jeff, Here is my configASSERT() #define configASSERT(x) EFM\_ASSERT(x) #define EFM\_ASSERT(expr) ((expr) ? ((void)0) : assertEFM(\_\_FILE\_\_, \_\_LINE\_\_)) 66 void assertEFM(const char \*file, int line) 67 { 68 (void)file; /\* Unused parameter \*/ 69 (void)line; /\* Unused parameter \*/ 70 71 while (true) { 72 } 73 } Thanks for your help! My freertos is "V10.4.3".

We both use Cortex-M33 core and here’s the implementation of sys tick irq:

> void SysTick\_Handler( void ) /\* PRIVILEGED\_FUNCTION _/  
> {  
> uint32\_t ulPreviousMask;  
> ulPreviousMask = portSET\_INTERRUPT\_MASK\_FROM\_ISR();  
> {  
> /_ Increment the RTOS tick. _/  
> if( xTaskIncrementTick() != pdFALSE )  
> {  
> /_ Pend a context switch. \*/  
> portNVIC\_INT\_CTRL\_REG = portNVIC\_PENDSVSET\_BIT;  
> }  
> }  
> portCLEAR\_INTERRUPT\_MASK\_FROM\_ISR( ulPreviousMask );  
> }

Although Sys tick irq suspends task scheduler, it is not run under critical section which can be interrupted by a higher IRQ(i2c irq). The problem is exactly the same as described by Yueming:

> configUSE\_PORT\_OPTIMISED\_TASK\_SELECTION is 0 then task selection is performed in a generic way. There might be a racing condition on uxTopReadyPriority.  
> Please check this failed case:
> 
> 1. Tick IRQ is a low priority IRQ.
> 2. When Tick IRQ finished this line “UBaseType\_t uxTopPriority = uxTopReadyPriority;” , let’s assume uxTopReadyPriority and uxTopPriority is 5 now.  
> {  
> ==\> UBaseType\_t uxTopPriority = uxTopReadyPriority;  
> /\* Find the highest priority queue that contains ready tasks. _/  
> while( listLIST\_IS\_EMPTY( &( pxReadyTasksLists[uxTopPriority] ) ) )  
> {  
> configASSERT( uxTopPriority );  
> –uxTopPriority;  
> }  
> /_ listGET\_OWNER\_OF\_NEXT\_ENTRY indexes through the list, so the tasks of
> 3. the same priority get an equal share of the processor time. _/  
> listGET\_OWNER\_OF\_NEXT\_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[uxTopPriority] ) );  
> uxTopReadyPriority = uxTopPriority;  
> } /_ taskSELECT\_HIGHEST\_PRIORITY\_TASK \*/
> 4. A higher priority IRQ occurs, tick IRQ is switched out. The higher priority IRQ adds a ready task into the ready list and sets uxTopReadyPriority to this task’s priority, let’s assume it is 6.
> 5. The higher priority IRQ finished and tick IRQ contine it’s code. uxTopReadyPriority will be set to a value \<= 5.
> 6. The task scheduler cannot call priority 6 task on next tick IRQ. That would cause some issues.

uxTopReadyPriority is written twice and the last time it is written by tick IRQ and set as the priority of idle task. If I use taskSELECT\_HIGHEST\_PRIORITY\_TASK(), the task scheduler will only check the ready list for priority 0(idle task).Unless there is another task trigger event that rewrite uxTopReadyPriority back to the overridden value, the task will always be stuck in ready list and never run.

Therefore, my solution is to abandon uxTopReadyPriority and taskSELECT\_HIGHEST\_PRIORITY\_TASK(). I instead search all the ready list. Since there are not too many tasks, the cost is affordable. And the porblem is solved in this way.

---

_[View the full topic](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m33/19696)._
