renesas / fsp

Flexible Software Package (FSP) for Renesas RA MCU Family
https://renesas.github.io/fsp/
Other
182 stars 82 forks source link

USBx DFU module has been updated for FORCE_DISCONNET event #323

Closed GodavarthyAravinda closed 8 months ago

GodavarthyAravinda commented 8 months ago

Issue

USBx DFU module has been updated to prevent 'USB remove event' being called twice when executing USB disconnection.

Workaround

This change requires application(s) to be updated in DFU callback to check DETACH state in FORCE_DISCONNECT event. Please see the example code:

 UINT usbx_status_callback (ULONG status)
 {
    UX_SLAVE_CLASS_DFU * dfu;
    UCHAR                state;
    switch (status)
    {
        case UX_DEVICE_ATTACHED:
        {
            tx_event_flags_set(&g_cdcacm_event_flags0, CDCACM_FLAG, TX_OR);
            break;
        }
        case UX_DEVICE_REMOVED:
        {
            tx_event_flags_set(&g_cdcacm_event_flags0, ~CDCACM_FLAG, TX_AND);
            break;
        }
        case UX_DEVICE_FORCE_DISCONNECT:
        {
            state = ux_device_class_dfu_state_get(dfu);
            if ((UX_SYSTEM_DFU_STATE_APP_DETACH == state) ||
                (UX_SYSTEM_DFU_STATE_DFU_MANIFEST_WAIT_RESET == state))
            {
                tx_event_flags_set(&g_cdcacm_event_flags0, DFU_DETACH_REQUEST_FLAG, TX_OR);
            }

            break;
        }

        default:
        {
            /* do nothing */
            break;
        }
    }

    return 0;
}