MM32F3273G8P火龙果开发板MindSDK开发教程5 - Gcc编译环境的配置
1、准备工作
用了几天Keil后,实在用不习惯,只好回到macos系统中来搭建gcc的编译环境。但是百问网火龙果开发板自带的DAP-Link在pyocd中根本识别不到,所以烧录还需要重新购置一块DAP-Link,我手头用的是EEMaker的,还不错。
a、arm-none-eabi- 交叉工具链
无论32单片机还是Linux,还是andorid,编译都离不开交叉工具链。
官网下载,window下载window版本,linux下载linux版本,macos下载Mac版本。官网
b、vscode
编写代码神器,强大到令人发指。
c、pyocd
用来烧录,调试用的,
安装用法看这个吧
我的烧录命令:
pyocd flash --erase auto --target MM32F3273G8P --base-address 0x8000000 ./build/KeyExti.bin
查找固件包命令 pyocd pack -f mm32f3273
安装固件包命令 pyocd pack -i mm32f3273
查看固件支持列表 pyocd list -t
d、灵动官网下载固件包
后来我下载不同系统armgcc版本发现,没啥区别。
固件中用的编译环境为cmake,而我的代码中,直接用的Makefile管理。
所以无论什么系统,只要搭好交叉工具链,配置好make,都能编译。
2、移植
a、新建工程keyExti
解压下载灵动固件包,将devices目录全部拷贝到keyExti目录下,
并将之前keil工程的core、user目录copy到keyExti目录下。
这里面最核心的两个文件其实是startup_mm32f3273g.s以及startup_mm32f3273g.ld文件,如果官方不提供这两个文件,那么我们只能自己仿照keil版本自己写了。
b、编写Makefile文件
我这个是在stm32cubemx自动生成的Makefile环境下copy出来自己改动的。
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.19.2] date: [Tue Apr 25 10:09:46 CST 2023]
##########################################################################################################################
# ------------------------------------------------
# Generic Makefile (based on gcc)
#
# ChangeLog :
# 2017-02-10 - Several enhancements + project update mode
# 2015-07-22 - first version
# ------------------------------------------------
######################################
# target
######################################
TARGET = KeyExti
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = -Og
#add by Max
BOOTLOADER_CODE = yes
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
######################################
# source
######################################
# C sources
C_DIRS += core
C_DIRS += drivers/drivers
C_DIRS += drivers/gcc
C_DIRS += drivers
C_DIRS += user
SRC_OBJS_DIRS += $(foreach DIR, $(C_DIRS), $(wildcard $(DIR)/*.c))
C_SOURCES = $(SRC_OBJS_DIRS)
# ASM sources
ASM_SOURCES = \
drivers/gcc/startup_mm32f3273g.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-m3
# fpu
# NONE for Cortex-M0/M0+/M3
# float-abi
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# AS includes
AS_INCLUDES =
# add by Max
ifeq ($(BOOTLOADER_CODE), yes)
BOOT_FLAGS = \
-DUSER_BOOTLOADER_CODE
endif
# C includes
C_INCS += core
C_INCS += drivers/CMSIS/include
C_INCS += drivers
C_INCS += drivers/drivers
C_INCS += user
INCS_OBJS_DIR = $(foreach DIR2, $(C_INCS), $(wildcard $(DIR2)/*.h))
INCS_OBJS_PATH = $(sort $(dir $(INCS_OBJS_DIR)))
C_INCLUDES = $(addprefix -I,$(INCS_OBJS_PATH))
# 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)"
#add By Max
CFLAGS += $(BOOT_FLAGS)
# add C_FLAG By Max
CFLAGS += -Wno-unused-variable
CFLAGS += -Wno-unused-function
CFLAGS += -Wno-unused-but-set-variable
CFLAGS += -Wno-incompatible-pointer-types
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = drivers/gcc/mm32f3273g_flash.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 update
#######################################
# 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)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir $@
update:
pyocd flash --erase auto --target MM32F3273G8P --base-address 0x8000000 ./build/$(TARGET).bin
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***
3、编译
在keyExti输入make即可编译烧录。
代码
工程链接