This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

callback isn't optional in app_pwm_init

Hi,

I bumped into a problem trying to get PWM working and traced it back to the app_pwm_init function, for a simple test case use the the pwm example in the 8.1.0 SDK and change:

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

to:

err_code = app_pwm_init(&PWM1,&pwm1_cfg, NULL);

This ultimately ends up running the hardfault handler; it should be allowed according to the docs "Pointer to ready callback function (or NULL to disable)."

developer.nordicsemi.com/.../a00983.html

My setup: sdk 8.1.0 sd: 8.0.0 ic: nRF51822 AA G0

perhaps it's because I'm using r2 silicon and not r3, just thought I'd let someone know.

All the best Wayne

Parents
  • Nothing at all to do with r2 and r3 silicon - all you have to do is look at the code for app_pwm_init and see the code says

    ret_code_t app_pwm_init(app_pwm_t const * const p_instance, app_pwm_config_t const * const p_config,
                            app_pwm_callback_t p_ready_callback)
    {
        ASSERT(p_instance);
        ASSERT(p_ready_callback);
    

    So yes that's going to assert right away if p_ready_callback is NULL.

    If you also check the two places in the code the callback is used, neither of them check for nil eg,

    if (ticks == p_ch_cb->pulsewidth)
        {
            p_cb->p_ready_callback(p_instance->p_timer->instance_id);
            return NRF_SUCCESS;     // No action required.
        }
    

    so NULL Is not an option. Clearly the header file is just wrong in this instance. You can remove the assert() and add a guard to the two places the callback is called only to call if not NULL, or just supply a simple do-nothing handler.

Reply
  • Nothing at all to do with r2 and r3 silicon - all you have to do is look at the code for app_pwm_init and see the code says

    ret_code_t app_pwm_init(app_pwm_t const * const p_instance, app_pwm_config_t const * const p_config,
                            app_pwm_callback_t p_ready_callback)
    {
        ASSERT(p_instance);
        ASSERT(p_ready_callback);
    

    So yes that's going to assert right away if p_ready_callback is NULL.

    If you also check the two places in the code the callback is used, neither of them check for nil eg,

    if (ticks == p_ch_cb->pulsewidth)
        {
            p_cb->p_ready_callback(p_instance->p_timer->instance_id);
            return NRF_SUCCESS;     // No action required.
        }
    

    so NULL Is not an option. Clearly the header file is just wrong in this instance. You can remove the assert() and add a guard to the two places the callback is called only to call if not NULL, or just supply a simple do-nothing handler.

Children
No Data
Related