Skip to main content
GYurk.1
Associate
August 11, 2021
Question

Device Configuration Tool and main.c

I'm developing production code for an STM32 project and using the Device Configuration Tool as much as possible. I need to organize the code so that everything is not in main.c.

Is there a way, for example, to move FreeRTOS tasks out of main into their own files so that they don't get regenerated back in main when I change something with the Device Config. Tool?

This topic has been closed for replies.

4 replies

Ethan HUANG
ST Employee
August 11, 2021

Hello @GYurk.1​,

Could you help check if the option marked in red in the attached picture is what you need?

It's in "Project Manager --> Code Generator". Please also note that the file structure of c/h files of peripherals changes after enabling the option.

GYurk.1
GYurk.1Author
Associate
August 11, 2021

Thanks, Ethan.

That helps a lot. The big issue now is that the FreeRTOS tasks are all in the same file. At least the Start functions are. I can leave the start functions there and move my code out to individual files and make calls so that nothing gets broken when I do a configuration update.

Ethan HUANG
ST Employee
August 12, 2021

It seems to me making task function as weak (shown in the attached picture) may be what you need. After making task function as weak, you could add implementation of the same task function (without compiling error) in the file you want:

// The weak implementation is done by CubeMX in freertos.c
 
__weak void StartDefaultTask(void const * argument)
{
 /* USER CODE BEGIN StartDefaultTask */
 /* Infinite loop */
 for(;;)
 {
 osDelay(1);
 }
 /* USER CODE END StartDefaultTask */
}
// Your implementation in the source file you want:
 
void StartDefaultTask(void const * argument)
{
 for(;;)
 {
 ...
 }
}

GYurk.1
GYurk.1Author
Associate
August 12, 2021

That would work, too.

I'm just going to replace the bodies of StartXTask() with calls to functions in my files. I'll have a source file for each task.