xStreamBufferSendFromISR break xStreamBufferReceive (portMAX_DELAY)

I want accumulate 4 bytes from uart’s ISR before analyze in main. So I use trigLevel == 4

myStreamBuffer = xStreamBufferCreate(xStreamBufferSizeBytes, 4);

In ISR I send bytes one by one from uart

    uint8_t c = UDR1;
    size_t xBytesSent;
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;
    xBytesSent = xStreamBufferSendFromISR(myStreamBuffer, &c, 1, &xHigherPriorityTaskWoken);

In main thread I am waiting 4 bytes to analyze:

uint8_t pack[4] = {0};
uint8_t amo = xStreamBufferReceive(myStreamBuffer, ( void * )pack,  sizeof(pack), portMAX_DELAY);

I hear Beep because of my function BeepMini(). And I look at amo and I see that amo == 1. Why?

I can use xStreamBufferBytesAvailable to check does myStreamBuffer contains 4 bytes, but I want Blocked state to wait without spending CPU time…

See also

Unrelated to your real problem, but don’t forget
taskYIELD_FROM_ISR( xHigherPriorityTaskWoken ); in the ISR.

1 Like

Are you doing it in a task after the scheduler is started? Is it possible that scheduler is suspended?

I do my 4 bytes waiting in task. As I know It’s unreal to run task before scheduler started. I never suspend scheduler, never do critical sections, no mutex or semaphores in my proj.

I hear Beep because of my function BeepMini(). And I look at amo and I see that amo == 1. Why?

int main(void){    

    xTaskCreate(vTaskWifiStream, "", 200, NULL, tskIDLE_PRIORITY+1, NULL);
    xTaskCreate(vBlinkOnboardUserLED, "", 200, NULL, tskIDLE_PRIORITY+1, NULL);
    //we should never be here because of scheduler

static void vTaskWifiStream( void *pvParameters ){
  uint8_t pack[4] = {0};
  uint8_t amo = xStreamBufferReceive(UDPStreamBuffer, ( void * )pack,  sizeof(pack), portMAX_DELAY);

Few things to try -

  1. Move the UART initialization code to a task so that UART RX ISR does not fire before the stream buffer is created.
  2. Define configASSERT and enable stack overflow checking.
  3. Try increasing stack sizes of your tasks.