Endpoint 0 is the best way to test the driver, I will later put the Linux driver experience, this buddy wrote how to send data: http://www.lcsky.org/2.0/node/43
Control transmission is useful when a small amount of control information is exchanged, such as sending commands and obtaining the status of the lower computer. It is convenient to use control transmission through the cypress standard firmware framework, you only need to add your own processing process to dr_vendorcmnd. For example:
Bool dr_vendorcmnd (void ){
Switch (setupdat [1]) {
Case vr_1: // custom command 1
Do_something ();
Break;
Case vr_2: // custom command 2
Do_something_else ();
Break;
Default:
Return (true );
}
Return (false); // No error; command handled OK
}
Control transmission is divided into three stages.
1. In the setup phase, use the setupdat 8-byte register,
Setupdat [0] = bmrequesttype
Setupdat [1] = bmrequest
Setupdat [2: 3] = wvalue
Setupdat [4: 5] = Windex
Setupdat [6: 7] = wlength
When we transmit custom commands, bmrequesttype does not need to be processed; bmrequest is our custom command, and the upper and lower computers can be unified; wvalue And Windex can be used freely, in a total of 4 bytes; wlength is the Data Length of the next "data phase.
2. Data phase. This phase is optional. If the wvalue And Windex data we transmit cannot accommodate, or the information needs to be read from the device, it needs to be carried out through the data phase, the data phase is implemented through the ep0buf, ep0bch, and ep0bcl registers. The data phase can transmit 64 bytes of data at a time.
This phase is often used incorrectly, especially when data is transmitted from the upper computer to the lower computer, which leads to a strange phenomenon: the correct data in the buffer zone needs to be transmitted twice in a row. The following is an example of incorrect use:
Case vr_1:
A = ep0buf [0];
B = ep0buf [1];
C = ep0buf [2];
D = ep0buf [3];
Ep0bch = 0;
Syncdelay;
Ep0bcl = 0;
Syncdelay;
Break;
This is intended to get some data from the host computer and tell ez-USB that the data has been read successfully through the last ep0bch = 0; ep0bcl = 0; but in fact, this will cause the above problems. Take a closer look at TRM and find the following:
Some control transfers do not have a data stage. Therefore the 8051
Code that processes the setup data shocould check the length field in
Setup data (in the 8-byte buffer at setupdat) and arm endpoint zero
The data phase (by loading in0bc or out0bc) only if the length is
Non-zero. [1]
At this point, the problem is solved when the data is transmitted twice to obtain the correct data. The downstream data needs to be notified through ep0bch and ep0bcl to EZ-USB to start the data phase! Change to the following code:
Case vr_1:
// Start data phase, see TRM 7.2
If (setupdat [7]! = 0 | setupdat [6]! = 0 ){
Ep0bch = setupdat [7];
Syncdelay;
Ep0bcl = setupdat [6];
Syncdelay;
While (ep0cs & bmepbusy );
}
A = ep0buf [0];
B = ep0buf [1];
C = ep0buf [2];
D = ep0buf [3];
Break;
In addition, for data-free transmission, you do not need to use ep0bch = 0 at the end; ep0bcl = 0 to "Tell ez-USB that the data has been read ".
3. Status phase. Use the ep0cs register to inform the host computer whether the command is processed or not. If not, inform the host machine through ezusb_stall_ep0 (); send ACK for confirmation through ep0cs | = bmhsnk. (This stage does not need to be processed. It has been processed in FW. C)
I will add how to receive data:
If (setupdat [1] = 0xd2) // custom receive data command
{
For (j = 0; j <64; j ++)
Ep0buf [J] = 0x11;
For (j = 0; j <10; j ++)
Ep0buf [J] = j <5? 0x55: 0xaa;
For (; j <20; j ++)
Ep0buf [J] = 0xcc;
For (; j <30; j ++)
Ep0buf [J] = 0x88;
//
Ep0bch = 0;
Ep0bcl = 40; // The number of messages to be sent, up to 64
Return false;
}
Return true;
Note: after the non-standard request command is processed, return false. Otherwise, the firmware will call ezusb_stall_ep0 (). If the computer considers it invalid, the following error occurs:
Vendor request failed
A device attached to the system is not functioning.
Error message.