PORTS Forum

Ports and Interfaces => USB => Topic started by: goodnewsjim on December 26, 2013, 04:59:09 pm

Title: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: goodnewsjim on December 26, 2013, 04:59:09 pm
Hello,

I'm on a new project testing the limitations of transfer speeds.  We may be able to get by with full speed at 1.2MB/s, but we want to test it with our device and what we can get.

I was able to do a bulk transfer from Jan's software:winusb_cs to the board.

What I don't get is how I'm supposed to send a transfer from the board to Jan's software.

I did 1,200,000/64 approximately equals 17,000.  So I figured every 1/17,000th of a second to send a 64 byte packet?

Every 1/17,000th of second
I tried:
    INPacket[0]=0x81;
    int i;
    for(i=1;i<64;i++)
        INPacket='a';
      USBGenWrite(USBGEN_EP_NUM,(BYTE*)&INPacket,64);

It didn't work, the bulk transfer received was only a single 64 byte packet.

I also tried looping to send 17,000 packets once every second:
    for(i=1;i<170000;i++)
      USBGenWrite(USBGEN_EP_NUM,(BYTE*)&INPacket,64);

So my two questions are:
A) What should I be doing right?
B) Should I forget this and just jump straight to high speed to begin with if full speed barely is good enough for my specs?
Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: Jan Axelson on December 26, 2013, 08:32:59 pm
An endpoint can send data only after receiving an IN token packet from the host.

So the device should write the next data to send only when an endpoint buffer is ready to receive new data, in other words, after the previous data has been sent and ACKed.

After writing data to send, be sure the endpoint is armed to send the packet on receiving an IN token packet. How to do that varies with the device architecture. See the data sheet for specifics.


Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: goodnewsjim on December 27, 2013, 12:36:29 pm
Thank you Jan.  I'll try and wrap my head around this.
Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: Jan Axelson on December 27, 2013, 02:50:27 pm
In other words, instead of

write
write
write

do

write
on receiving ACK, write
on receiving ACK, write
Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: goodnewsjim on December 30, 2013, 02:40:36 pm
Thank you Jan, here is more of the situation:

I write a 64 BYTE array of As to your bulk receiving function, and it gets it and displays it correctly.
I look for ACK though in firmware and no ACK is coming(more likely I don't know how to look for it).

Here is how I look for ACK:
In the firmware:
in static void USBCtrlEPService(void){
after line: ((BYTE_VAL*)&pBDTEntryEP0OutNext)->Val ^= USB_NEXT_EP0_OUT_PING_PONG;

 if(pBDTEntryEP0OutCurrent->STAT.PID == PID_ACK)
        {
breakpoint in here never gets reached;
        }

Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: Jan Axelson on December 30, 2013, 09:41:12 pm
USBCtrlEPService is for control endpoints. You are using bulk endpoints.

In my Microchip winusb example, see the BulkTransferLoopback routine.

You can do something like this in a loop until all of the data has been written:

 if (!USBHandleBusy(USBGenericBulkInHandle))
{
  // The CPU owns the endpoint. Prepare to send data to the host.
  // Copy your data to bulkInPacket, then:

  USBGenericBulkInHandle = USBGenWrite(USBGEN_BULK_EP_NUM,(BYTE*)&bulkInPacket, bulk_bytes_to_send);
}
Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: goodnewsjim on December 31, 2013, 01:29:52 pm
Jan, 

I tried your code that you supplied, and it never becomes "unbusy'.
I appreciate you helping :)

   int i;
    bufferstart=1;//control for now to know when to end
    for(i=0;i<64;i++)
        bulkbuffer='a';
//This line works and send a bulk transfer of one series of 64 'a'sto winusb_cs so long as the code after it is non-existant
USBGenericBulkInHandle = USBGenWrite( USBGEN_EP_NUM, bulkbuffer, 64 );

//Should send like 10 series of 64 'a's
while(bufferstart!=0){
 if (!USBHandleBusy(USBGenericBulkInHandle))//This part never gets unbusy, so it doesn't go in
{
 bufferstart++;
       if(bufferstart>10)
           bufferstart=0;
 
USBGenericBulkInHandle = USBGenWrite( USBGEN_EP_NUM, bulkbuffer, 64 );

}

Again thank you for your time,
Jim
Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: Jan Axelson on January 01, 2014, 12:10:42 pm
The host application needs to request data from the device.
Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: goodnewsjimcom on January 01, 2014, 01:02:38 pm
I'm using this from winusb_CS:
ReadDataViaBulkTransfer();

Do I need to modify that function?  I guess that is probably the case.  I just assumed it was set up for multiple packets.


Thanks again Jan for all your help.

Title: Re: How do I bulk transfer from a board? WinUSB -Generic Driver Demo/winusb_cs
Post by: Jan Axelson on January 01, 2014, 10:13:45 pm
Look at the function's parameters. It will attempt to read up to bytesToRead bytes. If you want to read more bytes, you need to increase that value or call the function again.

Also see Microsoft's documentation for WinUsb_ReadPipe.