I found a bug in the circular buffer where an overflow causes the code to think the buffer is empty. This is due to a lack of a floating empty space in the buffer. I fixed this in my project by allocating one extra space and not including it in the length when writing to the buffer.
--- system/FreeRTOS/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/Common/IOUtils_CircularBufferRx.c
+++ system/FreeRTOS/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/Common/IOUtils_CircularBufferRx.c
@@ -77,11 +77,11 @@ Circular_Buffer_Rx_State_t *pxCircularBufferState;
/* The semaphore was created correctly. Fill in the private
data structure. */
- pxCircularBufferState->pucBufferStart = pvPortMalloc( xBufferSize );
+ pxCircularBufferState->pucBufferStart = pvPortMalloc( xBufferSize + 1 );
if( pxCircularBufferState->pucBufferStart != NULL )
{
- pxCircularBufferState->usBufferLength = ( uint16_t ) xBufferSize;
+ pxCircularBufferState->usBufferLength = ( uint16_t ) xBufferSize + 1;
pxCircularBufferState->usErrorState = 0U;
pxCircularBufferState->usNextReadIndex = 0U;
pxCircularBufferState->usCharCount = 0U;
--- system/FreeRTOS/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/Include/IOUtils_CircularBufferRx.h
+++ system/FreeRTOS/FreeRTOS-Plus/Source/FreeRTOS-Plus-IO/Include/IOUtils_CircularBufferRx.h
@@ -67,7 +67,7 @@
uint16_t *pusNextWrite; \
while( ( xCondition ) ) \
{ \
/* If there is space in the circular buffer. */ \
- if( pxCircularBufferRxState->usCharCount < pxCircularBufferRxState->usBufferLength ) \
+ if( pxCircularBufferRxState->usCharCount < (pxCircularBufferRxState->usBufferLength - 1) ) \
{ \
pxCircularBufferRxState->pucBufferStart[ *pusNextWrite ] = ( xReceiveFunction ); \
ulReceived++; \
The following change seems to work for me.
Last edit: Kedar Patil 2019-07-01