我正在开发一个
STM32L072 项目,其环境由 arm-none-eabi-gcc 编译器版本 10-2020-q4、make 和 Eclipse IDE 组成。
我在启动文件中的 libc_init_array 函数调用中发生硬故障时遇到问题。在调试模式下使用反汇编,我可以看到导致问题的指令是“blx r3”,它在地址 0x0 处跳转。此时,r3寄存器值为0x0。
![]()
根据 ARM 文档,blx 指令交换指令集。然后我尝试在我的项目中编写 libc_init_array 函数,因为我认为可能使用的外部 libc_init_array 函数没有用正确的指令集编译。
虽然这不能解决我的问题,但我能够看到在 0x0 地址处的跳转是由于在 libc_init_array 函数中使用名为“__init_array_start”的回调数组使用 0x0 初始化的回调调用。
![]()
我现在被困在这一点上,真的不知道下一步该往哪里看。
我查看了链接器文件和映射文件,我尝试修改编译器和链接器选项,但到目前为止没有成功。
此外,编译器优化标志设置为 -O1。将其设置为 -Os 可防止在启动时进入 libc_init_array 错误,但稍后会出现更多问题。此外,使用优化只是一个短期解决方案。
你知道是什么导致了这个错误吗?
下面是编译器命令行和项目的链接器文件:
海湾合作委员会的论点:
“
C: ools lc lc.git\0.0.30....compilersgcc.git10-2020-q4-update/bin/arm-none-eabi-gcc” -mthumb - mcpu=cortex-m0plus -march=armv6-m -sta
tic -specs=nano.specs -specs=nosys.specs -specs=rdimon.specs -Wl,--gc-sections -mslow-flash-data -DDEBUG -g3 - gdwarf-2 -TC:/Projects/bsp/STM32/stm32L072.git/0.6.0/src/STM32L072CBTX_FLASH.ld -Wl,-Map,src/out/mapfile.map -o "src/out/application.elf" @./src/out/ObjectFiles.txt -lm
链接器文件:
- /* Entry Point */
- ENTRY(Reset_Handler)
- /* Highest address of the user mode stack */
- _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
- _Min_Heap_Size = 0x500; /* required amount of heap */
- _Min_Stack_Size = 0x500; /* required amount of stack */
- /* Memories definition */
- MEMORY
- {
- RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
- FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K
- EEPROM (rw) : ORIGIN = 0x8080000, LENGTH = 6K
- }
- /* Sections */
- SECTIONS
- {
- /* The startup code into "FLASH" Rom type memory */
- .isr_vector :
- {
- . = ALIGN(4);
- KEEP(*(.isr_vector)) /* Startup code */
- . = ALIGN(4);
- } >FLASH
- /* The program code and other data into "FLASH" Rom type memory */
- .text :
- {
- . = ALIGN(4);
- *(.text) /* .text sections (code) */
- *(.text*) /* .text* sections (code) */
- *(.glue_7) /* glue arm to thumb code */
- *(.glue_7t) /* glue thumb to arm code */
- *(.eh_frame)
- KEEP (*(.init))
- KEEP (*(.fini))
- . = ALIGN(4);
- _etext = .; /* define a global symbols at end of code */
- } >FLASH
- /* Constant data into "FLASH" Rom type memory */
- .rodata :
- {
- . = ALIGN(4);
- *(.rodata) /* .rodata sections (constants, strings, etc.) */
- *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
- . = ALIGN(4);
- } >FLASH
- .ARM.extab : {
- . = ALIGN(4);
- *(.ARM.extab* .gnu.linkonce.armextab.*)
- . = ALIGN(4);
- } >FLASH
- .ARM : {
- . = ALIGN(4);
- __exidx_start = .;
- *(.ARM.exidx*)
- __exidx_end = .;
- . = ALIGN(4);
- } >FLASH
- .preinit_array :
- {
- . = ALIGN(4);
- PROVIDE_HIDDEN (__preinit_array_start = .);
- KEEP (*(.preinit_array*))
- PROVIDE_HIDDEN (__preinit_array_end = .);
- . = ALIGN(4);
- } >FLASH
- .init_array :
- {
- . = ALIGN(4);
- PROVIDE_HIDDEN (__init_array_start = .);
- KEEP (*(SORT(.init_array.*)))
- KEEP (*(.init_array*))
- PROVIDE_HIDDEN (__init_array_end = .);
- . = ALIGN(4);
- } >FLASH
- .fini_array :
- {
- . = ALIGN(4);
- PROVIDE_HIDDEN (__fini_array_start = .);
- KEEP (*(SORT(.fini_array.*)))
- KEEP (*(.fini_array*))
- PROVIDE_HIDDEN (__fini_array_end = .);
- . = ALIGN(4);
- } >FLASH
- /* Used by the startup to initialize data */
- _sidata = LOADADDR(.data);
- /* Initialized data sections into "RAM" Ram type memory */
- .data :
- {
- . = ALIGN(4);
- _sdata = .; /* create a global symbol at data start */
- *(.data) /* .data sections */
- *(.data*) /* .data* sections */
- *(.RamFunc)
- . = ALIGN(4);
- _edata = .; /* define a global symbol at data end */
- } >RAM AT> FLASH
- SVC_NV_RAM_NB_PAGE = (4); /* set the number of page you want*/
- SVC_NV_RAM_PAGE_SIZE = (4096); /* set size of a page, this info is located in the datasheet from the uC*/
- SVC_NV_RAM_SIZE = (SVC_NV_RAM_NB_PAGE * SVC_NV_RAM_PAGE_SIZE);
- .SVC_NV_RAM_SECTION (ORIGIN(FLASH) + LENGTH(FLASH) - (SVC_NV_RAM_SIZE)) (NOLOAD):
- {
- /* align data to a page */
- . = ALIGN(SVC_NV_RAM_PAGE_SIZE);
- *(.SVC_NV_RAM_SECTION)
- } >FLASH
- /* Uninitialized data section into "RAM" Ram type memory */
- . = ALIGN(4);
- .bss :
- {
- /* This is used by the startup in order to initialize the .bss section */
- _sbss = .; /* define a global symbol at bss start */
- __bss_start__ = _sbss;
- *(.bss)
- *(.bss*)
- *(COMMON)
- . = ALIGN(4);
- _ebss = .; /* define a global symbol at bss end */
- __bss_end__ = _ebss;
- } >RAM
- /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
- ._user_heap_stack :
- {
- . = ALIGN(8);
- PROVIDE ( end = . );
- PROVIDE ( _end = . );
- . = . + _Min_Heap_Size;
- . = . + _Min_Stack_Size;
- . = ALIGN(8);
- } >RAM
- .ARM.attributes 0 : { *(.ARM.attributes) }
- }
您还会发现附加的映射文件。
0