How to deal with this scenario about messagebuffer

example code like below:
void vTaskA( void *pvPara )
{
uint8_t buff1[32];
size_t ucRbyte;
for( ;; )
{
//ucRbyte = xStreamBufferReceive( STH_ModbR, &buff1, 7, portMAX_DELAY );
ucRbyte = xMessageBufferReceive( MSH_ModbR, buff1, 6, portMAX_DELAY );
for( uint8_t i=0;i<ucRbyte;i++ )
{
printf( “buff[%d]: 0x%02x\r\n”, i, buff1[i] );
}
printf( “\r\n” );
}
}
void vA_USART_ISR_FOR_RECV(void)
{
BaseType_t xHighWake = pdFALSE;
xMessageBufferSendFromISR( MSH_ModbR, &ucSbuff[0], cntr, &xHighWake );
portYIELD_FROM_ISR( xHighWake );
}
when ISR get 1 byte or 2byte until 6byte,all run ok. when get 7 or more than this, vTaskA() will get run without stopping until app trigger the watchdog to reset.
can we flush the buffer,when it cantain a message whose bytes more than i wish.

vTaskA() will get run without stopping

Do you mean that xMessageBufferReceive() constantly returns without blocking?
What output do you see?

Can you also show how MSH_ModbR is created, with what parameters?

yes. it constantly returns without blocking.
and as it is gived a high priority,so always running, other low priority task can not take a chance to run.
the output i see like this: because the printf() run all the time, result in Rx number adding quickly on the computer screen. until system reset by watchdog overflow.
it is created like this below:
MessageBufferHandle_t MSH_ModbR = NULL;
MSH_ModbR = xMessageBufferCreate( 20 );
by the way, i guess, vTaskA() check messagebuffer ,and found that it is full(7byte in it),but he just want 6,so
return 0. and so on, constantly returns without blocking. so i came out the ideal to flush the unwanted message in the messagebuffer.

You are storing and retrieving the data as “messages”.

Can you try to use xStreamBufferCreate(), xStreamBufferSendFromISR() and xStreamBufferReceive() in stead?

When you are using the stream buffer to pass messages, at the receiving end you need a buffer size that is big enough to receive the largest possible message.

Suppose that a 10-byte message is stored, and you call:

ucRbyte = xMessageBufferReceive( MSH_ModbR, buff1, 6, portMAX_DELAY );

The reception is not possible, and the task will not block.

You indicate that you can only receive 6 bytes, which is including sizeof size_t.

When using the functions from stream_buffer.h, the buffer becomes a pure byte stream. You can add any amount of bytes, and also read any amount of bytes.

Mr.Hein Tibosch,
Thank you for replay.
i will take a think among queue, streambuffer and messagebuffer before choosing an appropriate one fitting app.

by the way, if i already use a messagebuffer as large as 2048bytes, but for an un expected behavior,
an message whose bytes are 2050bytes. so the app losts within helpless forever。can we do some favor for it at the moment.

Your program looks more or less like this:

#define BUFFER_SIZE     64
#define MAX_MSG_SIZE    ( BUFFER_SIZE - 1 )

void uart_ISR()
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
size_t rc;

    rc = getBytes( pcBuffer, sizeof pcBuffer);
    if( rc > MAX_MSG_SIZE )
    {
        /* Can not send to many bytes as a messages. */
    }
    else
    {
        xMessageBufferSendFromISR( xMessageBuffer, pcBuffer, rc, &xHigherPriorityTaskWoken );
    }
    portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}

void myTask( void *pvParameters )
{
char pcBuffer[ MAX_MSG_SIZE ];
TickType_t xTicksToWait = pdMS_TO_TICKS( 1000u );

    for( ;; )
    {
    size_t rc;

        rc = xMessageBufferReceive( xMessageBuffer, pcBuffer, sizeof pcBuffer, xTicksToWait );
        if( rc != 0 )
        {
        }
    }
}

I just ran it, just to be sure.

If you try to receive a messages that is larger than the buffer size, the function xMessageBufferReceive() will return 0 without sleeping (blocking).
Therefore your vTaskA() would consume all CPU-time.

In the above example, messages larger than MAX_MSG_SIZE bytes will be dropped.

When you use xStreamBufferCreate(), xStreamBufferSendFromISR() and xStreamBufferReceive(), you can pass any number of bytes. A reception buffer of 1 byte will even be enough.