Issue with debugging in Visual Studio Code for STM32 using Cotex-Debug extension`

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật