cancel
Showing results for 
Search instead for 
Did you mean: 

How to add additional c source file to TouchGFX project ?

JLakn
Associate II

Hey, my question is how to add additional c source files to TouchGFX project so I can build project in TouchGFX Designer?

I know I have to edit Makefile . I already tried it but with no success.

Here is the code of my makefile:

# Helper macros to convert spaces into question marks and back again
e := 
sp := $(e) $(e)
qs = $(subst ?,$(sp),$1)
sq = $(subst $(sp),?,$1)
 
# Get name of this Makefile (avoid getting word 0 and a starting space)
makefile_name := $(wordlist 1,1000,$(MAKEFILE_LIST))
 
# Get path of this Makefile
makefile_path := $(call qs,$(dir $(call sq,$(abspath $(call sq,$(makefile_name))))))
 
# Get path where the Application is
application_path := $(call qs,$(abspath $(call sq,$(makefile_path)../..)))
 
.PHONY: clean assets all
 
ifneq ($(words $(makefile_path))$(words $(MAKEFILE_LIST)),11)
all clean assets:
$(error Spaces not allowed in path)
else
 
project_path := $(call qs,$(abspath $(call sq,$(makefile_path)../../..)))
core_path := $(project_path)/Core/Inc
core_src := $(project_path)/Core/Src
 
 
ADDITIONAL_SOURCES :=$(core_src)
ADDITIONAL_INCLUDE_PATHS :=$(core_path)
ADDITIONAL_LIBRARY_PATHS := 
ADDITIONAL_LIBRARIES :=
export ADDITIONAL_SOURCES ADDITIONAL_INCLUDE_PATHS ADDITIONAL_LIBRARY_PATHS ADDITIONAL_LIBRARIES 
 
all: $(filter assets,$(MAKECMDGOALS))
all assets: $(filter clean,$(MAKECMDGOALS))
all clean assets:
	@$(MAKE) -r -f generated/simulator/gcc/Makefile -s $(MFLAGS) $@ -C "$(application_path)"
endif

1 ACCEPTED SOLUTION

Accepted Solutions

I believe the path starts where you have the .touchgfx file.

Therefore, I think you can write something like ../Core/Src/"file name".c

I would recommend to indicate all source files explicitly

So it would go something like

ADDITIONAL_SOURCES :=   ../Core/Src/main.c
ADDITIONAL_INCLUDE_PATHS := ../Core/Inc/

/Alexandre

View solution in original post

12 REPLIES 12
Alexandre RENOUX
Principal

Hello,

If you put your c source file in Core/Src, you should not need to change the Makefile already generated by TouchGFX.

/Alexandre

Hey @Alexandre RENOUX​ ,

I won't agree on that with you. I tried to copy the C source which I want to include in the project to TouchGFX\gui\src\  and  it compiles with no problem (just to clarify I'm talking about the builtin compiler in TouchGFX Designer - Run Simulator button) . When this source is in Core/Src I get compiler errors.

My bad, I though you were talking about the Run Target button.

What are these C source files for ?

Is putting your file in the TouchGFX/gui/src folder good enough for you ?

Also maybe this article can be of interest to you : https://support.touchgfx.com/docs/development/ui-development/working-with-touchgfx/simulator/

/Alexandre

No problem @Alexandre RENOUX​ 

I'm working on a custom board project. These C source files are some functions that are used by backend and also frontend. If there is no way to add them as source in TouchGFX designer simulator compiler I will just copy them to TouchGFX/gui/src folder. The reason I would like to have them in the Core/Src folder is just for better simplicity and transparency of the whole project. If I understand correctly I could add c source path in Makefile located in TouchGFX\generated\simulator\gcc\ folder  in lines:

source_paths = $(foreach comp, $(all_components), $(comp)/src) $(framework_source) simulator
c_source_files := $(call find, $(source_paths),*.c)

Problem is just that the code of this Makefile is overwritten by TouchGFX designer every compilation.

When you create CubeIDE project then you can place source files anywhere ... When use only TochGFX then need manual edit makefiles usw...

@MM..1​  I know that.

For this purpose when using only TouchGFX there is Makefile located in TouchGFX\simulator\gcc\ folder which is meant to be edited to add path to your own source code or header files but as I can see it only works for cpp files and not for c files.

Here is the section of Makefile where you can put your source path:

ADDITIONAL_SOURCES :=   //MY SOURCE
ADDITIONAL_INCLUDE_PATHS := //MY INCLUDE PATHS
ADDITIONAL_LIBRARY_PATHS := 
ADDITIONAL_LIBRARIES :=
export ADDITIONAL_SOURCES ADDITIONAL_INCLUDE_PATHS ADDITIONAL_LIBRARY_PATHS ADDITIONAL_LIBRARIES 

Correct me if I'm wrong.

Hello,

You are right. This is where you can add new files paths.

TouchGFX\generated\simulator\gcc\Makefile is generated and you should not modify it. The one you can modify is in TouchGFX/simulator/gcc/

/Alexandre

JLakn
Associate II

@Alexandre RENOUX​ can you please advise me how to properly add Core/Src to source in this Makefile?

I believe the path starts where you have the .touchgfx file.

Therefore, I think you can write something like ../Core/Src/"file name".c

I would recommend to indicate all source files explicitly

So it would go something like

ADDITIONAL_SOURCES :=   ../Core/Src/main.c
ADDITIONAL_INCLUDE_PATHS := ../Core/Inc/

/Alexandre