Content originally posted in LPCWare by David Perry on Sun Jan 17 17:17:38 MST 2016
This thread is old but maybe this will help somebody. Here are some simple changes that worked for me to increase the 64 byte limit to 512.
In cdc_com.c, replace this:
pVcom->rx_count = USBD_API->hw->ReadEP(hUsb, USB_CDC_OUT_EP, pVcom->rx_buff);
with this:
if(pVcom->rx_count > (VCOM_RX_BUF_SZ - 64)) {
pVcom->rx_count = 0; // Avoid buffer overflow (by discarding data)
}
pVcom->rx_count += USBD_API->hw->ReadEP(hUsb, USB_CDC_OUT_EP, &pVcom->rx_buff[pVcom->rx_count]);
And in vcom_bread, enter the critical section earlier so that pVcom->rx_count is not unexpectedly modified by the interrupt:
uint32_t vcom_bread(uint8_t *pBuf, uint32_t buf_len)
{
VCOM_DATA_T *pVcom = &g_vCOM;
uint16_t cnt = 0;
/* read from the default buffer if any data present */
if (pVcom->rx_count) {
/* enter critical section */
NVIC_DisableIRQ(USB0_IRQn);
cnt = (pVcom->rx_count < buf_len) ? pVcom->rx_count : buf_len;
memcpy(pBuf, pVcom->rx_buff, cnt);
pVcom->rx_rd_count += cnt;
if (pVcom->rx_rd_count >= pVcom->rx_count) {
pVcom->rx_flags &= ~VCOM_RX_BUF_FULL;
pVcom->rx_rd_count = pVcom->rx_count = 0;
}
/* exit critical section */
NVIC_EnableIRQ(USB0_IRQn);
}
return cnt;
}
It's not ideal because the buffer copy is done with interrupts blocked, but now it won't overrun the buffer until 512 bytes.