Storage type is simple, because of no timing restriction. You can apply above principles directly.
For host --> device direction,
On the PC application, send as large data size as you want, using single SimpleUSB.WriteData() call.
For example, to send 1M bytes of data, the data buffer is passed to single WriteData() call, claiming 1M Bytes in Size parameter (transfer size). WinUSB and PC host controller splits this request into a sequence of 64 bytes packets.
On the device side,
- your firmware polls arrival of a packet using CheckEndPointOUT().
- If CheckEndPointOUT() returns 1, read out the packet by calling EndPoint_OUT(). The packet is read out into EP3_Buffer[], and its size is held in EP3_OUT_SIZE after EndPoint_OUT() call. The packet size is usually 64 bytes. The last packet of the transfer may have less than 64 bytes, when the transfer size is not a multiple of 64.
- The firmware processes data on EP3_Buffer[].
- When data process finishes, the firmware returns to polling of CheckEndPointOUT()
Thanking to USB hardware flow control (NAK flow control), PC host controller waits for your firmware until it consumes the last packet. So, you don't need to worry about any packet loss.
To make this scenario work, you have to modify USB_Transaction_Handler() a little, so that it doesn't call EndPoint_OUT() on the endpoint interrupt.
Usb_Ep0_Handler.c
void USB_Transaction_Handler(void)
{
unsigned char stat = STAT;
if((stat & 0xF0 ) == 0x00)
{
stat &= 0xF8;
if(stat == EP00_OUT)
{
if(Bdtmap.ep0Bo.Stat.RecPid.PID == SETUP_TOKEN)
USB_CtrlTrf_SetupStage_Processing();
else
USB_CtrlTrf_Out_Handler();
}
else
{
if(stat == EP00_IN)
USB_CtrlTrf_In_Handler();
}
}
else
{
if(stat & 0x08)
asm(nop);
else // OUT handler
// EndPoint_OUT((stat & 0xF0)>>4); // <------ comment this line
asm(nop); // <------ add this line
}
}
I have to move to another place, now
To be continued ..
Tsuneo