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

Undefined reference to 'clock' after linking demo.elf

Hi all,

I am sorry if this is a rookie question. I had researched and tried the methods shown online, including:

  1. added $(ProjectDir)/flash_placement.xml to the linker section > section placement file of the project option
  2. editing the sdk_config.h by correcting CLOCK_ENABLED and TIMER_ENABLED from 0 to 1
  3. #include <timer.h> on the top and defined the t_latency with type clock_t

I will post my codes and the error messages in the following:

in main.c:

static void client_status_cb(const generic_on_off_client_t * p_self, generic_on_off_status_t status, uint16_t src)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_ERROR, "server status received \n");
    // Stop time for measuring latency
    t_latency_stop = clock();
    latency = t_latency_stop - t_latency_start;

... ...

... ...

void GPIOTE_IRQHandler(void)
{
    NRF_GPIOTE->EVENTS_PORT = 0;
   
        /* Check that the event was generated by a button press, and reject if it's too soon (debounce).
         * NOTE: There is a bug with this at the wrap-around for the RTC0 where the button could be
         * pressed before HAL_BUTTON_PRESS_FREQUENCY has passed a single time. It doesn't matter practically.
         */
   if( TIMER_DIFF(m_last_button_press, NRF_RTC0->COUNTER) > HAL_BUTTON_PRESS_FREQUENCY)
    {
        m_last_button_press = NRF_RTC0->COUNTER;
        // Start time for measuring latency
        t_latency_start = clock();
        button_event_handler(0);
    }
    
}
the error message:
Thank you for your time!
Best regards,
Parents Reply
  • Hi awneil,

    Thank you for your reply. Thank you for the tips for posting source code, that would be very helpful in the future!

    I had just found out online that embedded studio used to program the firmware is a freestanding embedded environment that does not support the standard C library, as someone had the same problem using clock() for other microcontroller. So the problem will arise during linking. Clock() is incorrect for the case of an embedded controller as it measures processor time taken for CPU. I have used the time elapsed after enabling Timer 0 and it worked fine.

    Best regards,

Children
Related