Hello,
I would like to share a simple demo (not the full application) to reproduce this scenario, but I can’t attach document to this forum because I am a new user
So I will try to describe the demo code (based on FreeRTOS v10.2.1) and share few snippets
The demo has:
- 1 user task
- 1 user queue
- IDLE task and Timer Service task
in main.c file
#define MSG_SUSPEND 1
#define MSG_DO_SOMETHING 2
typedef struct _Msg {
uint8_t nID;
} Msg;
TaskHandle_t g_xTask = NULL;
QueueHandle_t g_xQueue = NULL;
int main(void)
{
// board initialization.
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
g_xQueue = xQueueCreate(10, sizeof(Msg));
vQueueAddToRegistry(g_xQueue, "MyQueue");
xTaskCreate(TaskCode, "MyTask", configMINIMAL_STACK_SIZE, &g_xTask, 1, &g_xTask);
vTaskStartScheduler();
while (1)
{
}
}
void TaskCode( void * pvParameters )
{
TaskHandle_t *pxTask = (TaskHandle_t*)pvParameters;
UNUSED(pxTask);
Msg xMsg = {0};
xMsg.nID = MSG_SUSPEND;
xQueueSendToBack(g_xQueue, &xMsg, portMAX_DELAY);
for (;;) {
if (xQueueReceive(g_xQueue, &xMsg, portMAX_DELAY) == pdTRUE) {
switch (xMsg.nID) {
case MSG_SUSPEND:
vTaskSuspend(g_xTask);
break;
case MSG_DO_SOMETHING:
xQueueSendToBack(g_xQueue, &xMsg, portMAX_DELAY);
vTaskDelay(pdMS_TO_TICKS(1000));
break;
}
}
}
}
The ISR code is this:
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
BaseType_t xRes = pdTRUE;
if (GPIO_Pin == BUTTON_USER_Pin) {
// wake up the task
xRes = xTaskResumeFromISR(g_xTask);
assert_param(xRes);
Msg xMsg = {
.nID = MSG_DO_SOMETHING,
};
xRes = xQueueSendToBackFromISR(g_xQueue, &xMsg, NULL);
assert_param(xRes);
}
// END_OF_ISR
}
This simple demo reproduces what I am observing in my real application. When the task is suspended I trigger the ISR code and before leaving the ISR (// END_OF_ISR) the situation is as reported in the following task and queue table:
MyTask is READY but it is never rescheduled. The RUNNING task is always the IDLE.
Best regards,
Stefano