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

undefined reference to timer functions

Hello all, my compiler can't find the definition to timer functions : nrf_drv_timer_init(), nrf_drv_timer_extended_compare() and nrf_drv_timer_enable(). bellow my code :

/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
 *
 * The information contained herein is property of Nordic Semiconductor ASA.
 * Terms and conditions of usage are described in detail in NORDIC
 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
 *
 * Licensees are granted free, non-transferable use of the information. NO
 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
 * the file.
 *
 */

/** @file
 * @defgroup pwm_example_main main.c
 * @{
 * @ingroup pwm_example
 *
 * @brief PWM Example Application main file.
 *
 * This file contains the source code for a sample application using PWM.
 */

#include <stdio.h>
#include <string.h>
#include "nrf_drv_pwm.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "boards.h"
#include "bsp.h"
#include "nrf_drv_clock.h"
#define NRF_LOG_MODULE_NAME "APP"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_drv_gpiote.h"
#include "nrf_drv_timer.h"

#define PWM_ACT1_PIN 30

#define TOP_VALUE_PWM          100
#define PERIOD_PWM             NRF_PWM_CLK_4MHz

#define pwmDuty                25
static nrf_drv_pwm_t PWM = NRF_DRV_PWM_INSTANCE(0);

const nrf_drv_timer_t TIMER_PWM = NRF_DRV_TIMER_INSTANCE(0); /*<creating a timer driver instance>*/

static nrf_pwm_values_common_t seq0_values=100-pwmDuty;
nrf_pwm_sequence_t const       seq0 =
{
    .values.p_common = &(seq0_values),
    .length          = NRF_PWM_VALUES_LENGTH(seq0_values),
    .repeats         = 1,
    .end_delay       = 0
};

void timer_pwm_event_handler(nrf_timer_event_t event_type, void* p_context)
{
  switch (event_type)
  {
      case NRF_TIMER_EVENT_COMPARE0:


          break;

      default:
          //Do nothing.
          break;
  }
}
void init_timer()
{
  uint32_t time_ms = 100; //Time(in miliseconds) between consecutive compare events.
  uint32_t time_ticks;
  uint32_t err_code = NRF_SUCCESS;
  nrf_drv_timer_config_t timer_cfg;

  timer_cfg.frequency          = 0; // 16MHz
  timer_cfg.mode               = 0; //Timer
  timer_cfg.bit_width          = 0; // 16 bits
  timer_cfg.interrupt_priority = 3; // priotity 3

  err_code = nrf_drv_timer_init(&TIMER_PWM, &timer_cfg, timer_pwm_event_handler);
  APP_ERROR_CHECK(err_code);

  time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_PWM, time_ms);

  nrf_drv_timer_extended_compare(
    &TIMER_PWM,
    NRF_TIMER_CC_CHANNEL0,
    time_ticks,
    NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
    true);

  nrf_drv_timer_enable(&TIMER_PWM);
 //nrf_drv_timer_disable
}
static void demo1(void)
{
    uint32_t                   err_code;
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            PWM_ACT1_PIN, // channel 0
            NRF_DRV_PWM_PIN_NOT_USED,
            NRF_DRV_PWM_PIN_NOT_USED,
            NRF_DRV_PWM_PIN_NOT_USED,
        },
        .irq_priority = APP_IRQ_PRIORITY_LOW,
        .base_clock   = PERIOD_PWM,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = TOP_VALUE_PWM,
        .load_mode    = NRF_PWM_LOAD_COMMON,
        .step_mode    = NRF_PWM_STEP_AUTO
    };

    err_code = nrf_drv_pwm_init(&PWM, &config0, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_pwm_simple_playback(&PWM, &seq0, 1,
                                 NRF_DRV_PWM_FLAG_LOOP);
}

/*void update_pwm(int16_t duty_cycle)
{
    duty_cycle = 100-duty_cycle;
    nrf_drv_pwm_simple_playback(&PWM, &seq0, 1,
                                 NRF_DRV_PWM_FLAG_LOOP);
}*/

int main(void)
{
    init_timer();
    demo1();

    while(1)
    {
    }
}


/** @} */

the error message is :

/home/ac/Desktop/test_nRF52/examples/peripheral/pwm_driver/pca10040/blank/armgcc/../../../main.c:82: undefined reference to `nrf_drv_timer_init'
/home/ac/Desktop/test_nRF52/examples/peripheral/pwm_driver/pca10040/blank/armgcc/../../../main.c:87: undefined reference to `nrf_drv_timer_extended_compare'
/home/ac/Desktop/test_nRF52/examples/peripheral/pwm_driver/pca10040/blank/armgcc/../../../main.c:94: undefined reference to `nrf_drv_timer_enable'

Can someone help me please? :)

Parents Reply Children
  • If I disable APP_TIMER_ENABLE then I get other errors of undefined reference to app_timer_start. so if I want to use app timer so what changed do I need to do for solving nrfx_timer undefined errors?

  • App_timer and nrfx_timer are not related at all. app_timer runs on the LFCLK and RTC, while nrfx_timer is the driver for the HW TIMER peripheral. If you do not intend to use the timer, remove any source/header files related to it from the project, and disable it in sdk_config.h by setting NRFX_TIMER_ENABLED and TIMER_ENABLED to 0.

  • Actually, I have merged freeRTOS and SAADC example with ble_app_uart example as per my requirements. so in that m getting the following errors. Please suggest any solution for it.:

    Output/ble_app_uart_pca10040_s132 Release/Obj/bsp.o: In function `bsp_button_event_handler':
    undefined reference to `app_timer_start'
    undefined reference to `app_timer_stop'
    Output/ble_app_uart_pca10040_s132 Release/Obj/bsp.o: In function `bsp_led_indication':
    undefined reference to `app_timer_stop'
    undefined reference to `app_timer_stop'
    undefined reference to `app_timer_start'
    undefined reference to `app_timer_start'
    Output/ble_app_uart_pca10040_s132 Release/Obj/bsp.o: In function `bsp_init':
    undefined reference to `app_timer_create'
    undefined reference to `app_timer_create'
    undefined reference to `app_timer_create'
    Output/ble_app_uart_pca10040_s132 Release/Obj/main.o: In function `saadc_sampling_event_init':
    undefined reference to `nrfx_timer_init'
    undefined reference to `nrfx_timer_extended_compare'
    undefined reference to `nrfx_timer_enable'
    undefined reference to `nrf_drv_saadc_task_address_get'
    Output/ble_app_uart_pca10040_s132 Release/Obj/main.o: In function `timers_init':
    undefined reference to `app_timer_init'
    Output/ble_app_uart_pca10040_s132 Release/Obj/ble_conn_params.o: In function `conn_params_negotiation':
    undefined reference to `app_timer_start'
    Output/ble_app_uart_pca10040_s132 Release/Obj/ble_conn_params.o: In function `on_write':
    undefined reference to `app_timer_stop'
    Output/ble_app_uart_pca10040_s132 Release/Obj/ble_conn_params.o: In function `on_disconnect':
    undefined reference to `app_timer_stop'
    Output/ble_app_uart_pca10040_s132 Release/Obj/ble_conn_params.o: In function `ble_conn_params_init':
    undefined reference to `app_timer_create'
    Build failed

  • Make sure that you have included the following source files in your project: app_timer.c, nrfx_timer.c, and nrfx_saadc.c,  and make sure that the following defines are set in your sdk_config.h file: APP_TIMER_ENABLED, TIMER_ENABLED, SAADC_ENABLED.

    Unless you have modified the examples/function calls, I believe all these examples use the legacy driver APIs.

  • Yes, I have included all the above c files and also have enabled the macros. But still I am not getting what I am missing out.

Related