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

[bug] usb dfu transport does not work if nrf_drv_power_init() was already called

nRF5 SDK version 17.0.2

In usb_dfu_transport_init we have this:

NRF_LOG_DEBUG("Initializing drivers.");

err_code = nrf_drv_clock_init();
if (err_code != NRF_ERROR_MODULE_ALREADY_INITIALIZED)
{
    VERIFY_SUCCESS(err_code);
}

err_code = nrf_drv_power_init(NULL);
VERIFY_SUCCESS(err_code);

If the nrf_drv_power driver was already initialized, this will return NRF_ERROR_MODULE_ALREADY_INITIALIZED and the transport initialization will fail.

app_usbd_init already calls nrf_drv_power_init() by itself (and it handles the already initialized case), so it's probably not even needed in usb_dfu_transport_init

#if APP_USBD_CONFIG_POWER_EVENTS_PROCESS
    ret = nrf_drv_power_init(NULL);
    if ((ret != NRF_SUCCESS) && (ret != NRF_ERROR_MODULE_ALREADY_INITIALIZED))
    {
        /* This should never happen */
        APP_ERROR_HANDLER(ret);
    }
#endif

  • Hi, 

    If you refer to the <InstallFolder>\examples\dfu\secure_bootloader\pca10056_usb, you would see it use usb_dfu_transport_init to initial the nrf_drv_power and related drivers. It doesn't expect that the user initializes the nrf_drv_power driver before it. Or maybe it should check whether the driver is initialized in the usb_dfu_transport_init. Thanks for pointing out that.  

    -Amanda H.

Related