Hi :
Because USB endpoints have a maximum buffer of 1024bytes, if you need to read 10K bytes from I2C at a time, how to design it so that the USB endpoint can send data every 1024bytes when I2C reads continuously, instead of batching the data after I2C reads the data. Sent via USB endpoint.
Hi :
Thanks for your sugesstion.
You mean DMA ping-pong mode right.
If yes, I have one question that this DMA ping-pong mode callback function is excuted when all finished.
How to call sending function of USB each buffer full?
Hi,
Regarding the USB packet size, it is dependent on your USB end point types: control, bulk, interrupt and Isochronous, the maximum packet size of control, bulk, interrupt is 64 bytes, the Isochronous end point is 1024 bytes.
Because the I2C is not a stream interface, I suppose you can use bulk protocol.
You can use ping-pong mode,You can transfer the I2C received data to a ping buffer, when the buffer is full, the I2C received data will transfer to pong buffer, while, you can read the ping buffer to the bulk memory and call the sending function of USB.
The full speed USB is 12M BPS.
Hope it can help you
BR
XiangJun Rong
thanks for your reply.
I have one question , the callback function just run once when all DMA finished.
How to call the sending function of USB by every ping or pong buffer full?
Hi,
I suggest you refer to the *device_cdc_vcom_bm example, you can call the USB_DeviceCdcAcmSend() to transfer data to host once the buffer is full.
Hope it can help you
static void APPTask(void)
{
usb_status_t error = kStatus_USB_Error;
if ((1 == s_cdcVcom.attach) && (1 == s_cdcVcom.startTransactions))
{
/* User Code */
/* endpoint callback length is USB_CANCELLED_TRANSFER_LENGTH (0xFFFFFFFFU) when transfer is canceled */
if ((0 != s_recvSize) && (USB_CANCELLED_TRANSFER_LENGTH != s_recvSize))
{
int32_t i;
/* Copy Buffer to Send Buff */
for (i = 0; i < s_recvSize; i++)
{
s_currSendBuf[s_sendSize++] = s_currRecvBuf[i];
}
s_recvSize = 0;
}
if (s_sendSize)
{
uint32_t size = s_sendSize;
s_sendSize = 0;
error = USB_DeviceCdcAcmSend(s_cdcVcom.cdcAcmHandle, USB_CDC_VCOM_BULK_IN_ENDPOINT, s_currSendBuf, size);
if (error != kStatus_USB_Success)
{
/* Failure to send Data Handling code here */
}
}
#if defined(FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED) && (FSL_FEATURE_USB_KHCI_KEEP_ALIVE_ENABLED > 0U) && \
defined(USB_DEVICE_CONFIG_KEEP_ALIVE_MODE) && (USB_DEVICE_CONFIG_KEEP_ALIVE_MODE > 0U) && \
defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)
if ((s_waitForDataReceive))
{
if (s_comOpen == 1)
{
/* Wait for all the packets been sent during opening the com port. Otherwise these packets may
* wake up the system.
*/
usb_echo("Waiting to enter lowpower ...\r\n");
for (uint32_t i = 0U; i < 16000000U; ++i)
{
__NOP(); /* delay */
}
s_comOpen = 0;
}
usb_echo("Enter lowpower\r\n");
BOARD_DbgConsole_Deinit();
USB0->INTEN &= ~USB_INTEN_TOKDNEEN_MASK;
USB_EnterLowpowerMode();
s_waitForDataReceive = 0;
USB0->INTEN |= USB_INTEN_TOKDNEEN_MASK;
BOARD_DbgConsole_Init();
usb_echo("Exit lowpower\r\n");
}
#endif
}