简体   繁体   中英

Debugging STM32 using QT Creator

I'v decided to try Qt Creator with ARM GCC toolchain. I'v managed to setup a QBS project, it's built and a firmware is downloaded successfully. In addition, I use STM32F3-Discovery with STM32F303VCT on the board. But I can't debug the project because of following reasons:

  1. Breakpoints don't work. Process don't stop.
  2. I can't step in source files, only in Disassembler. Qt Creator switch to Disassembler itself, when I'm trying to step in Main.c.

How can I setup the Debugger to see registers, add Watch, set and clear bits in registers manually like in Keil or Eclipse? So, could anybody help? Thanks. PS Here is my Start.qbs

import qbs

Product
{
       type: ["application", "flash"]
       Depends { name: "cpp" }

       cpp.defines: ["STM32F30X_LD_VL"]
       cpp.positionIndependentCode: false
       cpp.enableExceptions: false
       cpp.executableSuffix: ".elf"
cpp.driverFlags:
[
    "-mthumb",
    "-mcpu=cortex-m4",
    "-mfloat-abi=soft",
    "-fno-strict-aliasing",
    "-g3",
    "-Wall",
    "-mfpu=vfp",
    "-Og",
    "-flto",
]

cpp.commonCompilerFlags:
[
    "-fdata-sections",
    "-ffunction-sections",
    "-fno-inline",
    "-std=c99",
    "-flto"
]

cpp.linkerFlags:
[
    "-specs=nano.specs",
    "--start-group",
    "--gc-sections",
    "-T" + path + "/STM32F303VCTx_FLASH.ld",
    "-lnosys",
    "-lgcc",
    "-lc",
    "-lstdc++",
    "-lm"
]

cpp.includePaths:
[
    "Inc",
    "Drivers/CMSIS/Include",
    "Drivers/CMSIS/Device/ST/STM32F3xx/Include",
    "Drivers/STM32F3xx_HAL_Driver/Inc"
]

files:
[
    "Inc/*.h",
    "Drivers/CMSIS/Include/*.h",
    "Drivers/CMSIS/Device/ST/STM32F3xx/Include/*.h",
    "Drivers/STM32F3xx_HAL_Driver/Inc/*.h",
    "Drivers/STM32F3xx_HAL_Driver/Src/*.c",
    "Src/*.c",
    "*.s"
]

Properties
{
    condition: qbs.buildVariant === "debug"
    cpp.defines: outer.concat(["DEBUG=1"])
    cpp.debugInformation: true
    cpp.optimization: "none"
}

Properties
{
    condition: qbs.buildVariant === "release"
    cpp.debugInformation: false
    cpp.optimization: "small"
}

Rule
{
    inputs: ["application"]

    Artifact
    {
        filePath: project.path + "/debug/bin/" + input.baseName + ".hex"
        fileTags: "flash"
    }

    prepare:
    {
        var sizePath = "C:/Users/kushnir/AppData/Roaming/gcc-arm-none-eabi-7-2017-q4-major-win32/bin/arm-none-eabi-size.exe";
        var objcopyPath = "C:/Users/kushnir/AppData/Roaming/gcc-arm-none-eabi-7-2017-q4-major-win32/bin/arm-none-eabi-objcopy.exe";
        var configStlinkPath = "C:/openocd-0.10.0/scripts/interface/stlink-v2-1.cfg";
        var configStm32Path = "C:/openocd-0.10.0/scripts/target/stm32f3x.cfg";
        var flashPath = "C:/openocd-0.10.0/bin-x64/openocd.exe";

        var argsSize = [input.filePath];
        var argsObjcopy = ["-O", "ihex", input.filePath, output.filePath];

       var argsFlashing =
        [
            "-f", configStlinkPath,
            "-f", configStm32Path,
            "-c", "init",
            "-c", "halt",
            "-c", "flash erase_sector 0 0 127",
            "-c", "reset",
            "-c", "halt",
            "-c", "flash write_image " + input.filePath,
            "-c", "verify_image " + input.filePath,
            "-c", "reset",
            "-c", "exit"
        ];

        var cmdSize = new Command(sizePath, argsSize);
        var cmdObjcopy = new Command(objcopyPath, argsObjcopy);
        var cmdFlash = new Command(flashPath, argsFlashing);

        cmdSize.description = "Size of sections:";
        cmdSize.highlight = "linker";

        cmdObjcopy.description = "convert to bin...";
        cmdObjcopy.highlight = "linker";

        cmdFlash.description = "download firmware to uC...";
        cmdFlash.highlight = "linker";

        return [cmdSize, cmdObjcopy, cmdFlash];
    }
}

}

Apparently, you have incorrectly configured optimization settings for the Debug mode. The variable cpp.debugInformation is set when the compiler starts, based on which compiler mode was selected in the QtCreator. I would replace the code

Properties
{
    condition: qbs.buildVariant === "debug"
    cpp.defines: outer.concat(["DEBUG=1"])
    cpp.debugInformation: true
    cpp.optimization: "none"
}

Properties
{
    condition: qbs.buildVariant === "release"
    cpp.debugInformation: false
    cpp.optimization: "small"
}

to the next:

Properties {
    // Debug
    condition: cpp.debugInformation
    cpp.defines: outer.concat(["DEBUG=1"])
    cpp.optimization: "none"
}
// Release
cpp.optimization: "small"

I have this code works very well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM