5147 views|3 replies

3414

Posts

0

Resources
The OP
 

[CH554 Modification Review] CH554 and libusb (Part 1) [Copy link]

This post was last edited by ljj3166 on 2018-4-16 16:31 Now I'm starting to get into the USB part, which is also a major selling point of this film. I played with the HID and KM demo in the example program. It's very simple to implement. You can get a general idea of the USB protocol by just understanding it a little bit. I won't go into the underlying USB protocol stuff in depth, as it makes me dizzy. The key point is to sort out a lot of descriptors and basically be able to run it. Think about it, the CH554 with integrated USB protocol is really convenient for full hardware implementation. Check the registers, play with the data, and click on anything you don't understand. It's great. The author uses the extremely hard OS usb driver. Although Qinheng also provides it, it is encapsulated and can't be played happily. So I thought of the invincible libusb-win32. The author uses CompatibilityHID. The VID used in the source code is 5131, and the PID is 2007. Take a look at the device descriptor: Note the order of high and low bytes. There is another very important place to configure the descriptor: The endpoint of the pipe describes the subsequent communication. This must match. First, change the windows driver and use the invincible libusb. Find the USB device corresponding to the VID and PID. If the device is broken, blame the OP. It is necessary to install 13. Then there are some basic installation operations. It is very sexy. The OP has 6 more videos like this one.
  1. while(1) { if(Ready&& (Ep2InKey==0)) { Enp2BlukIn() ; mDelaymS( 100 ); } // mDelaymS( 100 ); //Simulate the microcontroller to do other thingsif(send_flag == 0x01) { printf(Ep2Buffer); send_flag = 0x00; memset(Ep2Buffer, '\0', THIS_ENDP0_SIZE); } else {} }
复制代码
Slightly modify the single-chip chicken code. The general meaning is to print out the received data after receiving the data
  1. case UIS_TOKEN_OUT | 2: //endpoint 2# Endpoint batch downloadif ( U_TOG_OK ) // Unsynchronized data packets will be discarded{ len = USB_RX_LEN; // Receive data length, data is stored from the first address of Ep2Buffer// for ( i = 0; i < len; i ++ ) // { // Ep2Buffer[MAX_PACKET_SIZE+i] = Ep2Buffer[i];// ^ 0xFF; // OUT data is inverted to IN and verified by the computer// } // UEP2_T_LEN = len; UEP2_T_LEN = 8; Ep2Buffer[MAX_PACKET_SIZE+0] = 'g'; Ep2Buffer[MAX_PACKET_SIZE+1] = 'o'; Ep2Buffer[MAX_PACKET_SIZE+2] = 't'; Ep2Buffer[MAX_PACKET_SIZE+3] = ' '; Ep2Buffer[MAX_PACKET_SIZE+4] = 'd'; Ep2Buffer[MAX_PACKET_SIZE+5] = 'a'; Ep2Buffer[MAX_PACKET_SIZE+6] = 't'; Ep2Buffer[MAX_PACKET_SIZE+7] = 'a'; UEP2_CTRL = UEP2_CTRL & ~ MASK_UEP_T_RES | UEP_T_RES_ACK; // Allow upload send_flag = 0x01; }
复制代码
After receiving data in the USB interrupt, it returns "got data" and sets send_flag. I am afraid that the editor will crash. To be continued, please watch the next episode......This content is originally created by EEWORLD forum user ljj3166. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source
This post is from MCU

Latest reply

Oh, it turned out to be libusb-win32, which seems to have stopped updating. It is recommended to use libusb. I use libusb.  Details Published on 2018-4-21 21:47
Personal signature

So TM what......?

 


655

Posts

1

Resources
2
 
Old version of libusb,?????
This post is from MCU

Comments

Don't be fooled by the name  Details Published on 2018-4-20 22:05
 
 

3414

Posts

0

Resources
3
 
mars4zhu posted on 2018-4-20 21:55 Old version of libusb, ??????
Don't be confused by the name
This post is from MCU

Comments

Oh, it was libusb-win32, which seems to have stopped updating. It is recommended to use libusb. I use libusb.  Details Published on 2018-4-21 21:47
 
Personal signature

So TM what......?

 

 

655

Posts

1

Resources
4
 
ljj3166 posted on 2018-4-20 22:05 Don't be confused by the name
Oh, it turned out to be libusb-win32, which seems to have stopped updating. It is recommended to use libusb. I use libusb.
This post is from MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list