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


#1

I found that getting the Netbeans IDE up and running was a snap following the information here:

Everything works including flashing over USB.

How do I get GDB working in it though? I’d really like to do normal breakpoint debugging and stepping through code, rather than going the printf route.


#2

I am also interested in this. I have a J-LINK debugger and I can run the GDB server for that and it connects and detects the processor on the core. I just can’t figure out how to setup Netbeans to do the actual connection to the debugger and run the code and do breakpoints etc.


#3

This whole IDE thing is a bit crazy. Eclipse is way too hard to set up (at least for me on XP). You have to have addons just to allow you to specify a toolchain for instance.

Netbeans is easy (a snap) to set up but I can’t see how to hook in GDB. Coocox hooks into ST-Link easily and I have done real debugging using sample code running on an STM32F, but I can’t quite get it to compile the Spark Core code yet.

I would be really nice if someone in the know could figure out an easy to use local development environment running on windows.


#4

I need this too! I’ll be working on this as well…


#5

It would be good if we knew what the Spark Core team use for real time debugging. Assuming they have the JTAG shields assumes they have some way to debug at the code level?


#6

I just came across this link “Using netbeans for STM32 development with ST-Link”:

http://false.ekta.is/2012/05/using-netbeans-for-stm32-development-with-stlink-texane/

I got a Red McAfee Site Advisor warning as I was entering the page but decided to risk it anyway. Looks like some info that might be handy.

Though it may be straight forward under Linux, it looks like this may take a little bit of doing under Windows. You need to build your own texane stlink executable using mingw. I’m still working my way through that one. Here’s a little bit of helpful info:


#7

See here:


#8

Making a little progress here. Building texane stlink took some doing. I don’t know what state my existing MinGW was in, but it didn’t want to do the job. So I did a fresh install of that and all the other required packages. It finally built without errors on my XP machine.

(Edit: After going through all this, I see other people referencing st-flash and st-util and I doubt they went through this process. I have the ST ST-Link software installed on my system and I didn’t have either of those. That’s why I went through this whole process. But I still wonder if maybe they aren’t available from ST somewhere and I just missed it. Anyway, these are what the author of that article recommended.)

To save you quite a bit of trouble, I’ll keep the .exe files on my server for a month or so. If they prove useful to anyone, you’re free to grab them and put them where folks can find them better. Please use common sense, virus check, whatever. Also, I don’t know if they work on Windows 7 or 8, but they do seem to run ok on XP.

Here’s the link:
www.faradayco.com/sparkdev/stlink/stlink.zip

If you need compatible MinGW dlls:
www.faradayco.com/sparkdev/stlink/

Note: When I run st-flash core-firmware.bin 0x8005000 it seems to program the Spark Core okay, but when it’s done the Spark goes into an SOS mode for a while. It eventually recovers and starts breathing cyan. Don’t know what’s up with that. Also, I don’t quite have the gdb working with Netbeans yet. I think it’s a Netbean configuration problem, but who knows.

Edit: If you are looking for Netbeans documentation, the best place to go is the help button in the software itself. For the moment I’m struggling with Netbeans 8.0. The Run Commands and Debug Commands are co-mingled and aren’t behaving correctly. So, I’m going to install 7.1 and see if that helps.


#9

Another reference to an old thread about debugging:


#10

@faraday thanks for getting this built for windows!! So I’m going to share what I’ve got running so far and my commands in the hopes that we can push this further.


#Command Line Debugging on Windows

Got a ST-Link V2 JTAG programmer and Spark JTAG Shield? Great! Plug them all in, and plug your Spark Core into the JTAG Shield… also plug your Spark Core into a USB port.

Hopefully you have a local toolchain setup already. If so, navigate to the core-firmware\build\ directory and run the following command to build your application with debugging enabled:

make USE_SWD_JTAG=y

D:\spark\core-firmware\build>make USE_SWD_JTAG=y
Building core-common-lib
make[1]: Nothing to be done for `all'.

Building core-communication-lib
make[1]: Nothing to be done for `all'.

Building target: core-firmware.elf
Invoking: ARM GCC C++ Linker
arm-none-eabi-g++ -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb  -I../inc -I../libraries//Serial2 -I../../core-common-lib/CMSIS/Include -I../../core-common-lib/CMSIS/Device/ST/STM32F10x/Include -I../../core-common-lib/STM32F10x_StdPeriph_Driver/inc -I../../co
re-common-lib/STM32_USB-FS-Device_Driver/inc -I../../core-common-lib/CC3000_Host_Driver -I../../core-common-lib/SPARK_Firmware_Driver/inc -I../../core-communication-lib/lib/tropicssl/include -I../../core-communication-lib/src -I. -ffunction-sections -Wall
 -fmessage-length=0 -MD -MP -MF core-firmware.elf.d -DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD -DDFU_BUILD_ENABLE -DSPARK=1 -DUSE_SWD_JTAG -DRELEASE_BUILD  obj/src/application.o obj/src/main.o obj/src/newlib_stubs.o obj/src/spark_utilities.o obj/src/spark_wiri
ng.o obj/src/spark_wiring_eeprom.o obj/src/spark_wiring_i2c.o obj/src/spark_wiring_interrupts.o obj/src/spark_wiring_ipaddress.o obj/src/spark_wiring_network.o obj/src/spark_wiring_print.o obj/src/spark_wiring_servo.o obj/src/spark_wiring_spi.o obj/src/sp
ark_wiring_stream.o obj/src/spark_wiring_string.o obj/src/spark_wiring_tcpclient.o obj/src/spark_wiring_tcpserver.o obj/src/spark_wiring_time.o obj/src/spark_wiring_tone.o obj/src/spark_wiring_udp.o obj/src/spark_wiring_usartserial.o obj/src/spark_wiring_
usbserial.o obj/src/spark_wiring_wifi.o obj/src/spark_wlan.o obj/src/stm32_it.o obj/src/usb_desc.o obj/src/usb_endp.o obj/src/usb_istr.o obj/src/usb_prop.o obj/src/wifi_credentials_reader.o obj/startup/startup_stm32f10x_md.o --output core-firmware.elf -T.
./linker/linker_stm32f10x_md_dfu.ld -nostartfiles -Xlinker --gc-sections  -L../../core-common-lib/build -lcore-common-lib -L../../core-communication-lib/build -lcore-communication-lib -Wl,-Map,core-firmware.map --specs=nano.specs -lc -lnosys -u _printf_fl
oat

Invoking: ARM GNU Create Flash Image
arm-none-eabi-objcopy -O binary core-firmware.elf core-firmware.bin

Invoking: ARM GNU Create Flash Image
arm-none-eabi-objcopy -O ihex core-firmware.elf core-firmware.hex

Invoking: ARM GNU Print Size
arm-none-eabi-size --format=berkeley core-firmware.elf
   text    data     bss     dec     hex filename
  77584    1232   11892   90708   16254 core-firmware.elf

I don’t know if this is needed, because the GDB will program the target with this firmware later, but go ahead and program your Core with this core-firmware.bin via dfu-util. The dfu-util command is:

dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D core-firmware.bin

D:\spark\core-firmware\build>dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D core-firmware.bin


Put your Core into DFU mode.


Unzip the 3 exe’s from http://www.faradayco.com/sparkdev/stlink/stlink.zip to a directory somewhere, I put mine in D:\Spark\STLINK for WINDOWS\ for the time being. (I didn’t need to extract the MinGWDLLs.zip)

Open a command prompt and navigate to where you just put those STLINK files, then run the following command to start the GDB server on port 9025:

st-util -p 9025

(You could also just type st-util and later use the default port of 4242)

D:\Spark\STLINK for WINDOWS>st-util -p 9025
2014-07-19T15:38:19 INFO src/stlink-usb.c: -- exit_dfu_mode
2014-07-19T15:38:19 INFO src/stlink-common.c: Loading device parameters....
2014-07-19T15:38:19 INFO src/stlink-common.c: Device connected is: F1 Medium-density device, id 0x20036410
2014-07-19T15:38:19 INFO src/stlink-common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2014-07-19T15:38:19 INFO gdbserver/gdb-server.c: Chip ID is 00000410, Core ID is  1ba01477.
2014-07-19T15:38:19 INFO gdbserver/gdb-server.c: Target voltage is 3221 mV.
2014-07-19T15:38:19 INFO gdbserver/gdb-server.c: Listening at *:9025...

Open another command prompt and navigate back to where you built your firmware. Start the GDB process with the following command:

arm-none-eabi-gdb core-firmware.elf

This should start up the GBD tool and wait for further instruction:

D:\spark\core-firmware\build>arm-none-eabi-gdb core-firmware.elf
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140228-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-w64-mingw32 --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from D:\spark\core-firmware\build\core-firmware.elf...done.
(gdb) _

Now type the following command to connect to the target:

target remote:9025

(or target remote:4242 if you are using the default port)

(gdb) target remote:9025
Remote debugging using :9025
0x0800010c in ?? ()
(gdb) _

The GDB server window should say:

2014-07-19T16:02:58 INFO gdbserver/gdb-server.c: GDB connected.

And type the following command to program the target:

load

(gdb) load
Loading section .isr_vector, size 0x10c lma 0x8005000
Loading section .text, size 0x12e04 lma 0x8005110
Loading section .init_array, size 0x5c lma 0x8017f14
Loading section .data, size 0x474 lma 0x8017f70
Start address 0x8005110, load size 78816
Transfer rate: 7 KB/sec, 9852 bytes/write.
(gdb) _

You should see a bunch of stuff happening in your GDB server window now, it’s flashing your Core with the firmware.

2014-07-19T16:05:06 INFO src/stlink-common.c: Attempting to write 1024 (0x400) bytes to stm32 address: 134238208 (0x8005000)
Flash page at addr: 0x08005000 erased
2014-07-19T16:05:06 INFO src/stlink-common.c: Finished erasing 1 pages of 1024 (0x400) bytes
2014-07-19T16:05:06 INFO src/stlink-common.c: Starting Flash write for VL/F0 core id
2014-07-19T16:05:06 INFO src/stlink-common.c: Successfully loaded flash loader in sram

2014-07-19T16:05:06 INFO src/stlink-common.c: Starting verification of write complete
2014-07-19T16:05:06 INFO src/stlink-common.c: Flash written and verified! jolly good!
2014-07-19T16:05:06 INFO src/stlink-common.c: Attempting to write 1024 (0x400) bytes to stm32 address: 134239232 (0x8005400)
Flash page at addr: 0x08005400 erased
2014-07-19T16:05:06 INFO src/stlink-common.c: Finished erasing 1 pages of 1024 (0x400) bytes
2014-07-19T16:05:06 INFO src/stlink-common.c: Starting Flash write for VL/F0 core id
2014-07-19T16:05:06 INFO src/stlink-common.c: Successfully loaded flash loader in sram

...

2014-07-19T16:05:15 INFO src/stlink-common.c: Starting verification of write complete
2014-07-19T16:05:15 INFO src/stlink-common.c: Flash written and verified! jolly good!

At this point you are ready to start debugging by setting up breakpoints, trace commands, etc… and then you can start the core executing by typing `continue’

continue

(gdb) continue
Continuing.
_

The only problem I see now is nothing is running… I don’t have any breakpoints set and it will complain that it’s running already if you cancel this continue operation and then try to type run. You cancel by pressing CTRL+C.


To help you find a place to set a breakpoint, type list functionName, e.g. list main shows this:

(gdb) list main
151      * Input          : None.
152      * Output         : None.
153      * Return         : None.
154      *******************************************************************************/
155     int main(void)
156     {
157       // We have running firmware, otherwise we wouldn't have gotten here
158       DECLARE_SYS_HEALTH(ENTERED_Main);
159       DEBUG("Hello from Spark!");
160
(gdb)

Hit ENTER a few times to scroll down:

(gdb) list main
151      * Input          : None.
152      * Output         : None.
153      * Return         : None.
154      *******************************************************************************/
155     int main(void)
156     {
157       // We have running firmware, otherwise we wouldn't have gotten here
158       DECLARE_SYS_HEALTH(ENTERED_Main);
159       DEBUG("Hello from Spark!");
160
(gdb)
161     #ifdef SPARK_WLAN_ENABLE
162       if (SPARK_WLAN_SETUP)
163       {
164         SPARK_WLAN_Setup(Multicast_Presence_Announcement);
165       }
166     #endif
167
168       /* Main loop */
169       while (1)
170       {
(gdb)
171     #ifdef SPARK_WLAN_ENABLE
172         if(SPARK_WLAN_SETUP)
173         {
174           DECLARE_SYS_HEALTH(ENTERED_WLAN_Loop);
175           SPARK_WLAN_Loop();
176         }
177     #endif
178
179     #ifdef SPARK_WIRING_ENABLE
180                     static uint8_t SPARK_WIRING_APPLICATION = 0;
(gdb)
181     #ifdef SPARK_WLAN_ENABLE
182                     if(!SPARK_WLAN_SETUP || SPARK_WLAN_SLEEP || !SPARK_CLOUD_CONNECT || SPARK_CLOUD_CONNECTED || SPARK_WIRING_APPLICATION)
183                     {
184                             if(!SPARK_FLASH_UPDATE && !IWDG_SYSTEM_RESET)
185                             {
186     #endif
187                                     if((SPARK_WIRING_APPLICATION != 1) && (NULL != setup))
188                                     {
189                                             //Execute user application setup only once
190                                             DECLARE_SYS_HEALTH(ENTERED_Setup);
(gdb)
191                                             setup();
192                                             SPARK_WIRING_APPLICATION = 1;
193                                     }
194
195                                     if(NULL != loop)
196                                     {
197                                             //Execute user application loop
198                                             DECLARE_SYS_HEALTH(ENTERED_Loop);
199                                             loop();
200                                             DECLARE_SYS_HEALTH(RAN_Loop);
(gdb)

Say we want to set a breakpoint the point just after setup() is run and SPARK_WIRING_APPLICATION = 1;. You see it’s on line 192, so the command is:

break 192

(gdb) break 192
Breakpoint 1 at 0x8005e62: file ../src/main.cpp, line 192.
(gdb) _

As I said the Continue command doesn’t seem to do anything useful… so then I tried run and got this prompt to which I answered yes, start it from the beginning!

(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: D:\spark\core-firmware\build\core-firmware.elf

At this point the Core reset and finally got out of DFU yellow LED mode… and connected to the network, then the Cloud. I throught my breakpoint would have stopped it and showed me something useful, but no such luck. It seems to be running like there is no breakpoint.

##So now the question is for anyone that gets this far… how do we make it do something useful?

It seems pretty sensitive as well, if you get any kind of error you have to cancel everything and start over from the point where you start the GDB server.


Spark-core debugging via JTAG/SWD