Info about receiving buffer in usb cdc vcp application with stm32cube
Hi everybody,
I am a newbie trying to develop a simple application for an stm32f429 discovery board with freertos, STM32Cube_FW_F4_V1.5.0and vcp over usb capabilities. I used stm32cubemx to generate the project that works fine. I can run a simple echo program via terminal with the micro connected to a pc with windows7. However there are some things that are very unclear to me and I want to ask for an explanation. I unsuccesfullygoogled a lot, gave a look at the examples in STM32Cube_FW_F4_V1.5.0 and read theUser manualUM1734 (STM32Cube USB device library) Particularly, what I don't get is related to usbd_cdc_if.c. In the version generated by stm32cubemx there are/* Define size for the receive and transmit buffer over CDC */ /* It's up to user to redefine and/or remove those define */ #define APP_RX_DATA_SIZE 4 . . . /* Create buffer for reception and transmission */ /* It's up to user to redefine and/or remove those define */ /* Received Data over USB are stored in this buffer */ uint8_t UserRxBufferHS[APP_RX_DATA_SIZE]; /* Send Data over USB CDC are stored in this buffer */ uint8_t UserTxBufferHS[APP_TX_DATA_SIZE]; . . . /**
* @brief CDC_Init_HS
* Initializes the CDC media low layer over the USB HS IP
* @param None
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/
staticint8_t CDC_Init_HS(
void)
{hUsbDevice_1 = &hUsbDeviceHS;
/* USER CODE BEGIN 8 */
/* Set Application Buffers */
USBD_CDC_SetTxBuffer(hUsbDevice_1, UserTxBufferHS, 0);
USBD_CDC_SetRxBuffer(hUsbDevice_1, UserRxBufferHS);
return
(USBD_OK);
/* USER CODE END 8 */
} . . . staticint8_t CDC_Receive_HS (uint8_t* Buf, uint32_t *Len)
{/* USER CODE BEGIN 11 */
return
(USBD_OK);
/* USER CODE END 11 */
} The (I think defenitely wrong) idea I got in my mind is that in UserRxBufferHS is stored by the lower layer what I type over the terminal (that is what arrives at the endpoint out). The lower layer also calls CDC_Receive_HS. Basicly Buf, which is defined by the interface ofCDC_Receive_HS,is copied toUserRxBufferHS. I noticed that *Len is always 1 whatever I type and that inUserRxBufferHS there are always the last character I typed and two more odd characters (like interrupt characters, e.g. 0@). That is if I type ''t'' then I get ''t0@'' inUserRxBufferHS. According to this I wonder why one would set APP_RX_DATA_SIZE to wathever value greater than 3 since inUserRxBufferHS there always are 3 elements. Is this right? Can anybody give me a better insight? Thank you and regards.