【问题标题】:Debugging STM32 using QT Creator使用 QT Creator 调试 STM32
【发布时间】:2018-07-27 12:32:31
【问题描述】:

我决定尝试使用带有 ARM GCC 工具链的 Qt Creator。我设法设置了一个 QBS 项目,它已构建并且固件已成功下载。另外,我在板上使用STM32F3-Discovery和STM32F303VCT。但我无法调试项目,原因如下:

  1. 断点不起作用。过程不会停止。
  2. 我无法进入源文件,只能在反汇编程序中。当我尝试进入 Main.c 时,Qt Creator 切换到 Disassembler 本身。

如何设置调试器以查看寄存器、添加 Watch、设置和清除寄存器中的位,例如在 Keil 或 Eclipse 中?那么,有人可以帮忙吗?谢谢。 附言这是我的 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];
    }
}

}

【问题讨论】:

    标签: debugging qt-creator stm32 bare-metal


    【解决方案1】:

    显然,您为调试模式配置了错误的优化设置。变量 cpp.debugInformation 在编译器启动时设置,基于在 QtCreator 中选择的编译器模式。我会替换代码

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

    到下一个:

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

    我的这段代码运行良好。

    【讨论】:

    • 谢谢,但没有任何改变。
    • 更多想法?似乎 GDB 不能正常工作。我有 GDB 8.0
    • 请检查两个版本(发布和调试)的输出文件大小。我认为您的调试版本无法正常工作
    • 你的意思是 .bg 文件?
    • 我的意思是输出 .hex 文件和 .elf 文件。最后是调试最重要的一点
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-12
    • 2019-10-04
    • 2018-06-13
    • 1970-01-01
    • 2010-11-10
    • 2018-05-26
    相关资源
    最近更新 更多