cancel
Showing results for 
Search instead for 
Did you mean: 

CDC device status sending: default setting is too small

LLeva.1
Associate III

Default USB settings for command packet size is 8U (CDC_CMD_PACKET_SIZE), meanwhile, if we want to change "hardware flow control" flags, we need to send 10 bytes command packet. (for 32F103)

If CDC_CMD_PACKET_SIZE is redefined in cubeMX package, I receive lots of warnings:

In file included from USB_DEVICE/App/usb_device.c:26:
Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h:61: warning: "CDC_CMD_PACKET_SIZE" redefined
61 | #define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */

I suggest to add few lines in "usb_cdc.h":

#ifndef CDC_CMD_PACKET_SIZE
#define CDC_CMD_PACKET_SIZE                         8U  /* Control Endpoint Packet size */
#endif

Now I can change command packet size in CubeMX user constants.

Why I need this? To set serial port control pins status.

void USB_CDC_SerialStatus(unsigned char status)
{
unsigned char buf[10];
buf[0]=0b10100001; //request type.
buf[1]=0x20; //notification SERIAL STATE
buf[2]=0;
buf[3]=0;
buf[4]=0;
buf[5]=0;
buf[6]=2;
buf[7]=0;
buf[8]=status;
buf[9]=0;

USBD_LL_Transmit(&hUsbDeviceFS, 0x82, buf,10); // WARNING! default cubemx packet size is too small in endpoint descriptor
//#define CDC_CMD_PACKET_SIZE                         10U  /* Control Endpoint Packet size */
// file usbd_cdc.h
}

 And here is description of whole buffer and particular bits of "status" byte:

			// Class notifications:
			// SERIAL_STATE 20h, returns the current state of the carrier detects, DSR, break, and ring signal
			//
			// bmRequestType: 10100001b, SERIAL STATE, wValue 0, wIndex interface, wLenght 2, UART_STATE_BITMAP:
			// 15:7 reserved.
			// 6 bOverRun - received data has been discarded due to overrun in the device.
			// 5 bParity =parity error
			// 4 bFraming = framing error
			// 3 BRingSignal =RI
			// 2 bBreak = break detection state
			// 1 bTxCarrier = DATA SET READY (DSR)
			// 0 bRxCarrier = DCD, carrier detect
//0:  0xA1   bmRequestType
//1:  0x20   bNotification (SERIAL_STATE)
//2:  0x00   wValue
//3:  0x00
//4:  xx     wIndex (Interface number, 16 bits, LSB first)
//5:  xx
//6:  0x02   wLength (Data length = 2 bytes, LSB first)
//7:  0x00
//8:  xx     UART State Bitmap (16bits, LSB first)
//9:  xx

If it is another way to tell host the status, please share.

4 REPLIES 4
TDK
Guru

See same issue reported here 8 years ago:

https://community.st.com/t5/stm32-mcus-embedded-software/send-serial-state-with-stm32cubemx-usb-cdc-driver/td-p/482571

Reasonable request, but I wouldn't hold your breath on getting things changed.

If you feel a post has answered your question, please click "Accept as Solution".
LLeva.1
Associate III

Yeap, 8 years ago. But I proposed solution! :beaming_face_with_smiling_eyes:

Just add two lines around #define for "compatibility" or just replace 8U with 10U.

I think, that they added redefine option for other constants.

Maybe STM32Cube firmware package developers can look at it again! And we will not receive message from anon STM employee what it is impossible to change line in firmware package.

FBL
ST Employee

Hello @LLeva.1 

 

An internal ticket 175368 is submitted to add the proposed solution for CDC_CMD_PACKET_SIZE in order to facilitate CubeMX code regeneration.

Thank you for reporting this 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.


I'm out of offce with limited access to my emails.
Happy New Year!
LSung.1
Associate III

When editing, it would be nice to add '#ifndef~#endif' for every '#define'.