The old method would introduce a race condition where the buffer could be overwritten before the data was consumed. For slow, single character typing this was fine, but w/ packets being generated by a computer, this would cause corruption of the incoming data..irr_shared
| @@ -24,6 +24,7 @@ | |||||
| /* USER CODE BEGIN INCLUDE */ | /* USER CODE BEGIN INCLUDE */ | ||||
| uint8_t* CDC_RX_BUFFER = NULL ; | uint8_t* CDC_RX_BUFFER = NULL ; | ||||
| uint16_t CDC_RX_LEN = 0; | |||||
| /* USER CODE END INCLUDE */ | /* USER CODE END INCLUDE */ | ||||
| /* Private typedef -----------------------------------------------------------*/ | /* Private typedef -----------------------------------------------------------*/ | ||||
| @@ -264,8 +265,9 @@ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) | |||||
| { | { | ||||
| /* USER CODE BEGIN 6 */ | /* USER CODE BEGIN 6 */ | ||||
| USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); | USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); | ||||
| USBD_CDC_ReceivePacket(&hUsbDeviceFS); | |||||
| CDC_RX_BUFFER = Buf; | CDC_RX_BUFFER = Buf; | ||||
| CDC_RX_LEN = *Len; | |||||
| return (USBD_OK); | return (USBD_OK); | ||||
| /* USER CODE END 6 */ | /* USER CODE END 6 */ | ||||
| } | } | ||||
| @@ -91,6 +91,16 @@ | |||||
| extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; | extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; | ||||
| /* USER CODE BEGIN EXPORTED_VARIABLES */ | /* USER CODE BEGIN EXPORTED_VARIABLES */ | ||||
| extern USBD_HandleTypeDef hUsbDeviceFS; | |||||
| extern uint8_t* CDC_RX_BUFFER; | |||||
| extern uint16_t CDC_RX_LEN; | |||||
| /* | |||||
| * when CDC_RX_LEN != 0, CDC_RX_LEN bytes are available in CDC_RX_BUFFER. | |||||
| * Once all bytes have been consumed from the buffer, set CDC_RX_LEN to | |||||
| * zero and call: | |||||
| * USBD_CDC_ReceivePacket(&hUsbDeviceFS); | |||||
| * to receive more data. | |||||
| */ | |||||
| /* USER CODE END EXPORTED_VARIABLES */ | /* USER CODE END EXPORTED_VARIABLES */ | ||||