Skip to content

Commit

Permalink
Merge pull request 32blit#711 from Daft-Freak/fix-flashing
Browse files Browse the repository at this point in the history
Fix CDC FIFO used getting out of sync
  • Loading branch information
Gadgetoid authored Aug 26, 2021
2 parents d9ded2d + 5368ff3 commit c2c1207
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
8 changes: 1 addition & 7 deletions 32blit-stm32/Inc/CDCCommandStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct CDCFifoElement
class CDCCommandStream
{
public:
CDCCommandStream() : m_uFifoReadPos(0), m_uFifoWritePos(0), m_uFifoUsedCount(0)
CDCCommandStream() : m_uFifoReadPos(0), m_uFifoWritePos(0)
{
Init();
}
Expand All @@ -44,11 +44,6 @@ class CDCCommandStream
void ReleaseFifoWriteBuffer(uint8_t uLen);
CDCFifoElement *GetFifoReadElement(void);
void ReleaseFifoReadElement(void);
bool IsFifoFull(void)
{
return m_uFifoUsedCount==CDC_FIFO_BUFFERS;
}


private:
typedef enum { stDetect, stDetectCommandWord, stDispatch, stProcessing, stError } StreamState;
Expand All @@ -74,7 +69,6 @@ class CDCCommandStream
CDCFifoElement m_fifoElements[CDC_FIFO_BUFFERS];
uint8_t m_uFifoReadPos;
uint8_t m_uFifoWritePos;
uint8_t m_uFifoUsedCount;

bool m_bNeedsUSBResume;

Expand Down
6 changes: 2 additions & 4 deletions 32blit-stm32/Src/CDCCommandStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ uint32_t CDCCommandStream::GetTimeTaken(void)
uint8_t *CDCCommandStream::GetFifoWriteBuffer(void)
{
uint8_t *pData = NULL;
if(m_uFifoUsedCount < CDC_FIFO_BUFFERS - 1)
if((m_uFifoWritePos + 1) % CDC_FIFO_BUFFERS != m_uFifoReadPos)
{
pData = m_fifoElements[m_uFifoWritePos].m_data;
}
Expand All @@ -228,13 +228,12 @@ void CDCCommandStream::ReleaseFifoWriteBuffer(uint8_t uLen)
m_uFifoWritePos++;
if(m_uFifoWritePos == CDC_FIFO_BUFFERS)
m_uFifoWritePos = 0;
m_uFifoUsedCount++;
}

CDCFifoElement *CDCCommandStream::GetFifoReadElement(void)
{
CDCFifoElement *pElement = NULL;
if(m_uFifoUsedCount)
if(m_uFifoReadPos != m_uFifoWritePos)
pElement = &m_fifoElements[m_uFifoReadPos];
return pElement;
}
Expand All @@ -244,7 +243,6 @@ void CDCCommandStream::ReleaseFifoReadElement(void)
m_uFifoReadPos++;
if(m_uFifoReadPos == CDC_FIFO_BUFFERS)
m_uFifoReadPos = 0;
m_uFifoUsedCount--;
}

// usb host glue
Expand Down

0 comments on commit c2c1207

Please sign in to comment.