使用的 GCC Arm, st-flash 和 JLink 与前一篇相同, 可以参考前一篇的说明
这是为 GCC Arm 工具链准备的 AIR32F103x 项目开发模板
├── Build # 编译结果
├── Examples # 示例代码
│   ├── FreeRTOS # FreeRTOS示例代码
│   └── NonFreeRTOS # 非FreeRTOS示例代码
├── Libraries
│   ├── AIR32F10xLib # AIR32F103外设层库代码
│   │   ├── inc # .h头文件
│   │   ├── lib
│   │   │   └── cryptlib
│   │   └── src # .c源文件
│   ├── CORE # Coretex M 核心外设层源文件
│   ├── Debug # delay和printf支持
│   ├── DeviceSupport # AIR32F103的gcc arm startup文件
│   │   └── startup
│   │   └── arm-gcc
│   ├── FreeRTOS # FreeRTOS 库代码
│   └── LDScripts # 连接脚本
├── Makefile
├── Misc
│   └── flash.jlink # JLink烧录脚本
├── README.cn.md
├── README.md
├── rules.mk # make规则
└── User # 用户项目代码
1. 导出项目
git clone https://github.com/IOsetting/hk32f030m-template.git
2. 根据本地环境修改 Makefile
修改 Makefile 设置, 确保 ARM_TOOCHAIN 和 JLINKEXE(或ST_Flash) 指向正确的路径
##### Project #####
项目名称
PROJECT ?= app
编译结果目录
BUILD_DIR = Build
##### Options #####
是否使用 FreeRTOS, y:yes, n:no
USE_FREERTOS ?= n
烧录工具, jlink 或 stlink
FLASH_PROGRM ?= stlink
##### Toolchains #######
根据本地环境, 设置工具链路径
ARM_TOOCHAIN ?= /opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin
st-flash 可执行文件路径
ST_FLASH ?= st-flash
JLinkExe 可执行文件路径和设备类型
JLINKEXE ?= /opt/SEGGER/JLink/JLinkExe
JLINK_DEVICE ?= STM32F103CB
##### Paths ############
当前芯片的连接脚本
LDSCRIPT = Libraries/LDScripts/air32f103cbt6.ld
3. 编译默认项目并烧录
清理
make clean
编译
make
带详细输出的编译
V=1 make
烧录
make flash
默认的项目会点亮板载的三个LED
如果需要运行示例代码, 先将 User 目录下的文件清空, 将示例代码复制到 User 目录下, make clean清空, 然后重新编译和烧录.
c_cpp_properties.json 供参考
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"HK32F030MF4P6"
],
"compilerPath": "/opt/gcc-arm/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc",
"cStandard": "gnu99",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-arm",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "clean, build",
"type": "shell",
"command": "make clean;make",
"problemMatcher": []
},
{
"label": "build, download",
"type": "shell",
"command": "make;make flash",
"problemMatcher": []
},
{
"label": "build",
"type": "shell",
"command": "make",
"problemMatcher": []
},
{
"label": "clean",
"type": "shell",
"command": "make clean",
"problemMatcher": []
},
]
}
切换GCC编译器版本, 11.2, 11.3 和 12.2
printf 无法输出浮点数
printf输出浮点数默认是关闭的, 打印浮点无输出. 可以在 TGT_LDFLAGS
中增加选项 -u _printf_float
开启, 开启后会明显增加二进制程序尺寸.
TGT_LDFLAGS += $(ARCH_FLAGS) -specs=nano.specs -specs=nosys.specs -static -lc -lm \
-u _printf_float \
-Wl,-Map=$(BDIR)/$(PROJECT).map \
-Wl,--gc-sections \
-Wl,--print-memory-usage
开启后, 连接时会检查 _getpid(void)
和 _kill(pid_t pid, int sig)
这两个函数是否定义, 如果没定义会报warning.
对FreeRTOS的支持
运行 Examples/FreeRTOS 目录下的例子时, 需要在 Makefile 中开启对 FreeRTOS 的支持, 将需要下面的配置改为 y
Build with FreeRTOS, y:yes, n:no
USE_FREERTOS ?= n
切换不同的MCU型号
Makefile默认配置的是 AIR32F103CBT6 的编译选项, 如果需要切换到CCT6和RPT6, 需要在Makefile中修改两处
CCT6不用改, RPT6需要修改为 STM32F103RB
JLINK_DEVICE ?= STM32F103CB
...
对应的修改为 air32f103cct6.ld 和 air32f103rpt6.ld
LDSCRIPT = Libraries/LDScripts/air32f103cbt6.ld
Original: https://www.cnblogs.com/milton/p/16830655.html
Author: Milton
Title: AIR32F103(三) Linux环境基于标准外设库的项目模板
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/800057/
转载文章受原作者版权保护。转载请注明原作者出处!