I've finshed coding a USB MSC driver in pure assembly on the STM32F103. There are quite a few layers of protocol you need to deal with and you need to think about your file system too. Plus the block size the MSC driver operates at is typically 512 bytes which is almost certainly smaller than the block size of the storage you'll be using. This means Read-Modify-Erase-Write for generic file system access unless you emulate the FAT and manage file handling internally.
Hola BennVenn,
Finally I hear of someone who took the pain and succeeded.
I tried to program a 18F micro, following the code posted in a interesting thread in the Microchip forum but I couldn't follow the whole process in spite of reading the mother document about USB.
Is it any chance that you could post any flow diagram (if you have one of course) for me to have a fresh guide on that? I know it is hard work but I find that appealing.
I will appreciate any additional comments from you if the OP does not consider this derailing his thread. Gracias.
I am not C conversant, by the way.
Hi atferrari,
I hadn't found any information on an asm implementation of a USB 'driver' for an ARM. Finding anyone that codes an ARM in asm is rare, most of the comments I received were 'Just use C' or 'We can't help you if you are not using the supplied library' etc... I don't consider myself to be that confident in C so I went ahead and did it all in assembly.
I migrated from an AVR background so not only was there the learning curve of the ARM (NVIC, byte aligned addressing, user mode etc) but I had no idea on how USB actually worked. If there is one thing that really made all this possible it would be my USBee logic analyser (I paid just under $400 for mine, I’ve since seen Chinese clones on ebay that use the same hardware/software suit for $15...)
The USBee software has a USB decoder. It is pretty rough but has enough features to strip away the junk and leave you with the data going back and forward. I started playing with the hardware registers in the ARM until I was confident I could get the peripheral to do what I want (Respond to the host, pass data). From there it was simply reading through the USB spec sheets to get the lowest software layer OK, then build up with HID, MSC, SCSI etc...
Get yourself an old cheap USB mouse to interrogate the protocol. Find out what each of the packets mean, how the PC enumerates the device and then replicate that. Once you have the template coded, its is as simple as changing some of the information. MSC is more complex and relies on a state machine as there are different modes etc.. Transparent SCSI is a bit of code to bridge the mass storage to the MSC driver and handles Read-Modify-Write etc...
If you want to know more send me an email and we can nut it out. I don't program with flow charts or anything like that. I just write what I think will work and sometimes it does :-)
jnz: What dev board do you have?