USB communication data of stm32

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.