SOLVED: gcc 4.4 can't reference precompiled class

Hi,

I just got my Arduino Mega and I can't seem to get the serial port to do anything. If I create a simple program that uses Serial.setup(9600), even if the serial port is never used, it doesn't seem to execute anything in the program. I'm doing this:

void setup(void) {
 pinMode(13, OUTPUT);
}

void loop(void) {

  digitalWrite(13, LOW);
  delay(1000);
  digitalWrite(13, HIGH);
  delay(1000);
  //Serial.begin(9600);
}

This works great, unless I uncomment the Serial.begin line. Just having it anywhere makes the LED never blink, not even once.

If I activate the serial monitor, I do see transmitted characters on the LED, and I'm having no trouble uploading stuff.

What could I be doing wrong? Any tips or suggestions to debug this?

Try this...

void setup(void) {
 Serial.begin(9600);
 pinMode(13, OUTPUT);
}

void loop(void) {

  digitalWrite(13, LOW);
  delay(1000);
  digitalWrite(13, HIGH);
  delay(1000);
  Serial.println( "Hello world!" );
}

I'm having this exact same problem. I've tried putting Serial.begin in start(), but no success. The execution never seems to get past the begin() line. Even if I tell it to blink the LED in start(), after begin(), nothing. I've tried the ASCIITable example program that comes with the Arduino IDE, but that does nothing either. For monitoring serial, I've used the IDE's internal serial monitor, as well as screen, and putty. I'm using Gentoo. I'm open to any other ides, thanks!

I’ve tried putting Serial.begin in start(),

start? Did you mean setup?

That was quick, I was going to change that, but you responded already, thanks! Yes, setup(). I didn't have the code open when I made that post. I also forgot to mention I have an arduino mega. I've successully loaded various programs, reading from various inputs. Everything I've tested so far works fine, except for serial.

The execution never seems to get past the begin() line

That doesn't appear to be possible. In the version 15 IDE, begin sets two registers, three bits, and returns. There really isn't any way for begin to "lock up".

I've successully loaded various programs

Which is a good indication that the hardware is working correctly.

There isn't much left besides your Sketch. Someone else may be able to help but I'm afraid I'll have to see your code before I can offer anything more.

The test with setup in the begin section fails also. I think I might have a defective mega. :(

What surprises me is that it doesn't seem to be the begin() call that is causing the lockup. Just referencing the Serial object in the program anywhere, even if I don't call Serial.begin, seems to cause it not to start executing anything. Is there any bootstrap code that has to get sent if you reference Serial?

I tested this as well:

int i = 0;
void setup(void) {
 pinMode(13, OUTPUT);
}

void loop(void) {
  digitalWrite(13, LOW);
  delay(1000);
  digitalWrite(13, HIGH);
  delay(1000);
  if ( i++ == 10000 )
     Serial.begin(9600);
}

No blinks.

I solved my problem. The issue is that I'm using gentoo, and the compiler I have (gcc 4.4) doesn't match the version that was used to build the libraries. Rebuilding HardwareSerial.cpp with gcc 4.4 makes the problem go away.

Well, it's only partially solved. If I skip initializing Serial1 through Serial3, it works. This is enough for me at the moment because I only need one serial port.

It seems there's a problem with the Gentoo package. I've tried on 32 & 64-bit machines. On the 32-bit machine, I can at least communicate with the arduino over serial, provided I've compiled the program in Windows first. I have a VM for windows, so it's not a real big deal, but I was hoping to get it working in linux.