cancel
Showing results for 
Search instead for 
Did you mean: 

CTS signal on USB CDC

wjandsq
Associate III

To follow up this thread, CTS signal on USB CDC - STMicroelectronics Community

I'm experiencing a similar issue.

USBser.sys  have some problem

1. Only DTR Break can control alone

you can set  DTR is 1  or 0,  but  RTS have change,RTS only change with DTR.

2.  CDC Serial State

I  have test this code,  it  send from Endpoint 81h successfully,  but  PC USB Host  have no message

CDC_IN_Buf[0] = 0xA1; /* bmRequestType 0xA1 (10100001B)   */
CDC_IN_Buf[1] = 0x20; /* 0x21     (SERIAL_STATE)  */
CDC_IN_Buf[2] = 0x00; /* wValue   LowByte */
CDC_IN_Buf[3] = 0x00; /* wValue  HiByte */
CDC_IN_Buf[4] = 0x00; /* wIndex  LowByte  Default 0 */
CDC_IN_Buf[5] = 0x00; /* wIndex  HiByte */
CDC_IN_Buf[6] = 0x02; /* wLength  LowByte  Serial State Length  0x0002 */
CDC_IN_Buf[7] = 0x00; /* wLength  HiByte */
CDC_IN_Buf[8] = 0x14; /* Data       LowByte    */
CDC_IN_Buf[9] = 0x00; /* Data       HiByte  */
/*
CDC Serial State bit define (USB CDC 1.1  6.3.5 )
bit0  bRxCarrier     0x01
bit1  bTxCarrier      0x02
bit2  bBreak           0x04
bit3  bRingSignal    0x08
bit4  bFraming        0x10
bit5  bParity            0x20
bit6  bOverRun       0x40
*/
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, CDC_IN_Buf, 10);
USBD_LL_Transmit(&hUsbDeviceFS, CDC_CMD_EP, CDC_IN_Buf, 10);
 
Only CH341/FT232RL  can have  usb serial state notify ?
 
3.  Does ST have no technology? They can't write a single driver and can only use Microsoft's CDC driver。
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

Hi @wjandsq 

An internal ticket is submitted to dedicated team (227474) to check whether it's a bug. Would you provide more details about your HW setup and minimal project to reproduce the issue?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

View solution in original post

14 REPLIES 14
FBL
ST Employee

Hi @wjandsq 

An internal ticket is submitted to dedicated team (227474) to check whether it's a bug. Would you provide more details about your HW setup and minimal project to reproduce the issue?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL
gbm
Principal

Maybe there is some problem with the configuration descriptor.

Last time I checked, the CDC ACM notifications in my USB stack were correctly handled by Windows. The default Windows driver is greatly simplified with regard to notification data handling. I also observed the behavior you describe (RTS/DTR).

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
wjandsq
Associate III

you can set  DTR is 1  or 0,  but  RTS have no change,RTS only change with DTR.  this is a bug.  

Hi @wjandsq  Can you provide an example to reproduce the issue?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL
Pavel A.
Super User

But is there a real use case/story for DTR & RTS, besides of compatibility with FTDI and CH341?  Millions of users seem to be happy with the Windows in-box driver. 

 

Millions of users seem to be satisfied with Windows' built-in drivers, but I am not.

Current solutions:
1. Imitate CH340/CH341 devices by using CH340/CH341 drivers.
The current device imitation of CH340N works well and is more stable than the Microsoft CDC Driver. But there are still some problems:
Each packet is only 32 bytes, limiting speed. Authorization from the device manufacturer wch.cn has not been obtained, so it cannot be used compliantly.

2. Imitate FT232RL devices by using FT232RL drivers.
64-byte packets can be used, but it has not been successful yet, and authorization from the device manufacturer FTDI is also required.

3. Use a USB Composite Device, here being a Custom HID CDC_ACM device.
The current problem is:
Once USB FS (PA11 PA12) is in Composite mode, the macro USE_USBD_COMPOSITE is enabled.
Then the USB Device Library used for USB HS (PB14 PB15) also switches to Composite mode.
Therefore, USB FS and USB HS must be in the same Composite mode. The appearance of the macro USE_USBD_COMPOSITE in this USB Device Library is really unfriendly.

wjandsq
Associate III

in USB CDC ACM Device, RTS/DTR Code is here.

	case CDC_SET_CONTROL_LINE_STATE:  /* 0x22 */
	/*
		Endpoint 0	Default Control
		Generates RS-232/V.24 style control signals
		bmRequest         0x21
				  ...00001           Interface
				  .01.....           Class
				  1.......           Device to Host  
		bRequest          0x22               Set Control Line State
		wValue            0x0000  
		0 DTE             ........ .......0  Not Present
		1 Carrier Control ........ ......0.  Deactivate
		15..2 Reserved    00000000 000000..          	
		wIndex            0x0000             Interface
		wLength           0x0000

		wValue            0x0001             DTR = 1 RTS = 0
		wValue            0x0000             DTR = 0 RTS = 0
		wValue            0x0003             DTR = 1 RTS = 1
		wValue            0x0002             DTR = 0 RTS = 1

	*/		

	if (hUsbDeviceFS.request.bRequest == CDC_SET_CONTROL_LINE_STATE) {
		if ((hUsbDeviceFS.request.wValue & 0x0002) == 0x0000) {
			/* STM32 CDC RTS Status Control : RTS = 0 */
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_10, GPIO_PIN_SET);
		} else if ((hUsbDeviceFS.request.wValue & 0x0002) == 0x0002) {
			/* STM32 CDC RTS Status Control : RTS = 1 */
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_10, GPIO_PIN_RESET);
		}

		if ((hUsbDeviceFS.request.wValue & 0x0001) == 0x0000) {
			/* STM32_CDC DTR Status Control DTR = 0 */
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_11, GPIO_PIN_SET);
		} else if ((hUsbDeviceFS.request.wValue & 0x0001) == 0x0001) {
			/* STM32 CDC DTR Status Control DTR = 1 */
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_11, GPIO_PIN_RESET);
		}
	}
	break;

Thank you for this additional information. So, do you want to use RTS/CTS for flow control? If yes, how these signals are set by the WCH and FT drivers?  Do you have host side software that uses RTS/CTS flow control and relies on specific serial drivers or vendor's library, or middleware such as the Qt library?

[ trying to understand if the same can be implemented in the usbser in backward-compatible way, so it won't break existing apps... ]

[ AI suggests to check how this is handled by the TinyUSB library. ]

 

In CH340N Device, PC Software Set RTS , the control Endpoint 0 :

Setup Packet

Offset Field Size Value Description

0bmRequestType140h 
 4..0: Recipient ...00000 Device
 6..5: Type .10..... Vendor
 7: Direction 0....... Host-to-Device
1bRequest1A4h 
2wValue200BFh 
4wIndex20000h 
6wLength20000h

 

PC Software Reset RTS , the control Endpoint 0 :

Setup Packet

Offset Field Size Value Description

0bmRequestType140h 
 4..0: Recipient ...00000 Device
 6..5: Type .10..... Vendor
 7: Direction 0....... Host-to-Device
1bRequest1A4h 
2wValue200FFh 
4wIndex20000h 
6wLength20000h