Host MSD command + CDC virtual com example

This section provides a step-by-step example for how to implement a host that supports CDC virtual com and MSD command. This example is based on the existing host CDC virtual com example.

USB component files

Add the usb_host_msd component files, the usb_host_msd_ufi source file, and the host_msd_command component files into the current project. Normally, the host_msd_command component should be in the source folder, shown in Figure 2. The usb_host_msd component and the usb_host_msd_ufi source file should be located in the class folder showing in the Figure 3.

|

|

|

|

Parent topic:Host MSD command + CDC virtual com example

USB_HostEvent function

Add the USB_HostMsdEvent function into the USB_HostEvent function.

usb_status_t USB_HostEvent(usb_device_handle deviceHandle,
                           usb_host_configuration_handle configurationHandle,
                           uint32_t event_code)
{
    usb_status_t status1;
    usb_status_t status2;
    usb_status_t status = kStatus_USB_Success;
    switch (event_code)
    {
        case kUSB_HostEventAttach:
            status1 = USB_HostCdcEvent(deviceHandle, configurationHandle, event_code);
            status2 = USB_HostMsdEvent(deviceHandle, configurationHandle, event_code);
            if ((status1 == kStatus_USB_NotSupported) && (status2 ==
kStatus_USB_NotSupported))
            {
                status = kStatus_USB_NotSupported;
            }
            break;
        case kUSB_HostEventNotSupported:
            usb_echo("device not supported.\r\n");
            break;
        case kUSB_HostEventEnumerationDone:
            status1 = USB_HostCdcEvent(deviceHandle, configurationHandle, event_code);
            status2 = USB_HostMsdEvent(deviceHandle, configurationHandle, event_code);
            if ((status1 != kStatus_USB_Success) && (status2 != kStatus_USB_Success))
            {
                status = kStatus_USB_Error;
            }
            break;
        case kUSB_HostEventDetach:
            status1 = USB_HostCdcEvent(deviceHandle, configurationHandle, event_code);
            status2 = USB_HostMsdEvent(deviceHandle, configurationHandle, event_code);
            if ((status1 != kStatus_USB_Success) && (status2 != kStatus_USB_Success))
        {
            status = kStatus_USB_Error;
        }
        break;
    default:
        break;
    }
    return status;
}

Parent topic:Host MSD command + CDC virtual com example

Main function task

Add the USB_HostMsdTask function into the main function. The modified code should look like this:

int main(void)
{
    gpio_pin_config_t pinConfig;
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();
    /* enable usb host vbus */
    pinConfig.pinDirection = kGPIO_DigitalOutput;
    pinConfig.outputLogic = 1U;
    GPIO_PinInit(PTD, 8U, &pinConfig);
    APP_init();
    while (1)
    {
        USB_HostTaskFn(g_HostHandle);
        /* cdc class task */
        USB_HosCdcTask(&g_cdc);
        /* msd class task */
        USB_HostMsdTask(&g_MsdCommandInstance);
    }
}

Parent topic:Host MSD command + CDC virtual com example