cancel
Showing results for 
Search instead for 
Did you mean: 

cubeIDE shows: undefined reference to `MX_FREERTOS_Init()' if peripheral initialisation is generated as .c/.h files

xlin.1
Associate II

As a project expands, scolling down the main.cpp file is slowing me down. So I wished to break down the main.cpp by selecting "Generate peripheral initialisation as a pair of '.c/.h'files" inside the ioc file-> project manager -> Code Generation ->Generated files. After compiling the generated code, the IDE shows:

undefined reference to `MX_FREERTOS_Init()'

make: *** [makefile:83: MX_FreeRTOS_test.elf] Error 1

The same issue exsits in an empty project, and the issue would not appear if the project is converted to a C project. I noticed that other peripheral files such as usart has a pair of .c/.h file, whereas freertos only has a .c file been generated. in a C project.

How can I fix this issue? Will this be fixed in later versions of cubeIDE?

5 REPLIES 5
xlin.1
Associate II

I have fixed this error and figured out how MX_FREERTOS_Init() was meant to be used.

Noticed that:

  1. Only a function prototype was generated for MX_FREERTOS_Init().
  2. cubeMX inserted the MX_FREERTOS_init() conveniently between osKernelInitialize() and osKernelStart().

It is suggested that cubeMX is letting the user implement the main body of the function. And indeed, by implementing this function in main.cpp, the error went away. To be specofic, I added the following:

MX_FREERTOS_init(){

//your init code to run before rtos starts

}

It would be nice if there were comments in the code to inform the user of the usage, instead of throwing an error at them.

xlin.1
Associate II

After further investigation into the code, I realised my previous understanding was wrong. Instead, a simple fix is to rename the freertos.c to freertos.cpp

If you rename to .cpp, the next time you regenerate from the IOC file, a new freertos.c will be created. There needs to be a better solution.

Semer CHERNI
ST Employee

Hello @xlin.1​ 

First let me thank you for having reported.

I tried to reproduce the issue you faced but the projects I have generated compile without error ( the declaration and call for this function is ok MX_FREERTOS_Init() ).

PS : The test environment:

  • STM32G474E-EVAL as well as the NUCLEO-F429ZI boards
  • STM32CubeIDE 1.10.1
  • STM32CubeMX 6.6.1

For further investigation could you precise which MCU you are using as well as the SW versions.

Thanks in advance.

Semer.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Semer

Thanks for looking into this issue. I have screen recorded this issue which can be viewed here:

https://youtu.be/wh6w2Ai8Mr4

In the video I created an empty project in a new workspace with latest cubeIDE updates installed. the following procedures are key:

  • enable cmsis freertos v2 in the ioc file
  • tick "Generate peripheral initialization as pair of .c/.h file" in Project manager->Code generation
  • rename main.c to main.cpp and build the project

You should see the build err. In the video I also showed that this err goes away if freertos.c is renamed freertos.cpp

I am hopping cubeIDE could work more smoothly with c++. As mentioned by BPete.1 it does involve more work to use c++ in the current cubeIDE.

Best

Peter