You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

STM32链接脚本执行出现语法错误的排查求助

STM32裸机编程链接脚本语法错误排查问题

我正在学习Gbati Israel所著《裸机嵌入式C编程》,尝试实现STM32_NUCLEO-F411开发板的LED慢闪烁功能,严格遵循书中的三步编译流程操作:

  • 步骤1:编译main.c生成目标文件
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -std=gnu11 main.c -o main.o
    
  • 步骤2:编译启动文件生成目标文件
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -std=gnu11 stm32f411_startup.c -o stm32f411_startup.o
    
  • 步骤3:链接所有目标文件生成可执行文件
    rm-none-eabi-gcc -nostdlib -T stm32_ls.ld *.o -o 3_LinkerAndStartup.elf.elf
    

执行链接命令后持续出现以下错误:

c:/program files (x86)/gnu arm embedded toolchain/10 2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe:stm32_ls.ld:18: syntax error
collect2.exe: error: ld returned 1 exit status

根据错误提示检查了stm32_ls.ld脚本的第18行,但未发现明显问题,完整的链接脚本内容如下:

/*1.Entry Point*/
ENTRY(Reset_Handler)


/*2.Memory definitions*/

MEMORY
{
    FLASH(rx):ORIGIN =0x08000000,LENGTH =512K
    SRAM(rwx):ORIGIN =0x20000000,LENGTH =128K
}

_estack = ORIGIN(SRAM)+LENGTH(SRAM);
 
 /*3.Indicate required heap and stack size*/
__max_heap_size = 0x200;
__max_stack_size = 0x400;

/*Sections*/
SECTIONS
{
     /*first section of output file*/
    .text :
    {
      . = ALIGN(4);
      *(.isr_vector_tbl)  /*merge all .isr_vector_tbl sections of input files*/
      *(.text)             /*merge all .text sections of input files*/
      *(.rodata)           /*merge all .rodata sections of input files*/
      . = ALIGN(4);
     _etext = .;          /*Create a global symbol to hold end of text section*/
    }>FLASH
        

    /*second section of output file*/

    .data :
    {
     . = ALIGN(4);
    _sdata = .;   /*Create a global symbol to hold start of data section*/
      *(.data)
     . = ALIGN(4);
    _edata = .;   /*Create a global symbol to hold end of data section*/
    } > SRAM AT> FLASH  /*>(vma) AT> (lma)*/
    
    
    /*third section of output file*/
    .bss :
    {
     . = ALIGN(4);
    _sbss = .;  /*Create a global symbol to hold start of bss section*/
    *(.bss)  /*merge all .bss sections of input files*/
     . = ALIGN(4);
    _ebss = .;  /*Create a global symbol to hold end of bss section*/
    }> SRAM
}

环境信息

  • 编译工具链:gcc-arm-none-eabi-10.3-2021.10-win32.exe
  • 链接脚本位置:3_LinkerAndStartup文件夹
  • 操作系统:Windows 11
  • 参考代码:对应《裸机嵌入式C编程》第四章3_LinkerscriptAndStartup章节内容

内容的提问来源于stack exchange,提问作者JohnBellion

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.01 21:07:28