Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
Arduino compiler can't work properly (Read 6838 times)
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Arduino compiler can't work properly
May 12th, 2016 at 11: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  Sad.

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 ?
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Arduino compiler can't work properly
Reply #1 - May 12th, 2016 at 11: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.
Back to top
 

WWW  
IP Logged
 
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Re: Arduino compiler can't work properly
Reply #2 - May 13th, 2016 at 12:41am
 
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
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Arduino compiler can't work properly
Reply #3 - May 13th, 2016 at 12:47am
 
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.



Back to top
 

WWW  
IP Logged
 
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Re: Arduino compiler can't work properly
Reply #4 - May 13th, 2016 at 12:50am
 
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 !
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Arduino compiler can't work properly
Reply #5 - May 13th, 2016 at 12:59am
 
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.
Back to top
« Last Edit: May 13th, 2016 at 1:03am by Visual Micro »  

WWW  
IP Logged
 
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Re: Arduino compiler can't work properly
Reply #6 - May 13th, 2016 at 1:00am
 
Oh, thanks for the info !!!
Back to top
 
 
IP Logged
 
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Re: Arduino compiler can't work properly
Reply #7 - May 13th, 2016 at 1: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.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Arduino compiler can't work properly
Reply #8 - May 13th, 2016 at 1:16pm
 
Code:
const string = NO_VER "20160512001"; 



Needs to be:-

Code:
const char* NO_VER = "20160512001"; 



Looks like you might be redefining string Smiley

Back to top
« Last Edit: May 13th, 2016 at 6:53pm by Visual Micro »  

WWW  
IP Logged
 
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Re: Arduino compiler can't work properly
Reply #9 - May 13th, 2016 at 1:44pm
 
Hum  Embarrassed,

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
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Arduino compiler can't work properly
Reply #10 - May 13th, 2016 at 1:46pm
 
The verbose is best when posted or email otherwise it's just a conversation  Smiley
Back to top
 

WWW  
IP Logged
 
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Re: Arduino compiler can't work properly
Reply #11 - May 13th, 2016 at 1:51pm
 
Just sent it at info at ...
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Arduino compiler can't work properly
Reply #12 - May 13th, 2016 at 3: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"

Back to top
 

WWW  
IP Logged
 
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Re: Arduino compiler can't work properly
Reply #13 - May 13th, 2016 at 3: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
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Arduino compiler can't work properly
Reply #14 - May 13th, 2016 at 3: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.
Back to top
 

WWW  
IP Logged
 
Gilles Plante
Full Member
***
Offline



Posts: 156
Québec, Canada
Re: Arduino compiler can't work properly
Reply #15 - May 13th, 2016 at 6: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  Cool.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10529
United Kingdom
Re: Arduino compiler can't work properly
Reply #16 - May 13th, 2016 at 6:50pm
 
Great. Yes I agree that should be a compiler error.

Well found. Thanks for the update.
Back to top
 

WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print