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

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

1 Like