I've finally managed to cobble together a working mass storage driver
It mostly seems to work:
Transfers are slowww over FS usb interface.. but that's all I have to test with at the moment
Improvements, suggestions, bug fixes etc are welcome. Code available at the github link above
USB Mass Storage Device
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: USB Mass Storage Device
Looks like it runs at about 100KB/s... (that is writing to the disk via the file system, I couldn't get dd straight to the disk to work on my macbook)
So probably something isn't quite optimised right! I'll try benchmarking the R/W performance of the microSD card over SPI within chibios first to see what the max that can manage is.
So probably something isn't quite optimised right! I'll try benchmarking the R/W performance of the microSD card over SPI within chibios first to see what the max that can manage is.
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: USB Mass Storage Device
I think it could be improved by implementing an asynchronous prefetch mechanism and a cache.
Giovanni
Giovanni
Re: USB Mass Storage Device
That sounds like a good suggestion.
The driver could do with a mechanism for making sure that the usb transaction doesn't complete before the thread goes to sleep, so that it will always get woken. I suppose the usb callback should set a variable somewhere to indicate that an even has occurred, which is checked before going to sleep.
The driver could do with a mechanism for making sure that the usb transaction doesn't complete before the thread goes to sleep, so that it will always get woken. I suppose the usb callback should set a variable somewhere to indicate that an even has occurred, which is checked before going to sleep.
Re: USB Mass Storage Device
I did a test, the fastest I can read from my microSD over SPI3 (so not the fastest SPI) is about 360KB/s. I'll try pre-fetching the data
Re: USB Mass Storage Device
I have mostly implemented the cached read/write, but I'm having problems with waking the thread when a USB read or write callback is called.
My strategy is to use a binary semaphore, initialised as taken. The worker thread issues the USB transfer and the. Calls chBSemWait(). The callback wakes the thread with chBSemSignal. This all works fine until the USB transfer completes before chBSemWait() is called. Am I doing something wrong here? It seems like the bsem should be untaken as the callback signalled it so Id expect chBSemWait() to return immediately but it hangs!
BTW the code with caching and semaphores is not yet published as I am travelling on a train whilst working on this..
My strategy is to use a binary semaphore, initialised as taken. The worker thread issues the USB transfer and the. Calls chBSemWait(). The callback wakes the thread with chBSemSignal. This all works fine until the USB transfer completes before chBSemWait() is called. Am I doing something wrong here? It seems like the bsem should be untaken as the callback signalled it so Id expect chBSemWait() to return immediately but it hangs!
BTW the code with caching and semaphores is not yet published as I am travelling on a train whilst working on this..
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: USB Mass Storage Device
Here's a summary of how I'm using the binary semaphore. Any ideas?
Code: Select all
/* initialise binary semaphore as taken */
chBSemInit(&msdp->bsem, TRUE);
...
usbPrepareReceive(msdp->usbp, USB_MS_DATA_EP,
(uint8_t *)&msdp->cbw, sizeof(msd_cbw_t));
chSysLock();
usbStartReceiveI(msdp->usbp, USB_MS_DATA_EP);
chSysUnlock();
/* sleep until it completes */
chBSemWait(&msdp->bsem);
/* then in the end point callback: */
void msdUsbEvent(USBDriver *usbp, usbep_t ep) {
(void)usbp;
(void)ep;
chBSemSignalI(&((USBMassStorageDriver *)usbp->param)->bsem);
}
Return to “Development and Feedback”
Who is online
Users browsing this forum: No registered users and 14 guests