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


#21

I did try a variant of my theory. If you run Github for Windows and you get the PATH variable from within the git shell, you can add the github directories it puts at the front and make/bin to the PATH variable inside Eclipse and it will use the proper make and the mkdir and rm tools that use the proper unixy syntax. I’ve successfully built the feature/hal branch of the firmware Github repo inside Eclipse using your tutorial.

Haven’t debugged anything, yet, but will, and when I do, I’ll let you know.

Thank you for the tutorial.

100% agreed. Could not have said it better myself.


#22

@naikrovek: Hello man! That indeed works! ( given that the Git Shell is installed in a directory with no spaces in the name i.e. not in the Program Files ). That’s a neat solution thank you for sharing that. I will include the steps in this tutorial as soon as I get some free time.
And I’d like to express my gratitude towards your compliments on the tutorial. I’m happy if I have been of some help. Cheers!

P.S, I still think the makefile of the Spark Core project can be with very little effort and complications adapted to any environment including Windows and there should be no reason to avoid that.


#23

@omidontop Thanks for this tutorial, I just got my ST-Link/v2 and setup everything. I’m currently running into this problem -

I’m using the Spark JTAG sheild, I have both the JTAG powered via USB as well as the Spark Core.

Any Ideas?

UPDATE: If I manually put the core into DFU mode then I don’t get the OpenOCD error but I do get an error in Eclipse

Digging in a bit more looks like the Core is not happy. Not sure what to do with this… Maybe I’ll try and reset my core to factory and try again.


#24

@mtnscott: I think this is related to the fact that the Serial Wire JTAG pins are by default mapped as GPIO pins unless you compile the firmware using the USE_SWD_JTAG switch. What you need to do is to hold down the RESET button on your SparkCore and start the debugger. When you saw the message “monitor halt”, release the RESET button and you should be good to go!


#25

Thanks @omidontop
I am trying to follow your tutorial step by step. I get the error by following your tutorial after step 7. You may want to add the step that you need to put the core into DFU mode prior to step 7 - otherwise you will get the first error I discovered.

So how did you get past step 7? In my setup I get the error that the GDB is unable to erase the Spark Core. I read on some other threads that there may be some differences with the firmware on the STLink/V2 device. I will downgrade my device and see if that makes any difference.


#26

@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.


#27

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


#28

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


#29

@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:


#30

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?


#31

@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.


#32

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.


#33

@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:


#34

@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:


#35

@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:


#36

@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.


#37

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.


#38

[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.


#39

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:


#40

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: