Skip to content

Instantly share code, notes, and snippets.

@shirish47
Created November 8, 2017 10:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirish47/5b2a04f81eab4281b5c69f678a4da352 to your computer and use it in GitHub Desktop.
Save shirish47/5b2a04f81eab4281b5c69f678a4da352 to your computer and use it in GitHub Desktop.
how to use freeRTOS timer API's in ESP32 (basic). Needed it for stoping advertisement after some time as There is not time out functionality.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "esp_log.h"
#include "freertos/timers.h"
#define TAG "TIME"
/* timer calls the function ping after interval time. xTimerCreate() takes interval in TICKs so
pdMS_TO_TICKS() converts ms interval to appropriate TICKS. pdTRUE will set timer to call periodically and if Set pdFALSE,
function is called once only */
TimerHandle_t tmr;
int id = 1;
int interval = 5000;
void ping( TimerHandle_t xTimer )
{
ESP_LOGI(TAG,"tring tring!!!");
}
void app_main()
{
ESP_LOGI(TAG,"Timer Test.\n");
tmr = xTimerCreate("MyTimer", pdMS_TO_TICKS(interval), pdTRUE, ( void * )id, &ping);
if( xTimerStart(tmr, 10 ) != pdPASS ) {
printf("Timer start error");
}
}
@mrSilkie
Copy link

Thank you so much.

The xTimerCreate doc has vTaskStartScheduler(); in it which was causing run but not compile issues. Your code highlighted this issue

@ryanminnig
Copy link

The statement "ESP_LOGI(TAG,"tring tring!!!");" is causing a task stack overflow in the timer task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment