Pages: [1] 2   Go Down
Author Topic: Linux V0022 Mega 2560 crash (SOLVED?)  (Read 1751 times)
0 Members and 1 Guest are viewing this topic.
Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5394
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After  a couple days of testing, I found these commands cause the Mega 2560 to crash if compiled on Linux compiler:
Code:
Serial.begin(9600);
Client client(server,80);
Crashes on Linux compiled code. Runs fine on Windows compiled code.
OnLinux, I am using V0022 and avr-gcc 4.4.2

So no serial or ethernet client available on newest Linux compiler.  smiley-cry

What I mean by "crash" is it crashes on sketch upload, not when the command is executed.

« Last Edit: July 29, 2011, 11:50:55 am by SurferTim » Logged

Dallas, Texas
Offline Offline
Sr. Member
****
Karma: 3
Posts: 267
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Where did you get your compiler? Are you using the compiler supplied with your distribution? If so, that's likely the problem.

You may find this thread to be enlightening.
Logged


Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16548
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What I mean by "crash" is it crashes on sketch upload, not when the command is executed.

Well uploading usually leaves error messages in the IDE output window if unsuccessful, as uploading is a simple serial communications of the hex file data that avrdude uses to send to the bootloader code in the arduino board and stored in program flash memory area. If you get no errors on uploading (get the uploading complete message), then the code is indeed crashing as it tries to execute the code, more likely stuck in some infinite loop.

Usually one can embed diagnostic serial messages into the sketch code to determine how far the program is getting before 'crashing'.

Lefty

Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5394
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The upload shows successful, but the code will not start on upload or reset.
I have experimented with this for two days, and finally came up with this code to determine where the crash was happening. The LED does not light. Remark out the "Serial.begin(9600);", and all is as you would expect.

Code:
void setup()
{
  pinMode(13,OUTPUT);
  digitalWrite(13,HIGH);
  delay(1000);
  Serial.begin(9600);
}

void loop()
{
}

EDIT: The code produced by the Linux version and the Windows version are different sizes.
« Last Edit: July 26, 2011, 07:56:09 am by SurferTim » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16548
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That would imply that you should be able to upload the example blink sketch and it would run ok?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5394
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Blink runs great! This works perfect:

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

void loop()
{
  digitalWrite(13,HIGH);
  delay(500);
  digitalWrite(13,LOW);
  delay(500);
}

EDIT: I know it says "newbie", but that is not exactly true. Only with Arduino. I wrote my first compiler (yes, wrote a compiler) for the MCS51 series controller in 1996.
« Last Edit: July 26, 2011, 08:08:43 am by SurferTim » Logged

Dallas, Texas
Offline Offline
Sr. Member
****
Karma: 3
Posts: 267
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That's a basic confirmation of a buggy compiler. Again, I refer you to the thread linked above.

As this was seemingly, completely ignored, I'll stress this part once again:
Quote
Where did you get your compiler? Are you using the compiler supplied with your distribution? If so, that's likely the problem.
« Last Edit: July 26, 2011, 08:22:58 am by gerg » Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5394
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes. I did download it from the repository for my version of Linux. These are the versions they show:
avr-gcc 4.4.2
avr-binutils 2.20
avr-libc 1.67

The repository has been very reliable in the past. Do you see anything here that should be upgraded? Did I miss a utility?
If so, I can recommend the repository team compile new versions. It might take a while tho.

EDIT: I missed the link on your first post. I see it now, and thanks!  smiley

I do not really see a "problem solved" anywhere tho. The Windows version compiler works great. It is set a a tcp client with an ethernet shield, and after "flying" all night, it just "phoned home", and established 2-way comm immediately. Very impressive hardware.
« Last Edit: July 26, 2011, 09:11:12 am by SurferTim » Logged

Dallas, Texas
Offline Offline
Sr. Member
****
Karma: 3
Posts: 267
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes. I did download it from the repository for my version of Linux. These are the versions they show:
avr-gcc 4.4.2
avr-binutils 2.20
avr-libc 1.67

The repository has been very reliable in the past. Do you see anything here that should be upgraded? Did I miss a utility?
If so, I can recommend the repository team compile new versions. It might take a while tho.


Based on my own experience, chances are very high they are handing out known buggy compilers. You can compile your own binutils, compiler, and libc; which I strongly recommend. Again, from my own experience, the distros are very much aware they have a crappy AVR compiler but just don't care. I guess from their perspective, the number of users who not only cross compile for AVR AND are using one of the MCUs which are buggy with their compiler is so small, its not worth their time.

As a stop gap, so as to allow you to use the Serial interface with your compiler, try this. Modify HardwareSerial.cpp. Make the following changes at the end of the file.
Code:
#if defined(UBRR1H)
  //HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
  #warning serial port 1 disabled because of compiler bug
#endif
#if defined(UBRR2H)
  //HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
  #warning serial port 2 disabled because of compiler bug
#endif
#if defined(UBRR3H)
  //HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
  #warning serial port 3 disabled because of compiler bug
#endif

The Mega2560 has four hardware UARTS. This change means only one is available (Serial); without manually instantiating them inside your loop. Furthermore, instantiating other global objects will likely also trigger the compiler bug which screws up save/restore of a couple of registers. This in turn means you'll need to move some globals into the loop() scope. This in turn means lots of examples will not work without change. Furthermore, this means a lot of code will simply not work without yet more changes.

If compiling for the 2560 is important for your project, I strongly encourage you to compile your own compiler. The combination which works is documented in the thread. The important part is applying the patches. As noted in that thread, one hunk from one patch failed to apply for me. Regardless, once done you should have a compiler which at the very least is far more reliable than the one provided by your distribution.

Now if only the arduino devs would release a 0023 based on the current libc + gcc 4.6.x. In doing so, it would likely prevent the Linux problems altogether. But once again, I guess the cross section of users means they don't really care either.
« Last Edit: July 26, 2011, 09:24:29 am by gerg » Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5394
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks very much. I missed the link to the other post my first time through. I will try the patch, but my current app requires ethernet client to work also, so overall it will help, but not enough for this project.

Winavr works good. Gotta get back to my Windoze computer and do some coding. It is compiling everything correctly. Serial, ethernet client, and all....so  smiley but  smiley-cry
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5394
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A followup. I downloaded the newest 8-bit compiler from Atmel.
http://www.atmel.com/dyn/products/tools_card.asp?tool_id=17311&category_id=163&family_id=607&subfamily_id=760
Unzipped it and copied the files to the /usr/ folder.
Tried to compile a test program and crash! Got an error about delay.h when it compiled. An error about fabs and ceil.
No problem here. That is because they forgot the
#include <math.h>
So if you are following along, open
/usr/avr/include/util/delay.h
and add the #include <math.h>.
Try a compile, and crash!
Now something about "( or : expected before double".
So open
/usr/avr/include/math.h
and remark out this line:
Code:
extern double round (double __x) __ATTR_CONST__;
Can anyone see why that line generates an error?

EDIT2: IT IS WORKING!! Serial works, ethernet doesn't crash.  smiley
I forgot to set the board type after the new install. Now it uploads and all...
Thisis what I show now:

avr-gcc (AVR_8_bit_GNU_Toolchain_3.2.3_314) 4.5.1
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

But you must do the changes to the header files or it will still crash.
« Last Edit: July 29, 2011, 11:56:56 am by SurferTim » Logged

Dallas, Texas
Offline Offline
Sr. Member
****
Karma: 3
Posts: 267
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I should had said in the other thread that I also tried their compiler. It didn't work for me. I didn't spend much time on it but that also ignores they install the compiler into a system location they shouldn't be, which makes it all the more unattractive.

At any rate, I strongly encourage you to compile your own compiler.

Having said that, I may yet try again given your success.
« Last Edit: July 29, 2011, 12:29:50 pm by gerg » Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5394
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I disagree. If this were a compiler for Linux, I would agree. But it isn't. This codes for Atmel. Has nothing to do with the host machine. Kinda like Java in a way.

I really wish you would try it, just on a test machine if you have one. Wouldn't it be nice to be able to download this and have work right "out of the box"?
Logged

Dallas, Texas
Offline Offline
Sr. Member
****
Karma: 3
Posts: 267
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I disagree. If this were a compiler for Linux, I would agree. But it isn't. This codes for Atmel. Has nothing to do with the host machine. Kinda like Java in a way.

I really wish you would try it, just on a test machine if you have one. Wouldn't it be nice to be able to download this and have work right "out of the box"?


Standard convention is they should not be installing anything into /usr. They should be installing into /opt or /usr/local. To install third party software into /usr is a horrible violation of standard and best practices; especially since it can directly conflict with system provided packages. There is nothing about it which is a good idea.

And as I said, I did previously try it and it failed right off. I don't recall the nature of the issue I experienced but it may be what observed. Its also worth noting, I'm running 64-bit which can sometimes further complicate things. Again, as I said, I may give it another whirl.
Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 116
Posts: 5394
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many thanks for your input. I had not considered the location of the code. I had gone only by what the repository had done. That may be a good thing to consider. My repository put the files in
/usr/avr/
/usr/bin/
/usr/include/
etc.

The types of files that it put in those locations fit. That is the same file location/type that came from Atmel also. ??

Any time you download executable files, or even source code to build them, you are taking a bit of a chance. It is best if you stick to reputable suppliers. That link above is to the Atmel website, where I downloaded this from.

WARNING!! It did NOT work in all cases. ethernet client has problems with client.available() and client.read().
« Last Edit: July 29, 2011, 02:53:10 pm by SurferTim » Logged

Pages: [1] 2   Go Up
Jump to: