This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Calling NRF_LOG_INFO within a Timer Callback function

Hi,

This may be a basic question. I'm using NRF52840 DK and I'm trying to print some logs from timer callback function, however I havent been successful so far. Here is my code:

void example_timer_callback(void * pvParameter)
{
	NRF_LOG_DEBUG("Task Excuted..");
	NRF_LOG_FLUSH();
}

/**@brief Function for application main entry.
 */
int main(void)
{
    bool erase_bonds;

    // Initialize modules.
    log_init();
    clock_init();
	
	

    // Do not start any interrupt that uses system functions before system initialisation.
    // The best solution is to start the OS before any other initalisation.

#if NRF_LOG_ENABLED
    // Start execution.
    if (pdPASS != xTaskCreate(logger_thread, "LOGGER", 256, NULL, 1, &m_logger_thread))
    {
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }
#endif

    // Activate deep sleep mode.
    SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
		
		
    example_timer_handle = xTimerCreate( "SPIRead", 100, pdTRUE, NULL, example_timer_callback);
    UNUSED_VARIABLE(xTimerStart(example_timer_handle , 0));
			
		
    // Start FreeRTOS scheduler.
    vTaskStartScheduler();
		
    for (;;)
    {
        APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);
    }
		
}

I tried the following methods:

1- example_timer_callback: Calling NRF_LOG_INFO only without the NRF_LOG_FLUSH.  I didnt see any prints although the timer was working.

2- example_timer_callback: Calling NRF_LOG_FLUSH after NRF_LOG_INFO. I see some prints. however. the app crashes and I get this:

<error> hardfaul<debug> app: Task Excuted..

þ<error> hardfault: HARD FAULT at 0x20005C70

<error> hardfault: R0: 0x0003539C R1: 0x200088DC R2: 0x200088DC R3: 0x200059E8

<error> hardfault: R12: 0xA5A5A5A5 LR: 0x20005C70 PSR: 0x0000000E

<error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.

For this I tried to increase the Heap and Stack size in Keil, but this doesnt seem to help

So I'm not sure if printing logs is not allowed at all within the timer callback or if there another way to do it. Any help would be appreciated

Regards

 

Parents
  • You most likely are seeing a stack overflow corruption which might cause a hardfault/Busfault.

    Try to increase the below in your FreeRTOSConfig.h file with the amount you think the logs can take at worst scenario. For example try big values like

    #define configMINIMAL_STACK_SIZE ( 300 )
    #define configTOTAL_HEAP_SIZE ( 2*4096 )

    Since you are using logs in timer callback, do this also.

    #define configTIMER_TASK_STACK_DEPTH                                              ( 1024 )   

Reply
  • You most likely are seeing a stack overflow corruption which might cause a hardfault/Busfault.

    Try to increase the below in your FreeRTOSConfig.h file with the amount you think the logs can take at worst scenario. For example try big values like

    #define configMINIMAL_STACK_SIZE ( 300 )
    #define configTOTAL_HEAP_SIZE ( 2*4096 )

    Since you are using logs in timer callback, do this also.

    #define configTIMER_TASK_STACK_DEPTH                                              ( 1024 )   

Children
No Data
Related