Update: JTAG and SWD programming and debugging from Netbeans!

** Update **
I have something working now, see 3 posts down. I have removed most of this starting posts as it was mostly troubleshooting…

First of all, you will have to enable JTAG on the spark, by programming a JTAG enabled bin via DFU

See https://community.spark.io/t/netbeans-ide-easy-to-set-up-but-how-do-i-configure-it-for-gdb-debug/5759/9

If you want to compile st-link yourself from source, follow the instructions in


I had to remove sed.exe from C:/mingw/bin, so it would use sed.exe from msys.

Okay, this seems to be a workable process:

  • Netbeans run command will program the core via GDB
  • We can attach a debugger afterwards if needed

Create the file .gdbprogram containing this and store it in the same dir as your hex file:

target remote localhost:9025
monitor reset halt

Create a bat file that keeps st-util alive:

st-util.exe -p 9025
goto loop

Start the bat file. It will keep st-util up after Netbeans disconnects by restarting it immediately. Quit with ctrl-c.

Set up your run settings in Netbeans like this:
The run command is:

arm-none-eabi-gdb blink.elf -x .gdbprogram

This will execute the .gdbprogram script and uploade blink.elf to your core.

The debug settings can be left blank:

And you can now just attach the debugger after programming via the gdbserver plugin

Voila! Programming and debugging in Netbeans with the click of a single button!

BTW, blink is a bad test program for this. The little blue LED next to the USB connector is connected to one of the JTAG pins and will not blink.


Awww snap! Can’t wait to try this out @Elco I’m sure @mdma will love this as well. If you can post a simple example of walking through maybe the RGB LED blinking and breaking on various lines of code, that would be awexome!

Small issue:
when putting the .gdbprogram file in the target dir, it gets removed by clean.

We should put it somewhere else.

Another issue I have encountered: when the program is uploaded by the run command, breakpoints are still active and the program is halted. The .gdbprogram file should remove all breakpoints, but I have not yet figured out how.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0800010c in ?? ()

RUN SUCCESSFUL (total time: 11s)

BTW, you can customize your toolbar and add the “attach debugger” button

Followup question: on my brewing shield, the JTAG pins overlap with the display driving pins.
How can I use SWD instead of JTAG?

1 Like

Hi Elco, thanks for sharing this. I’m planning on doing something similar, but have wondered if there is all the code needed to return the spark core to the original state?


@ChrisDick, You can still just boot into DFU and flash any bin you like.
If you just run make without enabling JTAG and flash that with DFU, you are back to normal.

I tried enabling SWD, but disabling JTAG:
Have not had success yet.

SWD stands for Single Wire Debug and uses 2 wires in minimal configuration: I/O and CLK.
The pins are PA13 (JTAG TMS) and PA14 (JTAG CLK).
The programming shield therefore should work without modification.
SWD would also make it very easy to debug without the programmer shield: Just solder 2 wires (and VDD + GND) to the core, no resistors needed.

See the ST-Link datasheet, section 3.2

First test should be connecting with STM32 ST-Link Utility under SWD mode. If that works, figure out how to connect with Texane st-util via SWD.

I was wanting to use the CAN peripheral, which uses the same pins as the USB. I haven’t looked far enough into it yet to know if i can do everything I need to do. I was planning on re-configuring the pins to CAN outside of bootloader, but if I need to change the bootloader, I’d like to be able to put it back the way it was because the spark I’ll be using isn’t mine. I too will be using SW, so will be able to share what I find.

Allright, got SWD working too now.

I made a small custom shield, that only connects the SWD pins.

The connections are:

Pin  ST-LINK V2 cable                           Spark Core
1,2                         VDD                 3.3V
4,6,8,10,12,14,16*          GND                 GND
7                           TMS_SWDIO           D7
9                           TCK_SWCLK           D6
15                          NRST                RESET

* One is enough, but more is preferred according to ST-Link V2 datasheet

Here is my little board:

I sent in a pull request to enable SWD without enabling JTAG:

st-util finds the spark via SWD and debugging in Netbeans works great. As described above, I upload the elf file via the run button, then attach the debugger and step debug.
I am able to stop on breakpoints, step through code, step into functions, step out of functions, etc.

I cannot reset the core via Netbeans or pause it when it is running freely, so I will have to make sure I hit a breakpoint and can then step debug or let it run freely from break point to break point.

I can now debug my TFT display, which is connected to a few pins that are also JTAG pins. When step debugging, I can let the text appear on screen line by line.