请问哪位遇见过这样的错误
assembling startup_gd32f30x_hd.s...
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(27): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(28): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(29): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(30): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(32): error: A1163E: Unknown opcode Default_Handler , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(34): error: A1163E: Unknown opcode necessary , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(35): error: A1163E: Unknown opcode _sidata , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(36): error: A1163E: Unknown opcode _sdata , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(37): error: A1163E: Unknown opcode _edata , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(38): error: A1163E: Unknown opcode _sbss , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(39): error: A1163E: Unknown opcode _ebss , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(41): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(42): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(43): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(45): error: A1163E: Unknown opcode reset , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(46): error: A1167E: Invalid line start
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(47): error: A1105E: Area directive missing
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(47): warning: A1088W: Faking declaration of area AREA |$$$$$$$|
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(50): error: A1167E: Invalid line start
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(56): error: A1167E: Invalid line start
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(65): error: A1167E: Invalid line start
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(69): error: A1167E: Invalid line start
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(73): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(75): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(77): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(80): error: A1163E: Unknown opcode Reset_Handler, , expecting opcode or Macro
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(82): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(83): error: A1167E: Invalid line start
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(84): error: A1167E: Invalid line start
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(86): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(88): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(89): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(91): error: A1167E: Invalid line start
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(92): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(93): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(94): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(95): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(96): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(97): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(98): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(99): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(100): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(101): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(102): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(103): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(104): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(105): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(106): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(107): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(109): error: A1137E: Unexpected characters at end of line
Library\Firmware\CMSIS\GD\GD32F30x\Source\ARM\startup_gd32f30x_hd.s(110): error: A1137E: Unexpected characters at end of line
错误本质
你的 startup_gd32f30x_hd.s 启动文件是用 GNU 汇编语法 写的(比如 .weak Default_Handler、.word Reset_Handler、IF EF: 等),但 Keil MDK 默认使用的是 ARM 公司的 armasm 汇编器(ARM Compiler 5/6 里都自带 armasm)。armasm 不认识 GNU 语法,所以出现一堆 Unknown opcode、Unexpected characters at end of line、Invalid line start。
你切换 V5/V6 只是换了 C 编译器(armcc 或 armclang),汇编器始终是 armasm,所以清工程重编译也没用。
解决办法
要让 Keil 正确汇编 GNU 语法的 .s 文件,必须让 Keil 调用 GNU 工具链(arm-none-eabi-gcc 里的 arm-none-eabi-as)来汇编。
第一步:安装 GNU 工具链(如果还没装)
从 ARM 官网下载并安装 GNU Toolchain for ARM(推荐 arm-none-eabi 工具链,例如 gcc-arm-none-eabi 版本)。安装路径记下来,例如 C:\Program Files (x86)\GNU Tools ARM Embedded\8-2020-q3-update。
第二步:在 Keil 里切换到 GNU 工具链
打开工程,进入 Project → Options for Target '你的工程名'。
切换到 C/C++ 选项卡。
找到 Tool Chain Editor 区域,点 Select toolchain 的下拉框。
如果下拉框里只有 ARM Compiler 5 / ARMClang 6,说明 Keil 没有识别到 GNU 工具链。此时需要点击旁边的 Install 或确保已经安装了 GNU 支持包(Keil MDK 5.37 以上版本通常需要单独安装 GNU 工具链,并在 Keil 中注册)。
选择 GNU Toolchain(或者类似选项),然后在 PATH 里填写 GNU 工具链 bin 目录的完整路径,例如:
C:\Program Files (x86)\GNU Tools ARM Embedded\8-2020-q3-update\bin
确保该目录下存在 arm-none-eabi-gcc.exe、arm-none-eabi-as.exe 等文件。
第三步:重新编译
执行 Project → Clean Targets,然后 Rebuild all target files。
这次 Keil 会用 arm-none-eabi-as 汇编启动文件,GNU 语法就能正常识别,报错消失。
替代方案(如果坚持使用 ARM 编译器)
如果你不想装 GNU 工具链,那就需要把启动文件换成 ARM 汇编语法的版本。但 GD32 官方固件库一般只提供 GCC 版本的启动文件(GNU 语法),所以这条路通常走不通。
总结
问题不在 V5/V6 的选择,而在于 Keil 一直用 armasm 汇编 GNU 语法文件。
切换到 GNU 工具链后,不仅启动文件能正确汇编,后续链接、编译也会使用 GCC 的一套流程。这是在 Keil 里开发 GD32(以及其他国产 ARM Cortex‑M 芯片)的标准做法,很多 GD32 开发包都是默认基于 GCC 的,所以这个配置必不可少。
如果按上述步骤操作后还有问题,可以检查一下 GNU 工具链路径是否填写正确,或者确认 Keil 版本是否支持 GNU 工具链(MDK 5 以上一般都支持)。