I am having trouble with debugging in VSCode. Here is my setup:
- Build System: Ninja + CMake + arm-none-eabi-gcc
- Debugger Extension: Cortex-Debug
- Debugger Server: ST-Link GDB Server
- Board: Nucleo-C031C6
I have successfully built the binaries using Ninja and CMake. However, when I attempt to start debugging, GDB exits immediately and does not even launch the ST-Link GDB Server. I suspect there might be an issue with my configuration, but I can’t figure out what is wrong.
Debug Console:
<code>Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage
"configuration": {
"name": "ST-Link Debug with Embedded Tools ",
"executable": "/home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf",
"cwd": "/home/fenil/Documents/code/TI_test",
"type": "cortex-debug",
"device": "STM32C031C6",
"serverpath": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.linux64_2.1.100.202310302101/tools/bin/ST-LINK_gdbserver",
"servertype": "stlink",
"interface": "swd",
"gdbTarget": "localhost",
"request": "launch",
"runToEntryPoint": "main",
"cmsisPack": "/home/fenil/Documents/code/TI_test//Keil.STM32C0xx_DFP.1.0.0.pack",
"svdFile": "/home/fenil/Documents/code/TI_test//STM32C0_svd/STM32C0_svd_V1.1//STM32C031.svd",
"stm32cubeprogrammer": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.linux64_2.1.100.202311100844/tools/bin/STM32_Programmer_CLI",
"showDevDebugOutput": "raw",
"armToolchainPath": "/bin",
"serverArgs": [
"-d",
"-v",
"-p",
"61234",
"-e"
],
"preRestartCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
"__configurationTarget": 6,
"gdbServerConsolePort": 55878,
"pvtAvoidPorts": [],
"chainedConfigurations": {
"enabled": false
},
"debuggerArgs": [],
"swoConfig": {
"enabled": false,
"decoders": [],
"cpuFrequency": 0,
"swoFrequency": 0,
"source": "probe"
},
"rttConfig": {
"enabled": false,
"decoders": []
},
"graphConfig": [],
"preLaunchCommands": [],
"postLaunchCommands": [],
"preAttachCommands": [],
"postAttachCommands": [],
"postRestartCommands": [],
"preResetCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
"postResetCommands": [],
"toolchainPath": "/bin",
"toolchainPrefix": "arm-none-eabi",
"extensionPath": "/home/fenil/.vscode/extensions/marus25.cortex-debug-1.12.1",
"registerUseNaturalFormat": true,
"variableUseNaturalFormat": true,
"pvtVersion": "1.12.1",
"__sessionId": "1b9b17fc-5d0c-4c46-8558-992eaac6e020",
"pvtShowDevDebugOutput": "raw"
}
Reading symbols from /bin/arm-none-eabi-objdump --syms -C -h -w /home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf
Reading symbols from /bin/arm-none-eabi-nm --defined-only -S -l -C -p /home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf
Launching GDB: /bin/arm-none-eabi-gdb -q --interpreter=mi2
1-gdb-version
</code>
<code>Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage
"configuration": {
"name": "ST-Link Debug with Embedded Tools ",
"executable": "/home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf",
"cwd": "/home/fenil/Documents/code/TI_test",
"type": "cortex-debug",
"device": "STM32C031C6",
"serverpath": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.linux64_2.1.100.202310302101/tools/bin/ST-LINK_gdbserver",
"servertype": "stlink",
"interface": "swd",
"gdbTarget": "localhost",
"request": "launch",
"runToEntryPoint": "main",
"cmsisPack": "/home/fenil/Documents/code/TI_test//Keil.STM32C0xx_DFP.1.0.0.pack",
"svdFile": "/home/fenil/Documents/code/TI_test//STM32C0_svd/STM32C0_svd_V1.1//STM32C031.svd",
"stm32cubeprogrammer": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.linux64_2.1.100.202311100844/tools/bin/STM32_Programmer_CLI",
"showDevDebugOutput": "raw",
"armToolchainPath": "/bin",
"serverArgs": [
"-d",
"-v",
"-p",
"61234",
"-e"
],
"preRestartCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
"__configurationTarget": 6,
"gdbServerConsolePort": 55878,
"pvtAvoidPorts": [],
"chainedConfigurations": {
"enabled": false
},
"debuggerArgs": [],
"swoConfig": {
"enabled": false,
"decoders": [],
"cpuFrequency": 0,
"swoFrequency": 0,
"source": "probe"
},
"rttConfig": {
"enabled": false,
"decoders": []
},
"graphConfig": [],
"preLaunchCommands": [],
"postLaunchCommands": [],
"preAttachCommands": [],
"postAttachCommands": [],
"postRestartCommands": [],
"preResetCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
"postResetCommands": [],
"toolchainPath": "/bin",
"toolchainPrefix": "arm-none-eabi",
"extensionPath": "/home/fenil/.vscode/extensions/marus25.cortex-debug-1.12.1",
"registerUseNaturalFormat": true,
"variableUseNaturalFormat": true,
"pvtVersion": "1.12.1",
"__sessionId": "1b9b17fc-5d0c-4c46-8558-992eaac6e020",
"pvtShowDevDebugOutput": "raw"
}
Reading symbols from /bin/arm-none-eabi-objdump --syms -C -h -w /home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf
Reading symbols from /bin/arm-none-eabi-nm --defined-only -S -l -C -p /home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf
Launching GDB: /bin/arm-none-eabi-gdb -q --interpreter=mi2
1-gdb-version
</code>
Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage
"configuration": {
"name": "ST-Link Debug with Embedded Tools ",
"executable": "/home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf",
"cwd": "/home/fenil/Documents/code/TI_test",
"type": "cortex-debug",
"device": "STM32C031C6",
"serverpath": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.linux64_2.1.100.202310302101/tools/bin/ST-LINK_gdbserver",
"servertype": "stlink",
"interface": "swd",
"gdbTarget": "localhost",
"request": "launch",
"runToEntryPoint": "main",
"cmsisPack": "/home/fenil/Documents/code/TI_test//Keil.STM32C0xx_DFP.1.0.0.pack",
"svdFile": "/home/fenil/Documents/code/TI_test//STM32C0_svd/STM32C0_svd_V1.1//STM32C031.svd",
"stm32cubeprogrammer": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.linux64_2.1.100.202311100844/tools/bin/STM32_Programmer_CLI",
"showDevDebugOutput": "raw",
"armToolchainPath": "/bin",
"serverArgs": [
"-d",
"-v",
"-p",
"61234",
"-e"
],
"preRestartCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
"__configurationTarget": 6,
"gdbServerConsolePort": 55878,
"pvtAvoidPorts": [],
"chainedConfigurations": {
"enabled": false
},
"debuggerArgs": [],
"swoConfig": {
"enabled": false,
"decoders": [],
"cpuFrequency": 0,
"swoFrequency": 0,
"source": "probe"
},
"rttConfig": {
"enabled": false,
"decoders": []
},
"graphConfig": [],
"preLaunchCommands": [],
"postLaunchCommands": [],
"preAttachCommands": [],
"postAttachCommands": [],
"postRestartCommands": [],
"preResetCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
"postResetCommands": [],
"toolchainPath": "/bin",
"toolchainPrefix": "arm-none-eabi",
"extensionPath": "/home/fenil/.vscode/extensions/marus25.cortex-debug-1.12.1",
"registerUseNaturalFormat": true,
"variableUseNaturalFormat": true,
"pvtVersion": "1.12.1",
"__sessionId": "1b9b17fc-5d0c-4c46-8558-992eaac6e020",
"pvtShowDevDebugOutput": "raw"
}
Reading symbols from /bin/arm-none-eabi-objdump --syms -C -h -w /home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf
Reading symbols from /bin/arm-none-eabi-nm --defined-only -S -l -C -p /home/fenil/Documents/code/TI_test/out/build/CustomPreset/TI_Test.elf
Launching GDB: /bin/arm-none-eabi-gdb -q --interpreter=mi2
1-gdb-version
Launch.json
<code>{
"version": "0.2.0",
"configurations": [
{
"name": "ST-Link Debug with Embedded Tools ",
"executable": "${workspaceFolder}/out/build/CustomPreset/TI_Test.elf",
"cwd": "${workspaceFolder}",
"type": "cortex-debug",
"device": "STM32C031C6",
"serverpath": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.linux64_2.1.100.202310302101/tools/bin/ST-LINK_gdbserver",
"servertype": "stlink",
"interface": "swd",
"gdbTarget": "localhost",
"request": "launch",
"runToEntryPoint": "main",
"cmsisPack": "${workspaceFolder}//Keil.STM32C0xx_DFP.1.0.0.pack",
"svdFile": "${workspaceFolder}//STM32C0_svd/STM32C0_svd_V1.1//STM32C031.svd",
"stm32cubeprogrammer": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.linux64_2.1.100.202311100844/tools/bin/STM32_Programmer_CLI",
"showDevDebugOutput": "raw",
"armToolchainPath": "/bin",
"serverArgs": [
"-d",
"-v",
"-p",
"61234",
"-e"
],
"preRestartCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
}
]
}
</code>
<code>{
"version": "0.2.0",
"configurations": [
{
"name": "ST-Link Debug with Embedded Tools ",
"executable": "${workspaceFolder}/out/build/CustomPreset/TI_Test.elf",
"cwd": "${workspaceFolder}",
"type": "cortex-debug",
"device": "STM32C031C6",
"serverpath": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.linux64_2.1.100.202310302101/tools/bin/ST-LINK_gdbserver",
"servertype": "stlink",
"interface": "swd",
"gdbTarget": "localhost",
"request": "launch",
"runToEntryPoint": "main",
"cmsisPack": "${workspaceFolder}//Keil.STM32C0xx_DFP.1.0.0.pack",
"svdFile": "${workspaceFolder}//STM32C0_svd/STM32C0_svd_V1.1//STM32C031.svd",
"stm32cubeprogrammer": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.linux64_2.1.100.202311100844/tools/bin/STM32_Programmer_CLI",
"showDevDebugOutput": "raw",
"armToolchainPath": "/bin",
"serverArgs": [
"-d",
"-v",
"-p",
"61234",
"-e"
],
"preRestartCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
}
]
}
</code>
{
"version": "0.2.0",
"configurations": [
{
"name": "ST-Link Debug with Embedded Tools ",
"executable": "${workspaceFolder}/out/build/CustomPreset/TI_Test.elf",
"cwd": "${workspaceFolder}",
"type": "cortex-debug",
"device": "STM32C031C6",
"serverpath": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.stlink-gdb-server.linux64_2.1.100.202310302101/tools/bin/ST-LINK_gdbserver",
"servertype": "stlink",
"interface": "swd",
"gdbTarget": "localhost",
"request": "launch",
"runToEntryPoint": "main",
"cmsisPack": "${workspaceFolder}//Keil.STM32C0xx_DFP.1.0.0.pack",
"svdFile": "${workspaceFolder}//STM32C0_svd/STM32C0_svd_V1.1//STM32C031.svd",
"stm32cubeprogrammer": "/opt/st/stm32cubeide_1.14.0/plugins/com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.linux64_2.1.100.202311100844/tools/bin/STM32_Programmer_CLI",
"showDevDebugOutput": "raw",
"armToolchainPath": "/bin",
"serverArgs": [
"-d",
"-v",
"-p",
"61234",
"-e"
],
"preRestartCommands": [
"load",
"enable breakpoint",
"monitor reset"
],
}
]
}
CMakeLists.txt
<code>make_minimum_required(VERSION 3.24)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(TI_Test LANGUAGES C CXX ASM)
add_executable(TI_Test.elf )
# Compiler optimization flags
target_compile_features(TI_Test.elf PRIVATE cxx_std_20)
target_compile_options(TI_Test.elf PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(TI_Test.elf PRIVATE -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft -g3 -ggdb)
target_compile_options(TI_Test.elf PRIVATE -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions)
target_compile_options(TI_Test.elf PRIVATE -specs=nosys.specs)
target_compile_options(TI_Test.elf PRIVATE -specs=nano.specs )
target_compile_options(TI_Test.elf PRIVATE -O0) # Enable size optimization
#target_compile_options(TI_Test.elf PRIVATE -flto) # Enable link-time optimization
target_compile_definitions(TI_Test.elf PRIVATE STM32C031xx)
target_compile_definitions(TI_Test.elf PRIVATE DEBUG)
# Linker optimization flags
target_link_options(TI_Test.elf PRIVATE -T${CMAKE_SOURCE_DIR}/STM32C031C6TX_FLASH.ld)
target_link_options(TI_Test.elf PRIVATE -Wl,--print-memory-usage)
target_link_options(TI_Test.elf PRIVATE -Wl,--print-gc-sections)
target_link_options(TI_Test.elf PRIVATE -Wl,--entry=Reset_Handler)
target_link_options(TI_Test.elf PRIVATE -specs=nano.specs )
target_link_options(TI_Test.elf PRIVATE -specs=nosys.specs)
target_link_options(TI_Test.elf PRIVATE -Wl,--strip-all) # Strip all symbols
target_link_options(TI_Test.elf PRIVATE -Wl,--gc-sections) # Garbage collect unused sections
#target_link_options(TI_Test.elf PRIVATE -flto) # Enable link-time optimization
target_sources(TI_Test.elf PRIVATE
./main.cpp
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Source/Templates/system_stm32c0xx.c
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Source/Templates/gcc/startup_stm32c031xx.s
)
target_include_directories(TI_Test.elf PRIVATE
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Include
mcu-stm32/bsp/Drivers/CMSIS/Include
mcu-stm32/bsp/Drivers/STM32C0xx_HAL_Driver/Inc
mcu-stm32/bsp/Inc
)
# Generate .map file
set_target_properties(TI_Test.elf PROPERTIES LINK_FLAGS "-Wl,-Map=${CMAKE_BINARY_DIR}/TI_Test.map")
# Generate .hex file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:TI_Test.elf> ${CMAKE_BINARY_DIR}/TI_Test.hex
COMMENT "Generating .hex file"
)
# Generate .bin file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:TI_Test.elf> ${CMAKE_BINARY_DIR}/TI_Test.bin
COMMENT "Generating .bin file"
)
# Generate .lst file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJDUMP} -S $<TARGET_FILE:TI_Test.elf> > ${CMAKE_BINARY_DIR}/TI_Test.lst
COMMENT "Generating .lst file"
)
</code>
<code>make_minimum_required(VERSION 3.24)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(TI_Test LANGUAGES C CXX ASM)
add_executable(TI_Test.elf )
# Compiler optimization flags
target_compile_features(TI_Test.elf PRIVATE cxx_std_20)
target_compile_options(TI_Test.elf PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(TI_Test.elf PRIVATE -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft -g3 -ggdb)
target_compile_options(TI_Test.elf PRIVATE -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions)
target_compile_options(TI_Test.elf PRIVATE -specs=nosys.specs)
target_compile_options(TI_Test.elf PRIVATE -specs=nano.specs )
target_compile_options(TI_Test.elf PRIVATE -O0) # Enable size optimization
#target_compile_options(TI_Test.elf PRIVATE -flto) # Enable link-time optimization
target_compile_definitions(TI_Test.elf PRIVATE STM32C031xx)
target_compile_definitions(TI_Test.elf PRIVATE DEBUG)
# Linker optimization flags
target_link_options(TI_Test.elf PRIVATE -T${CMAKE_SOURCE_DIR}/STM32C031C6TX_FLASH.ld)
target_link_options(TI_Test.elf PRIVATE -Wl,--print-memory-usage)
target_link_options(TI_Test.elf PRIVATE -Wl,--print-gc-sections)
target_link_options(TI_Test.elf PRIVATE -Wl,--entry=Reset_Handler)
target_link_options(TI_Test.elf PRIVATE -specs=nano.specs )
target_link_options(TI_Test.elf PRIVATE -specs=nosys.specs)
target_link_options(TI_Test.elf PRIVATE -Wl,--strip-all) # Strip all symbols
target_link_options(TI_Test.elf PRIVATE -Wl,--gc-sections) # Garbage collect unused sections
#target_link_options(TI_Test.elf PRIVATE -flto) # Enable link-time optimization
target_sources(TI_Test.elf PRIVATE
./main.cpp
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Source/Templates/system_stm32c0xx.c
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Source/Templates/gcc/startup_stm32c031xx.s
)
target_include_directories(TI_Test.elf PRIVATE
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Include
mcu-stm32/bsp/Drivers/CMSIS/Include
mcu-stm32/bsp/Drivers/STM32C0xx_HAL_Driver/Inc
mcu-stm32/bsp/Inc
)
# Generate .map file
set_target_properties(TI_Test.elf PROPERTIES LINK_FLAGS "-Wl,-Map=${CMAKE_BINARY_DIR}/TI_Test.map")
# Generate .hex file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:TI_Test.elf> ${CMAKE_BINARY_DIR}/TI_Test.hex
COMMENT "Generating .hex file"
)
# Generate .bin file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:TI_Test.elf> ${CMAKE_BINARY_DIR}/TI_Test.bin
COMMENT "Generating .bin file"
)
# Generate .lst file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJDUMP} -S $<TARGET_FILE:TI_Test.elf> > ${CMAKE_BINARY_DIR}/TI_Test.lst
COMMENT "Generating .lst file"
)
</code>
make_minimum_required(VERSION 3.24)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(TI_Test LANGUAGES C CXX ASM)
add_executable(TI_Test.elf )
# Compiler optimization flags
target_compile_features(TI_Test.elf PRIVATE cxx_std_20)
target_compile_options(TI_Test.elf PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(TI_Test.elf PRIVATE -mcpu=cortex-m0plus -mthumb -mfloat-abi=soft -g3 -ggdb)
target_compile_options(TI_Test.elf PRIVATE -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions)
target_compile_options(TI_Test.elf PRIVATE -specs=nosys.specs)
target_compile_options(TI_Test.elf PRIVATE -specs=nano.specs )
target_compile_options(TI_Test.elf PRIVATE -O0) # Enable size optimization
#target_compile_options(TI_Test.elf PRIVATE -flto) # Enable link-time optimization
target_compile_definitions(TI_Test.elf PRIVATE STM32C031xx)
target_compile_definitions(TI_Test.elf PRIVATE DEBUG)
# Linker optimization flags
target_link_options(TI_Test.elf PRIVATE -T${CMAKE_SOURCE_DIR}/STM32C031C6TX_FLASH.ld)
target_link_options(TI_Test.elf PRIVATE -Wl,--print-memory-usage)
target_link_options(TI_Test.elf PRIVATE -Wl,--print-gc-sections)
target_link_options(TI_Test.elf PRIVATE -Wl,--entry=Reset_Handler)
target_link_options(TI_Test.elf PRIVATE -specs=nano.specs )
target_link_options(TI_Test.elf PRIVATE -specs=nosys.specs)
target_link_options(TI_Test.elf PRIVATE -Wl,--strip-all) # Strip all symbols
target_link_options(TI_Test.elf PRIVATE -Wl,--gc-sections) # Garbage collect unused sections
#target_link_options(TI_Test.elf PRIVATE -flto) # Enable link-time optimization
target_sources(TI_Test.elf PRIVATE
./main.cpp
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Source/Templates/system_stm32c0xx.c
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Source/Templates/gcc/startup_stm32c031xx.s
)
target_include_directories(TI_Test.elf PRIVATE
mcu-stm32/bsp/Drivers/CMSIS/Device/ST/STM32C0xx/Include
mcu-stm32/bsp/Drivers/CMSIS/Include
mcu-stm32/bsp/Drivers/STM32C0xx_HAL_Driver/Inc
mcu-stm32/bsp/Inc
)
# Generate .map file
set_target_properties(TI_Test.elf PROPERTIES LINK_FLAGS "-Wl,-Map=${CMAKE_BINARY_DIR}/TI_Test.map")
# Generate .hex file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:TI_Test.elf> ${CMAKE_BINARY_DIR}/TI_Test.hex
COMMENT "Generating .hex file"
)
# Generate .bin file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:TI_Test.elf> ${CMAKE_BINARY_DIR}/TI_Test.bin
COMMENT "Generating .bin file"
)
# Generate .lst file
add_custom_command(TARGET TI_Test.elf POST_BUILD
COMMAND ${CMAKE_OBJDUMP} -S $<TARGET_FILE:TI_Test.elf> > ${CMAKE_BINARY_DIR}/TI_Test.lst
COMMENT "Generating .lst file"
)
I have used CubeIDE to debug the same Nucleo-C031C6 board, and it works perfectly without any issues.