USB MSD Library documentation.
1. The interrupt procedure
In the interrupt procedure of the application the MSD processing procedure should be called.
This procedure does all USB_MSD processing (including handling of the "internal" USB_MSD activities like reading from
and writing to the SDMMC card) based on interrupts received from the PIC's SIE (the USB engine).
This is to be done like this:
For P18:
procedure interrupt;
begin
USB_Interrupt; // USB_CDC processing procedure
end;
For P24:
procedure USB1Interrupt(); iv IVT_ADDR_USB1INTERRUPT;
begin
USB_Interrupt;
end;
The USB initialization procedure ("InitUsb") takes care of the enabling of the necessary interrupts.
Important: There is no need to "force" extra interrupts, e.g. via a timer, the "USB_Interrupt" procedure will only do something when actually an interrupt came from the SIE (the PIC's USB engine).
2. Initialization
The initialization of the USB_MSD software is like:
InitUsb; // Init USB_MSD and start the enumeration process
repeat until ConfiguredUsb; // wait for the completion of the USB enumeration
As you can see, the initialisation of USB_MSD and starting up of the USB enumeration procedure is done with a call
to "InitUsb". This procedure does not wait for the USB enumeration process to complete.
The completeness of the enumeration process can be checked with "ConfiguredUsb": it returns true when emumeration is complete.
Important:
For P18 the initialisation of SPI and the MMC card is done within the library. Reason: calling SPI and MMC routines is only allowed from within one thread (here the interrupt thread).
For P24 the initialisation of SPI and the MMC card is done in the main unit (recursion and calling from multiple threads is allowed).
3. Data transport to and from the SDMMC card.
No code is needed in the application to make this happen. All MSD activities are done under interrupt.
Important:
- Do not try to read from or write to the card while the PIC is connected to the PC via USB!
- The MSD library assumes the SD/MMC card is always present and R/W (not write protected).
There is currently no mechanism to detect the removal or insertion of the card.
4. Technical data
- Full speed USB communications.
- Endpoint 0 (default pipe) packet size: 64.
- "Bulk" data transfers.
- The send and receive databuffersizes are 64 bytes
- The MSD "data" pipe is USB endpoint 4.
- The MSD "data" interface is USB interface 0.
-------------------------------------------