Is there a possibility to read program counter via ST-Link or J-Link without causing a reset on STM32F103 devices with RDP active?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-26 1:59 AM
On a serial product after a firmware update, there are some sporadic cases, where we get a hang up situation. It would be very helpful to know where exactly the program is stuck. According to ES0346 Rev. 6 chapter 2.8 it is possible to access program counter even with RDP set. How can I exactly read the value with CubeProgrammer + ST-Link (or alternatively with J-Link).
- Labels:
-
ST-Link
-
STM32F1 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-26 5:26 AM
There is, but I have never tested it myself
The gdb server supports -g, --attach
"This attaches to the running target. Attach is aimed to be used to connect to a running program in the device without doing a reset or downloading a new program."
How this works with a stuck MCU i am unsure but it is the place to start
Breg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-26 6:52 AM
If you're using STM32CubeIDE:
To debug your program without downloading it:
Go to Debug Configurations... -> Startup -> select load image -> Edit... -> uncheck Download
To debug without resetting the device:
Go to Debug Configurations... -> Debugger -> in Reset Behavior, select "None"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-26 7:00 AM
Try to hotplug attach with a debugger. In gdb "info regs" will give you the registers, or to only read the PC " p $pc". Most important is, can you attach? Second important probaby ist that you do it manually and not rely on some IDE to show you the values. Probably that wil step into some read protection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-26 9:25 AM
Instrument the obvious places code goes to die. Like the HardFault_Handler and Error_Handler, and anywhere you have unbounded while loops, so you're not working blind.
Perhaps check what routines are interrupted by the SysTick, see if it is stuck somewhere, or off in some unexpected code paths.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-27 5:30 AM
Thank you for your reply, I tried to use the CUBE programmer with command line interface instead of gdb, as this seemed to be the easier way with the call STM32_Programmer_CLI.exe -c port=SWD HOTPLUG -coreReg
which should do the same. But I allways get a PC value of 0xFFFFFFFE, even if I connect a device running in normal programm execution. Perhaps I will try the gdb-server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-27 5:31 AM
I use IAR, but I will try a similar path there,
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-28 2:48 AM
I will do these things, but as a first step, I would like to find out, where exactly the code hangs. So I tried to get the program counter with:
STM32_Programmer_CLI.exe -c port=SWD mode=HOTPLUG -coreReg PC
this gives the register values, and other values like SP make sense, but PC is always FFFFFFFE?!
Do you have some hint how to really get the PC?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-28 10:04 AM
The picture stille says "Software reset". Reset would destroy PC.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-10-28 5:13 PM
To fix this you'll have to change the code. If you can debug it in a secure laboratory, consider turning off RDP while you're debugging.
