The following information is collected online:
USB transmission bytes (from computer00)
The USB port buffer of stm32 is not fixed and is set by registers.
And myProgramIs defined as follows. The endpoint size is 0x40, and Endpoint 2 is used as the output endpoint,
0xd8 + 0x40 = 0x118, that is, the first 24 bytes of the buffer at the endpoint 1 overlap and are overwritten by the output data.
/* EP1 */
/* TX buffer base address */
# Define endp1_txaddr (0x100)
/* EP2 */
/* RX buffer base address */
# Define endp2_rxaddr (0xd8)
You can solve this problem by setting the sending Address of endpoint 1 to 0x98.
/* EP1 */
/* TX buffer base address */
# Define endp1_txaddr (0x98)
As for endpoint 1, it can also be used as an output. The program makes the following changes:
The Receiving address of endpoint 2 is changed to endpoint 1 for receiving:
/* EP1 */
/* RX buffer base address */
# Define endp1_rxaddr (0xd8)
Then, in the endpoint descriptor, change the original endpoint output 2 to the endpoint output 1:
0x01,/* bendpointaddress: endpoint address (Out endp 1 )*/
initialize the original endpoint 2 to initialize endpoint 1:
/* initialize endpoint 1 */
// seteptype (endp1, ep_interrupt );
seteprxaddr (endp1, endp1_rxaddr);
seteprxcount (endp1, 64);
// seteptxstatus (endp1, ep_tx_dis);
seteprxstatus (endp1, ep_rx_valid);
Change the original endpoint 2 callback function to endpoint 1 callback:
/*************************************** ****************************************
* Function name: epw.out_callback.
* Description: EP1 out callback routine.
* Input: none.
* Output: none.
* Return: none.
**************************************** ***************************************/
Void ep1_out_callback (void)
{
U8 datalen;
Datalen = geteprxcount (endp1 );
Pmatouserbuffercopy (outbuffer, endp1_rxaddr, datalen );
Seteprxvalid (endp1 );
}
Modify in the header file usb_conf.h:
// # Define ep1_out_callback nop_process
Void ep1_out_callback (void );
# Define ep2_out_callback nop_process
Then re-compile it to use endpoint 1.