2025-02-04 03:11 PM
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):
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.
My solution is to create a user constant to tell the GUI what size it is:
.. 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.