STM32L0上{_libc_init_array失败

时间:2018-03-06 22:22:19

标签: eclipse cortex-m openocd

我从linux上的STM32L053开始,使用Eclipse IDE,使用gcc-arm-none-eabi-7-2017-q4进行交叉编译,并使用openocd进行调试。

在进入main()之前,我会进入WWDG_IRQHandler()。 在调试器堆栈上,我可以看到:

  ↓ Reset_Handler() at 0x8002812
  ↓ __libc_init_array() at 0x8002836
  ↓ <signal handler called>() at 0xfffffff9
    WWDG_IRQHandler() at 0x8002830

来自Reset_Handler()的几行,顺便说一句我认为箭头显示错误的行,因为堆栈显示__libc_init_array()。

    Reset_Handler:
...
    08002806:   cmp     r2, r3
    08002808:   bcc.n   0x80027fe <Reset_Handler+30>
    0800280a:   bl      0x8000128 <SystemInit>
    0800280e:   bl      0x8002834 <__libc_init_array>
 -> 08002812:   bl      0x80027d8 <main>
...

对于__libc_init_array(),我希望箭头显示正确的行,而不是显示错误的下一行。

    __libc_init_array:
    08002834:   eors    r0, r6
 -> 08002836:   stmdb   sp!, {r2, r3, r5, r6, sp, lr}
    0800283a:   b.n     0x800237c <SPIx_Write+8>
    0800283c:   str     r4, [r5, r1]
...

对于WWDG_IRQHandler(),它并不重要,但无论如何都要发布

    WWDG_IRQHandler:
 -> 08002830:   b.n     0x8002830 <WWDG_IRQHandler>
    08002832:   movs    r0, r0

我的&#34; c&#34;代码只包含include(未达到主函数):

#include <stm32l0538_discovery.h>
#include <sys/types.h>

对于eclipse上的配置,我没有使用任何插件,我把它设置为:

C/C++ Build
|
|_Cross Settings
| |_Prefix : arm-none-eabi-
| \_Path : /.../gcc-arm-none-eabi-7-2017-q4-major/bin
|
|_Cross Gcc Compiler
| |_Command : gcc
| |_All Options : -nostdinc
| |               -I/.../gcc-arm-none-eabi-7-2017-q4-major/lib/gcc/arm-none-eabi/7.2.1/include
| |               -I/.../gcc-arm-none-eabi-7-2017-q4-major/arm-none-eabi/include
| |               -I/.../STM32Cube_FW_L0_V1.10.0/Drivers/BSP/STM32L0538-Discovery
| |               -I/.../STM32Cube_FW_L0_V1.10.0/Drivers/CMSIS/Include
| |               -I/.../STM32Cube_FW_L0_V1.10.0/Drivers/STM32L0xx_HAL_Driver/Inc
| |               -I/.../STM32Cube_FW_L0_V1.10.0/Drivers/CMSIS/Device/ST/STM32L0xx/Include
| |               -Os
| |               -g3
| |               -Wall
| |               -Wextra
| |               -mcpu=cortex-m0plus
| |               -march=armv6s-m
| |               -mlittle-endian
| |               -mthumb
| |               -DSTM32L053xx
| |               -c
| |               -v
| \_Command line pattern : ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
|
|_Cross Gcc Linker
| |_command : gcc
| |_All Options : -static
| |               -L/.../gcc-arm-none-eabi-7-2017-q4-major/
| |               -L/.../gcc-arm-none-eabi-7-2017-q4-major/arm-none-eabi/lib
| |               -L/.../gcc-arm-none-eabi-7-2017-q4-major/lib
| |               -L/.../gcc-arm-none-eabi-7-2017-q4-major/lib/gcc/arm-none-eabi/7.2.1
| |               -mcpu=cortex-m0plus
| |               -march=armv6s-m
| |               -mlittle-endian
| |               -mthumb
| |               -DSTM32L053xx
| |               -T/.../STM32Cube_FW_L0_V1.10.0/Projects/STM32L053C8-Discovery/Templates/TrueSTUDIO/STM32L053C8_Discovery/STM32L053C8_FLASH.ld
| |               -Wl,--gc-sections
| |               -Os
| \_Command line pattern: ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
|
\_Cross GCC Assembler
  |_command : as
  |_all options: /*blank*/
  \_Command line pattern : ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

在LD文件中,我只看到两件可能有趣的事情,我不会对整个文件进行CP处理:

    /* Entry Point */
    ENTRY(Reset_Handler)
...
    /* Remove information from the standard libraries */
    /DISCARD/ :
    {
      libc.a ( * )
      libm.a ( * )
      libgcc.a ( * )
    }
...

启动是由ST提供的,可以在Gogole上轻松恢复,就像这个文件:
https://github.com/AndiceLabs/STM32L053R8-Nucleo/blob/master/Drivers/CMSIS/Device/ST/STM32L0xx/Source/Templates/gcc/startup_stm32l053xx.s
除此之外,我将第151行设置为0,并且当前行205/206不在我的文件中。

我不是libc和设置环境的主人,我尝试了很多东西,比如(un)cheking&#34; nostdlibs&#34;,&#34; nostartfiles&#34;或者&#34; nodefaultlibs&#34;。但它总是会导致编译失败。

我真的不知道尝试了什么,请点亮我的道路! 谢谢!

Jibz

4 个答案:

答案 0 :(得分:0)

  

SP

这可能是您第一次实际在代码中使用堆栈。某些链接器skripts没有正确对齐堆栈,因此您可能最终在此指令中遇到(硬)错误。检查调试器中的WWDG_IRQHandler寄存器值。

除非您在源代码中设置自己的错误处理程序,否则将设置一些默认处理程序,它与您的from bs4 import BeautifulSoup import requests url = "https://www.basketball-reference.com/awards/mvp.html" source_code = requests.get(url) plain_text = source_code.text soup = BeautifulSoup(plain_text, 'html.parser') table = soup.find("table",attrs={"id":"mvp_NBA"}).find("tbody").findAll("tr") key = [] for row in table: season = row.findAll("th", {'class': 'left'}) for year in season: y = year.get_text().encode('utf-8') key.append(y) print key 一样完全

编译器/链接器对所有 undefiend IRQ和故障处理程序使用相同的功能 - 这可能会阻止您正确识别发生的实际故障。

答案 1 :(得分:0)

经过一番研究,我确信这不是与堆栈指针SP相关的问题 回到代码:

    __libc_init_array:
    08002834:   eors    r0, r6
 -> 08002836:   stmdb   sp!, {r2, r3, r5, r6, sp, lr}
    0800283a:   b.n     0x800237c <SPIx_Write+8>
    0800283c:   str     r4, [r5, r1]
...

Regarding the instruction set from different cortex (M0 to M4F) STMDB指令不包含在cortex-M0的指令集中,cortex-M0 +只有STM指令(第三个白色列,STM第10行,第一个蓝色列,第17个(STMDB)。

从GNU Arm嵌入式工具链(https://developer.arm.com/open-source/gnu-toolchain/gnu-rm)页面开始,写入支持Cortex-M0(+),所以我猜C librairy。在其他网站上,他们建议测试gcc多图书馆,我试试并且:

[jibz@Jazptop bin]$ ./arm-none-eabi-gcc --print-multi-lib
.;
thumb;@mthumb
hard;@mfloat-abi=hard
thumb/v6-m;@mthumb@march=armv6s-m
thumb/v7-m;@mthumb@march=armv7-m
thumb/v7e-m;@mthumb@march=armv7e-m
thumb/v7-ar;@mthumb@march=armv7
thumb/v8-m.base;@mthumb@march=armv8-m.base
thumb/v8-m.main;@mthumb@march=armv8-m.main
thumb/v7e-m/fpv4-sp/softfp;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=softfp
thumb/v7e-m/fpv4-sp/hard;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=hard
thumb/v7e-m/fpv5/softfp;@mthumb@march=armv7e-m@mfpu=fpv5-d16@mfloat-abi=softfp
thumb/v7e-m/fpv5/hard;@mthumb@march=armv7e-m@mfpu=fpv5-d16@mfloat-abi=hard
thumb/v7-ar/fpv3/softfp;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=softfp
thumb/v7-ar/fpv3/hard;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=hard
thumb/v8-m.main/fpv5-sp/softfp;@mthumb@march=armv8-m.main@mfpu=fpv5-sp-d16@mfloat-abi=softfp
thumb/v8-m.main/fpv5-sp/hard;@mthumb@march=armv8-m.main@mfpu=fpv5-sp-d16@mfloat-abi=hard
thumb/v8-m.main/fpv5/softfp;@mthumb@march=armv8-m.main@mfpu=fpv5-d16@mfloat-abi=softfp
thumb/v8-m.main/fpv5/hard;@mthumb@march=armv8-m.main@mfpu=fpv5-d16@mfloat-abi=hard

我相信它已经安装,因为Cortex-M0 +在ARMv6-M架构上。但结果显示ARMv6 s -M,是否会改变某些内容?

无论如何,我仍然不知道如何拥有正确的libc。

答案 2 :(得分:0)

已解决!!

我找到了armv6的libc.a,更改了一些链接器选项并添加了路径,这里是我的链接器配置:

C/C++ Build
|
|_Cross Settings
|
|_Cross Gcc Compiler
|
|_Cross Gcc Linker
| |_command : gcc
| |_All Options : -static
| |            => -L/.../gcc-arm-none-eabi-7-2017-q4-major/lib/gcc/arm-none-eabi/7.2.1/thumb/v6-m/
| |            => -L/.../gcc-arm-none-eabi-7-2017-q4-major/arm-none-eabi/lib/thumb/v6-m/
| |               -L/.../gcc-arm-none-eabi-7-2017-q4-major/arm-none-eabi/lib
| |               -L/.../gcc-arm-none-eabi-7-2017-q4-major/lib
| |               -L/.../gcc-arm-none-eabi-7-2017-q4-major/lib/gcc/arm-none-eabi/7.2.1
| |               -mcpu=cortex-m0plus
| |               -march=armv6s-m
| |               -mlittle-endian
| |               -mthumb
| |               -T/.../STM32Cube_FW_L0_V1.10.0/Projects/STM32L053C8-Discovery/Templates/TrueSTUDIO/STM32L053C8_Discovery/STM32L053C8_FLASH.ld
| |               -Wl,--gc-sections
| |               -Os
| \_Command line pattern: ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
|
\_Cross GCC Assembler

感谢Turbo J在那里和帮助,
Jibz

答案 3 :(得分:0)

在与某人写信后,他向我展示了我在配置中所犯的错误,所以我在这里(再次)发布配置:

|_Cross Settings : Prefix : arm-none-eabi-
|                  Path : ${GccPath}/bin
| 
|_Cross Gcc Compiler : command : gcc
| |_Preprocessor : uncheck "Do not search system directories(-nostdinc)",
| |                I believed that I will search in the native system x64
| |                machin, but no, it just means that it will search in
| |                the GCC folder.
| |                -D STM32L053xx :needed to use some code provided by ST
| |_Includes : removing all references of path to /gcc/*/include because
| |            now they are included without the -nostdinc option.
| |            -I ${DriversPath}/BSP/STM32L0538-Discovery
| |            -I ${DriversPath}/CMSIS/Include
| |            -I ${DriversPath}/STM32L0xx_HAL_Driver/Inc
| |            -I ${DriversPath}/CMSIS/Device/ST/STM32L053xx/Include
| |_Optimization : Optimization level : Optimization for size (-Os)
| |_Debugging : Debug Level : Maximum (-g3)
| |_Warnings : All Warnings (-Wall)
| |            Extra warnings (-Wextra)
| \_Miscellaneous : -mcpu=cortex-m0plus   : with march, GCC will know which lib it should use, and not using the first found in the paths provided previously with the linker option -L.
|                   -march=armv6s-m
|                   -mlittle-endian
|                   -mthumb
|                   -c
|                   -ffunction-sections   : it permits to remove not necessary code
|                   -fdata-sections       : it permits to remove not necessary data.
|                   -v (Verbose)
|
\_Cross GCC Linker : command : gcc
  |_general : No shared libraries (-static)
  |_Libraries : it should stay blank, I removed all -L options.
  \_Miscellaneous : -mcpu=cortex-m0plus
                    -mtune=cortex-m0plus  :Actually, I believe it is just an optimization for **that** cpu.
                    -march=armv6s-m
                    -mlittle-endian
                    -mthumb
                    -T${ProjDirPath}/LinkerScripts/STM32L053C8_FLASH.ld
                    -Wl,-Map=${ProjDirPath}/Logs/Pluviographe.map : The map file is a kind of log, showing links between elements. 
                    -Wl,-gc-sections : It removes some unused code, provided by the -ffunctions-sections and -fdata-sections from the compiler.

代码中可能仍然存在“小”错误,但它更干净。