Access the PC register through ST-Link V2?

Post here first, or if you can't find a relevant section!
tiger762
Posts: 29
Joined: Tue Jan 26, 2016 11:40 pm

Access the PC register through ST-Link V2?

Post by tiger762 » Mon Feb 12, 2018 9:28 pm

I have an stm32f103 (LQFP, $2 Ebay module) that sometimes drives off into the woods. I have a generic/clone ST-Link V2 programmer attached. I have tried to step through an ELF using st-util / gdb. Always flaky behavior.

I really just need to know where in the code it gets hung up. Is there a simple way to get the PC? Thanks in advance.

User avatar
RogerClark
Posts: 7680
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Access the PC register through ST-Link V2?

Post by RogerClark » Mon Feb 12, 2018 10:42 pm

I think you have to use OpenOCD and GDB to do that

dannyf
Posts: 228
Joined: Wed May 11, 2016 4:29 pm

Re: Access the PC register through ST-Link V2?

Post by dannyf » Mon Feb 12, 2018 11:08 pm

Why couldn't you just step through the code?

zmemw16
Posts: 1674
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Access the PC register through ST-Link V2?

Post by zmemw16 » Mon Feb 12, 2018 11:19 pm

one of the side effects of stepping through code in debug is that the behaviour will change.
the trick of how to interperet is the problem and the realisation of what is just the problem :D

srp

tiger762
Posts: 29
Joined: Tue Jan 26, 2016 11:40 pm

Re: Access the PC register through ST-Link V2?

Post by tiger762 » Tue Feb 13, 2018 12:48 am

I have never been able to step or set breakpoints or any of the features we're used to when debugging a program on a Linux box. I can pull up the registers (info reg) but having control over program execution still eludes me.

victor_pv
Posts: 1859
Joined: Mon Apr 27, 2015 12:12 pm

Re: Access the PC register through ST-Link V2?

Post by victor_pv » Tue Feb 13, 2018 1:50 am

I don't use GDB, so can't say much on how to do with it, but when I use Ozone to catch something like that, I normally first look a the call stack. It will show what are the last function calls wound in the stack, so you get an idea in what function it was when it crashed.
Once I have a suspect, I may place some break points in that function to see if it reaches the breakpoint before it crashes. If it doesn't I then move the breakpoint back. Seems to be better than running step by step which may be a lot of instructions.

zmemw16
Posts: 1674
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Access the PC register through ST-Link V2?

Post by zmemw16 » Tue Feb 13, 2018 2:25 am

time for priintf copiously

tiger762
Posts: 29
Joined: Tue Jan 26, 2016 11:40 pm

Re: Access the PC register through ST-Link V2?

Post by tiger762 » Tue Feb 13, 2018 2:55 am

Until I can get debugging working, I have resorted to a hardware solution. I have one of these:

https://www.ebay.com/itm/Arduino-Displa ... 2716381764

Attached to pins B12,B13,B14,B15,A8,A9 and I add this function:

void debug (int level) {
oPB12 = ((level >> 0) & 1);
oPB13 = ((level >> 1) & 1);
oPB14 = ((level >> 2) & 1);
oPB15 = ((level >> 3) & 1);
oPA8 = ((level >> 4) & 1);
oPA9 = ((level >> 5) & 1);
}

and then before/after every while() loop and in every ISR I have a unique debug(xxx) call. If/when it drives off into oblivion, I then look to see what binary number is displayed on the LED module. This has already helped me catch miscellaneous defects. For a Dollar, those LED modules are worth their weight in gold.

dannyf
Posts: 228
Joined: Wed May 11, 2016 4:29 pm

Re: Access the PC register through ST-Link V2?

Post by dannyf » Tue Feb 13, 2018 12:00 pm

Getting your debugger to work, or ro use uart or a display is much more efficient.

The chip has extensive built in debug capabilities.

fpiSTM
Posts: 314
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Access the PC register through ST-Link V2?

Post by fpiSTM » Tue Feb 13, 2018 1:12 pm

Ensure to have aggressively cache compiled core disabled in Arduino preference
Select Debug in Optimize menu.
Then after building your sketch:
Launch

Code: Select all

st-util
Launch gdb with the generated elf:

Code: Select all

<yourpath>/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gdb yourbuildsketch.elf
In gdb exec:

Code: Select all

target extended localhost:4242
load
Then you should be able to debug

Post Reply