cancel
Showing results for 
Search instead for 
Did you mean: 

Adding source files to STM32CubeIDE/TouchGFX project

ST_canada1
Associate II

What is the recommended procedure for adding source files (e.g. source1.c and source1.h) to a STM32CubeIDE project generated by TouchGFX? I assume I add them to one of the 'Core' directories, but I see multiple Core directories (root\STM32CubeIDE\CM7\Application\User\Core and root\CM7\Core). I see that adding my .h manually to root\CM7\Core\Inc works fine for the .h, but the IDE doesn't automatically pick up the .c if I place it in the corresponding root\CM7\Core\Src. If I place the .c in root\STM32CubeIDE\CM7\Application\User\Core, the .c file is accessible via the IDE, but the .h file is not found during compile.

What is the proper procedure for adding new user C source files? 

 

My STM32CubeIDE is 2.1.1 and TouchGFX is 4.26.1. I'm targeting a Riverdi board with a STM32H7.

 

6 REPLIES 6
PeterVang
ST Employee

Hello,

You can generally add files to your STM32CubeIDE project in whatever folder you like. The process is a bit different for header files and source files.

STM32CubeIDE automatically searches for header files in all the directories listed under "Include paths" in the project setting, as shown in the screenshot below. So you just need to place the header file in the folder you wish and make sure that this folder is in the list. Be aware that there are two separate lists for  c and cpp compilation.

PeterVang_0-1778654373757.png

.c and .cpp files generally need to be explicitly added to the project. This can be done by dragging-and-dropping a file from the Windows file explorer into the project tree in STM32CubeIDE, like shown in the screenshot below.

PeterVang_1-1778654812526.png

Best regards

Peter

 

I watched a tutorial which targeted older versions of the tool. In that version of CubeIDE, the user could just right click on the Core directory and select New->Source File and New->Header File. It worked for both .c and .h files and placed the files in the same directory. That was fairly straightforward and intuitive and did not require adding paths. Unfortunately, that no longer works for adding new header files in my version of CubeIDE. My choices seem to be between:

1) Add the header file alongside the .c file (preferred), but add the directory the INCLUDE_PATH

2) Add the header file to a completely different region of the directory structure that already has the include path defined

Do any of the ST online training videos use one of these methods? Which method is preferred? 

PeterVang
ST Employee

You can use both methods/structures, it is up to your personal preference.

If look at our example projects available in TouchGFX Designer, to can e.g. see that the core files generated by STM32CubeMX is split into Inc and Src folders, while X-CUBE-TOUCHGFX places header and source files in the same folders:

PeterVang_0-1779178951888.png


@ST_canada1 wrote:

the user could just right click on the Core directory and select New->Source File and New->Header File. It worked for both .c and .h files and placed the files in the same directory.


It places the files in whatever folder you selected.

 


@ST_canada1 wrote:

 That was fairly straightforward and intuitive and did not require adding paths.  


That's just because you selected a folder which was already in the Paths.

If you had selected a folder not in the paths, you would have had to add that folder to the paths.

 

Note that the compiler looks first in the folder containing the including file anyhow - so, if they are in the same folder, no Include Path is required.

 

Full description of how GCC finds included files:

https://gcc.gnu.org/onlinedocs/gcc-4.7.2/cpp/Search-Path.html 

https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

 

This is standard C stuff - not specific to STM32CubeIDE or Eclipse.

 

PS:

Note that you can add a folder to the Include Paths by right-clicking it, and choosing 'Add/remove Include Path...'

 

AndrewNeil_1-1779180092284.png

 

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

It's a bit surprising that adding a file to the Core dir in the previous version didn't require manually adding it to the INCLUDE_PATH, but the latest version requires the update to the INCLUDE_PATH. It was also confusing that the IDE Application/User/Core folder references files from both CM7/Core/Src and STM32CubeIDE/CM7Application/User/Core, but only automatically picks up the ones in STM32CubeIDE/CM7Application/User/Core.

I'll just place my files in STM32CubeIDE/CM7Application/User/Core and update the INCLUDE_PATH.

 

 

INaee.1
Senior

Hi ,,

adding new .c and .h files is different way.

for existing files to be added in cubeide , I mostly open a folder side by side with cubeide and drag and drop in required folder.

later you need to add that folder path in projects ..

 

regards

Imran