Pages: [1]   Go Down
Author Topic: Project targeting AVR and Due  (Read 1162 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 2
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all, this is a newbie question smiley-lol

Can I create a project with source shared between AVR and Due boards, and then recompile for one or the other?

I expect there will be some code specific to AVR or ARM, I would normally (with other IDEs) put that into a sub-folder, then reference it accordingly from the top level. But it seems Arduino only compiles source code in the top level folder, and ignores sub-folders.

How would people manage this?

If this is an FAQ, I apologise, I couldn't find it mentioned anywhere.

Cheers
Logged

Brighton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@bobcousins

I guess #ifdef is your friend at the moment, in the usual C/C++ style of selective inclusion of different #defines etc. for different platforms.

Also, I may be wrong but I believe the following should work in a .h, .c or .cpp file in the source folder:

Code:
#ifdef DUE
    #include sam\myDefs.h
#else
    #include avr\myDefs.h
#endif

(The DUE constant is hypothetical and that's another story - see other threads...)

The above is closer to your use case, but you''ll have to edit the files outside of the Arduino IDE (but hopefully the folks at VisualMicro.com will soon support the Due...).

HTH
Jim
« Last Edit: January 20, 2013, 12:16:09 pm by jgmdavies » Logged

St. Petersburg, FL
Offline Offline
Jr. Member
**
Karma: 1
Posts: 61
Retired physicist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried a similar scheme. It didn't solve my particular problem but the approach works.

#if defined(__SAM3X8E__)
    #include <sam/SomeDueThing.h> // For the Due
#else
    #include <avr/SomeAVRThing.h>    // For anything else
#endif
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So if I have source code file, mydriver.c, I have to do

void driver_init ()
{
#if defined(__SAM3X8E__)
    // For the Due
#else
    // for anything else
#endif
}

but I can't have files avr/mydriver.c and sam3x/driver.c ? 

Unless I include them in a top level file, I suppose. Still a bit messy.
Logged

Brighton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you can have in mydriver.c:

#ifdef SAM (or whatever)
    #include <path\mysamstuff.c>
#else
    #include <path\myavrstuff.c>
#endif

?
Jim
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't this to work. My sketch is:

Code:
#include "sub/mydriver.c"

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
  myfunc(2);
}

sub/mydriver.c :
Code:
int  myfunc (int a)
{
return a*a;
}

The compiler output is :
Code:
C:\Programs\arduino-1.5.2\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega1280 -DF_CPU=16000000L -DARDUINO=152 -IC:\Programs\arduino-1.5.2\hardware\arduino\avr\cores\arduino -IC:\Programs\arduino-1.5.2\hardware\arduino\avr\variants\mega C:\Users\bob\AppData\Local\Temp\build2805575431420087737.tmp\sketch_feb16b.cpp -o C:\Users\bob\AppData\Local\Temp\build2805575431420087737.tmp\sketch_feb16b.cpp.o
sketch_feb16b.ino:2:26: error: sub/mydriver.c: No such file or directory
sketch_feb16b.ino: In function 'void loop()':
sketch_feb16b:11: error: 'myfunc' was not declared in this scope

Using Arduino 1.5.2. I am doing something dumb?

ETA: I though that using chevron quotes #include <sub/mydriver.c> was finding the file but not compiling it, but in fact the include is ignored completely, and doesn't complain about missing files.

ETA2: Yes, I realize the above is from the AVR compiler, but the same applies for the ARM compiler. See below smiley-wink
« Last Edit: February 16, 2013, 12:09:22 pm by bobcousins » Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, the answer is kinda obvious, the IDE copies source files from the sketch directory to a temp folder, and compiles there. So any subfolders from the sketch folder do not exist in the temp folder.

Seems like the only way to do something similar is with libraries, but that is not a satisfactory solution. I think that the Arduino IDE is probably not a suitable tool for me.
Logged

Brighton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Bob,

I'm sure you realize, but for the benefit of other readers, you can use the full path for the include files and then the following works with 1.5.2:

Code:
#define ARM_PLEASE

#ifdef ARM_PLEASE
  #include "F:\Docs\- DEV\Arduino 1\Test\Sub1\mydriver_ARM.c"
#else
  #include "F:\Docs\- DEV\Arduino 1\Test\Sub1\mydriver_AVR.c"
#endif

HTH someone,
Jim
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 49
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Jim, that's worth noting.

Of course, I have "unstated requirements"  (aren't there always? smiley) I want to share my project via github, so can't make assumptions about where files are located.

For the moment, I will try to create a makefile project which uses the Arduino toolchain, and maybe figure out how to make it IDE compatible later.

Just as a little background, I am porting RepRap 3D printer firmware to Due. Currently most Repraps run on Arduino or AVR variant, and the existence of the Arduino platform has been a great help to Reprap. I am hoping that success will continue with Due.
Logged

Pages: [1]   Go Up
Jump to: