cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX makefile errors

Frank CA
Associate III
Posted on January 19, 2018 at 16:12

The makefile output feature of CMX is really great but as others have said here it has  bugs that make it somewhat problematic, and it appears that ST are not taking it too seriously.

I am trying to use CMX with Visual Studio Code via makefile. In particular the fact that you have to manually define the path for 'BINPATH = 'in the makefile is wrong because all changes to the makefile  are lost if you modify the project in CMX.  Better to make BINPATH (and possibly other makefile variables) a definition in CMX if you choose makefile output - that way it is always incuded in the generated makefile.

Anyone figured another way to do this?

4 REPLIES 4
Posted on January 20, 2018 at 10:41

Frank CA wrote:

... In particular the fact that you have to manually define the path for 'BINPATH = 'in the makefile is wrong because all changes to the makefile  are lost if you modify the project in CMX.

...

To be honest, I like how they structured the Makefile - it is elegant and a nice template for your own, whatever the project, toolchain and microcontroller...

I think that the last CMX version does not alter the Makefile if it was edited (well, you can figure this only if you change something inside the file

:)

 - maybe also looking at the time stamp of the file)...

Frank CA wrote:

...Better to make BINPATH (and possibly other makefile variables) a definition in CMX if you choose makefile output - ...

That would be handy, but I would be content with just a functional Makefile - they said it will be ok in the next version.

Doug Kehn
Senior
Posted on January 22, 2018 at 14:42

I modify the CubeMX Makefile and add the following line just after the all target (and before the 'build the application' comment).

-include $(TARGET).mak

In

$(TARGET).mak

,

BINPATH

, as well as other variables can be modified and/or changed as needed. CubeMX doesn't remove (...at least so far) the Makefile modification when regenerating.
Posted on March 07, 2018 at 00:57

I think for Linux users is easier to have the modification in the Makefile.tpl

In my home folder, I have the following folder structure:

0690X00000609yEQAQ.png

where the gcc-arm is a symlink to any of the gcc versions bellow, at my choice (or need).

So, inside the Makefile.tpl, the line looks like this:

BINPATH = $(HOME)/gcc-arm/bin�?

Posted on March 07, 2018 at 01:34

So, my Makefile.tpl template is a little more customized, because as many others, apart of the LL driver sources, in the PATH I want to include also my own folder with various libraries I use - this is how a part of my Project Explorer in Eclipse looks:

0690X00000609pxQAA.png

Where ll_library is a container of my libraries that are used by all the projects there.

Also, I need to specify in the CubeMX if I want to use printf with floating point support (in concordance with this post

https://community.st.com/0D50X00009XkW3aSAF

).

So in the end, the template looks like this (maybe the developers will find some points valid)

########################################################################################################################### File automatically-generated by tool: [projectgenerator] version: [PROJECTGEN_VERSION] date: [GEN_DATE]########################################################################################################################### ------------------------------------------------# Generic Makefile (based on gcc)## ChangeLog :#2017-02-10 - Several enhancements + project update mode# 2015-07-22 - first version# ------------------------------------------------####################################### target######################################TARGET = TARGET_VALUE####################################### building variables####################################### floating point enable (1 = enabled, 0 = disabled)USEFP = 0# printf with floating point enable (1 = enabled, 0 = disabled)USEFP_IN_PRINTF = 0# debug build? (1 = enabled, 0 = disabled)DEBUG = 1# your external library path relative to your root folder of your projectEXT_LIB = -I../ll_library# optimizationifeq ($(DEBUG), 1)OPT = -Ogelse# optimize for size as default - change as you wishOPT = -Osendif######################################## paths######################################## source pathSOURCES_DIR = SOURCES_DIR_VALUE# firmware library pathPERIFLIB_PATH = PERIFLIB_PATH_VALUE# Build pathBUILD_DIR = build####################################### source####################################### C sourcesC_SOURCES = C_SOURCES_VALUE# ASM sourcesASM_SOURCES = ASM_SOURCES_VALUE####################################### firmware library######################################PERIFLIB_SOURCES = PERIFLIB_SOURCES_VALUE######################################## binaries#######################################BINPATH = $(HOME)/gcc-arm/binPREFIX = arm-none-eabi-CC = $(BINPATH)/$(PREFIX)gccAS = $(BINPATH)/$(PREFIX)gcc -x assembler-with-cppCP = $(BINPATH)/$(PREFIX)objcopyAR = $(BINPATH)/$(PREFIX)arSZ = $(BINPATH)/$(PREFIX)sizeHEX = $(CP) -O ihexBIN = $(CP) -O binary -S######################################## CFLAGS######################################## cpuCPU_VALUE# fpuFPU_VALUE# float-abi#FLOAT-ABI_VALUE#ifeq ($(USEFP), 1)FLOAT-ABI = -mfloat-abi=softelseFLOAT-ABI =endif# mcuMCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)# macros for gcc# AS definesAS_DEFS = AS_DEFS_VALUE# C definesC_DEFS = C_DEFS_VALUE# AS includesAS_INCLUDES = AS_INCLUDES_VALUE# C includesC_INCLUDES = C_INCLUDES_VALUEC_INCLUDES += $(EXT_LIB)# compile gcc flagsASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sectionsCFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sectionsifeq ($(DEBUG), 1)CFLAGS += -g -gdwarf-2endif# Generate dependency informationCFLAGS += -MMD -MP -MF''$(@:%.o=%.d)'' -MT''$(@:%.o=%.d)''######################################## LDFLAGS######################################## link scriptLDSCRIPT = LINKER_FILE_VALUE# librariesLIBS = -lc -lm -lnosysLIBDIR =LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sectionsifeq ($(USEFP_IN_SPRINTF), 1)LDFLAGS += -u _printf_floatendif# default action: build allall: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin######################################## build the application######################################## list of objectsOBJECTS = $(sort $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))))vpath %.c $(sort $(dir $(C_SOURCES)))# list of ASM program objectsOBJECTS += $(sort $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))))vpath %.s $(sort $(dir $(ASM_SOURCES)))$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)$(AS) -c $(CFLAGS) $< -o $@$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile$(CC) $(OBJECTS) $(LDFLAGS) -o $@$(SZ) $@$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)$(HEX) $< $@$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)$(BIN) $< $@$(BUILD_DIR):mkdir $@######################################## clean up#######################################clean:-rm -fR .dep $(BUILD_DIR)######################################## dependencies#######################################-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)# *** EOF ***�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?