# How to debug core-firmware using GDB?

**URL:** <https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961>\
**Category:** Firmware\
**Created:** [April 17, 2014, 12:03am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961 "2014-04-17T00:03:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![gruvin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gruvin/32/765_2.png) [@gruvin](https://community.particle.io/u/gruvin)\
**Post date:** [April 17, 2014, 12:03am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/1 "2014-04-17T00:03:01Z")

</div>

Howdy

_This is a fairly advanced question, perhaps for @zachary – though anyone with good knowledge of (ARM) GDB might be able to help._

I have set myself up with an ST-Link/V2 and [st-util](https://github.com/texane/stlink), on my OS X 10.9 system. I am able to live debug the Sparkcore’s bootloader.elf, using GDB, basically because it installs at memory offset zero.

However, I have not been able to figure out how to use GDB to debug core-firmware, apparently because it installs at memory offset 0x5000 and core-firmware.elf has no knowledge of the boot loader code, at offset zero.

EDIT: So, although setting breakpoints and the like seems to use the correct addresses, I think the system reset performed just before jumping to user firmware is messing things up, maybe? Or for that matter, I just realised that the JTAG interface is likely being disabled entirely. Hmmm.

Thanks!

See. I told you it was an advanced question. 😛

EDIT: I understand that normally, only the boot loader contains the chip configuration boot code, for clock initialisation, etc and that it is told to install at memory offset zero by using linker script `linker_stm32f10x_md.ld` instead of `linker_stm32f10x_md_dfu.ld`. But that’s about as far as my current knowledge of all this goes.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [April 17, 2014, 7:46am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/2 "2014-04-17T07:46:09Z")

</div>

@gruvin I think you are right there

> [@gruvin](#):
>
> Or for that matter, I just realised that the JTAG interface is likely being disabled entirely.

But in main.h you can find this

```
/*
 * Use the JTAG IOs as standard GPIOs (D3 to D7)
 * Note that once the JTAG IOs are disabled, the connection with the host debugger
 * is lost and cannot be re-established as long as the JTAG IOs remain disabled.
 */
#ifndef USE_SWD_JTAG
#define SWD_JTAG_DISABLE
#endif

```

So I'd guess defining USE\_SWD\_JTAG might keep JTAG enabled.

---

<div class="post-metadata">

**Author:** ![gruvin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gruvin/32/765_2.png) [@gruvin](https://community.particle.io/u/gruvin)\
**Post date:** [April 18, 2014, 5:13am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/3 "2014-04-18T05:13:12Z")

</div>

> [@ScruffR](#):
>
> So I'd guess defining USE\_SWD\_JTAG might keep JTAG enabled

Yes is does! Great stuff and good spotting. 😄

* * *

The only catch (and essentially unrelated, actually) was that, for reasons I simply cannot understand, my ST-Link/V2 debugger doesn't work today -- won't even erase or flash the Sparkcore -- whereas my Olimex ARM-USB-OCD that was giving me all kinds of grief until I purchased the ST-Link/V2 to fix all that, is now working without a glitch. _ **So confused.** _ But, I digress.

---

<div class="post-metadata">

**Author:** ![zachary](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/zachary/32/20717_2.png) [@zachary](https://community.particle.io/u/zachary)\
**Post date:** [April 18, 2014, 7:43am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/4 "2014-04-18T07:43:50Z")

</div>

Hey @gruvin,

Sorry for being out of touch for the last few days—@ScruffR is exactly right. If you want to do JTAG debugging, you’ll need to define `USE_SWD_JTAG`. Normally it’s disabled so we can use D3–D7 for GPIO; when you enable JTAG those 5 pins can’t be IOs obviously.

You are correct that I’m the person at :spark: who most commonly uses gdb. I do so on a mac with `st-util` in my terminal and an ST-LINK/V2 ➕ Spark programmer shield. I find the combo very stable, as long as I remember to define that macro. 😉

Happy register inspecting!

---

<div class="post-metadata">

**Author:** ![gruvin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gruvin/32/765_2.png) [@gruvin](https://community.particle.io/u/gruvin)\
**Post date:** [April 18, 2014, 10:32pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/5 "2014-04-18T22:32:46Z")

</div>

> [@zachary](#):
>
> You are correct that I'm the person at who most commonly uses gdb. I do so on a mac with st-util in my terminal and an ST-LINK/V2 Spark programmer shield. I find the combo very stable

That's good to know @zachary. Thanks. My ST-Link/V2 must be faulty.

I wonder though if you'd be able to tell me **what version of firmware your ST-Link/V2 hardware has in it**? Only way I know to find this is to hook it up to Windows and hit the Connect button in the ST-Util Firmware upgrade option, from the main menu.

Mine currently has V2.J19.S4 installed. When I upgraded it to the latest V2.J20.??, it stopped working with `st-util` on the Mac entirely. Downgrading back to the firmware supplied with the latest ST-Util got it going again. Though as said, it stopped the next day, for no apparent reason

In any case, the version of firmware in the ST-Link/V2 seems to have an impact on whether or not it'll work with the current `st-util`.

Thanks.

EDIT: I just found [ST-Link/V2 firmware V2.14.3](https://drive.google.com/folderview?id=0Bzv7UpKpOQhnbXJVVEg4VUo2M1k) and downgraded to that. My ST-Link/V2 is working again! Yay \o/ ... Still interested to know what firmware version you have @zachary. Cheers.

EDIT2: Ha! Ironically, now my Windows ST-Link Utility is working! Far out. I could not get it working on either of the two previous firmwares, including the one that came embedded in ST-Link Utility itself. How bizarre. (I suppose it's possible that VMWare (for running Windows 8.1 Pro) is having something to do with my problems. But I doubt it.)

---

<div class="post-metadata">

**Author:** ![zachary](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/zachary/32/20717_2.png) [@zachary](https://community.particle.io/u/zachary)\
**Post date:** [April 18, 2014, 10:55pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/6 "2014-04-18T22:55:40Z")

</div>

No idea! And I don’t have Windows. @Dave — you want to grab the STLINK off my desk and test it with your Windows machine next week?

---

<div class="post-metadata">

**Author:** ![gruvin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gruvin/32/765_2.png) [@gruvin](https://community.particle.io/u/gruvin)\
**Post date:** [April 18, 2014, 10:56pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/7 "2014-04-18T22:56:29Z")

</div>

🙂 I have Windows only in VMWare machine – honest! 😛

@Dave – This is how I get the version. Basically, you run any of the available Firmware upgrades, [including any those in the link I gave above](https://drive.google.com/folderview?id=0Bzv7UpKpOQhnbXJVVEg4VUo2M1k), and go only as far as the Connect button, which then displays the current version. Here’s some paint by numbers, using the firmware upgrade that comes with ST-Util itself …

![](https://community.particle.io/uploads/particle/1140/283178f36f78a6f6.png)

![](https://community.particle.io/uploads/particle/1141/2fdc15088bfb49bb.png)

Don’t click that, “Yes \>\>\>” button or @zachary might get upset. 😉

Thanks guys.

---

<div class="post-metadata">

**Author:** ![gruvin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gruvin/32/765_2.png) [@gruvin](https://community.particle.io/u/gruvin)\
**Post date:** [April 18, 2014, 11:17pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/8 "2014-04-18T23:17:29Z")

</div>

> [@zachary](#):
>
> Happy register inspecting!

Yup. Going real good now. I can see everything. Breakpoints etc all working great. Yay \o/

Oh, Happy Easter!

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [April 21, 2014, 3:00pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/9 "2014-04-21T15:00:20Z")

</div>

I haven’t had a chance to check this yet, but I’ll try to follow-up when I get near my Windows computer 😄 – I’m giving myself a task for this so I don’t forget.

Thanks,  
David

---

<div class="post-metadata">

**Author:** ![jwebster](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jwebster/32/20862_2.png) [@jwebster](https://community.particle.io/u/jwebster)\
**Post date:** [May 14, 2014, 11:06pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/10 "2014-05-14T23:06:41Z")

</div>

Hey @Dave,

Any word on what version @zachary has on his ST-Link? I’m about to give this a go on my Mac. It looks like I have V2.J17.S4 on my ST-Link/v2 and I’m wondering if I really need to worry about downgrading to V2.14.3 as @gruvin suggests.

In the mean time, I’m going to proceed with the version I have and I’ll see if I have any issues.

Thanks!

---

<div class="post-metadata">

**Author:** ![gruvin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gruvin/32/765_2.png) [@gruvin](https://community.particle.io/u/gruvin)\
**Post date:** [May 15, 2014, 1:25am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/11 "2014-05-15T01:25:55Z")

</div>

Still waiting to hear. I think there’s a Maker Faire or something on at the moment, so I guess they’re all tied up with that.

Suck it and see, I guess. Can’t do any harm. So far, anything _prior to_ V2.19.xx has appeared stable for me. But there’s some weird stuff going on in amidst it all. I’d be very keen to learn from you how things went, on your Mac.

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [May 15, 2014, 1:55am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/12 "2014-05-15T01:55:02Z")

</div>

Hi Guys,

Most of the team is traveling for Maker Faire in San Francisco so the response time may be a little slower.

I wish I had a ST-Link and could help out, but I don’t. Sorry!

---

<div class="post-metadata">

**Author:** ![zachary](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/zachary/32/20717_2.png) [@zachary](https://community.particle.io/u/zachary)\
**Post date:** [May 15, 2014, 8:01am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/13 "2014-05-15T08:01:17Z")

</div>

Thanks for following up. As Brian says, we’re in the Bay Area for Maker Faire. Crazy schedules!

I recommend not worrying about this for now. If anyone has the Windows utility for checking the STLINK firmware version, we’ll check it, but I’m pretty sure Dave will not have brought his Windows laptop.

As mentioned earlier, we’ve never had any problems with STLINK programmers, but I look forward to confirming the firmware version.

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [May 15, 2014, 6:50pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/14 "2014-05-15T18:50:47Z")

</div>

Sorry about that, I haven’t been around my windows box to check on that yet, maybe I can borrow one here and get you a version # today.

Thanks!  
David

---

<div class="post-metadata">

**Author:** ![gruvin](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/gruvin/32/765_2.png) [@gruvin](https://community.particle.io/u/gruvin)\
**Post date:** [May 15, 2014, 8:16pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/15 "2014-05-15T20:16:38Z")

</div>

> [@Dave](#):
>
> maybe I can borrow one here and get you a version # today.

Remember, we're only really interested in the firmware version of @zachary's ST-Link specifically, on the basis that he's used it successfully many times, on his Mac -- and because I have had very limited success on my Mac, with several versions. So it's really just about finding some kind of 'confirmation', if available. No biggie.

Have fun at the fair!

---

<div class="post-metadata">

**Author:** ![jwebster](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jwebster/32/20862_2.png) [@jwebster](https://community.particle.io/u/jwebster)\
**Post date:** [May 16, 2014, 12:09am UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/16 "2014-05-16T00:09:44Z")

</div>

Thanks guys! Yeah, no rush on this. Have fun at Maker Faire! I’ve been able to program without any problems so far with my ST-Link running firmware version V2.J17.S4, so I’ll just avoid upgrading the firmware.

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [August 3, 2014, 4:19pm UTC](https://community.particle.io/t/how-to-debug-core-firmware-using-gdb/3961/17 "2014-08-03T16:19:55Z")

</div>

I can confirm that downgrading is the key to this working on windows - at least it was for me. GDB wasn’t working - wouldn’t load images and dropped into random addresses. After downgrading to 2.J14… it worked first time.

So, thanks for your efforts @gruvin - it certainly got me working after several hours trying.
