Spark Logic

Debugging Arduino sketch with STM32 Nucleo in Eclipse .. works !

michael_l Sat Aug 29, 2015 7:17 pm

I have followed this site http://gnuarmeclipse.livius.net/blog/install/ to install GNU arm toolchain, build tools, etc. Compiling works okay, binary is created. I’m using toolchain: gcc-arm-none-eabi-4_9-2015q2-20150609-win32
Debugging does not work. I am quite new to STM32, OpenOCD etc so I might do something wrong.

Based on this log I’m asking what could be wrong ? LD1 flashes red/green and nothing happens after this. It seems to be sort of stuck.

GNU ARM Eclipse 32-bits Open On-Chip Debugger 0.9.0-00073-gdd34716-dirty (2015-05-19-09:56)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Started by GNU ARM Eclipse
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v24 API v2 SWIM v11 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.243243
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection on tcp/3333
Info : device id = 0x20036410
Warn : STM32 flash size failed, probe inaccurate - assuming 128k flash
Info : flash size = 128kbytes
undefined debug reason 7 - target needs reset
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
semihosting is enabled
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc, semihosting
target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0xfffffffc, semihosting
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 00000000 pc: 0x20000000 msp: 0x08000028, semihosting
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 00000000 pc: 0x20000000 msp: 0x08000028, semihosting
===== arm v7m registers
(0) r0 (/32): 0x00000020
(1) r1 (/32): 0x00000000
(2) r2 (/32): 0x2000003C
(3) r3 (/32): 0x2000083C
(4) r4 (/32): 0x08000028
(5) r5 (/32): 0x2000006C
(6) r6 (/32): 0x00000020
(7) r7 (/32): 0x00000014
(8) r8 (/32): 0x00000000
(9) r9 (/32): 0x00000000
(10) r10 (/32): 0x00000000
(11) r11 (/32): 0x00000000
(12) r12 (/32): 0x00000000
(13) sp (/32): 0x08000028
(14) lr (/32): 0xFFFFFFFF
(15) pc (/32): 0x20000000
(16) xPSR (/32): 0x00000000
(17) msp (/32): 0x08000028
(18) psp (/32): 0x00000000
(19) primask (/1): 0x00
(20) basepri (/8): 0x00
(21) faultmask (/1): 0x00
(22) control (/2): 0x00
===== Cortex-M DWT registers
(23) dwt_ctrl (/32)
(24) dwt_cyccnt (/32)
(25) dwt_0_comp (/32)
(26) dwt_0_mask (/4)
(27) dwt_0_function (/32)
(28) dwt_1_comp (/32)
(29) dwt_1_mask (/4)
(30) dwt_1_function (/32)
(31) dwt_2_comp (/32)
(32) dwt_2_mask (/4)
(33) dwt_2_function (/32)
(34) dwt_3_comp (/32)
(35) dwt_3_mask (/4)
(36) dwt_3_function (/32)

Replies

RogerClark Tue Sep 01, 2015 6:49 am

Michael

The IDE including the Ino file seems like a mistake / bug to me. I suspect they didnt realise there was a reference to it in the elf file as AFIK they its not possible to do in-circuit debugging on AVR and for debugging on the new Arduino Zero people have to use Atmel Studio as their IDE.

I took a quick look on github at the Arduino sources, but there are 168 references to “.ino” so it would take quite a while to figure out precisely which one of those instances is the problem. :-(

michael_l Tue Sep 01, 2015 7:14 am

I’m not sure but it looks like this commit introduced using ‘#line’ with the .ino source file name the first time:
https://github.com/arduino/Arduino/comm … 359d886ccb

Reason is:
// These #line directives help the compiler report errors with
// correct the filename and line number (issue 281 & 907)

The same function is now in master branch in file: arduino-core/src/processing/app/debug/Compiler.java at around line 1383

and this line most probably makes the compiler to include the .ino file in the .elf too. I’m not an expert in this area but there seems to be a good reason to include the .ino file BUT Eclipse is having a hard time with that :)

EDIT: Does Atmel Studio handle the .ino file correctly or does it compile it so that it does not include .ino in the .elf at all ?

michael_l Tue Sep 01, 2015 7:44 pm

I’m quite sure now that this looks like a bug in Eclipse under Win32. While debugging I watched trace windows in Eclipse: what is sent to GDB and what GBD responds.

Hitting a breakpoint. this is what GDB prints:

Breakpoint 7, loop () at C:\cygwin\tmp\untitled8842960513440007790.tmp\sketch_sep01a/sketch_sep01a.ino:6
6 void loop() {

Rick Kimball Tue Sep 01, 2015 8:56 pm

The code probably got optimized out of the source. arm-none-eabi-objdump -CS foo.elf is your friend.

RogerClark Tue Sep 01, 2015 9:35 pm

you could change the optimization settings in platform.txt, just for debugging.

michael_l Wed Sep 02, 2015 5:08 am

Yes, I should test this with a code that actually does something. I’ll try the optimization settings too. Would you suggest using -O0 or something else ?

michael_l Wed Sep 02, 2015 8:28 am

Rick Kimball wrote:The code probably got optimized out of the source. arm-none-eabi-objdump -CS foo.elf is your friend.

RogerClark Wed Sep 02, 2015 8:42 am

But GDB does show the code ? Am I missing something ?

If you run GDB on the command line, it has commands to list the code i.e show the code around the current program counter, and to set breakpoints.

But normally an IDE like Exclipse handles this all for you.

So I’m not to sure what your question is really??

michael_l Wed Sep 02, 2015 8:56 am

RogerClark wrote:But GDB does show the code ? Am I missing something ?

If you run GDB on the command line, it has commands to list the code i.e show the code around the current program counter, and to set breakpoints.

But normally an IDE like Exclipse handles this all for you.

So I’m not to sure what your question is really??

RogerClark Wed Sep 02, 2015 10:05 am

Sorry Michael

I can’t help with that one. It sounds like a question for the Eclipse forum

michael_l Wed Sep 02, 2015 10:11 am

RogerClark wrote:Sorry Michael

I can’t help with that one. It sounds like a question for the Eclipse forum

michael_l Wed Sep 02, 2015 2:29 pm

here’s a little bit different situation:

I modified Arduino source code so that full path of .ino file is used

The .cpp generated by Arduino contains now:

#line 1 “c:\\sketch.ino”

in the first line. File is there in c:\sketch.ino

IDE Log:
!ENTRY org.eclipse.cdt.dsf.ui 2 0 2015-09-02 17:25:07.768
!MESSAGE Unable to locate file: c:\sketch.ino

and

Image

So that didn’t work.

Rick Kimball Wed Sep 02, 2015 3:17 pm

Did you press the “Locate File…” button and point it at the source code?

michael_l Wed Sep 02, 2015 3:25 pm

Rick Kimball wrote:Did you press the “Locate File…” button and point it at the source code?

Rick Kimball Wed Sep 02, 2015 3:37 pm

Sounds like you need to setup the file associations in eclipse so that the IDE knows that your .ino file is a C++ file and that the default is to use the Eclipse editor not the System editor (.ino must be associated with the arduino.exe)

A quick search on google indicates it might be a windows only issue, although I haven’t tried on windows. I did test my gdb setup ( command line arm-none-eabi-gdb ) with windows a while back and I was able to make that work. But of course eclipse wasn’t in that mix.

Please let us know exactly what your setup is and maybe we can try to recreate. There are so many places this can fall down, it is hard to guess what is different, what you have changed and what you have set.

-rick

PS I’m often on IRC, and it is often easier to solve these types of problems with a question answer format than a forum.

michael_l Wed Sep 02, 2015 3:51 pm

Rick,

Yeah, would be great to talk in IRC and try out different things. Thanks for your suggestion. I will ll try that too. Actually that really makes sense when I think about that. Eclipse can’t open the file in the IDE because it’s opened by Arduino IDE. However I think Eclipse should just load the file and not try to execute it with default program.

I did test my gdb setup ( command line arm-none-eabi-gdb ) with windows a while back and I was able to make that work. But of course eclipse wasn’t in that mix.

Yes, there’s some small mistake in Eclipse in the file handling part I believe. GBD plays nicely.

In the meanwhile looks like I got this working!! Hacked Arduino IDE sources so that it does not print #line directives:

Here’s the .cpp file produce by Arduino. NOrmally there would be “#line 1 “sketch_02sepb.ino”

#include "Arduino.h"
void setup();
void loop();
void setup() {

}

void loop() {

Serial.println("1234");
Serial.println("5678");
delay(2000);
}

Rick Kimball Wed Sep 02, 2015 4:08 pm

I compiled a simple blink sketch and then loaded the /tmp/xxxx/blink_std.cpp.elf into the eclipse debugger. I didn’t have to modify the arduino ide or mess with #line directives or include a .cpp. When the file associations are correct it should just work …
eclipse_screen.jpg
eclipse_screen.jpg (204.69 KiB) Viewed 812 times

michael_l Wed Sep 02, 2015 7:25 pm

Rick Kimball wrote:I compiled a simple blink sketch and then loaded the /tmp/xxxx/blink_std.cpp.elf into the eclipse debugger. I didn’t have to modify the arduino ide or mess with #line directives or include a .cpp. When the file associations are correct it should just work …

eclipse_screen.jpg

RogerClark Wed Sep 02, 2015 8:21 pm

michael, can you post your hacked IDE somewhere, i know a lot of people would be interested in trying it.

Rick Kimball Wed Sep 02, 2015 9:10 pm

michael_l wrote:Tried this and does not work. It still says can’t locate the file. Oh well, I have a hacked Arduino IDE that strips off those ‘#line’ directives and debugging the main sketch file works – this is ok for me for now.

Sign in to reply