Embedded program paste to IDE has problems.

My project is at http://github.com/tz1/bluev where I'm working on an interface to a radar detector. It works on the Mega series, but I just ran into a strange problem.

If I use the makefile (Malefile.ArduMega) to compile bluevmega.c, and manually use avrdude, it works fine. If I paste it into the IDE, it compiles and partially works, but the input capture timing is off - I am using ICP4 (and OC interrupts) to create a software UART but I am missing many edges when I use the IDE. I suspect there are other interrupts running which interfere or perhaps optimization is very, very low, or some subtle compiler setting is playing signed v.s. unsigned games, or even one of my subroutines is being superseded.

i could probably figure it out if I saw the actual build commands and generated files. I know you are adding and altering things, but there is no way I can find to recover the actual steps, e.g. recreate a script file to do the process or just see all the parameters for avr-gcc and the alteredprogram.c file to look for anything which may have changed. Are these available anywhere? I'm surprised that this is either not documented at all or hard to find, both just what is going on if I wanted to do the commands manually and the lack of any build logs or scripts, only errors on the console. I can't even find a "verbose" mode.

An earlier version of this worked fine - before I added sprintf and other calls to handle an onboard UI. I don't think I changed anything significant, but the binary is different - I would expect that, but I have no idea how to determine where those difference come from.

Any help would be appreciated, but mostly pointers as to how to generate or recover the build scripts or logs.

An earlier version of this worked fine - before I added sprintf and other calls to handle an onboard UI

It sounds like you may be running out of SRAM memory. Have you offloaded all the print strings into the program memory space?

Verbose mode is enabled in the preference dialog in IDE 1.0. Prior to 1.0, you hold shift (I think, or another modifier key) when compiling.

the size utility indicates there is enough sram, but I can try shrinking the strings.

The “verbose” on the preferences did the trick (though finding the TEMP directory proved interesting). I see what it is doing as far as the compile step.

It is treating it as C++, thought it is in C, and there doesn’t seem to be a way to tell it that it is a C and not a C++ file (I can pull setup and loop out as C++ if needed)

In the stderr, I get some expected messages, but also:

arduino-1.0\hardware\arduino\cores\arduino\Tone.cpp:93: warning: only initialized variables can be placed into program memory area

I've figured out how to use the C as plain C (create an INO separate from the C file but calling it).

Now I just have to get around whatever other init it is doing.

For some reason I have to declare global statics which can change both in interrupts and are read locally as "volatile". This does not highlight as a keyword, but adding it everywhere fixed the problem. Now I have to try narrowing down which are really needed.

I also needed to not call init() in arduino, so I added it to the c program.

Theoretically it is the same version of the compiler with the same optimization so I don't understand the lack of volatility.

Update:

To simplify things, you can use a minimal sketch, but take any embedded set of code but rename main to void init() and the first thing the Arduino code will do is jump to your routine - Usually "main" never returns, so in that case it would work.

I haven't found anything more about the "volatile" problem, but it is good practice to declare anything modified by multiple threads (or the equivalent in this case) as "volatile", at least if part of the logic is that they would change. In one case it works without the declaration and saves the interrupt from having to reread the variable many times.