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

Is it a bug in app_pwm.c?

Hi, as I tried out the example code for PWM in SDK 9, it didn't worked for me. A closer look showed that in method app_pwm_init the method app_pwm_channel_duty_ticks_set will be called before initialization is completed. This will fail because the latter method checks for p_cb->state != NRF_DRV_STATE_POWERED_ON which will be set by app_pwm_enable. But this must be called after initialization. If you comment this check, the ready_callback function will be called, which at this time is not yet initialized and therefore crashes. This leads to the conclusion, that the early call of app_pwm_channel_duty_ticks_set during initialization might be unwanted.

  • Hi codezork

    Thank you for your feedback !

    You have a point. I do not see either how calling app_pwm_channel_duty_ticks_set function before initialization is complete serves any purpose. The app_pwm_channel_duty_ticks_set function will simply return with error code NRF_ERROR_INVALID_STATE and do nothing . The error code is not checked so there is no harm done in this case but calling the app_pwm_channel_duty_ticks_set function before initialization is complete serves no purpose.

    I will report this for future improvement.

Related