How to debug core-firmware using GDB?


#1

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, 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. :stuck_out_tongue:

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.


Netbeans IDE easy to set up, but how do I configure it for GDB debug?
#2

@gruvin I think you are right there

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.


#3

Yes is does! Great stuff and good spotting. :smile:


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.


#4

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 :heavy_plus_sign: Spark programmer shield. I find the combo very stable, as long as I remember to define that macro. :wink:

Happy register inspecting!


How to Flash a brand new, freshly soldered STM32F103 chip
#5

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


#6

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?


#7

:slight_smile: I have Windows only in VMWare machine – honest! :stuck_out_tongue:

@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, 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 …

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

Thanks guys.


#8

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

Oh, Happy Easter!


#9

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

Thanks,
David


#10

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!


#11

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.


#12

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!


#13

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.


#14

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


#15

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!


#16

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.


#17

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.