USBD ROM Stack
2.0
ROM based USB device stack
|
This section introduces you to Mass Storage application development using USB ROM stack. The topics in this section provide step-by-step instructions on implementing a simple Mass Storage USB device using USB ROM stack.
After successfully initializing the USBD ROM stack i.e. USBD_HW_API_T::Init, the mass storage class driver needs to be initialized as follows:
The following example shows the configuration descriptor for the USB Mass storage class device:
After a successful MSC Initialization the stack is ready to receive the packets from host. Even if the device is physically connected to the host using an USB cable the host does not recognize the presence of device until the D+ line is pulled up using 1.5K ohm resistor (LPC device controllers operate in high-speed or full-speed mode only). To enable the connection the application software should call USBD_HW_API_T::Connect with enable set to 1. Before enabling the connection the application should enable the USB interrupt.
After connection the MSC class executes through callback functions setup during initialization.
USBD ROM stack implements the interrupt handler for USB device controller and invokes the USBD ROM stack routines according to the event type. Hence application should connect this handler to the application vector table. This is done by calling USBD_HW_API_T::ISR from the USB IRQ handler as shown in the code snippet below. The USBD ROM handle passed to the ISR() routine is the one obtained in previous step.
The MSC Class executes by calling callback routines setup during MSC initialization. The 4 call backs used in MSC are:
-MSC_Write: Called when a write request is sent from the host, the lower 32 bit offset and the high 32 bit offset together produce the 64 bit offset for the memory device, the source double pointer points to the data to be written to the memory device and the length indicates the number of bytes to be written. The implementation of the write procedure is dependent on the memory device used by the application.
-MSC_Read: Called when a read request is sent from the host, the lower 32 bit offset and the high 32 bit offset together produce the 64 bit offset for the memory device, the destination double pointer points to the buffer where the data read from the memory device should be updated and the length indicates the number of bytes to be read.
-MSC_Verify: Called when a verify request is sent from the host, the lower 32 bit offset and the high 32 bit offset together produce the 64 bit offset for the memory device, the buffer points to the data that needs to be compared with the data in the memory device and the length indicates the number of bytes to compare. The callback function should compare the buffer with the destination memory at the requested offset and the return 0 if the data matches else return -1.
-MSC_GetWriteBuf: Called during the command transport stage when host sends a write request , the lower 32 bit offset and the high 32 bit offset together produce the 64 bit offset for the memory device for the following write, the buff_adr double pointer points to the buffer where the stack can copy the write data and the length indicates the number of bytes that will be written. The callback function should update the buff_adr pointer so that the stack transfers the data directly to the target buffer.
Subsections: