Arduino blog

Arduino blog

Arduino thinkering

This blog is about things I come by related to Arduino which I feel are inspiring/important/funny enough to write about.

Debugging and unit testing Arduino (Part 3) Setting it up and debugging

eclipse pluginPosted by Jan Thu, July 02, 2015 00:00:38
EDIT for this to work you need to have a gcc compiler in your path capable of making local executables.

(This post assumes you know how to setup and use the arduino eclipse plugin)
For the sake of this post we will now create a new project based on the uno.
Use the create new sketch wizard to create a new sketch called debugDemo as follows:
Make sure you have selected the correct boards file!!
Lets take a blank ino file
click finisch

open debugDemo.ino and paste following code in the ino file.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include "Arduino.h"
void setup() {
// Add your initialization code here
}

void loop() {
static uint8_t ledState=LOW;
ledState = calcLedState(millis(), ledState);
digitalWrite(LED_BUILTIN, ledState);
}
#define INTERVAL 500
uint8_t calcLedState(uint32_t currentMillis, uint8_t ledState) {
static uint32_t previousMillis = 0;
if (currentMillis - previousMillis > INTERVAL) {
previousMillis = currentMillis;

if (ledState == LOW)
return HIGH;
else
return LOW;
}
return ledState;
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Compile and upload to a uno to verify it is working. (you should get a blinking led on pin 13)
Untill now we have done nothing new. We have just uploaded a blink without delay sketch to the uno.


Now we'll create a debug configuration for our debugDemo project using the "jantje hardware".
To do so you first need to install the hardware found at my github repository.
Once the hardware is on your system right click the project in the project explorer and select project properties->arduino.
Press the button called "manage configurations"

Press the button new to create a new configuration called "Debug" based on "Release" as shown on the image below.

Press ok 2 times to get back to the arduino properties.
Select "Debug" in the configuration in the combo box.
In the boards.txt file select the one that ends with "/hardware/jantje/avr_local/boards.txt"
In debug or unit test fill in "debug"

Make sure you do not have selected "use alternative size command" in compile options.

Compile the project in the debug configuration (this is not strictly needed but it makes it easier to fill in the following forms)
Right click the project->build configurations->build all.
If the build fails probably something went wrong when setting up the environment (but try to build again before looking for the root cause).

Now we have our sketch build for running on arduino and build for debugging on our local machine. What needs to be done now is
Setting up a debug configuration.
Right click the project and select "debug as"->debug configurations.
Select C/C++ application and new.
Here you will have to experiment a bit with the settings. On my system I have to use the "legacy create process launcher". I use the settings as shown below.

!!Note that forgetting to set the build configuration to Debug is a perfect way to increase your frustration level!!!!
Now click apply and then debug.
If all is well you should see eclipse compiling your project and eclipse may ask you to switch to debug perspective (click yes if he does).

The debugger breaks in the main function. Set a breakpoint where you want it and have a happy debugging session.
Best regards
Jantje





  • Comments(9)

Fill in only if you are not real





The following XHTML tags are allowed: <b>, <br/>, <em>, <i>, <strong>, <u>. CSS styles and Javascript are not permitted.
Posted by Jan Sat, July 04, 2015 20:38:15

best is to create an issue on github

Posted by Mr.Kim Sat, July 04, 2015 14:33:20

Hi.

Yes, I has probrem. after click Arduino Verify ( in compile ).

many error, see error message --Lower part --

Othergates, Send E-Mail to me (Kshok@naver.com), debugDemo workspace.

please

Thank, your answer.

Posted by Jan Sat, July 04, 2015 10:54:45

Hi Kim
I can't really follow.
From the given image there is little I can say.
Is there still a problem on your side or did you fix it?

Posted by Mr.Kim Sat, July 04, 2015 05:05:11

Sorry
http://www.4shared.com/download/Pm6OtmPVce/20150704-Include2.png?lgfp=3000

Thank, Jantje

Posted by Mr.Kim Sat, July 04, 2015 04:58:09

I was reattach.
20150704-Include2.png

Thank, Jantje

Posted by Mr.Kim Sat, July 04, 2015 04:41:03

Thank, your answer.

I was doing to your advice.

I found error when change to project > Arduino > Bords.txt file: C:\Arduino\hardware\jantje\boards.txt , Apply and OK and click the Arduino > Verify.

see screen shot http://www.4shared.com/download/I4FIhQNmce/20150703debugDemo.png?lgfp=3000

see error message --Lower part --

--Lower part --

Description Resource Path Location Type
'size_t strlen(const char*)' was declared 'extern' and later 'static' [-fpermissive] WString.h /debugDemo/arduino/core line 237 C/C++ Problem
'uint_farptr_t' has not been declared pgmspace.h /debugDemo/arduino/variant/avr line 1169 C/C++ Problem
expected primary-expression before 'len' pgmspace.h /debugDemo/arduino/variant/avr line 1168 C/C++ Problem
expression list treated as compound expression in initializer [-fpermissive] pgmspace.h /debugDemo/arduino/variant/avr line 91 C/C++ Problem
make: *** [.ino.cpp.o] Error 1 debugDemo C/C++ Problem
previous declaration of 'size_t strlen(const char*)' [-fpermissive] debugDemo line 49, external location: c:\mingw\include\string.h C/C++ Problem
'__progmem__' attribute directive ignored [-Wattributes] Arduino.h /debugDemo/arduino/core line 134 C/C++ Problem
'strlen_PF' initialized and declared 'extern' [enabled by default] pgmspace.h /debugDemo/arduino/variant/avr line 1167 C/C++ Problem
'strnlen_PF' initialized and declared 'extern' [enabled by default] pgmspace.h /debugDemo/arduino/variant/avr line 1168 C/C++ Problem
"pgm_read_byte" redefined [enabled by default] Arduino.h /debugDemo/arduino/core line 223 C/C++ Problem
"PROGMEM" redefined [enabled by default] pgmspace.h /debugDemo/arduino/variant/avr line 109 C/C++ Problem
#warning "device type not defined" [-Wcpp] io.h /debugDemo/arduino/variant/avr line 612 C/C++ Problem
attributes after parenthesized initializer ignored [-Wattributes] pgmspace.h /debugDemo/arduino/variant/avr line 91 C/C++ Problem
in expansion of macro 'strlen_P' pgmspace.h /debugDemo/arduino/variant/avr line 1184 C/C++ Problem
this is the location of the previous definition Arduino.h /debugDemo/arduino/core line 14 C/C++ Problem
this is the location of the previous definition pgmspace.h /debugDemo/arduino/variant/avr line 1046 C/C++ Problem

--end Lower part--

*ps

I found changed {project}>Include files when change to project > Arduino > Bords.txt file

Before ArduinoDebugTest>Include>Files

After debugDemo>Include>Files

See attach

http://www.4shared.com/download/PAeUsGAVba/20150704-Include.png?lgfp=3000

Thank, Jantje

Posted by Jan Fri, July 03, 2015 12:53:56

Mr Kim
You found a bug in the text :-).
You should install the hardware from my github repository
txs
Jantje

Posted by Mr.Kim Fri, July 03, 2015 08:04:04

Thank, your answer and contents.

Sorry, I am weak English.

I was install already Arduino eclipse extensions 2.4.0 with eclispse luna c/c++ and Arduino 1.6.1 to your advice.

But I am not found "/hardware/jantje/avr_local/boards.txt" in combo box.

jantje/avr_local/boards.txt in Arduino ?

or in Arduino eclipse extensions 2.4.0 ?

-- Lower part is your writing. --

Select "Debug" in the configuration in the combo box.
In the boards.txt file select the one that ends with "/hardware/jantje/avr_local/boards.txt"
In debug or unit test fill in "debug"


Posted by Jan Thu, July 02, 2015 00:12:03

When debugging the code above I found a bug :-)
Anyone else sees it?