KSDK 2.0 msc lite data receive seems to be asynchronous

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

KSDK 2.0 msc lite data receive seems to be asynchronous

989 Views
nobodyKnows
Contributor III

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

Labels (1)
Tags (1)
0 Kudos
6 Replies

712 Views
nobodyKnows
Contributor III

Is there an example for block devices out there?

0 Kudos

712 Views
ivadorazinova
NXP Employee
NXP Employee

Hello Maximilian,

In fact there is a callback to tell when the data receive is finished. In this example, you can check the status in USB_DeviceMscBulkOut.

 

The KSDK USB stack provides a similar example, usb_device_composite_cdc_msc_sdcard_lite , which works with SD Card instead of SPI flash. You can refer to that example as well. This example may not exist in KL26Z256 package due to the hardware limitation. However, you could get the example’s source code from some other packages, e.g.  FRDM-K64.

 

In disk_sdcard.c,

It writes data to SD card in the callback USB_DeviceMscBulkOut mentioned above.

 

usb_status_t USB_DeviceMscBulkOut(usb_device_handle deviceHandle,

                                  usb_device_endpoint_callback_message_struct_t *event,

                                  void *arg)

        /*write the data to sd card*/

        if (0 != event->length)

        {

            if (kStatus_Success != SD_WriteBlocks(usbDeviceMscCard, event->buffer, mscHandle->currentOffset,

                                                  event->length >> USB_DEVICE_SDCARD_BLOCK_SIZE_POWER))

            {

                g_deviceComposite->mscDisk.readWriteError = 1;

                usb_echo(

                    "Write error, error = 0xx%x \t Please check write request buffer size(must be less than 128 "

                    "sectors)\r\n",

                    error);

                error = kStatus_USB_Error;

            }

        }

I hope this helps you.

Best Regards,

Iva

0 Kudos

712 Views
nobodyKnows
Contributor III

Ok but I cant find any part which is checking a status flag or set a callback. It looks like writing to a buffer and write to sd card just before the next request is writing to the buffer.

0 Kudos

712 Views
joe_dimaggio
Contributor II

Sorry Iva Dorazinova but I didn't found the example "usb_device_composite_cdc_msc_sdcard_lite"  that you mentioned above.

There is a "composite cdc msc" and a "msc sd card" example, but there are to many differences between these two examples so I can't merge them together.

0 Kudos

712 Views
ivadorazinova
NXP Employee
NXP Employee

Hello Maximilian,

Please, could you upload here whole project?

Thank you in advance.

Best Regards,

Iva

0 Kudos

712 Views
nobodyKnows
Contributor III

No sry this is not possible because the nand driver is licenced from 3th party.

0 Kudos