xTimerCreate still runs even after Task is deleted
Posted: Thu Sep 21, 2023 7:08 pm
Ran into something strange today. I created a xTimerCreate inside a Task. When I delete the task the time continues to run. I expected it to stop. I though with vTaskDelete everything in that task gets wiped, no ?
Code: Select all
#include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/event_groups.h>
TaskHandle_t TaskHandle_Task_1;
/***********************************************************************
***********************************************************************/
void vKeepAliveCallback(TimerHandle_t pxTimer)
{
printf("Keep Alive Update %ld\r\n", (xTaskGetTickCount() * portTICK_PERIOD_MS));
}
/***********************************************************************
***********************************************************************/
void Task_1(void *parameter)
{
TimerHandle_t hSecondTimer;
printf("Task 1 Started\n");
hSecondTimer = xTimerCreate("KeepAlive", configTICK_RATE_HZ , pdTRUE, NULL, vKeepAliveCallback); // configTICK_RATE_HZ
xTimerStart(hSecondTimer, 0);
for(;;)
{
vTaskDelay(200 / portTICK_PERIOD_MS);
}
}
/***********************************************************************
***********************************************************************/
void app_main()
{
printf("\n***************************\n");
printf("*** ESP32 System Up **\n");
printf("***************************\n");
xTaskCreatePinnedToCore(
Task_1, // Task function.
"Task_1", // name of task.
2048, // Stack size of task
NULL, // parameter of the task
5, // priority of the task
&TaskHandle_Task_1, // Task handle to keep track of created task
1);
// Let timer run for 5 seconds before we kill Task_1
vTaskDelay(5000 / portTICK_PERIOD_MS);
vTaskDelete(TaskHandle_Task_1);
}