cancel
Showing results for 
Search instead for 
Did you mean: 

Device Configuration Tool and main.c

GYurk.1
Associate II

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?

4 REPLIES 4
Ethan HUANG
ST Employee

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
Associate II

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.

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
Associate II

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.