How to see RAM contents of a running STM32 MCU without resetting it?

336 Views Asked by At

I have developed a project using IAR EW for ARM and an STM32 MCU. For an issue, I need to inspect the RAM contents of a running device. How can I do that without resetting the device? because with the reset RAM will be re-initialized and I will lose the data.

2

There are 2 best solutions below

1
Clifford On

Reset does not modify or reinitialise the SRAM. That occurs in the runtime start-up. The on-chip SRAM will not be reinitialised unless you let the run-time start-up code run (which executes between reset and main()).

So all you need do is set a breakpoint at the reset vector and maintain power and you can connect the debugger and let it reset. It will halt before anything writes to the SRAM, the content of which will be preserved through a reset so long as power is maintained.

The reset vector is stored at offset 0x0004 from the start of the vector table. The address of that will depend on whether you are using ROM, Flash or SRAM boot mode (SRAM boot would of course be unhelpful in this case). It will also be the symbol __reset in your link-map. Anyhow you can set the symbol or the absolute address as a breakpoint before connection of the debugger, and it will halt before modifying SRAM.

Alternatively your debugger can almost certainly be configured to connect without asserting a reset (a long time since I have used EWB so I can't tell you exactly how - that is what the user manual is for), which would preserve not only the SRAM, but also the peripheral register states, the NVIC and core registers likely to be essential in many debugging situations. That said, you mention in a comment that you tried that without success. I too have had issues "hot connecting" to STM32 - I have never needed the feature sufficiently to resolve that issue, and assumed it was a misconfiguration, but perhaps it is a "feature"?

Ultimately the best solution is to be running with the debugger connected from the get go, so you can simply halt the processor to inspect it's state, or in mast cases, view the memory "Luce" while the processor continues to run.

2
0___________ On
  1. Reset does not purge RAM.

If you want to connect to uC but you want it to continue running then you need to connect to the running target.

It is very easy in Keil and Eclipse based IDEs. IAR - you need to find option to disable loading program at startup and resetting the uC.

For Keil:

enter image description here enter image description here enter image description here