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

Getting an undefined reference error for a defined function

SDK 14.2, S140, NRF52840

I was trying to use the low_power_pwm library but upon copying the code from the lpp example, I get this:

Linking ble_bse_pca10056_s40.elf, 4 errors

"C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 4.30/gcc/arm-none-eabi/bin/ld" -X --omagic -eReset_Handler --defsym=__vfprintf=__vfprintf_long --defsym=__vfscanf=__vfscanf_int -EL --gc-sections "-TC:/<path to project folder>/Output/ble_bse_pca10056_s140 Debug/Obj/ble_bse_pca10056_s140.ld" -Map Output/Debug/Exe/ble_bse_pca10056_s140.map -u_vectors -o Output/Debug/Exe/ble_bse_pca10056_s140.elf --emit-relocs --start-group "@C:/<path to project folder>/Output/ble_bse_pca10056_s140 Debug/Obj/ble_bse_pca10056_s140.ind" --end-group

even though I have specified #include "low_power_pwm.h" at the top of the file. Any ideas why this is happening? All my other #includes work.

PWM code below, where LED_GREEN is the GPIO pin number for the green LED. 

static low_power_pwm_t low_power_pwm_green;

/**
 * @brief Function to be called in timer interrupt.
 *
 * @param[in] p_context     General purpose pointer (unused).
 */
static void pwm_handler(void * p_context)
{
    uint8_t new_duty_cycle;
    static uint16_t led_0, led_1;
    uint32_t err_code;
    UNUSED_PARAMETER(p_context);

    low_power_pwm_t * pwm_instance = (low_power_pwm_t*)p_context;

	NRF_LOG_INFO("<in PWM handler>"); // placeholder to make sure function works
}

/**
 * @brief Function to initalize low_power_pwm instances.
 *
 */
static void pwm_init(void)
{
    uint32_t err_code;
    low_power_pwm_config_t low_power_pwm_config;

    APP_TIMER_DEF(pwm_timer_green);
    low_power_pwm_config.active_high    = false;
    low_power_pwm_config.period         = 220;
    low_power_pwm_config.bit_mask       = 1 << LED_GREEN;
    low_power_pwm_config.p_timer_id     = &pwm_timer_green;
    low_power_pwm_config.p_port         = NRF_GPIO;

    err_code = low_power_pwm_init((&low_power_pwm_green), &low_power_pwm_config, pwm_handler);
    APP_ERROR_CHECK(err_code);
    err_code = low_power_pwm_duty_set(&low_power_pwm_green, 20);
    APP_ERROR_CHECK(err_code);

    err_code = low_power_pwm_start((&low_power_pwm_green), low_power_pwm_green.bit_mask);
    APP_ERROR_CHECK(err_code);
}

pwm_init(); is called in main() after services_init(), advertising_init(), etc.

I have tried rebuilding the solution, cleaning & rebuilding the solution. Nothing solves the compilation error. The file low_power_pwm.h is unmodified. The error persists after I add the low_power_pwm.c file to the project via these instructions from Segger. I added it as an existing file, then I dragged it to the nrf_Libraries folder within the project.

Parents
  • Hi,

    You must also add the path of the header file low_power_pwm.h to user include directories in SES. You can do this by right clicking on your project in the project explorer in SES, "Project '<project_name>'", and then selecting Options > Preprocessor > User Include Directories. Make sure that configurations is set to common, and not debug or release. Please note that you need to have the correct depth of the path, so you must have enough "../../../" before the folder the header file is located in. You can compare with the other user include directories to see how you should add this.

    Best regards,

    Marte

  • It was already there when I had this problem, so it seems like something else is wrong...

    Also, I have had that problem before, where the right paths are not included in the User Include Directories. The compilation error that happens in this case is instead "<file path>: no such file or directory."

    The error I am getting is: "undefined reference to <function name>"

Reply Children
Related