AnsweredAssumed Answered

Info about receiving buffer in usb cdc vcp application with stm32cube

Question asked by thy on Apr 10, 2015
Latest reply on Apr 22, 2015 by thy
Hi everybody,
I am a newbie trying to develop a simple application for an stm32f429 discovery board with freertos, STM32Cube_FW_F4_V1.5.0 and 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 unsuccesfully googled a lot, gave a look at the examples in STM32Cube_FW_F4_V1.5.0 and read the User manual UM1734 (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
01./* Define size for the receive and transmit buffer over CDC */
02./* It's up to user to redefine and/or remove those define */
03.#define APP_RX_DATA_SIZE  4
04..
05..
06..
07./* Create buffer for reception and transmission           */
08./* It's up to user to redefine and/or remove those define */
09./* Received Data over USB are stored in this buffer       */
10.uint8_t UserRxBufferHS[APP_RX_DATA_SIZE];
11. 
12./* Send Data over USB CDC are stored in this buffer       */
13.uint8_t UserTxBufferHS[APP_TX_DATA_SIZE];
14..
15..
16..
17./**
18.  * @brief  CDC_Init_HS
19.  *         Initializes the CDC media low layer over the USB HS IP
20.  * @param  None
21.  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
22.  */
23.static int8_t CDC_Init_HS(void)
24.{
25.  hUsbDevice_1 = &hUsbDeviceHS;
26.  /* USER CODE BEGIN 8 */
27.  /* Set Application Buffers */
28.  USBD_CDC_SetTxBuffer(hUsbDevice_1, UserTxBufferHS, 0);
29.  USBD_CDC_SetRxBuffer(hUsbDevice_1, UserRxBufferHS);
30.  return (USBD_OK);
31.  /* USER CODE END 8 */
32.}
33..
34..
35..
36.static int8_t CDC_Receive_HS (uint8_t* Buf, uint32_t *Len)
37.{
38.  /* USER CODE BEGIN 11 */
39.  return (USBD_OK);
40.  /* USER CODE END 11 */
41.}

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 of CDC_Receive_HS, is copied to UserRxBufferHS. I noticed that *Len is always 1 whatever I type and that in UserRxBufferHS 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@" in UserRxBufferHS.

According to this I wonder why one would set APP_RX_DATA_SIZE to wathever value greater than 3 since in UserRxBufferHS there always are 3 elements.

Is this right? Can anybody give me a better insight?

Thank you and regards.

Outcomes