Tutorial: Using Eclipse + ST-LINK/v2 + OpenOCD to debug

@peekay123, @kennethlimcp, @naikrovek, @Neurofrantic

Have you been able to follow this tutorial and get the sample app to flash? I seem to be having problems either -

  1. flashing the sample app and starting debugging
  2. flashing the Spark firmware and getting GDB to locate the source files. I can get the firmware flashed however GDB can not locate the source files (is that because I built the firmware outside of eclipse?, I have a project in eclipse with the feature/hal branch)

Any help appreciated. I have spend several days trying to get a debugging environment up and running.

Haven’t had time to set up but will let you know when I have something.

What you mentioned about building outside eclipse might be the issue

@mtnscott, I will be working on this this week. I’ll get back to you as soon as I get results. :smile:

1 Like

@mtnscott, eclipse is complaining that my JVM is outdated and i have no interest to fix things in order to get stuff running so i’m sorry :stuck_out_tongue:

1 Like

Thanks @kennethlimcp I appreciate the attempt.

Thanks @peekay123 I’ll keep troubleshooting and see if I can find the problem.

@omidontop Are you using a spark core or a discovery board?

@mtnscott: I’m sorry for the late reply but I had limited access to my computer the past few days. Well the firmware version of my ST-Link/V2 is V2.J23.S4 STM32+STM8 Debugger if you need it as a reference and I’m using a Spark Core and not a discovery board. Have you tried to perform the exact sequence I described in my last comment? I have saved an image of my original Spark Core firmware before I flashed it and tried that sequence a few times successfully every time. If I don’t hold the RESET button here’s what I get,

And if I hold down the RST button on the core and start the debugger and keep holding it down until I see this screen:

And then I’d let go of the RST button, I will get this:

And we get to step 7:

I suggest you try again and restore your Spark Core to its factory conditions and do the same thing I did and if still it didn’t work, please share the error messages and screenshots of your errors.

This comment -

I’m not sure what you are referring to… Are you suggesting that I need to add the switch USE_SWD_JTAG with the LED blink sample application? If that’s the case I must have missed that in your step by step tutorial. I’ve reviewed your instructions several times - but maybe I missed it?

I know that the Spark firmware needs that switch added to the command line when you build the spark firmware, but I’m not yet to the point of trying to debug the spark core firmware. I’m just following your tutorial above and the example LED app? Is it needed for that as well?

When I hold down the RESET button on the core (D7 goes on and stays on) then I try to start the debugger but I never get your screen with monitor - halt.

This is what I eventually get - and only after click on “terminated exit value: -1 openocd” in the top left window.

@mtnscott, I am getting similar errors except on Windows 7x64. If I don’t hold RESET then I get the same thing that @omidontop got. If I hold reset,run the debugger and hold reset, I get this:

GNU ARM Eclipse 64-bit Open On-Chip Debugger 0.8.0-00063-gbda7f5c (2015-01-31-18:41)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.sourceforge.net/doc/doxygen/bugs.html
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Started by GNU ARM Eclipse
Info : This adapter doesn't support configurable speed
Info : STLINK v2 JTAG v23 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.232461
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection from 3333
Info : device id = 0x20036410
Warn : STM32 flash size failed, probe inaccurate - assuming 128k flash
Info : flash size = 128kbytes
undefined debug reason 7 - target needs reset
Error: timed out while waiting for target halted
TARGET: stm32f1x.cpu - Not halted

in procedure 'reset'
Info : Halt timed out, wake up GDB.
Error: timed out while waiting for target halted
in procedure 'halt'
semihosting is enabled
Error: timed out while waiting for target halted
TARGET: stm32f1x.cpu - Not halted

in procedure 'reset'

Error: Target not halted
Error: failed erasing sectors 0 to 7
Error: flash_erase returned -304
Info : dropped 'gdb' connection
I also get the pop-up error:

I also get this pop-up error:

1 Like

@peekay123 - Looks like we are both hitting the same errors. I can’t seem to get anything working with this tutorial. Oh well. guess I will try another path to getting a debugging setup on the core. :frowning:

@mtnscott, I feel we are close! Just need to find that one thing that is not working :weary:

@omidontop, any guidance is greatly appreciated :wink:

1 Like

@omidontop Thanks for the tutorial!

just one comment on the openOCD tool, that the website has 0.9 version available, but it won’t work, at lease in my case. I would suggest you to put a comment there to remind others to download the 0.8 version.

@peekay123 I was having exactly the same problem as yours. I thought it might because the beginning sectors of the sparkcore was locked, and I tried to unlock it with according to this thread. But it seems the core was still locked according to my st-link utility, after loaded the unlocker binary. I’ll let you know when I get any progress.

Yes, it is the flash protection problem.

it seems the dfu-util tool is not working for me to unlock the core. I have to use st-link programmer to flash the unlocker-firmware.bin to the sparkcore and do the whole chip erase. Then the debug function works for me now.

[quote=“FlyingYanz, post:37, topic:10042”]
it seems the dfu-util tool is not working for me to unlock the core. I have to use st-link programmer to flash the unlocker-firmware.bin to the sparkcore and do the whole chip erase. Then the debug function works for me now.
[/quote] There must be a way to have it only flash specific sections of flash. Having to erase the entire core +bootloader - seems like you don’t really have a spark anymore.

Hi, great tutorial @omidontop!
But has there been any progress regarding the errors people found? I have got the same using OpenSTM32 IDE. I’m searching for a way in window to set up a nice debug / compile environment for the core and now the photon. Seems to be difficult or its just me :-p . Can’t do efficient development with webIDE and serial debug. Need JTAG/ SWD! :slight_smile:

Hi @Martin! Thanks a lot for the compliment. Well, I must apologize both to you and to @mtnscott, @FlyingYanz and @peekay123 as at the time they asked me those questions I was on a long overseas trip and had no access to my hardware and limited internet access so I couldn’t really be of any help. It’s been a while since I haven’t done anything with my Core or Photon which I recently received since I have been busy with other projects. However, I am planning on updating this tutorial and include information regarding Photon as well within the next month. I hope at that time it still would be of use to you :smile:

2 Likes

I have now get the compile up and running with out any problem with the latest branch of Photon :smile:
When I upload the compiled (default tinker) *.bin file with dfu both direct from compile or later everything works great.

Problem is when it comes to the *.elf file. I get the STLinkV2 to download it and Photon boot up correct.
But STLink don’t stop at the first breakpoint I set at setup() and then Particle Android app says that the unit is online but not with the tinker app. If I leave the debugger connected to the target and choose to flash it from the Android app with the tinker code then after the reboot after flash debugger halt at the breakpoint and I could do stepping.

I have checked the user-part.map and .module_start 0x080a0000 it seems right. Bootloader works correct so it looks like the debugger flash the right address area.

Any ideas anyone ?

here is eclipse jtag full debug in uboot and kernel

Hi there,

I realy like the idea of using this IDE and OpenOCD but what if I want to flash an existing project?
also when I try to do the conversation of my ST link V2:

with the reflash software it says error and it wont let even tough the computer recognizes it and it’s confirmed to work.

also is it possible to use it with the NRF52832?

Hey guys! Just to be clear, is Semihosting available to the ST-Link V2 debugger?

HI
I have a problem:

Open On-Chip Debugger 0.10.0 (2018-07-28) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
User : 13 1 command.c:544 command_print(): debug_level: 3
Unexpected command line argument: Files\GNU

Could you please help me?