Can't understand how xStreamBufferSetTriggerLevel and xStreamBufferReceive works

I expect xStreamBufferReceive will wait until all 52 bytes read:

	bool set_res = xStreamBufferSetTriggerLevel(stream, 52);
	size_t bytes_read = xStreamBufferReceive(stream, read_buffer, 52, portMAX_DELAY);

but it returns immediately with bytes_read = 3. How it possible?

Part of my FreeRTOSConfig.h:

	#define configUSE_TRACE_FACILITY            1
	#define INCLUDE_uxTaskGetStackHighWaterMark 1
	#define configCHECK_FOR_STACK_OVERFLOW      2
	#define configASSERT(x)                     if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }

Tested with FreeRTOS 10.4.3 and 10.4.4

According to the API docs (xStreamBufferSetTriggerLevel() RTOS API documentation) the trigger level is used only if the receive function must block. And the receive function blocks only if the stream is empty.

Hmm… I can’t find information about it in FreeRTOS docs

On this page (xStreamBufferReceive() RTOS API function documentation), see the description of parameter xTicksToWait.

I was going to suggest look at the docs for the trigger level. That is how many bytes the task will block for.

Thanks. But it is still not clear for me after reading this doc how xTicksToWait affects function’s behavior if buffer is NOT empty
It is only clearly said that “xStreamBufferReceive() will return immediately if xTicksToWait is zero”

If the buffer is not empty, the is no wait, you just get what is there. If the buffer is empty, it will wait for the first of trigger bytes or the time out to happen.