Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDC_Receive() and USBD_CUSTOM_HID_SendReport() usage #26

Open
msiweka opened this issue Mar 30, 2023 · 2 comments
Open

CDC_Receive() and USBD_CUSTOM_HID_SendReport() usage #26

msiweka opened this issue Mar 30, 2023 · 2 comments

Comments

@msiweka
Copy link

msiweka commented Mar 30, 2023

I tried to use this wrapper on STM32G0Bxx.
Wrapper is initialized in main function with this functions:

MX_USB_DRD_FS_PCD_Init();
MX_USB_DEVICE_Init();

I can send data by CDC_Transmit(), but I don't know how to get data from callback function CDC_Receive(). Also USBD_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

@paspartu22
Copy link

paspartu22 commented Sep 1, 2023

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;
    }
}

@russeree
Copy link

russeree commented Oct 30, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants