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
Related