我正在用 Ceedling 对 STM32 代码进行单元测试。我的问题是 Ceedling 使用 crt0.S 作为启动文件,但我需要它来使用 .S 代替(否则它会一直失败)。可以在 project.yml 中的某处指定吗?
这是我的编译器设置:
:tools:
:test_compiler:
:executable: arm-none-eabi-gcc
:arguments:
- "${1}"
- '-c'
- '-g'
- '-mthumb'
- '-mcpu=cortex-m4'
- '-mfloat-abi=hard'
- '-mfpu=fpv5-sp-d16'
- '-mthumb'
- '-mabi=aapcs'
- '-ffunction-sections'
- '-ffreestanding'
- '-fdata-sections'
- '-Wall'
- '-Wno-address'
#- '-std=c99'
#- '-pedantic'
- -I"$": COLLECTION_PATHS_TEST_TOOLCHAIN_INCLUDE #expands to -I search paths
- -I"$": COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR #expands to -I search paths
- -D$: COLLECTION_DEFINES_TEST_AND_VENDOR #expands to all -D defined symbols
- -I"$": COLLECTION_PATHS_SOURCE_INCLUDE_VENDOR
- '-DTEST'
- '-DUNITY_EXCLUDE_STDINT_H'
- '-DUNITY_EXCLUDE_LIMITS_H'
- '-DUNITY_EXCLUDE_SIZEOF'
- '-DUNITY_INCLUDE_DOUBLE'
- '-DUNITY_SUPPORT_TEST_CASES'
- '-DUNITY_INT_WIDTH=32'
- '-DUNITY_LONG_WIDTH=32'
:test_linker:
:executable: arm-none-eabi-gcc
:arguments:
- '-lm'
- '-mcpu=cortex-m4'
- '-mthumb'
- '-specs=nosys.specs'
- '-T STM32F412VGTx_FLASH.ld'
- '-ffreestanding'
这是错误消息:
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol Reset_Handler; defaulting to 0000000008000000
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/lib/thumb/v7e-m/nofp/crt0.o: in function `_mainCRTStartup':
/build/newlib-CVVEyx/newlib-3.3.0/build/arm-none-eabi/thumb/v7e-m/nofp/libgloss/arm/semihv2m/../../../../../../../../libgloss/arm/crt0.S:545: undefined reference to `main'
collect2: error: ld returned 1 exit status
ERROR: Shell command failed.
> Shell executed command:
'arm-none-eabi-gcc -lm -mcpu=cortex-m4 -mthumb -specs=nosys.specs -T STM32F412VGTx_FLASH.ld'
> And exited with status: [1].
还有我的 CMake 配置:
set(OBJECT_GEN_FLAGS "-ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS}" CACHE INTERNAL "C Compiler options")
set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS}" CACHE INTERNAL "C++ Compiler options")
set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS}" CACHE INTERNAL "ASM Compiler options")
# -Wl,--gc-sections Perform the dead code elimination.
# --specs=nano.specs Link with newlib-nano.
# --specs=nosys.specs No syscalls, provide empty implementations for the POSIX system calls.
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections -ffunction-sections -fdata-sections -Wl,-Map=${CMAKE_PROJECT_NAME}.map" CACHE INTERNAL "Linker options")
# source files
set(SOURCES
src/main.c
src/ledblink.c
src/sum2nums.c
Drivers/system_stm32f4xx.c
inc/ledblink.h
inc/sum2nums.h
Drivers/stm32f4xx.h
Drivers/system_stm32f4xx.h
startup/startup_stm32f412vx.s
)
add_executable(${PROJECT_NAME}.elf ${SOURCES})
这些项目构建得很好......