#技术资源# #申请原创#
试了好久,终于成功搭建windows下的GCC开发环境。开发环境如下:
系统:Win11
编译环境:GCC
仿真环境:pyOCD
整个开发环境的搭建,可以参考:https://mp.csdn.net/mp_blog/creation/editor/142444700
gcc开发环境下MCU编程,除了要搭建好开发环境之外,还有三个重要的文件,分别是makefile、.ld文件及.s文件。
在HC32F448提供的DDL demo中,有eclipse工程,里边包含了.ld文件及.s文件,还差了makefile文件。
在此奉献上我调试好的makefile文件,抛砖引玉,让更多人来使用及优化。也希望大神能提出不足及指正。
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [4.5.0-B34] date: [Sun Sep 22 18:25:32 CST 2024]
##########################################################################################################################
# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ChangeLog :
# 2017-02-10 - Several enhancements + project update mode
# 2015-07-22 - first version
# ------------------------------------------------
######################################
# target
######################################
TARGET = adc_awd
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = -O0
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
C_SOURCES = \
../source/main.c \
../../../../../../drivers/bsp/components/tca9539/tca9539.c \
../../../../../../drivers/bsp/ev_hc32f448_lqfp80/ev_hc32f448_lqfp80.c \
../../../../../../drivers/bsp/ev_hc32f448_lqfp80/ev_hc32f448_lqfp80_tca9539.c \
../../../../../../drivers/cmsis/Device/HDSC/hc32f4xx/Source/system_hc32f448.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_adc.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_aos.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_clk.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_efm.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_fcg.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_fcm.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_gpio.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_i2c.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_icg.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_interrupts.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_keyscan.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_pwc.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_tmr0.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_usart.c \
../../../../../../drivers/hc32_ll_driver/src/hc32_ll_utility.c
# ASM sources
ASM_SOURCES =
# ASM sources
ASMM_SOURCES = \
startup_hc32f448.S
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m4
# fpu
FPU = -mfpu=fpv4-sp-d16
# float-abi
FLOAT-ABI = -mfloat-abi=hard
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# C defines
C_DEFS = \
-D__DEBUG \
-DHC32F448 \
-DUSE_DDL_DRIVER
# AS includes
AS_INCLUDES =
# C includes
C_INCLUDES = \
-I../../../../../../drivers/cmsis/Device/HDSC/hc32f4xx/Include \
-I../../../../../../drivers/cmsis/Include \
-I../../../../../../drivers/hc32_ll_driver/inc \
-I../source \
-I../../../../../../drivers/bsp/ev_hc32f448_lqfp80 \
-I../../../../../../drivers/bsp/components/tca9539
# 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
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = ./config/linker/HC32F448xA.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASMM_SOURCES:.S=.o)))
vpath %.S $(sort $(dir $(ASMM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) [ DISCUZ_CODE_58 ]lt; -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) [ DISCUZ_CODE_58 ]lt; -o $@
$(BUILD_DIR)/%.o: %.S Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) [ DISCUZ_CODE_58 ]lt; -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) [ DISCUZ_CODE_58 ]lt; $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) [ DISCUZ_CODE_58 ]lt; $@
$(BUILD_DIR):
mkdir $@
#######################################
# clean up
#######################################
clean:
rd /s/q $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***
在此上传文本,方便下载。
Makefile.zip
(1.8 KB)
将此文件放到HC32F448_DDL_Rev1.1.0\projects\ev_hc32f448_lqfp80\examples\adc\adc_awd\GCC目录下,其他工程目录,需要更改相应的内容。
在HC32F448_DDL_Rev1.1.0\projects\ev_hc32f448_lqfp80\examples\adc\adc_awd\GCC目录下右键选择在终端中打开,执行make
编译成功后显示
下载:
观察串口log
可以看到gcc-ARM编译的文件在F448上已经成功执行。
|