Usage of printf() xTaskGetTickCount() vTaskDelay() #52
Replies: 10 comments
-
It is likely that both these issues are caused by a Stack overflow. The Given you're using a ATmega2560, try using 512 bytes of Stack for each Task, for example. If that doesn't work, add a comment here. |
Beta Was this translation helpful? Give feedback.
-
OK |
Beta Was this translation helpful? Give feedback.
-
I give 2048 byte of stack for each task.
|
Beta Was this translation helpful? Give feedback.
-
Tested working with below code. The #include <Arduino_FreeRTOS.h>
static void task( void *pvParameters );
// Task Body
void task(void *pvParameters)
{
Serial.print("pcTaskGetName=");
Serial.println(pcTaskGetName(NULL));
pinMode(LED_BUILTIN, OUTPUT);
for (;;) // A Task shall never return or exit.
{
Serial.print(F("xTaskGetTickCount="));
Serial.println(xTaskGetTickCount());
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
vTaskDelay( 1000 / portTICK_PERIOD_MS ); // wait for one second
}
vTaskDelete( NULL );
}
//------------------------------------------------------------------------------
void setup() {
portBASE_TYPE xTask1, xTask2;
Serial.begin(38400);
Serial.println(F("setup() start"));
Serial.print(F("configTICK_RATE_HZ:"));
Serial.println(configTICK_RATE_HZ);
Serial.print(F("portTICK_PERIOD_MS:"));
Serial.println(portTICK_PERIOD_MS);
Serial.print(F("freeRTOS version:"));
Serial.println(tskKERNEL_VERSION_NUMBER);
xTask1 = xTaskCreate(task, "Task1", 256, NULL, 2, NULL);
// xTask2 = xTaskCreate(task, "Task2", 256, NULL, 2, NULL);
/* Check everything was created. */
configASSERT( xTask1 );
// configASSERT( xTask2 );
// Now the task scheduler, which takes over control of scheduling individual tasks, is automatically started.
}
//------------------------------------------------------------------------------
// WARNING loop() called from vApplicationIdleHook(), so don't use this function.
// loop must never block
void loop() {
// Not used.
}
|
Beta Was this translation helpful? Give feedback.
-
printf() crashes the system.
|
Beta Was this translation helpful? Give feedback.
-
I mentioned above that if you want to use Also, Please, read the instructions on how to use the library from the FreeRTOS web site, and use working examples as a tutorial. |
Beta Was this translation helpful? Give feedback.
-
In my environment, printf() crashes even if I include stdio.h.
I tried the code you provided.
This code don't work.
My environment:
|
Beta Was this translation helpful? Give feedback.
-
I'd note that a quick Google search would inform that Open the |
Beta Was this translation helpful? Give feedback.
-
You can't do a delay depending on the scheduler, before the scheduler has been started...
Read the comment at the bottom of the setup...
|
Beta Was this translation helpful? Give feedback.
-
OK!! I understood everything. |
Beta Was this translation helpful? Give feedback.
-
My environment:
Arduino-IDE 1.8.5 + ATMEGA2560
There is 2 issues.
#1 xTaskGetTickCount() makes a system crash.
#2 printf() not work.
Source Code:
Beta Was this translation helpful? Give feedback.
All reactions