Hopefully fix the SAVE/PROG issues by waiting for fifo to be full before writting.
diff --git a/32blit-stm32/Src/CDCCommandStream.cpp b/32blit-stm32/Src/CDCCommandStream.cpp index d26ec52..9968096 100644 --- a/32blit-stm32/Src/CDCCommandStream.cpp +++ b/32blit-stm32/Src/CDCCommandStream.cpp
@@ -31,20 +31,34 @@ void CDCCommandStream::Stream(void) { - while(CDCFifoElement *pElement = GetFifoReadElement()) - { - if(pElement->m_uLen) - Stream(pElement->m_data, pElement->m_uLen); - ReleaseFifoReadElement(); - } + static uint32_t uLastResumeTime = HAL_GetTick(); - // restart USB CDC if fifo was full - if(m_bNeedsUSBResume && m_uFifoUsedCount == 0) - { - m_bNeedsUSBResume = false; - USBD_CDC_SetRxBuffer(&hUsbDeviceHS, GetFifoWriteBuffer()); - USBD_CDC_ReceivePacket(&hUsbDeviceHS); - } + if(m_bNeedsUSBResume) // FIFO Full, so empty and resume USB + { + while(CDCFifoElement *pElement = GetFifoReadElement()) + { + if(pElement->m_uLen) + Stream(pElement->m_data, pElement->m_uLen); + ReleaseFifoReadElement(); + } + m_bNeedsUSBResume = false; + USBD_CDC_SetRxBuffer(&hUsbDeviceHS, GetFifoWriteBuffer()); + USBD_CDC_ReceivePacket(&hUsbDeviceHS); + uLastResumeTime = HAL_GetTick(); + } + else + { + if(HAL_GetTick() > uLastResumeTime + 10) // USB Stalled, empty FIFO + { + // empty fifo + while(CDCFifoElement *pElement = GetFifoReadElement()) + { + if(pElement->m_uLen) + Stream(pElement->m_data, pElement->m_uLen); + ReleaseFifoReadElement(); + } + } + } } uint8_t CDCCommandStream::Stream(uint8_t *data, uint32_t len)