Bug in Cy_USBFS_Dev_Drv_Disable() Function of USBFS v1.0 Driver - KBA225989

Author: SergiiV_71         Version: **

 

Question: Why fault occurs when Cy_USBFS_Dev_Drv_Disable() is called with USBFS driver endpoint management mode configured to CPU Manual?

 

Answer:

the Cy_USBFS_Dev_Drv_Disable() calls an internal function to disable all DMA channels without checking endpoint management mode. For CPU Manual mode, the DMA channels are not allocated and DMA function is called with incorrect arguments, which causes a fault. To work-around this issue, implement disable function as provided below:

void Cy_USBFS_Dev_Drv_Disable_CpuMode(USBFS_Type *base, cy_stc_usbfs_dev_drv_context_t *context)

{

    /* Suppress a compiler warning about unused variables */

    (void) context;

 

    /* Disable D+ pull-up */

    USBFS_DEV_LPM_POWER_CTL(base) &= ~USBFS_USBLPM_POWER_CTL_DP_UP_EN_Msk;

    (void) USBFS_DEV_LPM_POWER_CTL(base);

 

    /* Disable device to respond to usb traffic */

    USBFS_DEV_CR0(base) &= ~USBFS_USBDEV_CR0_USB_ENABLE_Msk;

}

This issue in the USBFS driver also has impact on the USB Device middleware, because Cy_USB_Dev_Disconnect() function calls Cy_USBFS_Dev_Drv_Disable() function. To work-around this issue, implement disconnect function as provided below:

void Cy_USB_Dev_Disconnect_CpuMode(cy_stc_usb_dev_context_t *context)

{

    /* Disable D+ pull-up */

USBFS_DEV_LPM_POWER_CTL(context->drvBase) &= ~USBFS_USBLPM_POWER_CTL_DP_UP_EN_Msk;

    (void) USBFS_DEV_LPM_POWER_CTL(context->drvBase);

   

    /* Disable device to respond to usb traffic */

    USBFS_DEV_CR0(context->drvBase) &= ~USBFS_USBDEV_CR0_USB_ENABLE_Msk;

   

    /* Set device in the default state */

    context->state   = CY_USB_DEV_DISABLED;

    context->address = 0U;

    context->configuration  = 0U;

}

 

The defect in the Cy_USBFS_Dev_Drv_Disable() function will be fixed in the next release of the Peripheral Driver Library.