CDC device status sending: default setting is too small
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 */
#endifNow 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: xxIf it is another way to tell host the status, please share.
