Adding CubeIDE back (keeping Makefile too) - c++ nature added

This commit is contained in:
Attila Body 2019-10-25 12:56:01 +02:00
parent c91bfd8be9
commit f0ddd19150
14 changed files with 940 additions and 23 deletions

View file

@ -15,7 +15,6 @@
######################################
TARGET = f407ve_hs_uart
######################################
# building variables
######################################
@ -93,6 +92,9 @@ Middlewares/Third_Party/FatFs/src/option/ccsbcs.c
ASM_SOURCES = \
startup_stm32f407xx.s
CXX_SOURCES = \
$(wildcard app/*.cpp) \
$(wildcard lib/*.cpp)
#######################################
# binaries
@ -102,18 +104,20 @@ PREFIX = arm-none-eabi-
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
CXXC = $(GCC_PATH)/$(PREFIX)gcc -x c++
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
CXXC = $(PREFIX)gcc -x c++
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
@ -134,7 +138,7 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
AS_DEFS =
# C defines
C_DEFS = \
COMMON_DEFS = \
-DUSE_FULL_LL_DRIVER \
-DUSE_HAL_DRIVER \
-DSTM32F407xx \
@ -142,12 +146,15 @@ C_DEFS = \
-DHAVE_CONFIG \
-D_ENABLE_DIAG
C_DEFS = \
CXX_DEFS = \
# AS includes
AS_INCLUDES =
AS_INCLUDES = \
# C includes
C_INCLUDES = \
COMMON_INCLUDES = \
-IInc \
-IDrivers/STM32F4xx_HAL_Driver/Inc \
-IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \
@ -157,19 +164,25 @@ C_INCLUDES = \
-Ilib \
-Iapp
C_INCLUDES = \
CC_INCLUDES = \
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(COMMON_DEFS) $(C_DEFS) $(COMMON_INCLUDES) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CXXFLAGS = $(MCU) $(COMMON_DEFS) $(CC_DEFS) $(COMMON_INCLUDES) $(CC_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
CXXFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
CXXFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#######################################
@ -191,16 +204,26 @@ all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
OBJECTS = $(addprefix $(BUILD_DIR)/,$(C_SOURCES:.c=.o))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
OBJECTS +=$(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 $@
OBJECTS +=$(addprefix $(BUILD_DIR)/,$(notdir $(CXX_SOURCES:.cpp=.o)))
vpath %.cpp $(sort $(dir $(CXX_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
mkdir -p $(@D)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(<:.c=.lst) $< -o $@
$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
mkdir -p $(@D)
$(CXXC) -c $(CXXFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(<:.cpp=.lst) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
mkdir -p $(@D)
$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
@ -214,7 +237,7 @@ $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir $@
mkdir -p $@
#######################################
# clean up