2015-05-26 01:13 PM
Hello, in my earlier post I asked abouot buffer handling.
I investigated any further and found one potential error and one unused buffer. 1) buffer overflow in file usbd_cdc_if.c &sharpdefine APP_RX_DATA_SIZE 4 ... uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; ... static int8_t CDC_Init_FS(void) { ... USBD_CDC_SetRxBuffer(hUsbDevice_0, UserRxBufferFS); ... } @see USBD_CDC_SetRxBuffer doesn't take any length information in file usbd_cdc.c this buffer is used in function: static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { ... USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer, CDC_DATA_HS_OUT_PACKET_SIZE); ... } So that means for safe operation the length of UserRxBufferFS must be minimum CDC_DATA_HS_OUT_PACKET_SIZE size. 2) unused buffer in file usbd_cdc_if.c &sharpdefine APP_TX_DATA_SIZE 4 ... uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; ... static int8_t CDC_Init_FS(void) { ... USBD_CDC_SetTxBuffer(hUsbDevice_0, UserTxBufferFS, 0); ... } This buffer is never used anywhere else. The transmit code uses the buffer the user gives to the function. The buffer UserTxBufferFS is not needed here and misleading. Am I right? Best regards, Adib. #cdc #stm32f4 #usb #vcp