打印
[其他]

windows下使用GCC环境编译HC32F448工程

[复制链接]
1227|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
czq2317|  楼主 | 2024-9-22 23:53 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
#技术资源# #申请原创#
试了好久,终于成功搭建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上已经成功执行。


使用特权

评论回复
沙发
wubangmi| | 2024-9-23 10:40 | 只看该作者
感谢楼主的辛苦分享,但是小华原厂提供的GCC工程都是可以直接下载并仿真的,并不需要自行编写Makefile文件。

使用特权

评论回复
板凳
dukedz| | 2024-9-23 13:27 | 只看该作者
为啥不直接用 linux

使用特权

评论回复
地板
WoodData| | 2024-9-23 15:47 | 只看该作者
感谢分享,收藏一下

使用特权

评论回复
5
shenxiaolin| | 2024-9-29 10:31 | 只看该作者
不错的经验

使用特权

评论回复
6
更多更合适ii| | 2024-9-30 17:27 | 只看该作者
在Makefile中可以添加检查步骤,观察源文件存在,GCC路径设置正确。在编译前捕捉到潜在问题。

使用特权

评论回复
7
更多更合适ii| | 2024-9-30 17:27 | 只看该作者
可以将常用的路径和文件名抽象成变量,方便后续修改和维护。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

83

帖子

1

粉丝