AnsweredAssumed Answered

KSDK 2.0 msc lite data receive seems to be asynchronous

Question asked by Maximilian Niedernhuber on Sep 20, 2016
Latest reply on Sep 27, 2016 by Maximilian Niedernhuber

Hello,

I modified the Demo KL26Z256/dev_composite_cdc_msc_lite_bm to work togher with a SPI flash.

But the demo code have a strange behavior.

It seems that USB_DeviceRecvRequest does not receive data immediately. If I add a delay after this funktion everything works great. However what flag I have to check to know that the data receive is finished?

 

 

usb_status_t USB_DeviceMscRecv(usb_device_msc_struct_t *mscHandle)
{
    usb_status_t error = kStatus_USB_Success;
    usb_device_lba_app_struct_t lba;

    lba.offset = mscHandle->currentOffset;
    /*bulkOutBufferSize is the application buffer size, USB_DEVICE_MSC_MAX_RECV_TRANSFER_LENGTH is the max transfer
       length by the hardware,
       lba.size is the data pending  for transfer ,select the minimum size to transfer ,the remaining will be transfer
       next time*/

    lba.size = (mscHandle->bulkOutBufferSize > USB_DEVICE_MSC_MAX_RECV_TRANSFER_LENGTH) ?
                   USB_DEVICE_MSC_MAX_RECV_TRANSFER_LENGTH :
                   mscHandle->bulkOutBufferSize;
    lba.size =
        (mscHandle->transferRemaining > lba.size) ? lba.size : mscHandle->transferRemaining; /* whichever is smaller */
   
    lba.buffer = nandGetWriteCachePtr();
   
    if (mscHandle->currentOffset < (mscHandle->totalLogicalBlockNumber))
    {
        error = USB_DeviceRecvRequest(g_deviceComposite->deviceHandle, mscHandle->bulkOutEndpoint, lba.buffer, lba.size);
        for(int i=100000;i;i--);
       
        nandWriteCache( lba.offset );
       
       
        //if(lba.size != 2048)
        //printf("USB Write Sector %lu Size %lu \n",lba.offset, lba.size);

       
       
    }
    else
    {
        printf("USB Write Sector currentOffset smaller than lba\n");
        mscHandle->needOutStallFlag = 0;
        mscHandle->outEndpointStallFlag = 1;
        mscHandle->dataOutFlag = 0;
        mscHandle->stallStatus = (uint8_t)USB_DEVICE_MSC_STALL_IN_DATA;
        USB_DeviceStallEndpoint(g_deviceComposite->deviceHandle, mscHandle->bulkOutEndpoint);
    }
    return error;
}

 

 

Thanks a lot and best regards

 

Maximilian

Outcomes