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

PWM Uninit not working

app_pwm_uninit is hanging the code. The control goes to pwm_dealloc() and then in nrf_drv_ppi_channel_free() it hangs.

Using SDK10. I want to change the PWM frequency and have to call app_ pwm_init every time for re-initializing the channel time period. The code doesnt run pwm init twice. Hence, I figured pwm uninit should be done. But its not working.

PAN-73 workaround is there in pwm_enable and disable. Still, I am unable to figure out the issue.

  • I am having problems reproducing this issue. Can you upload a simple piece of code that reproduces it? Here is my modifications to SDK 10 PWM example, where app_pwm_uninit() is called after a short time one iteration of the original main loop. Using a debugger I see that the call to app_pwm_uninit() is successful in this case. How does yours differ?

    --- a/examples/peripheral/pwm/main.c
    +++ b/examples/peripheral/pwm/main.c
    @@ -70,8 +70,15 @@ int main(void)
                 APP_ERROR_CHECK(app_pwm_channel_duty_set(&PWM1, 1, value));
                 nrf_delay_ms(25);
             }
    +
    +        break;
         }
    
    +    err_code = app_pwm_uninit(&PWM1);
    +    APP_ERROR_CHECK(err_code);
    +
    +    while(1){}
    +
     }
    
  • The difference i find is that after app_pwm_init I call app_pwm_enable, then app_pwm_disable, and then uninit. Still I dont understand how that creates an issue. I am adding the pwm snippets I use below :

    Init

    err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    

    PWM use:

     app_pwm_enable(&PWM1);
     app_pwm_channel_duty_set(&PWM1, 0,duty);
     nrf_timer_delay_us(45);    //This is my function
     app_pwm_disable(&PWM1);
    

    Uninit:

    err_code = app_pwm_uninit(&PWM1);
    APP_ERROR_CHECK(err_code);    
    

    Then I want to run the sequence again with different frequency. So I call init again. But the code is getting stuck at uninit.

  • On further debugging I observed on commenting out the nrf_drv_timer_disable inside nrf_timer_uninit (pwm_dealloc), the code runs smooth.

    I dont know if this is a legit solution though.

  • I am not able to reproduce this issue, calling app_pwm_disable() before app_pwm_uninit() or not. If you have not done so already, can you disable optimization, define DEBUG for your project, and use a debugger to see what actually happens when you see that your application "hangs"? This way it should be easier to understand what is going on. If you need some guidance on the debugging techniques, the introduction to error handling in nRF5 projects is worth a read.

Related