AIR32F103(三) Linux环境基于标准外设库的项目模板

目录

Linux 开发环境

使用的 GCC Arm, st-flash 和 JLink 与前一篇相同, 可以参考前一篇的说明

关于 Air32F103-Template

项目地址: https://gitee.com/iosetting/air32f103-template

这是为 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

示例代码

示例代码位于 Examples 目录下, 项目中的示例代码几乎都是迁移自合宙的Keil项目中的示例代码, 已经在GCC Arm下运行验证过.

如果需要运行示例代码, 先将 User 目录下的文件清空, 将示例代码复制到 User 目录下, make clean清空, 然后重新编译和烧录.

VSCode 配置文件

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

项目模板测试过的最新的GCC Arm编译器版本为12.2, 对比 11.2 和 11.3, 12.2 编译会带来一些性能提升, 但是检查也更严格, 按11.2和11.3的配置会产生不少warning. 在GCC Arm 12.2编译提示 LOAD segment with RWX permissions 警告GCC Arm 11.3rel1, 12.2编译提示 _close is not implemented and will always fail 中有说明

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 

发表评论

评论已关闭。

相关文章