0
\$\begingroup\$

I am testing RTOS's StreamBuffer and it doesn't receive what it sends:

    #include "main.h"
    #include "cmsis_os.h"
    #include "usb_device.h"
    #include "stream_buffer.h"




    StreamBufferHandle_t StreamBufferHandle = NULL;
    uint8_t data_send[4];
    uint8_t data_receive[4];
    void Emmc_Rtos_read(void const * argument);
    void Usb_Rtos_send(void const * argument);


             void app_main(void)
            {
                StreamBufferHandle = xStreamBufferCreate(3,3);
                osThreadDef(MyTask01,Emmc_Rtos_read,osPriorityHigh,0,1024);
                MyTask01Handle = osThreadCreate(osThread(MyTask01), NULL);
             osThreadDef(MyTask02,Usb_Rtos_send,osPriorityHigh,0,1024);
                MyTask02Handle = osThreadCreate(osThread(MyTask02), NULL);
                osKernelStart(); 
             }




    void Emmc_Rtos_read(void const * argument)
    {
      /* init code for USB_DEVICE */
        data_send[0] = 0x1;
        data_send[1] = 0x2;
        data_send[2] = 0x3;
        data_send[3] = 0x4;
      /* USER CODE BEGIN 5 */
      /* Infinite loop */
      for(;;)
      {
            xStreamBufferSend(xStreamBuffer, data_send, sizeof(data_send), portMAX_DELAY);    
      }
      /* USER CODE END 5 */
    }
    void Usb_Rtos_send(void const * argument)
    {
      /* init code for USB_DEVICE */
    
      /* USER CODE BEGIN 5 */
      /* Infinite loop */
      for(;;)
      {    
       size_t bytesRead = xStreamBufferReceive(xStreamBuffer,data_receive , sizeof(data_receive), portMAX_DELAY);           
      }
      /* USER CODE END 5 */
    }

Tasks work fine, but streambuffer doesn't receive or doesn't send anything. I have checked uint8_t data_receive[4]; with debug and it is all zeroes

I am using an STM32H743 microcontroller with CUBEMX FreeRTOS generated code.

I don't understand the reason. I tried to do everything by the manuals.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Where's your xStreamBufferCreate() call? Your xStreamBuffer is probably still NULL... \$\endgroup\$ Commented Dec 6, 2023 at 22:02
  • \$\begingroup\$ @brhans i haver changed the code with your edit but nothing changed, seems like the app just hangs after StreamBufferHandle = xStreamBufferCreate(3,10); \$\endgroup\$ Commented Dec 7, 2023 at 21:58
  • \$\begingroup\$ @KlimDuda You changed the code and it made this answer to be incorrect, because you added code that this answer said was missing. And what you added was not correct, the FreeRTOS manual is clear on this. You can't have a trigger level of 10 items if your buffer can only fit 3 items. \$\endgroup\$ Commented Dec 7, 2023 at 22:28
  • \$\begingroup\$ As currently written in your question, your code won't even compile. You're putting the result of the xStreamBufferCreate() call into a StreamBufferHandle variable, but you never defined a variable with that name. If you've renamed your original xStreamBuffer to StreamBufferHandle, then you also need to make it volatile. As @Justme pointed out, you're making the xStreamBufferCreate() with invalid parameters. And are you sure that the call even returned a valid handle/pointer? Do you have enough (or any) dynamic memory in your project for FreeeRTOS to allocate to this new stream? \$\endgroup\$ Commented Dec 8, 2023 at 0:56
  • \$\begingroup\$ @brhans thanks guys for your notes, ive corrected the code, seems like streambuffer starts now im checking if it NULL or not, and its not. But StreaBufferRecive still not trigger and not getting any data \$\endgroup\$ Commented Dec 8, 2023 at 21:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.