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

Timestamp problem

Hi team,

I am using sdk 12.1.0 and ble_app_hrs_c example.I enabled #define NRF_LOG_USES_TIMESTAMP 0 to 1 and iam usng nrf51822 dongle.my program gets hanged.I need to print the timestamp.I am unable to view the data from serial.please tell me what is the problem??

  • Hi,

    With the NRF_LOG_USES_TIMESTAMP functionality the user can create his own timestamp function. If you have enabled NRF_LOG_USES_TIMESTAMP, and have not provided the timestamp-function, initialization will fail with error NRF_ERROR_INVALID_PARAM.

    Note: Most terminal programs have their own timestamp-functionality you can enable to get timestamps. In e.g. Termite you can enable timestamp in “Settings” -> Plug-ins.

  • A quick and probably dirty way to get timestamps working.

    Copy counters.c and counter.h from examples/ble_central_and_peripheral/experimental/ble_app_att_mtu_throughput/ into your project.

    Then make the following code changes. Assumes using pca10040 and armgcc. But should be similar for other setups.

    --- a/main.c
    +++ b/main.c
    @@ -45,6 +45,8 @@
     #include "bsp.h"
     #include "bsp_btn_ble.h"
    +#include "counter.h"
    +
    @@ -773,7 +775,12 @@ int main(void)
         uint32_t err_code;
         bool erase_bonds;
    
    -    err_code = NRF_LOG_INIT(NULL);
    +#if NRF_LOG_USES_TIMESTAMP==1
    +    counter_init();
    +    counter_start();
    +#endif
    +
    +    err_code = NRF_LOG_INIT(counter_get);
         APP_ERROR_CHECK(err_code);
    --- /pca10040/s132/armgcc/Makefile
    +++ /pca10040/s132/armgcc/Makefile
    @@ -29,6 +29,7 @@ SRC_FILES += \
       $(SDK_ROOT)/components/drivers_nrf/common/nrf_drv_common.c \
       $(SDK_ROOT)/components/drivers_nrf/gpiote/nrf_drv_gpiote.c \
       $(SDK_ROOT)/components/drivers_nrf/uart/nrf_drv_uart.c \
    +  $(SDK_ROOT)/components/drivers_nrf/rtc/nrf_drv_rtc.c \
       $(SDK_ROOT)/components/libraries/bsp/bsp.c \
       $(SDK_ROOT)/components/libraries/bsp/bsp_btn_ble.c \
       $(SDK_ROOT)/components/libraries/bsp/bsp_nfc.c \
    @@ -122,6 +123,7 @@ INC_FOLDERS += \
       $(SDK_ROOT)/components/drivers_nrf/timer \
       $(SDK_ROOT)/components/libraries/util \
       $(SDK_ROOT)/components/drivers_nrf/pwm \
    +  $(SDK_ROOT)/components/drivers_nrf/rtc \
       ../config \
       $(SDK_ROOT)/components/libraries/usbd/class/cdc \
       $(SDK_ROOT)/components/libraries/csense \
    
    --- a/pca10040/s132/config/sdk_config.h
    +++ b/pca10040/s132/config/sdk_config.h
    @@ -3658,7 +3658,7 @@
     // <i> Function for getting the timestamp is provided by the user
    
     #ifndef NRF_LOG_USES_TIMESTAMP
    -#define NRF_LOG_USES_TIMESTAMP 0
    +#define NRF_LOG_USES_TIMESTAMP 1
     #endif
    
    --- a/pca10040/s132/armgcc/Makefile
    +++ b/pca10040/s132/armgcc/Makefile
    @@ -36,6 +36,7 @@ SRC_FILES += \
    +  $(PROJ_DIR)/counter.c \
       $(SDK_ROOT)/external/segger_rtt/RTT_Syscalls_GCC.c \
       $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c \
       $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c \
    
    --- a/pca10040/s132/config/sdk_config.h
    +++ b/pca10040/s132/config/sdk_config.h
    @@ -1835,7 +1835,7 @@
    
    
     #ifndef RTC2_ENABLED
    -#define RTC2_ENABLED 0
    +#define RTC2_ENABLED 1
     #endif
    
  • Note counters.c is setup to count in 10ms intervals.

  • Hallo, this modifications that I need to do it in the makefile or in the main code?

  • Hi DavidC,

    Q: this modifications that I need to do it in the makefile or in the main code?

    A: If you are using a makefile(you are in fact usign armgcc), you need to apply changes in both main code and in the makefile. All changes needed is covered in the patch snippet above.

Related