本帖最后由 陈炼大雕萌妹 于 2021-1-1 14:28 编辑
window环境搭建
1、window下需要提前安装vscode,然后收索插件iotlink,这个插件是华为开发的。感觉挺好用的。
2、安装完成之后重启vscode。
3、gcc编译的重点在于makefile,本项目工程的makefile是基于STM32cubemx生成的STM32 makefile工程,但是并不适用于雅特力的芯片,所以自己在基于这个上更改了一些.
makefile内容######################################
# target //生成的hex文件名。
######################################
TARGET = Socket
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization 优化等级
OPT = -Og
#######################################
# paths 生成编译文件的目录
#######################################
# Build path
BUILD_DIR = build
######################################
# source 用到的.c文件的路径 \ 是makefile的换行符
######################################
# C sources
C_SOURCES = \
USER/main.c \
USER/system_at32f4xx.c \
USER/at32f4xx_it.c \
SYSTEM/delay/delay.c \
SYSTEM/sys/sys.c \
SYSTEM/usart/usart.c \
AT32F4xx_StdPeriph_Driver/src/at32f4xx_gpio_ex.c \
AT32F4xx_StdPeriph_Driver/src/at32f4xx_rcc.c \
AT32F4xx_StdPeriph_Driver/src/at32f4xx_usart.c \
AT32F4xx_StdPeriph_Driver/src/at32f4xx_tim.c \
AT32F4xx_StdPeriph_Driver/src/misc.c
# ASM sources 汇编文件,gcc的汇编文件与MDK的汇编文件不同,不要引用错了
ASM_SOURCES = \
CMSIS/CM4/DeviceSupport/startup/gcc/startup_at32f421k8t7.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的架构,AT32F4都是M4的芯片,所以都是cortex-m4
#######################################
# cpu
CPU = -mcpu=cortex-m4
# fpu 开启硬件浮点类型
FPU = -mfpu=fpv4-sp-d16
#######################################
# CFLAGS
#######################################
# fpu
# NONE for Cortex-M0/M0+/M3
# float-abi
# mcu
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS =
# C defines 类似MDK的C/C++里面的define配置
C_DEFS = \
-DAT_START_F421_V1_0 \
-DAT32F421K8T7 \
-DUSE_FULL_ASSERT
# AS includes
AS_INCLUDES =
# C includes 头文件目录
C_INCLUDES = \
-ISYSTEM/delay \
-ISYSTEM/sys \
-ISYSTEM/usart \
-IAT32F4xx_StdPeriph_Driver/inc \
-IUSER \
-ICMSIS/CM4/DeviceSupport \
-ICMSIS/CM4/CoreSupport \
-ICMSIS/CM4/DeviceSupport
# 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 链接ld文件的目录
#######################################
# link script
LDSCRIPT = CMSIS/CM4/DeviceSupport/startup/gcc/linker/AT32F421x8_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
#######################################
# 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)) [ DISCUZ_CODE_2 ]lt; -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) [ DISCUZ_CODE_2 ]lt; -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(HEX) [ DISCUZ_CODE_2 ]lt; $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) [ DISCUZ_CODE_2 ]lt; $@
$(BUILD_DIR):
mkdir $@
#######################################
# clean up
#######################################
clean:
del $(BUILD_DIR)
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# *** EOF ***
#库文件需要的往里面添加
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_adc.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_bkp.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_can.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_comp.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_crc.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_dac.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_dbgmcu.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_dma.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_ertc.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_eth.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_exti.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_flash.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_gpio_ex.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_iwdg.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_pwr.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_rcc.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_rtc.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_sdio.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_spi.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_syscfg.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_wwdg.c \
# AT32F4xx_StdPeriph_Driver/src/Src/at32f4xx_xmc.c
4、有了makefile工程,就可以导入vscode。
5、iotlink的使用教程 https://flyfishzy.github.io/iotstudio-doc/zh/,里面可以用openocd,调试debug,编写代码。iotlink的依赖项需要C/C++,大家记得安装。
c_cpp_properties.json配置文件,可以写,也可以直接勇敢C/C++插件配置{
"env": {
"sdkPath": "iot_link"
},
"configurations": [
{
"name": "Win32",
"includePath": [
"C:/Users/admin/.iotlink/tools/gcc-arm-none-eabi/arm-none-eabi/include",
"C:/Users/admin/.iotlink/tools/gcc-arm-none-eabi/lib/gcc/arm-none-eabi/9.2.1/include",
"${workspaceFolder}/**",
"${workspaceFolder}/SYSTEM/delay",
"${workspaceFolder}/AT32F4xx_StdPeriph_Driver/inc",
"${workspaceFolder}/CMSIS/CM4/DeviceSupport",
"${workspaceFolder}/CMSIS/CM4/CoreSupport",
"${workspaceFolder}/SYSTEM/sys",
"${workspaceFolder}/SYSTEM/usart",
"${workspaceFolder}/USER",
"${sdkPath}/**"
],
"browse": {
"limitSymbolsToIncludedHeaders": true
},
"defines": [
"_DEBUG",
"__CC_ARM",
"AT_START_F421_V1_0",
"AT32F421K8T7",
"USE_FULL_ASSERT",
"USE_STDPERIPH_DRIVER"
],
"intelliSenseMode": "msvc-arm",
"cStandard": "c99",
"cppStandard": "c++14",
"compilerPath": ""
}
],
"version": 4
}
gitee工程:https://gitee.com/elec123/socket
如果有想了解雅特力芯片的可以加群 1121757020
如果有想了解如何搭建换记得可以加群 274407988
|