What is the difference between your usb_transfer_bulk_in and usb_transfer_bulk_out functions? A single declaration? If this is the case, try using only one function. Building a Transfer Descriptor, whether it be in or out, is (almost) identical, with only a few minor differences, easily passed in a flags parameter. Also, you should send the length (in this case, 31) as a parameter, though I get the idea you are simply 'experimenting' at the moment anyway.
Also, does your compiler return an error on:
Code: Select all
packets[pid].buffer = payload + i;
It should.
On an IN transfer, your transfer_packets() function is waiting for a response, correct? You have to wait for the 'bulk in' to actually take place. It can take a little while (depending on your stack frame, milliseconds in fact) before it happens. If the Queue for the CSW is in the same frame as the Queue for the CBW, the devices hasn't had time to respond before the controller executes the CSW. You need to wait for the CBW to be executed by the device before you send the CSW.
Since you are not using an interrupt interface, if your transfer_packets() function doesn't wait for the device to execute the Command phase, then the Response phase, your Status phase will be zeros. Just a thought, since there is no reference to your transfer_packets() function except for the call itself, it is waiting for the device to fill the result phase, correct?
In experimentation, wait 10mS or so before you retrieve the CSW. See if there is something there.
A few more notes. Your toggle needs to be aware of short packets. If you create, for example, 6 IN packets, each toggling with an ending toggle bit of 1 (so that the next new packet will have a toggle of 0), let's say that you short packet on the fifth packet. The device will expect the next packet to have a toggle of 1, but your code will give it a toggle of 0. The error in the toggle will invalidate any remaining packets until you clear_endpoint() or fix the toggle bit.
Also, you are assuming that the LUN is zero. This is the case for most devices, however some devices will have multiple LUN values starting with 1. Have you sent the Get_Max_LUN request yet?
Ben