on 2021-05-18 06:46 AM
USBD_CDC_LineCodingTypeDef LineCoding = { 115200, /* baud rate */ 0x00, /* stop bits-1 */ 0x00, /* parity - none */ 0x08 /* nb. of bits 8 */ };then structure need to be correctly added into CDC_control_xS function:
static int8_t CDC_Control_xS(uint8_t cmd, uint8_t* pbuf, uint16_t length) { /* USER CODE BEGIN 5 */ switch(cmd) { ... case CDC_SET_LINE_CODING: LineCoding.bitrate = (uint32_t) (pbuf[0] | (pbuf[1] << 8) | (pbuf[2] << 16) | (pbuf[3] << 24)); LineCoding.format = pbuf[4]; LineCoding.paritytype = pbuf[5]; LineCoding.datatype = pbuf[6]; break; case CDC_GET_LINE_CODING: pbuf[0] = (uint8_t) (LineCoding.bitrate); pbuf[1] = (uint8_t) (LineCoding.bitrate >> 8); pbuf[2] = (uint8_t) (LineCoding.bitrate >> 16); pbuf[3] = (uint8_t) (LineCoding.bitrate >> 24); pbuf[4] = LineCoding.format; pbuf[5] = LineCoding.paritytype; pbuf[6] = LineCoding.datatype; break; ... return (USBD_OK); /* USER CODE END 5 */ }
But how to use it for USB Host? Any example plz?
Hello,
line coding may be used on USB host side as well to set correctly parameters of UART peripheral behind. Example of line coding handling on host side can be found in USB CDC host examples in our repositories. Multiple such examples on multiple STM32 families available, one of them on following link:
Best regards,
Lubos