0

I am unit-testing STM32 code with Ceedling. My issue is that Ceedling uses crt0.S as startup file, but I need it to use .S instead (otherwise it keeps failing). Can it be specified somewhere in project.yml?

Here is my compiler setup:

: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'

Here is the error message:

/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].

And my CMake config:

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})

The projects builds just fine...

nero
  • 33
  • 3
  • How do you build your normal application? You could try to compare the compiler and linker arguments with the ceedling configuration and add/modify the arguments. – Bodo Mar 22 '21 at 17:30
  • In my CMake setup I pass the startup file along with other sourcefiles. This doesn't help here tho. Ceedling still uses gcc for some preprocessor stuff so maybe that is the problem. – nero Mar 22 '21 at 17:39
  • Please [edit] your question to add clarification or requested information. Showing the CMake configuration and the resulting compiler and linker commands and the compiler and linker commands created by ceedling may help. I guess you might have options to disable the use of the standard startup file in your CMake setup. If you can't specify your startup file with ceedling, maybe as a workaround you can compile it manually and add the object file as a linker argument. – Bodo Mar 22 '21 at 17:55
  • I edited the question, I tried to link just the object file but maybe I'm doing it wrong? Can you show me some example how to link it properly? – nero Mar 22 '21 at 18:02
  • The command line below "Shell executed command" doesn't show any object files that would be linked. Are the files listed in a linker script `-T STM32F412VGTx_FLASH.ld`? – Bodo Mar 24 '21 at 09:42

0 Answers0