Skip to main content
JLakn
Associate III
August 19, 2020
Solved

How to add additional c source file to TouchGFX project ?

  • August 19, 2020
  • 2 replies
  • 4173 views

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

This topic has been closed for replies.
Best answer by Alexandre RENOUX

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

2 replies

Alexandre RENOUX
Visitor II
August 19, 2020

Hello,

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

/Alexandre

JLakn
JLaknAuthor
Associate III
August 19, 2020

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.

Alexandre RENOUX
Visitor II
August 19, 2020

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

JLakn
JLaknAuthor
Associate III
August 20, 2020

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

Alexandre RENOUX
Alexandre RENOUXBest answer
Visitor II
August 20, 2020

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

JLakn
JLaknAuthor
Associate III
August 21, 2020

Thank you @Alexandre RENOUX​ now it's working. As you said each source needs to be explicitly indicated.