Browse Source

add framework for properly receiving/handling incoming data..

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
John-Mark Gurney 3 years ago
parent
commit
8a9c2927dc
2 changed files with 13 additions and 1 deletions
  1. +3
    -1
      stm32/usb/usbd_cdc_if.c
  2. +10
    -0
      stm32/usb/usbd_cdc_if.h

+ 3
- 1
stm32/usb/usbd_cdc_if.c View File

@@ -24,6 +24,7 @@

/* USER CODE BEGIN INCLUDE */
uint8_t* CDC_RX_BUFFER = NULL ;
uint16_t CDC_RX_LEN = 0;
/* USER CODE END INCLUDE */

/* Private typedef -----------------------------------------------------------*/
@@ -264,8 +265,9 @@ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
CDC_RX_BUFFER = Buf;
CDC_RX_LEN = *Len;
return (USBD_OK);
/* USER CODE END 6 */
}


+ 10
- 0
stm32/usb/usbd_cdc_if.h View File

@@ -91,6 +91,16 @@
extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS;

/* 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 */



Loading…
Cancel
Save