KSDK2.0 USB MSD medium not present flag

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KSDK2.0 USB MSD medium not present flag

769 Views
nobodyKnows
Contributor III

Hello,

does anyone know if it is possible to hotplug the storage medium with ksdk 2.0 msd without repluging the usb? Like a USB Card reader or so.

 

Thanks a lot and best regards,

 

Maximilian

Labels (1)
0 Kudos
2 Replies

590 Views
nobodyKnows
Contributor III

Hello,

I dont want to disconnect the USB. I want to tell the usb host that no medium is present. How ever I got it to work.

I modified the USB_DeviceMscProcessUfiCommand function to set the sensekey.

According to the USB UFI Spec the ASC is 0x3A.

=> #define USB_DEVICE_MSC_UFI_MEDIUM_NOT_PRESENT 0x3AU

If found also a vilolation of the UFI Spec in MSC examples from NXP.

The USB_DEVICE_MSC_UFI_ADDITIONAL_LENGTH was set to 0x20 but should 0x1F according to the UFI Spec.

http://www.usb.org/developers/docs/devclass_docs/usbmass-ufi10.pdf  Page 20.

The Additional Length field shall specify the length in bytes of the parameters. If the Allocation Length of the Command Packet is too small to transfer all of the parameters, the Additional Length shall not be adjusted to reflect the truncation. The UFI device shall set this field to 1Fh.

However I have not discovered any effect or impact of this violation.

usb_status_t USB_DeviceMscProcessUfiCommand(usb_device_msc_struct_t *mscHandle)
{
    usb_status_t error = kStatus_USB_Error;
    usb_device_msc_ufi_struct_t *ufi = NULL;

    ufi = &mscHandle->g_mscUfi;

    ufi->requestSense.senseKey = USB_DEVICE_MSC_UFI_NO_SENSE;
    ufi->requestSense.additionalSenseCode = USB_DEVICE_MSC_UFI_NO_SENSE;
    ufi->requestSense.additionalSenseQualifer = USB_DEVICE_MSC_UFI_NO_SENSE;
    
    ufi->thirteenCase.hostExpectedDataLength = mscHandle->g_mscCbw.dataTransferLength;
    ufi->thirteenCase.hostExpectedDirection =
        (uint8_t)(mscHandle->g_mscCbw.flags >> USB_DEVICE_MSC_CBW_DIRECTION_SHIFT);
    /*The first byte of all ufi command blocks shall contain an Operation Code, refer to ufi spec*/
    switch (mscHandle->g_mscCbw.cbwcb[0])
    {
        /* ufi commmand operation code*/
        case USB_DEVICE_MSC_INQUIRY_COMMAND: /*operation code : 0x12*/
            error = USB_DeviceMscUfiInquiryCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_READ_10_COMMAND: /*operation code : 0x28 */
        case USB_DEVICE_MSC_READ_12_COMMAND: /*operation code : 0xA8 */
            error = USB_DeviceMscUfiReadCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_REQUEST_SENSE_COMMAND: /*operation code : 0x03*/
            error = USB_DeviceMscUfiRequestSenseCommand(mscHandle);           
            break;
        case USB_DEVICE_MSC_TEST_UNIT_READY_COMMAND: /*operation code : 0x00 */
            error = USB_DeviceMscUfiTestUnitReadyCommand(mscHandle);
            
            if (mscHandle->g_mscCsw.cswStatus != USB_DEVICE_MSC_PHASE_ERROR)
            {
                if ((not_ready_flg))
                {
                    mscHandle->g_mscCsw.cswStatus = USB_DEVICE_MSC_COMMAND_FAILED;
                }
            }
            
            break;
        case USB_DEVICE_MSC_WRITE_10_COMMAND: /*operation code : 0x2A */
        case USB_DEVICE_MSC_WRITE_12_COMMAND: /*operation code : 0xAA */
            error = USB_DeviceMscUfiWriteCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_PREVENT_ALLOW_MEDIUM_REM_COMMAND: /*operation code :0x1E */
            error = USB_DeviceMscUfiPreventAllowMediumCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_FORMAT_UNIT_COMMAND: /*operation code : 0x04*/
            error = USB_DeviceMscUfiFormatUnitCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_READ_CAPACITY_10_COMMAND: /*operation code : 0x25*/
        case USB_DEVICE_MSC_READ_CAPACITY_16_COMMAND: /*operation code : 0x9E*/
            error = USB_DeviceMscUfiReadCapacityCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_MODE_SENSE_10_COMMAND: /* operation code :0x5A*/
        case USB_DEVICE_MSC_MODE_SENSE_6_COMMAND:  /* operation code : 0x1A */
            error = USB_DeviceMscUfiModeSenseCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_MODE_SELECT_10_COMMAND: /*operation code : 0x55 */
        case USB_DEVICE_MSC_MODE_SELECT_6_COMMAND:  /*operation code : 0x15 */
            error = USB_DeviceMscUfiModeSelectCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_READ_FORMAT_CAPACITIES_COMMAND: /*operation code : 0x23 */
            error = USB_DeviceMscUfiReadFormatCapacityCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_SEND_DIAGNOSTIC_COMMAND: /*operation code : 0x1D*/
            error = USB_DeviceMscUfiSendDiagnosticCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_VERIFY_COMMAND: /*operation code : 0x2F*/
            error = USB_DeviceMscUfiVerifyCommand(mscHandle);
            break;
        case USB_DEVICE_MSC_START_STOP_UNIT_COMMAND: /*operation code : 0x1B*/
            error = USB_DeviceMscUfiStartStopUnitCommand(mscHandle);
            break;
        default:
            error = USB_DeviceMscUfiUnsupportCommand(mscHandle);
            mscHandle->dataOutFlag = 0;
            mscHandle->dataInFlag = 0;
            mscHandle->outEndpointStallFlag = 0;
            mscHandle->inEndpointStallFlag = 0;
            mscHandle->needOutStallFlag = 0;
            mscHandle->needInStallFlag = 0;
            break;
    }
    
     if (mscHandle->g_mscCsw.cswStatus != USB_DEVICE_MSC_PHASE_ERROR)
    {
        if ((not_ready_flg))
        {
            ufi->requestSense.senseKey = USB_DEVICE_MSC_UFI_NOT_READY;
            ufi->requestSense.additionalSenseCode = USB_DEVICE_MSC_UFI_MEDIUM_NOT_PRESENT;
            ufi->requestSense.additionalSenseQualifer = USB_DEVICE_MSC_UFI_NO_SENSE;         
        }
    }
    
    return error;
}
0 Kudos

590 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Maximilian,

I see your application that you hotplug the storage medium with ksdk 2.0 msd without repluging the usb stick, you hope that the USB device is disconnected automatically. When you plug the storage medium, the usn can reenumerate.

Frankly speaking, I never experience to disconnect  the USB, but it seems that you can use the api function to disconnect USB device.

static usb_status_t USB_DeviceControl(usb_device_handle handle, usb_device_control_type_t type, void *param)

the above function is defined in usb_device_dci.c

Hope it can help you

BR

Xiangjun Rong

0 Kudos