cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX: Where to place own source/header files?

Andreas Freund
Associate II
Posted on June 23, 2017 at 15:24

Hey guys,

i just created a project for the STM32L4 Discovery Board with CubeMX (I'm using Atollic TrueStudio). I assume that CubeMX always generates the same structure, namely the folders 'Drivers', 'Inc', 'Src', 'startup' and 'Middlewares'. Is this assumption correct or is this structure only generated when using CubeMX with Atollic TrueStudio (e.g. I could have used Eclipse + OpenSTM32 instead)?

Now, where can I place my own source code and header files? Do I have to use the folders 'Src' and 'Inc'? I would prefer using my own structure, because I only want to port an already existing software to STM32.

Thanks in advance!

#atollic #cube #hal #cubemx #truestudio #source-file #header-file #mx #own
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on June 30, 2017 at 15:49

Thanks for your advice!

I also have little experience with TrueStudio, but I finally found a solution for my problem: I've already added the new folders to the compiler's include paths, but somehow TrueStudio didn't recognize them (in Project Properties -> C/C++ Build -> Tool Chain Editor)

I also had to add them to the 'Includes' Tab in Project Properties -> C/C++ General -> Paths and Symbols.

View solution in original post

4 REPLIES 4
Zt Liu
Senior III
Posted on June 24, 2017 at 01:57

Hi, andreas,

Normally, in the generated files, you will see something like this:

/* USER CODE BEGIN Init */

/* USER CODE END Init */

you may insert your codes in between these lines.

Next time when you modify your ioc project and regenerates it, these parts would be kept. 

If you put some codes somewhere not between these lines, the generated codes would probably erase your codes.

Also enable the backup functionality in the project settings

0690X00000602TnQAI.bmp

Good luck!

Andreas Freund
Associate II
Posted on June 27, 2017 at 15:59

Thanks for your answer. I know this user-code-scheme, but my questions did not refer to editing the CubeMX generated source code (i'm sorry if my wording was ambiguous ). I want to know if it is possible to add additional header/source files or if I have to stick to the given structure and/or to the given CubeMX generated files.

misagh
Associate III
Posted on June 27, 2017 at 17:48

Hi

Freund.Andreas

‌,

You do not need to use 'Src' and 'Inc' Folders, but if you create a new folder on your project, you need to introduce it to your compiler to find your header files.

Bests,

Misagh

P.S: I have zero experience with TrueStudio, but in Keil you need to go to Project Option->C/C++ tab and add the directory in Include Paths Field to make sure the compiler will check it for your header files. Your compiler also may have the same process.

Posted on June 30, 2017 at 15:49

Thanks for your advice!

I also have little experience with TrueStudio, but I finally found a solution for my problem: I've already added the new folders to the compiler's include paths, but somehow TrueStudio didn't recognize them (in Project Properties -> C/C++ Build -> Tool Chain Editor)

I also had to add them to the 'Includes' Tab in Project Properties -> C/C++ General -> Paths and Symbols.