Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRFX_TIMER1_INST_IDX Error I need help.

Hello, everyone.
I use sdk v17 and pca10040.

I put the example 'pwm_library' in the example 'ble_app_uart'.

However, 'NRFX_TIMER_INSTANCE (id)' in 'nrfx_timer.h' will generate an error.

So I modified NRFX_TIMER_ENABLEED from sdk_config.h to 1

 .

But it's still the same problem.

This is the PWM code I wrote.
//Buzzer(PWM)
APP_PWM_INSTANCE(PWM1,1);                   // Create the instance "PWM1" using TIMER1.

static volatile bool ready_flag;            // A flag indicating PWM status.

void pwm_ready_callback(uint32_t pwm_id)    // PWM callback function
{
    ready_flag = true;
}
.
.
.

int main(void)
{
    bool erase_bonds;
    
    //PWM setting
    ret_code_t err_code;
  
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1500, buzzer_pin); //period_in_us(sound), pin

    /* Switch the polarity of the second channel. */
    pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    //app_pwm_enable(&PWM1); //pwm start


    // Initialize.
    uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

//=================================================================================================================================
    //add Initialize
    bsp_board_init(BSP_INIT_LEDS); //board led init
    //bsp_board_init(BSP_INIT_BUTTONS);
    nrf_drv_systick_init(); //systick init
    //buttons_init();
  

    // Start execution.
    printf("\r\nUART started.\r\n");
    NRF_LOG_INFO("Debug logging for UART over RTT started.");
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
         
        //send data to app (OK)
        ble_nus_data_send(&m_nus, data_string1, &length1, m_conn_handle); 


       //PWM
       ready_flag = false;
       //wait for callback
       while (app_pwm_channel_duty_set(&PWM1, 0, 10) == NRF_ERROR_BUSY); //p_instance, channel, duty cycle(%)
       //app_pwm_channel_duty_set(&PWM1, 0, 10); 
       app_pwm_enable(&PWM1); //start pwm
       nrf_delay_ms(1000);
       app_pwm_disable(&PWM1); //stop pwm
       nrf_delay_ms(1000);
 
    }
}

Can I get a solution to this problem?


Thank you in advance.
  • Hi,

    The problem here is likely that the nrfx configuration macros arere defined to the value of the old river configuration by apply_old_config.h. The straightforward fix is simply to configure the old configuration macros correctly, and then that will be used. For instance, to enable the TIMER module, set TIMER_ENABLED to 1 instead of 0. And to enable (e.g.) TIMER1, set TIMER1_ENABLED to 1 instead of 0. The nrfx macros will then get the correct configuration.

    This is not important, but if you want to know the detail the reason for having to use the above approach is this conversion (which is used for most nrfx configuration macros):

    ...
    #if defined(TIMER0_ENABLED)
    #undef NRFX_TIMER0_ENABLED
    #define NRFX_TIMER0_ENABLED  TIMER0_ENABLED
    #endif
    ...

Related