sample timer program not working

lalatdas
Posts: 3
Joined: Wed Jun 21, 2017 2:44 pm

sample timer program not working

Postby lalatdas » Wed Jun 21, 2017 3:05 pm

Hi All,
I was trying to do a hands-on using FreeRTOS timer infrastructure on a ESP32 board. I wrote a simple program of repetitive timer which will just print the no. of times timer is fired.

Only config I have alter from default config is as below
- Set TICK_RATE set to 1000 , I am assuming doing this will make 1 tick = 1second
- Changed another config to invoke GDBstub when a panic occurs to debug the issue better.

Unfortunately the system is panicking with following message

Code: Select all

I (912) cpu_start: Starting scheduler on PRO CPU.
****SAMPLE Timer TEST Start*** 
I (200) cpu_start: Starting scheduler on APP CPU.
Hndl 0x3ffaffc8
CREATE PASS
TIMER START PASS
/home/das/esp/esp-idf/components/freertos/./queue.c:1442 (xQueueGenericReceive)- assert failed!
abort() was called at PC 0x400832ff on core 0
0x400832ff: xQueueGenericReceive at /home/das/esp/esp-idf/components/freertos/./queue.c:2034

Guru Meditation Error: Core  0 panic'ed (abort)

Backtrace: 0x40008155:0x3ffb5ce0 0x40007d16:0x3ffb5d00 0x40083434:0x3ffb5d40 0x40081c68:0x3ffb5d60 0x40081d48:0x3ffb5d90 0x400d82b1:0x3ffb5db0 0x400dc6d0:0x3ffb60c0 0x400dbb42:0x3ffb6110 0x40084e9a:0x3ffb6130 0x40084f10:0x3ffb6150 0x40084f83:0x3ffb6170 0x400850b3:0x3ffb61a0
0x40083434: xQueueTakeMutexRecursive at /home/das/esp/esp-idf/components/freertos/./queue.c:2034

0x40081c68: lock_acquire_generic at /home/das/esp/esp-idf/components/newlib/./locks.c:147

0x40081d48: _lock_acquire_recursive at /home/das/esp/esp-idf/components/newlib/./locks.c:161

0x400d82b1: _vfprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vfprintf.c:862

0x400dc6d0: printf at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/printf.c:61

0x400dbb42: tm_clbk at /home/das/esp/sample_timer_app/main/./sample_timer.c:14

0x40084e9a: prvSwitchTimerLists at /home/das/esp/esp-idf/components/freertos/./timers.c:744

0x40084f10: prvSampleTimeNow at /home/das/esp/esp-idf/components/freertos/./timers.c:539

0x40084f83: prvProcessTimerOrBlockTask at /home/das/esp/esp-idf/components/freertos/./timers.c:462

0x400850b3: prvTimerTask at /home/das/esp/esp-idf/components/freertos/./timers.c:445 (discriminator 1)
My sample program looks as below

Code: Select all

/*
 *  Timer Example
 *
 */
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"

volatile int g_cnt = 1;
void tm_clbk(TimerHandle_t tm_hndl)
{
    printf("Timer Callback Called %d time", g_cnt);
    ++g_cnt;
}

void one_shot_timer_start(void)
{
    TimerHandle_t tm_hndl;
    char *tm_name = "Demo Timer";
    TickType_t tm_period = 3000;
    int ret;

    tm_hndl = xTimerCreate(tm_name, tm_period, pdTRUE, (void *) 0, tm_clbk);
    printf("Hndl %p\n", tm_hndl);
    if(tm_hndl == NULL) {
        printf("timer create FAILED\n");
        return;
    } else {
        printf("CREATE PASS\n");
        ret = xTimerStart(tm_hndl, 0);
        if(ret != pdPASS) {
            printf("Timer Start FAILED\n");
            return;
        }
        printf("TIMER START PASS\n");
    }

    vTaskStartScheduler();
}


void app_main()
{
    //xTaskCreate(&blink_task, "blink_task", 512, NULL, 5, NULL);
    printf("****SAMPLE Timer TEST Start***\n");
    one_shot_timer_start();
    for (;;);
}
Function name and its implementation are opposite in nature and it is intentional.
Moreover the timer specific config set is
CONFIG_TIMER_TASK_PRIORITY=1
CONFIG_TIMER_TASK_STACK_DEPTH=2048
CONFIG_TIMER_QUEUE_LENGTH=10

Is this a known issue? Am I missing some other config here with respect to ESP32 board config.
The esp-idf I am using is 1 week old. I assume there is nothing fixed in past 1 week which has fix for this issue. At least googling it did not point me that way.

Thanks

ESP_Sprite
Posts: 9835
Joined: Thu Nov 26, 2015 4:08 am

Re: sample timer program not working

Postby ESP_Sprite » Thu Jun 22, 2017 2:09 am

A TICK_RATE of 1000 means 1000 ticks/second, so a tick is 1ms. Furthermore, why do you call vTaskStartScheduler yourself? When esp-idf calls your main function, the scheduler already is running.

lalatdas
Posts: 3
Joined: Wed Jun 21, 2017 2:44 pm

Re: sample timer program not working

Postby lalatdas » Thu Jun 22, 2017 8:06 am

yeah you are right about the tick Rate. My bad in typo.
Moreover I am using vTaskStartScheduler() because I saw the same in a FreeRTOS sample timer code explanation. I may have misinterpreted it. http://www.freertos.org/FreeRTOS-timers ... reate.html

--snip from the web page---
/* Starting the RTOS scheduler will start the timers running
as they have already been set into the active state. */
vTaskStartScheduler();
---snip from web page---
If esp-idf is already started it then we shouldn't start it. And after removing it, The code worked fine.
Thanks a lot for pointing it.

But I am facing another issue if I run this function one_shot_timer_start() as part of a thread, then the system is panicking.
say instead of calling one_shot_timer_start() from app_main(), If I call it via a thread as below
xTaskCreate(&one_shot_timer_start, "tim_task", 2048, NULL, 3, NULL);
Then the system is panicking.
Is it evident. I am not calling vTaskStartScheduler() in this case too.

ESP_Sprite
Posts: 9835
Joined: Thu Nov 26, 2015 4:08 am

Re: sample timer program not working

Postby ESP_Sprite » Thu Jun 22, 2017 8:31 am

Without code, it's hard to say, but is that task exiting by deleting itself using vTaskDelete(NULL) or is it just returning? If the second, that panics indeed; make it delete itself instead and it'll work fine.

lalatdas
Posts: 3
Joined: Wed Jun 21, 2017 2:44 pm

Re: sample timer program not working

Postby lalatdas » Thu Jun 22, 2017 2:33 pm

Yeah vTaskDelete(NULL) resolved the issue
Thanks a lot.

Who is online

Users browsing this forum: No registered users and 136 guests