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

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
User avatar
Rick Kimball
Posts: 728
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

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

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


... could be a Windows problem ... Sorry it doesn't work for you smoothly for you. I do know that command line arm-none-eabi-gdb with either openocd, texanne st-util, or BMP worked fine for me even in windows when I was testing this stuff months ago.

-rick
-rick

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby RogerClark » Wed Sep 02, 2015 9:17 pm

Michael,

I can concur with Rick.

GDB on the command line works fine.

I had to use it yesterday to find a nasty bug which caused __error() to be called, and I used backtrace "bt" to show the stack and work out precisely which line number things were on.

Well, I must admit, I didn't list / display the code when I was doing by debugging yesterday, but I'm sure I've done it in the past, so I'm fairly sure that GDB knows where to look even with the Arduino IDE adding the Ino into the elf file etc

michael_l
Posts: 219
Joined: Mon Aug 24, 2015 6:11 pm

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

Postby michael_l » Thu Sep 03, 2015 4:22 am

Thanks guys for your support. It is a bug in Eclipse IDE. I submitted an issue - let's see what happens. Would be nice to fix it but I could not find any instruction on how to download and build Eclipse C/C++ plus CDT from source.

Well, I do seem to have a problem too with my new progam receiving SIGINT. I compiled and ran for the first time my original program for Nano.

Then I pressed 'Suspend' on the IDE

Code: Select all

#0  0x080022fe in gpio_write_bit (dev=0x20000324 <gpiob>, pin=1 '\001', val=1 '\001') at C:\Users\mika\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple/include/libmaple/gpio.h:92
#1  0x080023c6 in throb () at C:\Users\mika\Documents\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple\libmaple\util.c:141
#2  0x08002348 in __error () at C:\Users\mika\Documents\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple\libmaple\util.c:56
#3  0x08002348 in __error () at C:\Users\mika\Documents\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple\libmaple\util.c:56
#4  0x00000000 in ?? ()


any changes to get error led working that is referred in throb() ? would be kind of nice to see that

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby RogerClark » Thu Sep 03, 2015 6:28 am

Michael

I had the throb() problem the other day.

Well, throb() is not the problem, its a symptom of the problem.

There is a error exception callback defined in one of the jump tables, called __error() and __error() calls throb() which flashes the LED

When I was debugging an issue I had with USB Serial, it ended up in throb() but i was able to use backtrace "bt" to see the call stack and work out which line in the boards setup source had really caused the problem. I just opened the file in notepad++ and looked at the line and it was then obvious what I'd been doing wrong.,
In my case it was an issue of variables not being initialised when they were used (read)


Anyway, lets hope the Eclipse team accept it as a bug and fix it.

michael_l
Posts: 219
Joined: Mon Aug 24, 2015 6:11 pm

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

Postby michael_l » Thu Sep 03, 2015 9:21 am

Instructions to debug Arduino sketches in Eclipse C/C++ IDE with STM32 and OpenOCD

Most of the stuff has been taken from: http://gnuarmeclipse.livius.net/blog/ which I followed. Here it is in a little more compact form.

# Eclipse IDE

Download and unzip Eclipse Mars for C/C++ (Win32) here:

https://www.eclipse.org/downloads/packa ... pers/marsr

# GNU ARM plug-ins

The recommended way to install these plug-ins is to use the Eclipse standard install/update mechanism: In the Eclipse menu: Help ? Install New Software… -> Add

fill in Name: with GNU ARM Eclipse Plug-ins
fill in Location: with http://gnuarmeclipse.sourceforge.net/updates

Select all the plugins and install. It might warn you about untrusted plugins. Ignore that.

Next we'll install :
- toolchain
- optional build tools (if you are running on Windows)
- debugging tools


# Toolchain

https://launchpad.net/gcc-arm-embedded

and from right select the second one which should be this:

https://launchpad.net/gcc-arm-embedded/ ... -win32.exe

Install to (default): C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2015q2

!! leave unchecked: 'Add path to environment variable' and 'launch gccvar.bat'


# Build tools (for windows)

http://sourceforge.net/projects/gnuarme ... d%20Tools/

Download the first one on the list: (win32 2.6.xx)
http://sourceforge.net/projects/gnuarme ... e/download

Install to (default) C:\Program Files\GNU ARM Eclipse\Build Tools folder:

Check the global tools path: Windows->Preferences->Build->Global Tools Path. If you installed toolchain and built tools in default locations these should have been found by IDE

Image


# Debugging tools (OpenOCD)

Install GNU ARM OpenOcd plugin from here: http://sourceforge.net/projects/gnuarme ... D/Windows/ . I installed 0.9.0 which was latest. Installation goes by default here: C:\Program Files (x86)\GNU ARM Eclipse\OpenOCD\0.9.0-201505190955

This will enable OpenOCD Debugging.

Check Preferences->Run/Debug->OpenOCD to see if openocd.exe points to correct folder. It was filled automatically by IDE.

Board config file goes into 'Config' section: "-f board\st_nucleo_f103rb.cfg". In my case there was a ready made config file for Nucleo-F103RB. There are more board config files to choose in directory scripts\board.

It's time to test if OpenOCD can connect to your board. In my case there was ready made config for Nucleo-F103RB. As you might understand this is a mandatory step to get debugging working. OpenOCD will talk to your debugging interface forwarding commands from IDE.

Code: Select all

C:\Program Files (x86)\GNU ARM Eclipse\OpenOCD\0.9.0-201505190955\bin>openocd.exe -f ..\scripts\board\st_nucleo_f103rb.cfg
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 mi
ght 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
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.247525
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints


Image


# Compiling and debugging


Switch to Arduino IDE

enable 'Show verbose output during [x] compilation' from Arduino IDE

Now you have two choices:

1) Use regular Arduino IDE:
because of a bug in Eclipse Win32 IDE you have to make a small change in your .ino file. Without this step you won't be able to debug original .ino file. Let's say you have a sketch called blink.ino

for 'blink.ino' create blink2.cpp file (not blink.cpp)

copy contents of blink.ino into blink2.cpp

edit original blink.ino file so that it contains only this line: #include "C:\Program Files (x86)\Arduino\examples\01.Basics\myblink\myblink2.cpp" and add #include <Arduino.h> to the first line.

2) use modified Arduino IDE. Download link is here: http://www.megafileupload.com/54w6/arduino-02-Sep-2015.zip. During compilation of .ino file it will remove #line directives from the .cpp that Arduino generates. #line directive generates reference to blink.ino file in the .elf and it seems to confuse Eclipse IDE (Win32 at least) so that it can't find the file. More about that in this thread.


Compile sketch in Arduino IDE

Note and copy the output path in the Arduino IDE (this will be needed in Eclipse and luckily needs to be done only once per project).

Open Eclipse and create an STM project. File -> New C project. Select for example STM32F10x. Press Next several times and create some name for your project. Let's call it debug_test.

Click on created project 'debug_test' and mouse right click: Debug as->Debug configurations...

Create a new 'GDB OpenOCD Debugging configuration'

In 'C/C++ Application' box under 'Main' tab press 'Browse..' and enter full path to .elf file compiled by Arduino IDE

Press 'Debug' to start debugging

cross your fingers ;)


Roger, should I move this to the first page or ? Feel free to move/edit this..
Last edited by michael_l on Sun Sep 06, 2015 8:08 pm, edited 7 times in total.

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby RogerClark » Thu Sep 03, 2015 10:13 am

Hi Michael

I think its best to leave it here until a few people have tried the instructions and have ironed out any kinks etc

Once we are sure the instructions work for most people, we can move it to the top of the thread

Thanks again

Roger

michael_l
Posts: 219
Joined: Mon Aug 24, 2015 6:11 pm

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

Postby michael_l » Thu Sep 03, 2015 3:06 pm

Here's the DL link for modified Arduino IDE I have used.
http://www.megafileupload.com/54w6/arduino-02-Sep-2015.zip

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby RogerClark » Thu Sep 03, 2015 8:54 pm

thanks for the link

User avatar
RogerClark
Posts: 5467
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

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

Postby RogerClark » Sun Sep 06, 2015 10:33 am

michael

I have tried following your instructions, and have installed Eclipse etc

However I had a problem with the Arduino IDE.

I changed my bink_pc13.ino to just have an include to my cpp e.g.

Code: Select all

#include "C:\Users\roger\Documents\Arduino\blink_pc13\blink_src.cpp"


and blink_src.cpp is in the same folder as blink_pc13.ino and is this

Code: Select all

void setup() {
  // put your setup code here, to run once:
pinMode(PC13,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(PC13,!digitalRead(PC13));
delay(1000);
}


But I got a load of error messages, which transpired to be because I need to include <Arduino.h> in the top of my new cpp file.


Anyway.

After that compiled, I triedl to follow your other instructions but it fails to debug.

I get this error message
Error while launching command: ${cross_prefix}gdb${cross_suffix} --version


Do I need to install any STLink drivers etc? or can you think what else is missing.

Also, what does the -f board\st_nucleo_f103c8.cfg do ? does it need to be that file name I tried stm323f103c8 as I'm not using an rb

but I also tried changing it to -f board\st_nucleo_f103c8.cfg and it didnt make any difference

I suspect I am missing this config file or a openOCD driver etc

BTW. What are you using STLink or Black Magic Probe or perhaps even JLink ?

michael_l
Posts: 219
Joined: Mon Aug 24, 2015 6:11 pm

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

Postby michael_l » Sun Sep 06, 2015 6:27 pm

Roger,

Very good points here and a few mistakes from me. I just edited and added more information.

The error message you're seeing is because you most probably didn't create a 'dummy' STM32 project from File->New C Project->STM32F10x, did you ? This sets the correct path for ARM compiler and enables variables: {cross_prefix} and {cross_suffix}. I did get the same error. If you dont' get this working I believe you can hard-code the full path to arm-none-eabi-gdb.exe because that's what it uses.

Yes, you'll have to have ST-Link drivers installed and working. I have Nucleo-F103RB which has on-board ST-Link v2.1.I just installed driver package from ST's website. Anyway.. for Nucleo-F103RB there's a ready made configuration under OpenOCD's directory. It's a script that executes several other config files:

Code: Select all

# This is an ST NUCLEO F103RB board with a single STM32F103RBT6 chip.
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF259875

source [find interface/stlink-v2-1.cfg]

transport select hla_swd

source [find target/stm32f1x.cfg]

reset_config srst_only


stm32f1x.cfg is a large file and contains a lot of different config files. But as said there was a ready config for Nucleo-F103RB so I did not have to change anything. It might be that for your setup perhaps some commands need to be modified. I am waiting for my Maple Mini clone and will test this with that board too. If you know exact differences between maple mini clone and F103RB this configuration file should make more sense.. I'll just copy the contents of stm32f1x.cfg here so other's can see it too. I assume this would work with C8 too as the config is for f1x- series. So after all your debugging might just work with the same '-f board\st_nucleo_f103rb.cfg' as mine..

Code: Select all

# script for stm32f1x family

#
# stm32 devices support both JTAG and SWD transports.
#
source [find target/swj-dp.tcl]
source [find mem_helper.tcl]

if { [info exists CHIPNAME] } {
   set _CHIPNAME $CHIPNAME
} else {
   set _CHIPNAME stm32f1x
}

set _ENDIAN little

# Work-area is a space in RAM used for flash programming
# By default use 4kB (as found on some STM32F100s)
if { [info exists WORKAREASIZE] } {
   set _WORKAREASIZE $WORKAREASIZE
} else {
   set _WORKAREASIZE 0x1000
}

#jtag scan chain
if { [info exists CPUTAPID] } {
   set _CPUTAPID $CPUTAPID
} else {
   if { [using_jtag] } {
      # See STM Document RM0008 Section 26.6.3
      set _CPUTAPID 0x3ba00477
   } {
      # this is the SW-DP tap id not the jtag tap id
      set _CPUTAPID 0x1ba01477
   }
}

swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID

if { [info exists BSTAPID] } {
   # FIXME this never gets used to override defaults...
   set _BSTAPID $BSTAPID
} else {
  # See STM Document RM0008
  # Section 29.6.2
  # Low density devices, Rev A
  set _BSTAPID1 0x06412041
  # Medium density devices, Rev A
  set _BSTAPID2 0x06410041
  # Medium density devices, Rev B and Rev Z
  set _BSTAPID3 0x16410041
  set _BSTAPID4 0x06420041
  # High density devices, Rev A
  set _BSTAPID5 0x06414041
  # Connectivity line devices, Rev A and Rev Z
  set _BSTAPID6 0x06418041
  # XL line devices, Rev A
  set _BSTAPID7 0x06430041
  # VL line devices, Rev A and Z In medium-density and high-density value line devices
  set _BSTAPID8 0x06420041
  # VL line devices, Rev A
  set _BSTAPID9 0x06428041
}

if {[using_jtag]} {
 swj_newdap $_CHIPNAME bs -irlen 5 -expected-id $_BSTAPID1 \
   -expected-id $_BSTAPID2 -expected-id $_BSTAPID3 \
   -expected-id $_BSTAPID4 -expected-id $_BSTAPID5 \
   -expected-id $_BSTAPID6 -expected-id $_BSTAPID7 \
   -expected-id $_BSTAPID8 -expected-id $_BSTAPID9
}

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME

$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0

# flash size will be probed
set _FLASHNAME $_CHIPNAME.flash
flash bank $_FLASHNAME stm32f1x 0x08000000 0 0 0 $_TARGETNAME

# JTAG speed should be <= F_CPU/6. F_CPU after reset is 8MHz, so use F_JTAG = 1MHz
adapter_khz 1000

adapter_nsrst_delay 100
if {[using_jtag]} {
 jtag_ntrst_delay 100
}

reset_config srst_nogate

if {![using_hla]} {
    # if srst is not fitted use SYSRESETREQ to
    # perform a soft reset
    cortex_m reset_config sysresetreq
}

$_TARGETNAME configure -event examine-end {
   # DBGMCU_CR |= DBG_WWDG_STOP | DBG_IWDG_STOP |
   #              DBG_STANDBY | DBG_STOP | DBG_SLEEP
   mmw 0xE0042004 0x00000307 0
}

$_TARGETNAME configure -event trace-config {
   # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync
   # change this value accordingly to configure trace pins
   # assignment
   mmw 0xE0042004 0x00000020 0
}


I added note about this to check the path and test that OpenOCD is able to connect to your debugging interface.

When starting OpenOCD opens up a port for GDB and OpenOCD telnet interface. You can see what the IDE sends to/from GDB from windows at the bottom. There's a small icon with tooltip (fourth from right) : Display selected console. By default the window where GDB traces (what IDE sends) is not selected - so you'll have to activate that window.

Hope this helps!


Return to “IDE's”

Who is online

Users browsing this forum: No registered users and 1 guest