FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2013 Threads] SAM3 Tasks not SwitchingPosted 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) { UNUSED(pvParameters); while (1) {
LED_Toggle(LED0); printf("Task 1 : 1\n\r"); printf("Task 1 : 2\n\r"); printf("Task 1 : 3\n\r"); //taskYIELD(); } }
static void task2(void *pvParameters) { UNUSED(pvParameters); while (1) { printf("Task 2 : 1\n\r"); printf("Task 2 : 2\n\r"); printf("Task 2 : 3\n\r"); //taskYIELD(); } }
RE: SAM3 Tasks not SwitchingPosted 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 SwitchingPosted 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.
Regards.
RE: SAM3 Tasks not SwitchingPosted 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 ?
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|