开发板开箱
- 开发板正面,两个miniUSB接口,五颗静音按键,三颗LED灯。
资料获取
根据手册访问ftp://58.250.18.138 获取资料,我电脑的Explorer访问ftp://58.250.18.138 访问不了,所以用FileZilla来远程访问FTP服务器。
使用FileZilla来访问FTP服务器:
- 选择协议为FTP
- 主机设置为58.250.18.138
- 登陆类型选择匿名
- 连接即可
连接成功,因为我申请的是N32G457这款单片机,所以资料是放在2-Microcontrollers里面,然后就是漫长的下载过程。。。。
开发环境搭建(vscode + GCC + pyocd(python3.11) + gdb)
版本信息
- vscode 1.74.2
- arm-none-eabi-gcc 10.2.1
- python 3.11.1
- pyocd 0.34.3
- arm-none-eabi-gdb 10.1.90.20201028-git
python 包的安装
这里需要用到两个python的包:
compiledb
用于导出 compile_commands.json
来支持补全
pyocd
用于启动一个 gdbserver
直接pip一键安装即可 pip install compiledb pyocd
pyocd 导入 pack 包
在工程目录下创建 pyocd.yaml
来指定 pack 包的位置
pack:
- ./tools/Nationstech.N32G45x_DFP.1.0.5.pack
运行一行命令来查看N32的pack是否导入成功 pyocd list --targets | grep n32g457
整理工程,配置vscode工作区
将官方给出的vscode示例工程文件复制到本目录,一番整理后工程目录如下
相对应的 Makefile脚本也需要修改,修改后的内容如下:
TARGET = output
ifeq ($(release), y)
DEBUG = 0
else
DEBUG = 1
endif
OPT = -Os
BUILD_DIR = build
TARGET_PLATFORM := n32g45x
DEFS += -DN32G45X
DEFS += -DUSE_STDPERIPH_DRIVER
USELIB = 0
CROSS_COMPILE = arm-none-eabi-
CODE_PATH = code
BSP_PATH = bsp
FIRMWARE_PATH = firmware
C_DIRS += ${CODE_PATH}/src
C_DIRS += ${BSP_PATH}/src
C_DIRS += ${FIRMWARE_PATH}/CMSIS/device
C_DIRS += ${FIRMWARE_PATH}/$(TARGET_PLATFORM)_std_periph_driver/src
SRC_OBJS_DIRS += $(foreach DIR, $(C_DIRS), $(wildcard $(DIR)/*.c))
C_SOURCES = $(SRC_OBJS_DIRS)
ASM_SOURCES = ${FIRMWARE_PATH}/CMSIS/device/startup/startup_$(TARGET_PLATFORM)_gcc.s
C_INCS += ${CODE_PATH}/inc
C_INCS += ${BSP_PATH}/inc
C_INCS += ${FIRMWARE_PATH}/CMSIS/core
C_INCS += ${FIRMWARE_PATH}/CMSIS/device
C_INCS += ${FIRMWARE_PATH}/$(TARGET_PLATFORM)_std_periph_driver/inc
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))
ifeq ($(USELIB), 1)
SRC_LIB_DIR += ${FIRMWARE_PATH}/$(TARGET_PLATFORM)_algo_lib/src
INC_LIB_DIR += ${FIRMWARE_PATH}/$(TARGET_PLATFORM)_algo_lib/inc
LIB_SOURCES = $(foreach DIR3, $(SRC_LIB_DIR), $(wildcard $(DIR3)/*.lib))
LIB_SOURCES_L = $(addprefix -L,$(LIB_SOURCES))
C_LIBS = $(LIB_SOURCES_L)
LIB_INCS = $(foreach DIR4, $(INC_LIB_DIR), $(wildcard $(DIR4)/*.h))
LIB_INCS_PATH = $(sort $(dir $(LIB_INCS)))
LIB_INCS_PATH_I = $(addprefix -I,$(LIB_INCS_PATH))
C_INCLUDES += $(LIB_INCS_PATH_I)
endif
CPU = -mcpu=cortex-m4
FPU = -mfpu=fpv4-sp-d16
FLOAT-ABI = -mfloat-abi=hard
MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
CFLAGS += $(MCU) -Wall
CFLAGS += $(OPT)
CFLAGS += -ffunction-sections -fdata-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
LFLAGS += $(MCU)
LFLAGS += -Wl,--gc-sections
LFLAGS += --specs=nosys.specs
LFLAGS += -Xlinker -Map=$(BUILD_DIR)/$(TARGET).map
LDSCRIPT = ${FIRMWARE_PATH}/CMSIS/device/$(TARGET_PLATFORM)_flash.ld
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CROSS_COMPILE)gcc $(CFLAGS) $(DEFS) $(C_INCLUDES) $(C_LIBS) -c -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(CROSS_COMPILE)gcc $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CROSS_COMPILE)gcc $(OBJECTS) $(LFLAGS) -T$(LDSCRIPT) -o $@
$(CROSS_COMPILE)size $@
$(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
$(CROSS_COMPILE)objcopy -O binary -S $< $@
$(BUILD_DIR)/$(TARGET).hex: $(BUILD_DIR)/$(TARGET).elf
$(CROSS_COMPILE)objcopy -O ihex -S $< $@
$(BUILD_DIR):
@-mkdir $@
clean:
@-rm -rf $(BUILD_DIR)
-include $(wildcard $(BUILD_DIR)/*.d)
download:
@pyocd flash --target=N32G457VEL7 --erase=auto --frequency=1000000 .\build\output.bin
@echo "Download Completed!"
db:
@compiledb make -j8 all
运行 make db
命令,导出 compile_commands.json
文件,并且移动到 build目录
编写最重要的 Demo.code-workspace
文件:
{
"folders": [
{
"path": "."
}
],
"settings": {
"files.exclude": {
"**/.settings": true,
"**/Debug": true,
"**/Objects": true,
"**/objects": true,
"**/Listings": true,
"**/listings": true,
"**/Output": true,
"**/output": true,
"**/*.map": true,
"**/.config*": true,
"**/.project*": true,
"**/.cproject*": true,
"**/*.POMIN": true,
".gitattributes": true
},
"files.encoding": "utf8",
"editor.fontFamily": "Consolas, OPPOSans",
"terminal.integrated.profiles.windows": {},
"terminal.integrated.defaultProfile.windows": "PowerShell",
"C_Cpp.formatting": "clangFormat",
"C_Cpp.clang_format_style": "{ BasedOnStyle: Google, IndentWidth: 4 }",
"C_Cpp.default.intelliSenseMode": "gcc-x86",
"C_Cpp.default.cppStandard": "c++14",
"C_Cpp.default.cStandard": "c99",
"C_Cpp.default.defines": [],
"C_Cpp.default.compilerPath": "D:/Maker/Console/arm-gcc/bin/arm-none-eabi-gcc.exe",
"C_Cpp.default.includePath": ["${workspaceFolder}/**"],
"C_Cpp.default.forcedInclude": [],
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
"cortex-debug.variableUseNaturalFormat": false,
"files.associations": {
}
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": ["make"],
"args": ["-j8", "all"]
}
]
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "N32 pyocd dbg",
"type": "cortex-debug",
"cwd": "${workspaceRoot}",
"executable": "./build/output.elf",
"request": "launch",
"runToEntryPoint": "main",
"servertype": "pyocd",
"targetId": "n32g457vel7",
"svdFile": "./tools/N32G457.svd",
"showDevDebugOutput": "both",
"preLaunchTask": "build",
"cmsisPack": "./tools/Nationstech.N32G45x_DFP.1.0.5.pack"
}
]
}
}
重启vscode,完美补全
完美 debug,在SRAM基址偏移100KB的位置写入字符串,在memory窗口显示