2021-06-04 06:41 AM
I am using a STM32F4 on a custom board with USB configured as custom hid device.
I need to know how to get the received data from the USB_ReadPacket placed inside the HAL_PCD_IRQHandler (I suppose this is the function called when the device receive data from USB).
This is the function:
/**
* @brief USB_ReadPacket : read a packet from the RX FIFO
* @param USBx Selected device
* @param dest source pointer
* @param len Number of bytes to read
* @retval pointer to destination buffer
*/
void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
{
uint32_t USBx_BASE = (uint32_t)USBx;
uint32_t *pDest = (uint32_t *)dest;
uint32_t i;
uint32_t count32b = ((uint32_t)len + 3U) / 4U;
for (i = 0U; i < count32b; i++)
{
__UNALIGNED_UINT32_WRITE(pDest, USBx_DFIFO(0U));
pDest++;
}
return ((void *)pDest);
}
Thank you
2021-06-07 12:52 AM
Can anyone help me? Thanks
2021-06-07 02:16 AM
"how to get the received data from the USB_ReadPacket placed inside the HAL_PCD_IRQHandler"
Much the same way that you'd get data from any other interrupt handler?
Presumably, "destination" is the place for the data to go?
2021-06-07 02:23 AM
I didn't manage to get data from the source. I get something that seems to be an address or isn't what I expect. Maybe I am not doing the right operations with the pointers. I should receive a buffer of data (len is equal to 8). Could you help me? Thank you
2021-06-10 12:09 AM
It seems that I can receive the data through this function that is called by interrupt and adding the pointer read_buffer, that I use inside the RxUSB() function to get the data and do the necessary operations on it.
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size)
{
HAL_StatusTypeDef hal_status = HAL_OK;
USBD_StatusTypeDef usb_status = USBD_OK;
read_buffer = pbuf;
hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
usb_status = USBD_Get_USB_Status(hal_status);
if(usb_status == USBD_OK)
RxUSB();
return usb_status;
}
Instead I transmit using in every point I need (for example in the functions that are in the Main) the function USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, ArrayTxUSB, CODA_USB);. It's not called by an interrupt.
But I am seeing that the communication stops to work soon and sometimes I can't even transmit. Maybe this is not the right way to trasmit and receive.
Could anyone help me? I'm stuck on this problem.