Arduino refusing to blink without Serial.begin(9600)

Hey, while taking my first steps with my Arduino Duemilanove, i've encountered an interesting Problem/Bug:

When i'm uploading the Example-Code for a blinking LED, it doesn't blink. The LED just turns on. But if i insert Serial.begin(9600); in void setup() it works.

Here is the code:

/*
  Blink
  Turns on an LED on Pin 12 for one second, then off for one second, three times.
  Then LED 13 blinks once.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);  
  
  Serial.begin(9600);
}

void loop() {
  digitalWrite(12, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  
 // Serial.println(1);      //Serial Output for debugging issues

  digitalWrite(12, LOW);    // set the LED off
  delay(1000);              // wait for a second
  
//  Serial.println(2);
  
  digitalWrite(12, HIGH);   // set the LED on
  delay(1000);   // wait for a second     

 // Serial.println(3);
  
  digitalWrite(13,HIGH);
  delay(1000);
  digitalWrite(13,LOW);
  delay(1000);
}

Your thoughts on this? I seriously have no idea...

The sketch works for me without the Serial.begin(). I don't have an LED on D12 but the built-in LED on D13 blinks one second on and four seconds off.

Oh, i forgot to comment the Serial begin. The Problem ist, that it just works with it, but it should work without.

mri_delta: ...The LED just turns on...

Hmmm...

What Operating System are you using? What version of avr-gcc?

The reason that I asked is that I have run across situations where avr-gcc screwed up when it linked programs with no data variables.

mur_delta: But if i insert Serial.begin(9600); in void setup() it works.

With this in the sketch (even if you don't use Serial.print or other Serial functions) it instantiates a HardwareSerial object that occupies memory in the data block of RAM.

So...

What happens if you try the following slightly modified Blink sketch?

 /*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.

  Modified by davekw7x to use a variable in the data block of RAM
 */
int ledPin = 13;
void setup() {                
  // initialize the digital pin as an output.
  pinMode(ledPin, OUTPUT);     
}

void loop() {
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

I mean, my suggestion is based on a really WAG, and you really shouldn't have to do this, but...

Regards,

Dave

What Operating System are you using? What version of avr-gcc?

I'm running Fedora 14 with avr-gcc (Fedora 4.5.1-2.fc14.1) 4.5.1, and your version of the blink-sketch works. Really interesting.

The reason that I asked is that I have run across situations where avr-gcc screwed up when it linked programs with no data variables.

Do you think it's a problem directly related to my avr-gcc Version?

Very interesting. I think i keep this in mind when it comes up to interesting Problems. Thank you :)

mri_delta: I'm running Fedora 14 with avr-gcc (Fedora 4.5.1-2.fc14.1) 4.5.1, and your version of the blink-sketch works. Really interesting.

Yes, these are "interesting times."

[quote author=mri_delta link]Do you think it's a problem directly related to my avr-gcc Version?[/quote]Yes. I have been through several versions of avr-gcc on various Linux platforms. avr-gcc version 4.3.4 on Ubuntu does not have the problem that we are seeing, on the other hand, when I built the same version from source code on my Centos workstation, it turns out that it has the problem. Go figure.

I tracked down something in the linker flags that causes the problem to come and go. Leaving out the -Wl,--gc-sections flag from a manual compilation, makes the difference. (This is a version-dependent avr-gcc bug, not an Arduino bug.)

[quote author=mri_delta link]Very interesting. I think i keep this in mind when it comes up to interesting Problems.[/quote]

The specific problem (doesn't work for programs with no data variables) is not a real shortcoming, I'm thinking, but it is very disappointing that the very first program that most of us run (the Blink sketch in the Arduino distribution) doesn't give any satisfaction.

Regards,

Dave