USB CDC : How send SERIAL_STATE notification?
Hello,
I have to implement a USB CDC device that uses flow control. After a few research it seems to be possible to send a notification SERIAL_STATE that holds the signal DSR in its bitmap.
Also, I have found topics on this platform trying to answer this question:
- Notification SERIAL_STATE on VCP STM32F105
- 2. I'm trying to send signals DSR and DCD through the structure and command endpoint, see example USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) { static uint8_t Buf[0xA]; Buf[0] = 0xA1; Buf[1] = 0x20; Buf[2] = 0; Buf[3] = 0; Buf
- CTS signal on USB CDC
- Send SERIAL_STATE with STM32CubeMX USB CDC driver
None of which are helpful, #2 and #3 are closed without an answer, #1 and #4 seems to use the same code which does not work for me yet.
Based on example from #4, here is my code:
// usbd_cdc_if.h
typedef union
{
uint8_t val;
struct{
unsigned dcd :1;
unsigned dsr :1;
unsigned break_err :1;
unsigned ri :1;
unsigned frame_err :1;
unsigned parity_err :1;
unsigned overrun_err :1;
unsigned reserved :1;
};
} USBD_CDC_SerialStateTypeDef;
uint8_t CDC_Serial_State(USBD_CDC_SerialStateTypeDef serial_state);
// usbd_cdc_if.c
uint8_t CDC_Serial_State_Buf[10] = {
0xA1, // vmRequestType
0x20, // SERIAL_STATE
0x00, // wValue
0x00,
0x00, // wIndex
0x00,
0x02, // wLength
0x00,
0x00, // UART state bitmap
0x00,
};
/**
* @brief CDC_Serial_State
* Send SERIAL_STATE over USB IN interrupt endpoint through this function.
* @note
*
*
* @param serial_state: Uart State Bitmap Value
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
*/
uint8_t CDC_Serial_State(USBD_CDC_SerialStateTypeDef serial_state)
{
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)&hUsbDeviceHS.pClassData;
if (hcdc->TxState != 0){
return USBD_BUSY;
}
CDC_Serial_State_Buf[8] = serial_state.val;
hUsbDeviceHS.ep0_state = USBD_EP0_STATUS_IN;
hUsbDeviceHS.ep_in[0].total_length = 10;
hUsbDeviceHS.ep_in[0].rem_length = 10;
/* Start the transfer */
USBD_LL_Transmit (&hUsbDeviceHS, CDC_CMD_EP, CDC_Serial_State_Buf, 10);
return USBD_OK;
}Now when calling CDC_Serial_State() the device seems to be stuck in the USB IRQ Handler and never returns from CDC_Serial_State().
What is the problem with this code? How am I supposed to send USB notifications?
Thanks for your support,
Morgan
