Quality RTOS & Embedded Software

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


SAM3 Tasks not Switching

Posted by MSH on August 26, 2013
Hi, Im new to FreeRTOS and Im trying to run 2 tasks with the same priority running on ATMEL SAM3 arm cortex m3 evaluation board
Im creating the two tasks with simple command to print some text, the problem is that the tasks are not switching if I don't add taskYIELD or vTaskDelay in both tasks ,
Can you help with that
here is the code

static void task1(void *pvParameters)
while (1)

printf("Task 1 : 1\n\r");
printf("Task 1 : 2\n\r");
printf("Task 1 : 3\n\r");

static void task2(void *pvParameters)
while (1)
printf("Task 2 : 1\n\r");
printf("Task 2 : 2\n\r");
printf("Task 2 : 3\n\r");

RE: SAM3 Tasks not Switching

Posted by Richard Damon on August 26, 2013
Have you enabled preemption in FreeRTOSConfig.h? Without preemption being enabled, task switches only happen on API calls.

Note also, that with these two tasks, no tasks of lower priority will ever be run (even with the yields) so hopefully these are set to priority 0.

RE: SAM3 Tasks not Switching

Posted by Richard on August 26, 2013
...also, your printf() calls could cause any number of problems.

If the printf() output is using something slow, or something like semi-hosting, then it is likely that the output will interfer with the workings of the scheduler (semi hosting and the RTOS trying to control the hardware at the same time). When this is the case it is often found that context switches don't happen unless you put a *lot* of time space between each printf() call.

If the printf() outout is not so crude, and is instead using some sort of buffering, DMA, etc. then you will at least need to use some mutual exclusion on the printf() calls so both tasks cannot access the output channel (be that a UART, or any other console IO) at the same time. Mutual exclusion should not be removed until the buffered output has actually been sent (the buffer is empty) which is very inefficient.

Generally speaking using printf() from more than one place in a very small embedded system is just a bad idea. For one thing, if you are using newlib (which some people still do, although the new nano newlib is a lot better) then you will use a *lot* of stack and add 10s of K to your code size.


RE: SAM3 Tasks not Switching

Posted by MSH on August 27, 2013
Thank you Richard,
I see now the switching is working fine , my question is why when i enabled the preemption mode I had to increase the stack size to 1024 at least otherwise i got overflow ?

[ 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