Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using debugger for code run in RAM (SDRAM) #400

Closed
ch1648 opened this issue Feb 16, 2021 · 3 comments
Closed

Using debugger for code run in RAM (SDRAM) #400

ch1648 opened this issue Feb 16, 2021 · 3 comments
Assignees
Labels

Comments

@ch1648
Copy link

ch1648 commented Feb 16, 2021

Currently debugger issues Reset command after loading code to device.
This does not work to debug application loaded and run in RAM (SDRAM).
Because the Jlink Reset command will reinit the SDRAM and erase code loaded to RAM (SDRAM)

Is it possible to add a configuration in launch.json to specify an application run in RAM and thus will issue Reset/Halt command first and then load the code.

I added the following postLaunchCommands and it seems work around the issue for now, but this will need to download the code twice.

        "postLaunchCommands": [
            "monitor clrbp",
            "monitor reset",
            "monitor halt",
            "monitor regs",
            "file /mnt/c/sandbox/myapp.elf",
            "load",
            "monitor halt",
            "tb main",
       ],
@Marus Marus added the bug label Feb 17, 2021
@Marus Marus self-assigned this Feb 17, 2021
@beg0
Copy link

beg0 commented Jun 22, 2021

Hi ch1648,

I had the same issue. I resolved the issue by forcing launch commands in launch.json

If using openocd and a ST-Link debug probe, I add the following:

{
           // ....
           // other config in your launch.json
          
            "overrideLaunchCommands": [
                "-interpreter-exec console \"monitor reset halt\"",
                "-target-download",
               // "-interpreter-exec console \"monitor reset halt\"",
                "-enable-pretty-printing",
            ],
}

If you are using a JLink probe, you probably should use:

{
           // ....
           // other config in your launch.json


            "overrideLaunchCommands": [
                "-interpreter-exec console \"monitor halt\"",
                "-interpreter-exec console \"monitor reset\"",
                "-target-download",
               // "-interpreter-exec console \"monitor reset\"",
                "-enable-pretty-printing",
            ],
}

Note that commands are not "magic", it's the content of the launchCommand() from https://github.com/Marus/cortex-debug/blob/master/src/jlink.ts#L40, but we commented the second "reset" command (the one which actually is reseting the SRAM).

By the way, thank you @Marus and al. to make the Cortex-debug extension and to allow it to be so versatile and so powerful. That allows to overcome issues in most unusual situations.

@haneefdm
Copy link
Collaborator

With various devices and gdb-servers the definition of reset is complicated. With OpenOCD, it defines a convention -- see here. As you can see (in links below) there are so many variations of a reset, the device vendor provides scripts on how a reset happens and this is not uniform. Doing a reset may or may-not reset peripherals. We don't know. Dual/multi processors are even more fun :-)

http://openocd.org/doc/html/General-Commands.html#resetcommand
https://www.segger.com/downloads/jlink/UM08001

What we try to do is to do a 'reset & halt' (together if possible) before programming. In case the MCU is stuck in an exception handler, it will be freed.

Next is programming, which may use the MCU itself to do the programming (usually in chunks) and potentially leave the SP, PC in a random state.

So, we need a second reset to put things back into a known state (hopefully) and run YOUR program

This recipe generally works for most people but when it doesn't then override.... commands to the rescue. I was (partially) the reason why we introduced those commands.

@ch1648
Copy link
Author

ch1648 commented Jun 23, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants