# Task stuck in ready state on cortex-m4

**URL:** <https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970>\
**Category:** Kernel\
**Created:** [November 27, 2024, 9:54am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970 "2024-11-27T09:54:44Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 27, 2024, 9:54am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/1 "2024-11-27T09:54:44Z")

</div>

Hi, I use freeRTOS kernel version 10.0.1 with IAR 7.2 on Cortex M4.

My test case just reviece data from uart irq and sent it to a queue for process in another task named “UartDataProcess” run at Priority 6,  
Everything works fine when I run the system to transmit data at the beginning. After transmitting 10+ hours, somehow the task “UartDataProcess” will get stuck at ready state and never jump out. In this case, other Tasks, including IDLE Tasks, are normally scheduled

and the Task will be resume if i modify the bit of Priority 6 on “uxTopReadyPriority”, after that everything run is OK.

It is looks like topic of [Task stuck in ready state on cortex-M33] very mush.

But no irq with Priority 0

Below is my Macro:  
configUSE\_PREEMPTION 1  
configUSE\_TIME\_SLICING 1  
configUSE\_PORT\_OPTIMISED\_TASK\_SELECTION 1  
#define \_\_NVIC\_PRIO\_BITS 3U  
#define configLIBRARY\_LOWEST\_INTERRUPT\_PRIORITY 0xf

Does anyone have any idea why the stuck issue happens?

Thanks,  
Rob

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [November 27, 2024, 9:57am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/2 "2024-11-27T09:57:15Z")

</div>

we need to see code, everything else is crystal ball guessing.

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 27, 2024, 10:04am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/3 "2024-11-27T10:04:44Z")

</div>

Thanks for feedback,

Yes, I know, But I am not sure what code to show,  
it seems some problem in “uxTopReadyPriority” in OS code

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [November 27, 2024, 10:09am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/4 "2024-11-27T10:09:16Z")

</div>

not necessarily.

Show us at least the code for the rask that you believe to be stuck.

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 27, 2024, 10:13am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/5 "2024-11-27T10:13:56Z")

</div>

![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/a/ac9824bc6ba7827086d7f272124711927d68ef99.png)

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 27, 2024, 10:16am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/6 "2024-11-27T10:16:14Z")

</div>

and this Task is still in pxReadyTasksLists, but the corresponding bit of “uxTopReadyPriority” is not set

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [November 27, 2024, 10:17am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/7 "2024-11-27T10:17:29Z")

</div>

why do you claim the critical section? Try without it. When the system is in the problematic state, do you still get sys tick interrupts? I suspect that your task blocks while it still holds the critical section which will mayexplain the behavior you see.

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 27, 2024, 10:21am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/8 "2024-11-27T10:21:52Z")

</div>

According to the logs,  
the Task has left the critical zone,  
and it can be reproduced without claim the critical section before

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 27, 2024, 10:30am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/9 "2024-11-27T10:30:11Z")

</div>

sys tick interrupts is OK, anyother task scheduled is OK except this one,  
when i modify the bit of Priority 6 on “uxTopReadyPriority”, this task will resume

---

<div class="post-metadata">

**Author:** ![kstribrn](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/kstribrn/32/2085_2.png) [@kstribrn](https://forums.freertos.org/u/kstribrn)\
**Post date:** [November 27, 2024, 4:42pm UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/10 "2024-11-27T16:42:57Z")

</div>

What is your `configMAX_SYSCALL_INTERRUPT_PRIORITY`/`configMAX_API_CALL_INTERRUPT_PRIORITY` value? What is your `configKERNEL_INTERRUPT_PRIORITY` value?

[Reference link](https://www.freertos.org/Documentation/02-Kernel/03-Supported-devices/02-Customization)

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 28, 2024, 1:23am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/11 "2024-11-28T01:23:52Z")

</div>

Thanks for you feedback,  
and i check these in the printf as below:  
configMAX\_SYSCALL\_INTERRUPT\_PRIORITY = 160  
configKERNEL\_INTERRUPT\_PRIORITY = 480  
configPRIO\_BITS = 3

 ![image](https://d2v6vdsk2p900z.cloudfront.net/original/2X/a/aa811910993f420a8851833b64177b71863e5629.png)

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 28, 2024, 1:36am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/12 "2024-11-28T01:36:23Z")

</div>

And my Uart IRQ is 8

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [November 28, 2024, 6:24am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/13 "2024-11-28T06:24:54Z")

</div>

two more things to try:

- application stack overflow. Try running the task with a larger stack.
- there may be a race condition where your queue wait timeout expires just before the queue is refilled. check your log whether there is an entry that indicates timeout short before communication ceases.

Other than that, the configuration looks ok, but almost all of your task code is calling non native functions that may be subject to all kinds of problems.

Note that the observation you make about the bit you can manipulate to get the task back to running is just a symptom. Concurrency problems may manifest themselves in literally a bazillion of ways.

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 28, 2024, 6:32am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/14 "2024-11-28T06:32:24Z")

</div>

Thanks for your feedback again  
Stack was not overflow viewed by IAR Debugger

And I found \_\_NVIC\_PRIO\_BITS defined 3U in other header file, so configLIBRARY\_LOWEST\_INTERRUPT\_PRIORITY 0xf is not appropriate, right?

But I found many other project of M4 core, \_\_NVIC\_PRIO\_BITS defined 4U,  
So, I modify it for revalidate.

but I’m not sure if this is a good change

---

<div class="post-metadata">

**Author:** ![RAc](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rac/32/1389_2.png) [@RAc](https://forums.freertos.org/u/RAc)\
**Post date:** [November 28, 2024, 8:16am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/15 "2024-11-28T08:16:51Z")

</div>

well, M4 based PODs are explicitly allowed to support different numbers of irqs, so you must tailor that to your POD.

Have you looked at the timeout race issue?

---

<div class="post-metadata">

**Author:** ![huigs](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/huigs/32/5183_2.png) [@huigs](https://forums.freertos.org/u/huigs)\
**Post date:** [November 28, 2024, 8:28am UTC](https://forums.freertos.org/t/task-stuck-in-ready-state-on-cortex-m4/21970/16 "2024-11-28T08:28:41Z")

</div>

Yes， queue recieve will be timeout when everything is OK, then will never enter when problems arise.

Well, the root cause will be “\_\_NVIC\_PRIO\_BITS and configLIBRARY\_LOWEST\_INTERRUPT\_PRIORITY not match” ?
