STM32CubeMX 5.1.0 FreeRTOS code generation problem for statically generated tasks, mutexes , etc... if they were to be recreated.
Hello,
During my development I came across this (sort of) bug which will require manual code modification if a specific FreeRTOS function is to be used.
** Definition of the problem **
FreeRTOS V9 has a feature to define the TCB of a task in compile time instead of run time in order to eliminate the need to Malloc the required RAM space in run-time and prevent any forthcoming problems that may arise if the RAM cannot be allocated.
STM32CubeMX defines the TCB block inside the MX_FREERTOS_Init() function. using this pattern :
#define osThreadStaticDef(name, thread, priority, instances, stacksz, buffer, control)
osThreadStaticDef(task_name, task_start_function, osPriority, 0, stack_size, Task_buffer, &task_TCB);the place for this definition has no problem unless we were to delete a statically created task and then recreate it using "THE SAME TCB" (which is usually the case).
if we were to use the same TCB , we must be able to extern the TCB definitions in other files where that task creation function is called but since the definition is inside a function , that is not possible.
The same problem exists for other RTOS objects like mutex, semaphore, etc.
** Possible Solution **
one quick solution is to move
osThreadStaticDef(task_name, task_start_function, osPriority, 0, stack_size, Task_buffer, &task_TCB);outside of the
MX_FREERTOS_Init()function, preferably where the task_handle , Task_controlBlock and task buffer are defined. this way the developer can easily extern those without having to modify the code.
right now , one has to comment or delete the CubeMX generated code and rewrite it outside the function which is automatically undone if the project is regenerated with CubeMX.
