VS Arduino
Visual Micro >> General Board >> Arduino compiler can't work properly
https://www.visualmicro.com/forums/YaBB.pl?num=1463091881

Message started by Gilles Plante on May 12th, 2016 at 10:24pm

Title: Arduino compiler can't work properly
Post by Gilles Plante on May 12th, 2016 at 10:24pm
Hi,

I understand the the question is not related to Visual Micro extension, but we are experiencing some really nasty bugs because the compiler goes crazy.

A colleague of mine develops with AtmelStudio 6.2 - I understand it's not the latest and greatest, but we prefer not to upgrade for now. Two Arduino IDEs are installed: 1.5.7 and 1.0.6.

Working on a project with 1.5.7, target Atmega 2560, the compiler suddenly acted strangely. First some Serial.Print() would not work. The guy spent a few hours to find what was wrong - nothing's wrong with the code - and at one point the compiler generated badly formed binaries, the program simply hanged.

Then he went to the 1.0.6 IDE and the compiler this time did it right... sort of. The program seems to behave correctly, but the .hex file is, hum, strange. I noticed because I created a small tool that rewrites part of the .hex to write a serial number.

To make a long story short, I first make a bin file from the hex file - works much better with a bin file - search for the position of a specific string and then overwrite the faked serial number. Then I convert that edited bin file to a hex file. Thing is, that specific string is found 10+ times, and that fools the tool. To make sure my colleague searched for that string in the hex file, and found ou that the .hex generated by the compiler - or avrdude ? - hex file was wrong at the beginning.

Sorry for the long story, but that bugs us a lot  :(.

Any help would be appreciated.

PS I know that first a .elf file is created, and then it's converted in an hex file. Could that be this process that fails ?

Title: Re: Arduino compiler can't work properly
Post by Visual Micro on May 12th, 2016 at 10:35pm
Hi,

In both the arduino ide and visual micro your can switch on verbose messages and see the commands. Then you can run them from a bat file to try them out yourself.

You haven't said which board you are using but it probably doesn't matter

With verbose enabled you can also see the build folder and look at the real .cpp source code that is made by the pre-processor.

For loss of serial I suspect that you might have added a file to a project that overrides an arduino core source or have damaged hardware\avr folders below the arduino ide.

If the compiler is playing up then the tools folder below the arduino ide is damaged or not being found. Delete the arduino ide installations and re-download from arduino.cc using the zips.

If you are using custom hardware then delete and re-download.

Title: Re: Arduino compiler can't work properly
Post by Gilles Plante on May 12th, 2016 at 11:41pm
Hi Tim,

capturing the command to compile and using it in a batch file can be helpful, thanks.

The board is the Sparkfun Pro 3.3 V, which is a little bit different than the Arduino Mega2560. We added a board definition in the IDE under hardware if I recall well.

I have VisualStudio 2015 Community on another computer: I will install Arduino 1.6.8 and VisualMicro and give a try to see if the hex is still ill created. My guess is that the chain tool must be different in 1.6.8.

Regarding Serial.print(), it was failing in a specific place in the code, elsewhere it was working right. Strange. I wonder if the String object could be buggy.

Thanks

Title: Re: Arduino compiler can't work properly
Post by Visual Micro on May 12th, 2016 at 11:47pm
I think if the string object was buggy it would have affected many people.

Normally when things start failing for no reason at certain points in the code it means out of memory.

If you are hitting memory limits then you need to make sure you build with visual micro in release mode and not debug mode.

If you have many string constants in your you should make sure you use F("") or similar.




Title: Re: Arduino compiler can't work properly
Post by Gilles Plante on May 12th, 2016 at 11:50pm
The compiler says the RAM usage is 89%, but that is before the program runs, so ?!?. Lots strings constants are used with F().

All that means more investigations to come !

Title: Re: Arduino compiler can't work properly
Post by Visual Micro on May 12th, 2016 at 11:59pm
Yes that's too high. You can never get to 100%. More than 75% can be  problem.

If you are using the String object that can consume a lot of extra memory at run-time.

So it sounds certainly like memory issues.

I compared the resulting program size between 1.0.6 and 1.6.9 with just a Serial.begin(n) in the setup().

1.6.9 was half the size or 1.0.6 so it might help.

Title: Re: Arduino compiler can't work properly
Post by Gilles Plante on May 13th, 2016 at 12:00am
Oh, thanks for the info !!!

Title: Re: Arduino compiler can't work properly
Post by Gilles Plante on May 13th, 2016 at 12:11pm
Hi again Tim,

forgot to mention that the issue is occurring during setup(), at a time where memory usage is at it's lowest. This is the code summarize:

const string = NO_VER "20160512001";

setup()
{

...
Serial.Print("Version 1:");
Serial.PrintLn(NO_VER);               // works
...
foo();
...
Serial.Print("Version 2:");
Serial.PrintLn(NO_VER);               // works
...
}

void foo()
{
...
Serial.Print("Version 3:");
Serial.PrintLn(NO_VER);               // does not work
...
}

The Serial.PrintLn(NO_VER) that does not work simply prints a '\n', as if the argument was an empty string.

If we replace NO_VER by "anything", then it works.

Title: Re: Arduino compiler can't work properly
Post by Visual Micro on May 13th, 2016 at 12:16pm

Code (]const string = NO_VER "20160512001";[/code):


Needs to be:-

[code]const char* NO_VER = "20160512001";


Looks like you might be redefining string :)


Title: Re: Arduino compiler can't work properly
Post by Gilles Plante on May 13th, 2016 at 12:44pm
Hum  :-[,

typed it real fast.

I just compiled with verbose on. It creates one .cpp.o for each module, I just don't find the combined .cpp file.

Thanks

Title: Re: Arduino compiler can't work properly
Post by Visual Micro on May 13th, 2016 at 12:46pm
The verbose is best when posted or email otherwise it's just a conversation  :)

Title: Re: Arduino compiler can't work properly
Post by Gilles Plante on May 13th, 2016 at 12:51pm
Just sent it at info at ...

Title: Re: Arduino compiler can't work properly
Post by Visual Micro on May 13th, 2016 at 2:15pm
I think you should use the official sparkfun cores for that board.

Download the zip from the first link on the following page. Expand into mydocuments\arduino\hardware. Retstart all ide's and pick the correct Sparkfun board from the list.

http://wiki.wiring.co/wiki/SparkfunHardware


The verbose output shows a clean build ising the arduino 1.5.7 toolchain for a custom mega board.

The combined cpp is located as follwos and will probably be okay. I think the problem will be the wrong core.

"C:\Users\[your_name]\AppData\Local\V.Micro\Arduino\Builds\IPCTRL-G1\mega_atmega2560\Autotune.cpp"


Title: Re: Arduino compiler can't work properly
Post by Gilles Plante on May 13th, 2016 at 2:34pm
Sorry for the error, it's another card that is similar to the Sparkfun board. This one is similar to a Mega2560 so it's correct.

The combined.cpp is not Autotune.cpp, this one is one of the modules. Should the combined .ccp follow a specific name ? I checked the project name, IPCTRL-G1.cpp, but the contents is the one of the .ino.

Thanks

Title: Re: Arduino compiler can't work properly
Post by Visual Micro on May 13th, 2016 at 2:41pm
Good point I will have a look later today.

The IPCTRL-G1.cpp should contain all the code from the .ino files along with an #include for arduino.h and prototypes for all methods in .ino files. It should be the last file that is compiled.

Title: Re: Arduino compiler can't work properly
Post by Gilles Plante on May 13th, 2016 at 5:28pm
Tim,

I found it. This code

Code (c++):
const string NOVERSION = "20160512001";

was located in defines.h. And defines.h is included in many modules, because it contains things needed in more than one places.

Both compilers compiles ill formed binaries, but differently:

1.0.6 adds the constant name and value many times, as many as defines.h is included.

1.5.7 add the constant name and value only one time, but the code that uses the that constant is wrong so sometimes when we Serial.print() nothings shows, some other times the program just hangs somewhere.

In my opinion this should be flagged by the compiler as an error (defining a constant more than once), but that does not seem the case.

Wom, am I happy I found out what was wrong ! We removed the code from defines.h and added it in one place in the .ino file.

Have a nice weekend  8-).

Title: Re: Arduino compiler can't work properly
Post by Visual Micro on May 13th, 2016 at 5:50pm
Great. Yes I agree that should be a compiler error.

Well found. Thanks for the update.

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.