Open msiweka opened 1 year ago
Sooo, maybe its not intended way to do it, but i did this.
I added
uint16_t dataRxLength;
to the USBD_CDC_ACM_HandleTypeDef;
after i saved buffer to hcdc->data and len to hcdc->dataRxLength (hcdc->RxLength is len of whole buffer, but hcdc->dataRxLen is len of current message).
static int8_t CDC_Receive(uint8_t cdc_ch, uint8_t *Buf, uint32_t *Len){
/* USER CODE BEGIN 6 */
CDC_Transmit(cdc_ch, Buf, *Len); // echo back on same channel
USBD_CDC_SetRxBuffer(cdc_ch, &hUsbDevice, Buf);
extern USBD_CDC_ACM_HandleTypeDef CDC_ACM_Class_Data[];
USBD_CDC_ACM_HandleTypeDef *hcdc = NULL;
hcdc = &CDC_ACM_Class_Data[cdc_ch];
hcdc->dataRxLength = *Len;
memcpy(hcdc->data, Buf, *Len);
USBD_CDC_ReceivePacket(cdc_ch, &hUsbDevice);
return (USBD_OK);
/* USER CODE END 6 */
And when i want to read buffer i did
void CDC_Event()
{
extern USBD_CDC_ACM_HandleTypeDef CDC_ACM_Class_Data[];
USBD_CDC_ACM_HandleTypeDef *hcdc = NULL;
hcdc = &CDC_ACM_Class_Data[0];
if (hcdc->dataRxLength != 0)
{
//////////// work with hcdc->data here///////
hcdc->dataRxLength = 0;
}
}
void CDC_Event() { extern USBD_CDC_ACM_HandleTypeDef CDC_ACM_Class_Data[]; USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; hcdc = &CDC_ACM_Class_Data[0]; if (hcdc->dataRxLength != 0) { //////////// work with hcdc->data here/////// hcdc->dataRxLength = 0; } }
Is the above blocking code? Is interrupt based execution possible, such as data comes in, interrupt handler takes care of the event then moves back into main execution?
I tried to use this wrapper on STM32G0Bxx. Wrapper is initialized in main function with this functions:
I can send data by
CDC_Transmit()
, but I don't know how to get data from callback functionCDC_Receive()
. AlsoUSBD_CUSTOM_HID_SendReport()
returns 0(USBD_OK) in first run, but in all next returns 1(USBD_BUSY).I can't find specification for this wrapper Same here: https://stackoverflow.com/questions/75885164/how-to-get-data-from-callback-function-cdc-receive