USB CDC Setup Block Description
This block enables the configuration of the USB peripheral interface in CDC (Communication Device Class) mode within STM microcontrollers.

Table of Contents
- Inputs
- Outputs
- Block Parameters
- CubeMX Configuration for a Given MCU Model
- Comments and Troubleshooting
- See Also
Inputs
This block has no inputs.
Outputs
This block has no outputs.
Block Parameters
| Parameter | Description |
|---|---|
| USB type | The target USB peripheral module type:USB_FS – Full SpeedUSB_HS – High Speed |
| Size of RX buffer | The maximum data capacity allocated for the memory receive buffer. |
| Size of TX buffer | The maximum data capacity allocated for the memory transmit buffer. |
| Baudrate (bps) | The serial data transmission rate evaluated in bits per second. |
| Stop bits | The total number of stop bits appended to frame boundaries. |
| Parity | The error checking parity protocol type:None – no parity bitEven – even parity parity bitOdd – odd parity parity bit |
| Number of bits (without stop bits) | The character data payload word length (excluding stop bits). |
| Reset USB Pins on start | Enables a force-reconnection routine by toggling the hardware state of the USB lines upon application initialization. |
| USB DP Port | Conditional Parameter The GPIO alphanumeric port letter designated for the USB DP line. Supply this designator in a string format such as 'A', 'B', etc. This parameter is accessible only when the Reset USB Pins on start option is enabled. |
| Pin | Conditional Parameter The specific GPIO hardware pin number designated for the USB DP line. This parameter is accessible only when the Reset USB Pins on start option is enabled. |
| Tx wait for first Rx | Stalls any active data transmission loops until at least one initial inbound packet is verified by the receiver subsystem. |

CubeMX Configuration for a Given MCU Model
The required hardware peripheral setup is detailed in the dedicated CubeMX Configuration for a Given MCU Model subpage.
Comments and Troubleshooting
”Error in open port” Exception
Should you encounter an “Error in open port” runtime exception, compile and run the firmware binary utilizing a dedicated Release optimization build profile.
USB CDC Setup Integration in FS Mode
To integrate the USB CDC Setup block in FS (Full Speed) operations, insert the following two source lines within the CDC_Control_FS routine implementation inside the usbd_cdc_if.c file:
extern int8_t USB_CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length);
USB_CDC_Control_FS(cmd, pbuf, length);After pasting the lines above, the project fragment should look like this:

USB CDC Setup Integration in HS Mode
To use the USB CDC Setup block in HS mode, add two lines in the CDC_Control_HS function in the usbd_cdc_if.c file:
extern int8_t USB_CDC_Control_HS(uint8_t cmd, uint8_t* pbuf, uint16_t length);
USB_CDC_Control_HS(cmd, pbuf, length);After pasting the lines above, the project fragment should look like this:
