Freertos software timer, RTT logs -> Hard Fault

Hello. 

I am trying to use FreeRTOS and have run into a problem. If I call logging in the FreeRTOS software timer handler, the program stops. 

Here is a simple example:

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "nrf_drv_common.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#include "FreeRTOS.h"
#include "timers.h"
#include "task.h"

volatile TimerHandle_t xOneSec_Timer;

void blink_task(void *p){
    
    while(1){
        NRF_LOG_INFO("Blink");
        vTaskDelay(1000);
    }
};

void vOneSecTimer( TimerHandle_t xTimer ){
	configASSERT( xTimer );
	
    NRF_LOG_INFO("Timer");
}

int main(void)
{
    ret_code_t err_code;
    
    // Initialize.
    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("Start");

    for(uint32_t i=0; i<20; i++){
        NRF_LOG_INFO("Count %d",i);
        for(uint32_t k=0; k<0x100000; k++){__NOP();};
    }
    
    xOneSec_Timer = xTimerCreate( "1STimer", 1000 , pdTRUE, NULL, vOneSecTimer);
    xTimerStart(xOneSec_Timer,0);

    xTaskCreate(blink_task, "Blink", 256, NULL, 2, NULL);
    vTaskStartScheduler();

    while(1);
}

The output to the Ozone terminal looks like this: I see a "Start" message, messages with a counter, but as soon as the timer handler is called, the program stops. If in the timer handler you do not call a log entry, but for example blink the LED, then everything works. I see messages from the blink task and blinking LED.

What am I doing wrong?

Parents
  • Hi Irek, Thanks for your patience. I tested your code now..

    What you are seeing is a stack overflow in the timer thread due to the use of LOG in your vOneSecTimer callback. This is very similar to what is mentioned here. You need to increase configTIMER_TASK_STACK_DEPTH in your FreeRTOSConfig.h file to something liek 250 and this issue goes away. 

    As an application engineer, it is your responsibility to know which RTOS task's stack usage. Seems like default 80 bytes of stack for the timer is not enough. 

Reply
  • Hi Irek, Thanks for your patience. I tested your code now..

    What you are seeing is a stack overflow in the timer thread due to the use of LOG in your vOneSecTimer callback. This is very similar to what is mentioned here. You need to increase configTIMER_TASK_STACK_DEPTH in your FreeRTOSConfig.h file to something liek 250 and this issue goes away. 

    As an application engineer, it is your responsibility to know which RTOS task's stack usage. Seems like default 80 bytes of stack for the timer is not enough. 

Children
No Data
Related