cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX Custom Queue Sizes in FreeRTOS

eweststrate
Associate

I am having trouble creating custom queue sizes and making them work with the Heap Usage tool within CubeMX.  But I found a workaround until the bug gets fixed.

I created a queue using a custom item size (the message_data_t type is defined in my code):

eweststrate_0-1738710049448.png

The code generation is correct:

 

 

/* Create the queue(s) */ /* creation of UsbRxQueue */ UsbRxQueueHandle = osMessageQueueNew (16, sizeof(message_data_t), &UsbRxQueue_attributes); /* creation of BufferQueue */ BufferQueueHandle = osMessageQueueNew (8, sizeof(message_data_t), &BufferQueue_attributes); /* creation of SystemQueue */ SystemQueueHandle = osMessageQueueNew (16, sizeof(message_data_t), &SystemQueue_attributes);

 

 

 

When the Heap Usage tool calculates the memory the queue needs, it incorrectly uses 4 bytes by default the heap size is wrong.

eweststrate_1-1738710182293.png

My solution is to create a user constant to tell the GUI what size it is:

eweststrate_2-1738710291653.png

.. then I #undef the message_data_t it creates so the code compiles correctly!

 

 

/* Private defines -----------------------------------------------------------*/ #define GAIN_COMP1 0 #define GAIN_COMP2 0 #define message_data_t 8 #define USART2_TX_Pin GPIO_PIN_2 #define USART2_TX_GPIO_Port GPIOA .... /* USER CODE BEGIN Private defines */ // CubeMX bugfix: #undef message_data_t

 

 

 

I think it works, but will post any updates.

 

STM32CubeMX - STM32 Device Configuration Tool

Version: 6.12.1-RC4

Build: 20240912-2256 (UTC)

 

2 REPLIES 2
eweststrate
Associate

I made some other changes to the code, and after a while, CubeMX started generating the code incorrectly.  I had to manually type in the "sizeof(" here. This errored out:

/* Create the queue(s) */ /* creation of UsbRxQueue */ UsbRxQueueHandle = osMessageQueueNew (16, message_data_t, &UsbRxQueue_attributes); /* creation of BufferQueue */ BufferQueueHandle = osMessageQueueNew (8, message_data_t, &BufferQueue_attributes); /* creation of SystemQueue */ SystemQueueHandle = osMessageQueueNew (16, message_data_t, &SystemQueue_attributes);

 As far as I can tell I didn't change anything relating to this in the .ioc file.

Ramboooka
Associate

using "sizeof(message_data_t)" is no longer needed !!!

In STMCubeIDE V1.18.1 you can just type the length you need    eg: 64

Ramboooka_0-1746066312174.png

 

then code code generator makes

Queue_DataHandle = osMessageQueueNew (8, 64, &Queue_Data_attributes);