This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to add timestamp in RTT viewer using NRF log module

Currently developing on NRF52 sdk12 with a terminal

In my source code i have nrf_log_init(null), and this allows me to print stuff to the RTT viewer.

Now I want to be able to show time stamp minutes:seconds:miliseconds on my RTT viewer, when I print my data out from the uC. I'm looking at the on the Nordic infocenter nRF Log Module , and it seems like that I have to initiate the time stamp function by passing a parameter in the init function below:

ret_code_t nrf_log_init	(	nrf_log_timestamp_func_t 	timestamp_func	)	

Currently, in my source code, I have this parameter set be NULL. So, what do I replace the NULL with in order to print out time stamp?

if someone could write out an example on how to use the timestamp function in NRF log module, then it would be great.

Thank you all for your time.

  • Hi Fordy,

    We need to clarify what kind of timestamp you are looking for here.

    Note that on the chip, there is no date time minute second etc. The chip doesn't know that. If you want to use timestamp_func, you need count your own time with a 32bit counter.

    If you want hour:minute:second in real normal time, then you need to do that on a PC. You record the timestamp when the log arrive. You can use telnet to do that as shown here and here.

  • This will achieve adding time-stamps to NRF logs, in some of the nRF example applications.

    1. Add this to main .c

    uint32_t get_rtc_counter(void)
    {
        return NRF_RTC1->COUNTER;
    }

    2. Change this in main.c

    uint32_t err_code = NRF_LOG_INIT();

    to this

    uint32_t err_code = NRF_LOG_INIT(get_rtc_counter);

    3. Change sdk_config.h

    from this

    #define NRF_LOG_USES_TIMESTAMP 0

    to this

    #define NRF_LOG_USES_TIMESTAMP 1

    The result will be to change logs from this:

    <info> app: Setting vector table to bootloader: 0x000F1000
    <info> app: Setting vector table to main app: 0x00026000
    <info> app: Buttonless DFU Application started.
    <info> app: RTC 8211
    <info> app: Received indication state 1
    <info> app: Received indication state 0

    to this:


    [00:00:00.000,000] <info> app: Setting vector table to bootloader: 0x000F1000
    [00:00:00.000,000] <info> app: Setting vector table to main app: 0x00026000
    [00:00:00.440,002] <info> app: Buttonless DFU Application started.
    [00:00:00.440,032] <info> app: RTC 14419
    [00:00:22.580,566] <info> app: Received indication state 1
    [00:00:30.905,548] <info> app: Received indication state 0

  • terminal time stamp added by windows will not suffice in some cases, since windows threading granularity will not allow a finer resolutio as fine as 1 msec, but rather a resolution only as low as 10-15 msec. This will group several log lines to have the same time-tag, even though they were sent several msec apart.

  • Hi Team,

    What is the resolution of this time stamp, like [00:00:30.905,548] , like  [ Hr:Min:Sec:Msec ].

    Regards,

    Srinivas.V

  • Note:

    You will probably also need to change another line in sdk_config.h (line 3 in this excerpt):

    // <o> NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY - Default frequency of the timestamp (in Hz) or 0 to use app_timer frequency. 
    #ifndef NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY
    #define NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY 0
    #endif

    The number 0 should be changed to the correct frequency.

    For example, my code was using LFCLK with PRESCALER = 1. 

    Per here, the counter increment frequency is 32768 / (PRESCALER + 1 ), so I set the number to 0x8000 / (1+1) = 0x4000

Related