Hi Martin,
I am running into a road block with the USB MSD utilizing the flashX driver per your suggestion.
Below is from the MQX USB Device User’s Manual:
To use MSD class layer API functions from the application:
- Call USB_Class_MSC_Init() to initialize the class driver, all the layers below it, and the device
- Event callback functions are also passed as a parameter to this function.
- When the callback function is called with the USB_APP_ENUM_COMPLETE event, the
application should move into the ready state.
- Callback function is called with the USB_MSC_DEVICE_READ_REQUEST event to copy data
from the storage device before sending it to the USB bus. It reads data from the mass storage device
to the driver buffer.
- Callback function is called with the USB_MSC_DEVICE_WRITE_REQUEST event to copy data
from the USB driver buffer to the Storage device. It reads data from the driver buffer to the mass
storage device.
Specifically my issue is that the callback is called from an interrupt handler routine that for the RAM Disk simply (for a read) copies from RAM to the buffer passed into the callback. In my case, the flashX driver is calling the MQX SPI driver which utilizes semaphores. MQX (with good reason) will not allow you to potentially block on a semaphore in an interrupt handler. The end result is I cannot use the flashX driver from the callback and utilize the fseek(), fwrite(), fread() functions.
My next thought was when the callback is issued to simply have it signal a Task which will perform the fseek(),fwrite(), fread(). This gets around the first problem, but I encounter another. Specifically it takes too much time to go through the flashX layer, custom SPI layer, MQX SPI layer before the next callback occurs.
Looking at the low-level MQX USB driver code for MSD (usb_msc.c). I see the following in an interrupt handler:
msc_obj_ptr->param_callback.callback(USB_MSC_DEVICE_READ_REQUEST, (void*)&lba_data, msc_obj_ptr->param_callback.arg);
error = USB_MSC_Bulk_Send_Data(msc_obj_ptr->msc_handle,lba_data.buff_ptr,lba_data.size);
The first is where the callback occurs. The second is where the data, copied into the buffer in the callback, is sent back to the HOST.
All this occurring via the interrupt and callback which does not leave much overhead to get the data in the callback buffer.
I have been going through the documentation trying to understand how to work around this.
Has anyone else had similar issues (have not been able to get up onto the message boards due to maintenance)?
Any thoughts?
Thanks,
Brent W.