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.

Parents
  • 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

Reply
  • 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

Children
Related