Debug-Help required: Arduino sketch hangs in delay, timer broken?!

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

 

I'm having a strange debug issue which I do not understand.

 

Details:

 

Arduino Sketch for Arduino Leonardo

--> get's compiled, but let the arduino hang. Code in setup() seems not to run

 

The sketch is doing almost nothing (commented out almost everything to track down the issue), but: 

* initialize a static object of one of my libraries

* setup() runs a "blink test" with the onboard LED

 

My expectation was, that when I run this in Atmel Studio (on Win10 in Virtualbox with ATMEL ICE debugger) and debug the code, that I find some kind of uninitialized variables or so, which crash the AVR.

 

But I face this:

 

https://www.youtube.com/watch?v=...

 

 

I'm not so familiar with the internals of the Arduino code, but it seems that there's a problem with the timer. "micros()" always returns the same time (0x000008ae).

 

The delay() is called from this function in CDC.cpp:

 

 

// This operator is a convenient way for a sketch to check whether the
// port has actually been configured and opened by the host (as opposed
// to just being connected to the host).  It can be used, for example, in
// setup() before printing to ensure that an application on the host is
// actually ready to receive and display the data.
// We add a short delay before returning to fix a bug observed by Federico
// where the port is configured (lineState != 0) but not quite opened.
Serial_::operator bool() {
	bool result = false;
	if (_usbLineInfo.lineState > 0)
		result = true;
	delay(10);
	return result;
}

The strange thing is:

 

  • I don't get any hint (stacktrace...) on which line of code is calling this function
  • I'm sure that neither setup()/loop() nor the constructor of the static class instance is using Serial (as I said, commented out almost everything to keep it simple)

 

If I fake the "m" variable in the delay() function during debug, so that the delay finally returns, sketch continues and code in setup() finally runs. 

 

I'm finally not sure if I really debug the issue I face with the arduino IDE (arduino.cc), or if this is a new side-effect from importing the sketch to Atmel Studio :-(

 

 

 Has anybody any clue on what's wrong with this?

Last Edited: Mon. May 9, 2016 - 07:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try posting a minimum sketch that demo's the problem, otherwise it's hard to see with out "seeing" the code!

 

 

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not able to reduce it to a minimum sketch :-( That would imply that I know in which area the bug is. But I have absolutely no clue. 

 

But I can at least reduce one point:

 

I'm finally not sure if I really debug the issue I face with the arduino IDE (arduino.cc), or if this is a new side-effect from importing the sketch to Atmel Studio :-(

I found out, that the Arduino IDE is creating an ELF file which can be opened by Atmel Studio. So I flashed again the arduino bootloader + flashed my broken sketch (with USBTiny as always), connected everything to AS7 + Atmel ICE, enabled the JTAG fuse and started debugging with this ELF file.

 

Again, the code is hanging at the point shown in the video. Exactly the same behavior. So it's a first good sign that I'm on the right way with my debugging session. 

 

Is there anything else I can provide (out of the debug session?). I can post the links to CDC.cpp and wiring.c where the "problem" occurs...(takes some time to find the right files...)

 

 

wiring.c

https://github.com/arduino/Ardui...

 

CDC.cpp

https://github.com/arduino/Ardui...

 

The sketch is very minimalistic:

#include <KnxDevice.h>

void setup() {


    for (int i = 0; i < 5000;i++) {
        analogWrite(13, 128);
        delay(100);
        analogWrite(13, 255);
        delay(180);
    }


}

void loop() {
}

I'll check if I can somehow reduce the code behind KnxDevice.h ... 

 

Last Edited: Mon. May 9, 2016 - 07:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Finally found the issue:

 

I had a header-file, which had a line like this:

 

static Serial_ __DEBUG_SERIAL;

This header file was not "#include"d by any other file or by the sketch... My expectation was: This is dead code and the compiler will just leave it as "unused". But actually this wasn't the case. Accessing Serial in this way lead to initialize the serial line ... which fails at this stage. 

 

Removed the obsolete, unused header file and code is running again without error....