Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Task Suspend & Resume

Posted by akhil on May 9, 2013

I am using FreeRTOS CORTEX_M4F_STM32F407ZG-SK Project for my STM32F4-Discovery board.
I have two tasks i.e, Task1(Priority 4) & Task2(Priority 3)
1. Task1 gives input to the Task2 and goes to suspend state
2. Task2 does some data processing and writes onto SPI and then it resumes Task1.
Above two steps are repeated infinite times(150-200 times in a second).
After running it for 2-3hours, found Task1 is giving input to Task2 but Task2 doesn't process the data.
FreeRTOS plugin shows both tasks as suspended.

Can anyone help me on how to debug this issue.

Thanks in advance

RE: Task Suspend & Resume

Posted by Richard on May 9, 2013
“FreeRTOS plugin shows both tasks as suspended.”

Be careful how you interpret what the plug-in is telling you. The plug-in cannot tell the difference between a task that is actually suspended (in the Suspended state) and a task that is in the Blocked state with an infinite timeout. Therefore if you call a blocking function such as xQueueReceive() and give it a block time of portMAX_DELAY then, if INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h (which it must be in your case), the plug-in will show the task as being in the Suspended state.

It is almost certain that the task is actually in the Blocked state, not the Suspended state.


RE: Task Suspend & Resume

Posted by akhil on May 9, 2013
Thanks for the reply richardbarry,

-> I am not using any FreeRTOS Queue SPIs.
-> I have question:
how can I suspend a task with timeout, something like this...vTaskSuspend(handle,timeout)?

My code template looks like this:
Code Template:
xTaskHandle task1_handle;
xTaskHandle task2_handle;
void *data_pkt = NULL;
void task1_prepare(void *arg)
data_pkt = malloc(1000);
data_pkt = NULL;

void task2_process(void *arg)
/*do some processing like writing onto USART/SPI*/
printf("input buffer is NULL\n");

RE: Task Suspend & Resume

Posted by akhil on May 9, 2013

It is , -> I am not using any FreeRTOS Queue APIs.

RE: Task Suspend & Resume

Posted by Richard on May 9, 2013
I'm not sure why you would be allocating a packet in one task for use by another task - but assume if I saw all your code rather than this snippet it would be more obvious. Also personally I would always try and avoid repeatedly allocating and freeing memory blocks in this way - although heap_4.c would normally make this ok.

There is no suspend with timeout function. For that you would need to use a delay, not a suspend, but then there is no way of another task 'undelaying' as per your unsuspending (resuming). You could probably make the functionality by having the task block on a semaphore with a delay - then the other task can "give" the semaphore to unblock the task if the delay has not expired.

Task suspend and resume are not features I use very often myself. They can be dangerous to use as a synchronisation method because if a task tries to a resume another task that has not yet got to the point of suspending itself then the resume has no effect (and is not latches, as it would be if a semaphore were used instead).


RE: Task Suspend & Resume

Posted by akhil on May 9, 2013
Thanks for your inputs,

Actually , Task1 has another job like taking user inputs from USART, before while(1) loop.
and In future I have to create few more tasks and all these tasks will use Task2 to send the data out on USART/SPI.

Anyway, I will try using semaphore once.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner