Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Undefined symbol nrf_drv_pwm_init (referred from main.o).

Hello, I am trying to modify my code by adding lines from a PWM example code.

However, I keep facing the same error message.

.\_build\nrf52832_xxaa.axf: Error: L6218E: Undefined symbol nrf_drv_pwm_init (referred from main.o).

.\_build\nrf52832_xxaa.axf: Error: L6218E: Undefined symbol nrf_drv_pwm_init (referred from main.o).

code for this part is below,

void pwm_update_duty_cycle(uint8_t duty_cycle)
{
    
    // Check if value is outside of range. If so, set to 100%
    if(duty_cycle >= 100)
    {
        seq_values->channel_0 = 100;
    }
    else
    {
        seq_values->channel_0 = duty_cycle;
    }
    
    nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 1, NRF_DRV_PWM_FLAG_LOOP);
}

static void pwm_init(void)
{
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            OUTPUT_PIN, // channel 0
            NRF_DRV_PWM_PIN_NOT_USED,             // channel 1
            NRF_DRV_PWM_PIN_NOT_USED,             // channel 2
            NRF_DRV_PWM_PIN_NOT_USED,             // channel 3
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_1MHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 100,
        .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    // Init PWM without error handler
    APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));
    
}

I included these headers.

#include "nrf_drv_pwm.h"	
#include "app_util_platform.h"	
#include "nrf_drv_clock.h"			

And also checked whether they are contained in the project.

Does anyone have a clue about my problem, or can you help me to solve this issue?

  • Howdy! Note that driver implementations usually have compiler guards that keep the source code from being compiled unless the driver has been enabled in your sdk_config.h. In SDK 17 the nrfx_pwm.c has "#if NRFX_CHECK(NRFX_PWM_ENABLED)" at the top so check your sdk_config.h and make sure that you have NRFX_PWM_ENABLED defined as 1. If you look at the sdk_config.h in the original PWM example that you are taking code from you'll probably find some other NRFX_PWM-related symbols that you'll need to copy into your sdk_config.h.

  • Howdy! It might be a stupid question, but I could find neither of the NRFX_PWM_ENABLED in the sdk_config.h or nrfx_pwm.c from the project tree.

    However, I found PWM enabling code from the sdk_config.h, so I changed it as 1

    #ifndef PWM_ENABLED
    #define PWM_ENABLED 1		//originally 0
    #endif
    #if  PWM_ENABLED

    #ifndef APP_PWM_ENABLED
    #define APP_PWM_ENABLED 1		//originally 0
    #endif
    

    #ifndef LOW_POWER_PWM_ENABLED
    #define LOW_POWER_PWM_ENABLED 1			//originally 0
    #endif

    Unfortunately, the same error messages have appeared.

    Do you think I am missing something?

  • It looks like you're using a quite old version of the SDK. Back in SDK 14 the driver was just called nrf_drv_pwm but the same idea applies. If you look at the top of nrf_drv_pwm.c you'll see an additional compiler guard

    #define ENABLED_PWM_COUNT (PWM0_ENABLED+PWM1_ENABLED+PWM2_ENABLED)
    #if ENABLED_PWM_COUNT

    so make sure you have at least one of the PWMX_ENABLED constants set in your sdk_config.h. In fact, I'd probably just copy all of the PWM stuff from "examples/peripheral/pwm_driver/pca10040/blank/config/sdk_config.h" starting at line 133. Once it compiles you can go back and adjust the values as necessary.

  • Thank you very much!

    Actually, I enabled all the options that are relevant to the PWM, and it works now!!

Related