quot;: "shell",
"command": "make clean;make",
"problemMatcher": []
},
{
"label": "build, download",
"type": "shell",
"command": "make;make flash",
"problemMatcher": []
},
{
"label": "download",
"type": "shell",
"command": "make flash",
"problemMatcher": []
},
{
"label": "build",
"type": "shell",
"command": "make",
"problemMatcher": []
},
{
"label": "clean",
"type": "shell",
"command": "make clean",
"problemMatcher": []
},
]
}
平时使用时, 用Alt + Shift + F10
就可以调出Task菜单, 快速执行编译和烧录等操作.
编译选项
项目中新增代码目录和单个C文件
User目录下的代码, Makefile已经覆盖, 会自动添加无需修改 Makefile. 如果新增其他的目录需要包含整个目录, 或包含单个源文件, 可以编辑Makefile中的这部分
# C source folders
CDIRS := User \
Libraries/CMSIS \
Libraries/HC32L110_Driver/src
# C source files (if there are any single ones)
CFILES :=
其中 CDIRS 用于目录的添加, CFILES 用于单个C源文件的添加.
除此以外, 如果有新增的 include 路径, 需要添加到 INCLUDES 这个变量中
# Include paths
INCLUDES := Libraries/CMSIS \
Libraries/HC32L110_Driver/inc \
User
如果编译与预期不符, 在make时增加V=1
查看实际的命令行.
调整编译参数
编译的参数都在 rules.mk 文件中,
# Global compile flags
CFLAGS = -Wall -ggdb -ffunction-sections -fdata-sections
ASFLAGS = -g -Wa,--warn
# Arch and target specified flags
OPT ?= -Os
CSTD ?= -std=c99
ARCH_FLAGS := -fno-common -mcpu=cortex-m0plus -mthumb
# c flags
TGT_CFLAGS += $(ARCH_FLAGS) $(addprefix -D, $(LIB_FLAGS))
# asm flags
TGT_ASFLAGS += $(ARCH_FLAGS)
# ld flags
TGT_LDFLAGS += --specs=nano.specs -mcpu=cortex-m0plus -mthumb -nostartfiles -Wl,--gc-sections -Wl,-Map=$(BDIR)/$(PROJECT).map -Wl,--print-memory-usage
如果要优化编译的结果大小或执行速度, 需要修改OPT参数, -O0
是无优化, -O1
是基础优化, -Os
是尺寸压缩, 具体优化项参考 https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
OPT ?= -Os
其中-ffunction-sections -fdata-sections
和-Wl,--gc-sections
是非常重要的参数, 如果不使用这些参数, 编译的结果大概会超出HC32L110的16K字节限制.