Skip to Content

USB CDC Receive Block Description

This block enables receiving data from the USB receive buffer in CDC (Communication Device Class) mode within STM microcontrollers.



USB CDC Receive block

Table of Contents

Inputs

This block has no inputs.

Outputs

Output NameTypeDescription
Statusuint8The operational status of the data reception from the Rx buffer. Returns:
1 – reception completed successfully
0 – reception failed / no data available
Num rx framesuint32The total number of received data frames.
Frame lengthuint32The length of the currently received data frame.
Datauint8The raw received data payload.

Block Parameters

ParameterDescription
USB typeThe target USB peripheral module type:
USB_FS – Full Speed
USB_HS – High Speed
Receive modeThe data reception format mode. The Binary matrix format is selected by default.
Hex formatEnables detection of the incoming data header sequence in hexadecimal notation. When activated, characters supplied in the Header parameter are parsed as literal hex values.
LengthConditional Parameter
The total length of the header evaluated in Hex format. This parameter is accessible only when the Hex format option is enabled.
HeaderThe pre-defined header sequence expected within the incoming payload stream. If the hex interpretation mode is active, the entered value will be converted to its corresponding hexadecimal bytes.
Output data typeThe data type configured for the block output signals.
Max data length (bytes)Specifies the maximum byte size allocation for incoming data reception.
Search only last frameRestricts the validation and search for matching headers strictly to the last buffered data frame received.
Max receive framesThe maximum total number of buffered frames allowed for simultaneous reception processing.
Enable (Terminator settings)Activates detection and framing options for the trailing payload terminator sequence.
Hex formatConditional Parameter
Enables detection of the incoming payload terminator sequence in hexadecimal notation. When activated, characters supplied in the Terminator parameter are parsed as literal hex values. This parameter is accessible only when the Enable (Terminator settings) option is enabled.
LengthConditional Parameter
The total length of the terminator evaluated in Hex format. This parameter is accessible only when the Hex format option is enabled.
TerminatorConditional Parameter
The terminator data sequence applied to validate packets. This parameter is accessible only when the Enable (Terminator settings) option is enabled. If hex interpretation mode is active, the entered value will be converted to its corresponding hexadecimal bytes.
Sample time [ms]The cyclic execution time interval of the block evaluated in milliseconds.


Block parameters for USB CDC Receive

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

USB Receive in FS Mode

To utilize the USB CDC Receive block in FS (Full Speed) mode, the following line of code must be appended to the CDC_Receive_FS function within the usbd_cdc_if.c source file:

USB_CDC_Read_Buff(&hUsbDeviceFS, Buf, Len);

Once applied, your project source block implementation should align with the structure below:

CDC_Receive_FS

USB CDC Setup Integration in HS Mode

To integrate the USB CDC Setup block configuration inside HS (High Speed) routines, insert the following two source lines within the CDC_Control_HS routine implementation inside the usbd_cdc_if.c file:

USB_CDC_Read_Buff(&hUsbDeviceHS, Buf, Len);

After adding the code, the function looks as follows: Funkcja CDC_Receive_HS

See Also

Last updated on