Marus / cortex-debug

Visual Studio Code extension for enhancing debug capabilities for Cortex-M Microcontrollers
MIT License
985 stars 238 forks source link

Peripheral Register/SVD Error #1033

Open dadede opened 1 month ago

dadede commented 1 month ago

Hello,

I am using the cortex-debug and peripheral-viewer to debug a STM32F3 Discovery board. I can confirm that cortex-debug is working, however it seems there is a problem reading the registers using St-Link or OpenOCD.

The code is just a basic PWM timer (everything working as expected with the code) but I cannot seem to read the value of the TIM1 CNT register. Or other peripheral registers for that matter. Basic search for similar issues in the repo keep pointing to SVD not updating registers so I tried to figure it out to no avail.

In the peripheral viewer, the register value randomly changes when I interrupt and try -data-read-memory-bytes 0x40010800 16 (also tried 8, 10, 20) but I keep getting the errors as shown from the debug console below.

Now, it could be a problem with something else or the SVD file and if it is I am not sure what the problem could be. I appreciate any help with this, thank you.

Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage
Reading symbols from /home/dnld/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/13.2.1-1.1.1/.content/bin/arm-none-eabi-objdump --syms -C -h -w /home/dnld/embedded/ppm/build/ppm.elf
Reading symbols from /home/dnld/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/13.2.1-1.1.1/.content/bin/arm-none-eabi-nm --defined-only -S -l -C -p /home/dnld/embedded/ppm/build/ppm.elf
Launching GDB: /usr/bin/arm-none-eabi-gdb -q --interpreter=mi2
    IMPORTANT: Set "showDevDebugOutput": "raw" in "launch.json" to see verbose GDB transactions here. Very helpful to debug issues or report problems
Launching gdb-server: /usr/bin/st-util -p 50000 --no-reset
    Please check TERMINAL tab (gdb-server) for output from /usr/bin/st-util
Finished reading symbols from objdump: Time: 17 ms
Finished reading symbols from nm: Time: 26 ms
Output radix now set to decimal 10, hex a, octal 12.
Input radix now set to decimal 10, hex a, octal 12.
main () at Core/Src/main.c:99
99    while (1)
Program stopped, probably due to a reset and/or halt issued by debugger
Note: automatically using hardware breakpoints for read-only addresses.

Temporary breakpoint 1, main () at Core/Src/main.c:76
76    HAL_Init();
Failed to update peripheral TIM1: Error: peripheral-viewer: readMemory failed @ 0x40012c00 for 100 bytes: CodeExpectedError: Busy, session=13e176fc-855e-4858-a8d4-08018c1d1dd1
interrupt
{"output":"","token":27,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[]}}

Program
 received signal SIGTRAP, Trace/breakpoint trap.
main () at Core/Src/main.c:99
99    while (1)
-data-read-memory-bytes 0x40012c00 20
{"output":"","token":34,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["memory",[[["begin","0x40012c00"],["offset","0x00000000"],["end","0x40012c14"],["contents","010000000000000000000000000000001f000300"]]]]]}}
-data-read-memory-bytes 0x40012c00 16
{"output":"","token":37,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["memory",[[["begin","0x40012c00"],["offset","0x00000000"],["end","0x40012c10"],["contents","01000000000000000000000000000000"]]]]]}}
Failed to update peripheral TIM1: Error: peripheral-viewer: readMemory failed @ 0x40012c00 for 100 bytes: CodeExpectedError: Busy, session=13e176fc-855e-4858-a8d4-08018c1d1dd1

Program
 received signal SIGTRAP, Trace/breakpoint trap.
main () at Core/Src/main.c:99
99    while (1)
Attempt to use a type name as an expression.

Here is the output of the GDB server terminal...

[2024-07-24T02:57:50.103Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session connected. You can switch to "DEBUG CONSOLE" to see GDB interactions.
/usr/bin/st-util -p 50000 --no-reset
st-util 1.8.0-32-g32ce4bf
2024-07-23T22:57:50 INFO common.c: STM32F302_F303_358: 40 KiB SRAM, 256 KiB flash in at least 2 KiB pages.
2024-07-23T22:57:50 INFO gdb-server.c: Listening at *:50000...
2024-07-23T22:57:50 INFO common.c: STM32F302_F303_358: 40 KiB SRAM, 256 KiB flash in at least 2 KiB pages.
2024-07-23T22:57:50 INFO gdb-server.c: Found 6 hw breakpoint registers
2024-07-23T22:57:50 INFO gdb-server.c: GDB connected.
2024-07-23T22:57:51 INFO gdb-server.c: Found 6 hw breakpoint registers
2024-07-23T22:57:51 INFO common.c: STM32F302_F303_358: 40 KiB SRAM, 256 KiB flash in at least 2 KiB pages.
2024-07-23T22:57:51 INFO gdb-server.c: flash_erase: block 08000000 -> 2000
2024-07-23T22:57:51 INFO gdb-server.c: flash_erase: page 08000000
2024-07-23T22:57:51 INFO gdb-server.c: flash_erase: page 08000800
2024-07-23T22:57:51 INFO gdb-server.c: flash_erase: page 08001000
2024-07-23T22:57:51 INFO gdb-server.c: flash_erase: page 08001800
2024-07-23T22:57:51 INFO flash_loader.c: Starting Flash write for VL/F0/F3/F1_XL
2024-07-23T22:57:51 INFO flash_loader.c: Successfully loaded flash loader in sram
2024-07-23T22:57:51 INFO flash_loader.c: Clear DFSR
2024-07-23T22:57:51 INFO gdb-server.c: flash_do: block 08000000 -> 2000
2024-07-23T22:57:51 INFO gdb-server.c: flash_do: page 08000000
2024-07-23T22:57:51 INFO gdb-server.c: flash_do: page 08000800
2024-07-23T22:57:51 INFO gdb-server.c: flash_do: page 08001000
2024-07-23T22:57:51 INFO gdb-server.c: flash_do: page 08001800
2024-07-23T22:57:52 INFO gdb-server.c: Found 6 hw breakpoint registers

image

launch.json

{
    "configurations": [
        {
            "name": "STlink launch",
            "cwd": "${workspaceRoot}",
            "executable": "${workspaceRoot}/build/ppm.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "stutil",
            "device": "STM32F303VC",
            "interface": "swd",
            // "runToEntryPoint": "main",
            "runToMain": true, 
            "preLaunchTask": "Build all",
            "svdPath": "${workspaceFolder}/STM32F303.svd",
            "swoConfig": {}
        },
        {
            "name": "STlink attach",
            "cwd": "${workspaceRoot}",
            "executable": "${workspaceRoot}/build/ppm.elf",
            "request": "attach",
            "type": "cortex-debug",
            "servertype": "stutil",
            "device": "STM32F303VC",
            "interface": "swd",
            // "runToEntryPoint": "main",
            "runToMain": true, 
            "preLaunchTask": "Build all",
            "svdPath": "${workspaceFolder}/STM32F303.svd",
            "swoConfig": {}
        },
 // {
        //     "showDevDebugOutput": "parsed",
        //     "cwd": "${workspaceRoot}",
        //     "executable": "./build/ppm.elf",
        //     "name": "Debug STM32",
        //     "request": "launch",
        //     "type": "cortex-debug",
        //     "servertype": "openocd",
        //     "preLaunchTask": "Build STM",
        //     "device": "stm32f303xc.s",
        //     "configFiles": [
        //         "openocd.cfg"
        //     ]
        // },
        // {
        //     "showDevDebugOutput": "parsed",
        //     "cwd": "${workspaceRoot}",
        //     "executable": "./build/ppm.elf",
        //     "name": "Attach STM32",
        //     "request": "attach",
        //     "type": "cortex-debug",
        //     "servertype": "openocd",
        //     "preLaunchTask": "Build STM",
        //     "device": "stm32f303xc.s",
        //     "configFiles": [
        //         "openocd.cfg"
        //     ]
        // }

    ]
}

settings.json

{
    // "cortex-debug.armToolchainPath": "/home/dnld/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/13.2.1-1.1.1/.content/bin",
    "cortex-debug.gdbPath": "/usr/bin/arm-none-eabi-gdb",
    "cortex-debug.openocdPath": "/usr/bin/openocd",
    "cortex-debug.stutilPath": "/usr/bin/st-util",
    "cortex-debug.armToolchainPath": "/home/dnld/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/13.2.1-1.1.1/.content/bin",
}
haneefdm commented 1 month ago

Several things

For now, leave this issue on this repo, but provide better info. Please don't assume were know what your code/device looks like. And, what buttons, menu items, etc. you were pressing at the time.

In the peripheral viewer, the register value randomly changes when I interrupt and try -data-read-memory-bytes 0x40010800 16 (also tried 8, 10, 20) but I keep getting the errors as shown from the debug console below.

I don't even know what that means.