Access the PC register through ST-Link V2?

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.


RogerClark
Mon Feb 12, 2018 10:42 pm
I think you have to use OpenOCD and GDB to do that

dannyf
Mon Feb 12, 2018 11:08 pm
Why couldn’t you just step through the code?

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
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
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
Tue Feb 13, 2018 2:25 am
time for priintf copiously

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
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
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 st-util

Vassilis
Tue Feb 13, 2018 2:59 pm
– Which operating system do you use ?
– Do you produce the .ELF file in Arduino IDE ?

Maybe the Ultra Simple STM32 Debugger can help you


tiger762
Thu Feb 15, 2018 10:53 am
Centos 7/64 and Fedora 25. Lately I have been building from the command line, using a makefile that contains captured compilation/linking commands to mimic the Arduino build process.

Leave a Reply

Your email address will not be published. Required fields are marked *