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.
xStreamBufferCreate()call? YourxStreamBufferis probably stillNULL... \$\endgroup\$xStreamBufferCreate()call into aStreamBufferHandlevariable, but you never defined a variable with that name. If you've renamed your originalxStreamBuffertoStreamBufferHandle, then you also need to make itvolatile. As @Justme pointed out, you're making thexStreamBufferCreate()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\$