Logging with timestamp on SDK 15.2

i have recently upgraded to SDK 15.2, and since doing so I am struggling to get timestamps working in the logger.

I am initialising the logger here:

    //Start microsecond timer:
    us_timer_config();
    ret_code_t err_code = NRF_LOG_INIT(time_us);
    APP_ERROR_CHECK(err_code);

And here is my microsecond timer. 

#include "velo_us_timer.h"
//
const nrf_drv_timer_t us_timer = NRF_DRV_TIMER_INSTANCE(1);


void us_timer_config(void)
{
	uint32_t err_code=NRF_SUCCESS;
		nrf_drv_timer_config_t timer_cfg = 
	{
		.frequency = NRF_TIMER_FREQ_1MHz,	//Sets prescaler to get a counter increment at 1MHz.
		.mode = NRF_TIMER_MODE_TIMER,		// in this mode counter increments by 1 on each clock cycle (clock x prescaler actually)
		.bit_width = NRF_TIMER_BIT_WIDTH_32,    
		.interrupt_priority = TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, 
    .p_context          = NULL     
		
	};
		err_code=nrf_drv_timer_init(&us_timer,&timer_cfg,us_timer_event_handler);
		APP_ERROR_CHECK(err_code);
    nrf_drv_timer_enable(&us_timer);
}

// Timestamp function for logging
uint32_t time_us(void)
{
	uint32_t time = nrf_drv_timer_capture(&us_timer,NRF_TIMER_CC_CHANNEL0);
	return time;
}

When I log (using NRF_LOG_INFO("comment")) no timestamp appears.  This code worked in SDK 14.2 .  Any ideas what I'm misssing?  Thank you.

  • Hi

    Have you taken a look at our migration guide for the SDK 15? There is probably something there you missed, as there are tweeks in each major SDK release.

    Best regards,

    Simon

  • hi,

    No there is nothing in the migration guide about the logging module.

  • Hi

    What example are you basing your project in? And how exactly did you upgrade the SDK? There might be some changes done to the logger in the sdk_config.h file if you just changed the SDK version of the example and added your custom code.

    Best regards,

    Simon

  • I didnt base on an example.  I just went through bit by bit fixing all teh issues I had.  My code is quite complex so it wasnt really appropriate to start from an example.

    Are you able to give me an example of how to setup the timer usage inside the logger?

  • Hi

    You can use the example SDK15.2\examples\ble_peripheral\experimental\ble_app_cli as a template, and look at the core_init function there. Also,make sure you have enabled NRF_LOG_USES_TIMESTAMP in your config file, set NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY as 0 to use the app_timer frequency, or set the frequency yourself.

    Best regards,

    Simon

    EDIT: I think I found an easier starting point, as the aforementioned project might be confusing. You can look at the SDK15.2\examples\ble_peripheral\ble_app_hrs example instead, here too make sure to enable NRF_LOG_USES_TIMESTAMP, and use app_timer as the frequency variable (at least I did). Then run NRF_LOG_INIT(app_timer_cnt_get), by default that function is NRF_LOG_INIT(NULL) so you have to change that. 

    Also I don't know if you are using UART or RTT as a backend, but I recommend RTT as UART might mix up the timestamp info depending on what terminal you are using.

Related