mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-28 16:32:05 -07:00
feat: improve make rule
This commit is contained in:
parent
8b7da6d0c6
commit
4de05b7e25
@ -4,6 +4,8 @@
|
||||
#include "py32f0xx_bsp_printf.h"
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
UART_HandleTypeDef DebugUartHandle;
|
||||
|
||||
/**
|
||||
* @brief DEBUG_USART GPIO Config,Mode Config,115200 8-N-1
|
||||
* @param None
|
||||
|
||||
10
Makefile
10
Makefile
@ -7,14 +7,16 @@ BUILD_DIR = Build
|
||||
|
||||
##### Options #####
|
||||
|
||||
# Enable printf float %f support, y:yes, n:no
|
||||
ENABLE_PRINTF_FLOAT ?= n
|
||||
# Programmer, jlink or pyocd
|
||||
FLASH_PROGRM ?= pyocd
|
||||
|
||||
##### Toolchains #######
|
||||
|
||||
#ARM_TOOCHAIN ?= /opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin
|
||||
ARM_TOOCHAIN ?= /opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin
|
||||
#ARM_TOOCHAIN ?= /opt/gcc-arm/arm-gnu-toolchain-12.2.mpacbti-bet1-x86_64-arm-none-eabi/bin
|
||||
#ARM_TOOCHAIN ?= /opt/gcc-arm/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin
|
||||
ARM_TOOCHAIN ?= /opt/gcc-arm/arm-gnu-toolchain-12.2.mpacbti-bet1-x86_64-arm-none-eabi/bin
|
||||
|
||||
# path to JLinkExe
|
||||
JLINKEXE ?= /opt/SEGGER/JLink/JLinkExe
|
||||
@ -37,8 +39,7 @@ LIB_FLAGS = PY32F003x8
|
||||
CDIRS := User \
|
||||
Libraries/CMSIS/Device/PY32F0xx/Source \
|
||||
Libraries/PY32F0xx_HAL_Driver/Src \
|
||||
Libraries/BSP/Src \
|
||||
Libraries/BSP/PY32F003xx_Start_Kit
|
||||
Libraries/BSP/Src
|
||||
# C source files (if there are any single ones)
|
||||
CFILES :=
|
||||
|
||||
@ -52,7 +53,6 @@ INCLUDES := Libraries/CMSIS/Include \
|
||||
Libraries/CMSIS/Device/PY32F0xx/Include \
|
||||
Libraries/PY32F0xx_HAL_Driver/Inc \
|
||||
Libraries/BSP/Inc \
|
||||
Libraries/BSP/PY32F003xx_Start_Kit \
|
||||
User
|
||||
|
||||
include ./rules.mk
|
||||
|
||||
53
rules.mk
53
rules.mk
@ -15,11 +15,11 @@ TOP = .
|
||||
BDIR = $(TOP)/$(BUILD_DIR)
|
||||
|
||||
# For each direcotry, add it to csources
|
||||
CSOURCES := $(foreach dir, $(CDIRS), $(shell find $(TOP)/$(dir) -name '*.c'))
|
||||
CSOURCES := $(foreach dir, $(CDIRS), $(shell find $(TOP)/$(dir) -maxdepth 1 -name '*.c'))
|
||||
# Add single c source files to csources
|
||||
CSOURCES += $(addprefix $(TOP)/, $(CFILES))
|
||||
# Then assembly source folders and files
|
||||
ASOURCES := $(foreach dir, $(ADIRS), $(shell find $(TOP)/$(dir) -name '*.s'))
|
||||
ASOURCES := $(foreach dir, $(ADIRS), $(shell find $(TOP)/$(dir) -maxdepth 1 -name '*.s'))
|
||||
ASOURCES += $(addprefix $(TOP)/, $(AFILES))
|
||||
|
||||
# Fill object files with c and asm files (keep source directory structure)
|
||||
@ -28,32 +28,35 @@ OBJS += $(ASOURCES:$(TOP)/%.s=$(BDIR)/%.o)
|
||||
# d files for detecting h file changes
|
||||
DEPS=$(CSOURCES:$(TOP)/%.c=$(BDIR)/%.d)
|
||||
|
||||
# Global compile flags
|
||||
CFLAGS = -Wall -ggdb -ffunction-sections -fdata-sections
|
||||
ASFLAGS = -g -Wa,--warn
|
||||
|
||||
# Arch and target specified flags
|
||||
OPT ?= -Os
|
||||
ARCH_FLAGS := -mthumb -mcpu=cortex-m0plus
|
||||
# Debug options, -gdwarf-2 for debug, -g0 for release
|
||||
# https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Debugging-Options.html
|
||||
# -g: system’s native format, -g0:off, -g/g1,-g2,-g3 -> more verbosely
|
||||
# -ggdb: for gdb, -ggdb0:off, -ggdb/ggdb1,-ggdb2,-ggdb3 -> more verbosely
|
||||
# -gdwarf: in DWARF format, -gdwarf-2,-gdwarf-3,-gdwarf-4,-gdwarf-5
|
||||
DEBUG_FLAGS ?= -gdwarf-3
|
||||
|
||||
# c flags
|
||||
OPT ?= -O3
|
||||
CSTD ?= -std=c99
|
||||
ARCH_FLAGS := -fno-common -mcpu=cortex-m0plus -mthumb
|
||||
TGT_CFLAGS += $(ARCH_FLAGS) $(DEBUG_FLAGS) $(OPT) $(CSTD) $(addprefix -D, $(LIB_FLAGS)) -Wall -ffunction-sections -fdata-sections
|
||||
|
||||
### c flags ###
|
||||
TGT_CFLAGS += $(ARCH_FLAGS) $(addprefix -D, $(LIB_FLAGS))
|
||||
# asm flags
|
||||
TGT_ASFLAGS += $(ARCH_FLAGS) $(DEBUG_FLAGS) $(OPT) -Wa,--warn
|
||||
|
||||
### asm flags ###
|
||||
TGT_ASFLAGS += $(ARCH_FLAGS)
|
||||
# ld flags
|
||||
TGT_LDFLAGS += $(ARCH_FLAGS) -specs=nano.specs -specs=nosys.specs -static -lc -lm \
|
||||
-Wl,-Map=$(BDIR)/$(PROJECT).map \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,--print-memory-usage \
|
||||
-Wl,--no-warn-rwx-segments
|
||||
|
||||
### ld flags ###
|
||||
TGT_LDFLAGS += --specs=nosys.specs -mcpu=cortex-m0plus -mthumb -Wl,--gc-sections -Wl,-Map=$(BDIR)/$(PROJECT).map -Wl,--print-memory-usage
|
||||
# Use newlib-nano instead of newlib for smaller flash size
|
||||
TGT_LDFLAGS += --specs=nano.specs
|
||||
# Exclude standard initialization actions, when __libc_init_array exists, this should be omit, \
|
||||
otherwise it will generate "undefined reference to `_init'" error. \
|
||||
**Remove** `bl __libc_init_array` from startup.s if you want to enable this.
|
||||
# TGT_LDFLAGS += -nostartfiles
|
||||
ifeq ($(ENABLE_PRINTF_FLOAT),y)
|
||||
TGT_LDFLAGS += -u _printf_float
|
||||
endif
|
||||
|
||||
|
||||
### included paths ###
|
||||
# include paths
|
||||
TGT_INCFLAGS := $(addprefix -I $(TOP)/, $(INCLUDES))
|
||||
|
||||
|
||||
@ -76,18 +79,18 @@ echo:
|
||||
$(BDIR)/%.o: %.c
|
||||
@printf " CC\t$<\n"
|
||||
@mkdir -p $(dir $@)
|
||||
$(Q)$(CC) $(TGT_CFLAGS) $(OPT) $(CFLAGS) $(TGT_INCFLAGS) -MT $@ -MMD -MP -MF $(BDIR)/$*.d -o $@ -c $<
|
||||
$(Q)$(CC) $(TGT_CFLAGS) $(TGT_INCFLAGS) -MT $@ -o $@ -c $< -MD -MF $(BDIR)/$*.d -MP
|
||||
|
||||
# Compile asm to obj
|
||||
$(BDIR)/%.o: %.s
|
||||
@printf " AS\t$<\n"
|
||||
@mkdir -p $(dir $@)
|
||||
$(Q)$(CC) $(TGT_ASFLAGS) $(ASFLAGS) -o $@ -c $<
|
||||
$(Q)$(CC) $(TGT_ASFLAGS) -o $@ -c $<
|
||||
|
||||
# Link object files to elf
|
||||
$(BDIR)/$(PROJECT).elf: $(OBJS) $(TOP)/$(LDSCRIPT)
|
||||
@printf " LD\t$@\n"
|
||||
$(Q)$(CC) $(OBJS) $(TGT_LDFLAGS) -T$(TOP)/$(LDSCRIPT) -o $@
|
||||
$(Q)$(CC) $(TGT_LDFLAGS) -T$(TOP)/$(LDSCRIPT) $(OBJS) -o $@
|
||||
|
||||
# Convert elf to bin
|
||||
%.bin: %.elf
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user