Pages: [1]   Go Down
Author Topic: [SOLVED] Makefile for the Due  (Read 3151 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using a makefile instead of the Arduino IDE has several advantages. For the older arduinos, there is an excellent makefile available from the official Ubuntu repositories.

For the Due, the only Makefile I can find is the one by olikraus for u8glib:http://code.google.com/p/u8glib/source/browse/sys/arduino/HelloWorld/Makefile.152.due

Using a simple sketch attached and the above makefile (modified for paths and file extensions), I can however not make the arduino blink. Using the IDE, it works as expected.

I believe there are others interested in a makefile for the Due, so I hope we can create a working Makefile also for the Due. Please help getting a working makefile!

EDIT: here is a repo with a working makefile: https://github.com/pauldreik/arduino-due-makefile

* Makefile (8.85 KB - downloaded 38 times.)
* makefile.ino (0.45 KB - downloaded 33 times.)
« Last Edit: May 04, 2013, 03:59:10 am by pauldreik » Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Your Makefile works fine. But the Serial is not activated during compilation state. If you remove the "Serial" commands from your example, then the blinking will work:
Code:
enum constants {
  ledpin=13
};
void setup() {
  // put your setup code here, to run once:
    // initialize the digital pin as an output.
  pinMode(ledpin, OUTPUT);   
  //Serial.begin(115200);
  //Serial.println("Configuration complete");
}

void loop() {
  // put your main code here, to run repeatedly:
 static bool ledstate=false;
 //Serial.print("led is ");
 //Serial.println(ledstate);
 digitalWrite(ledpin,ledstate);
 ledstate=!ledstate;
 delay(1000);
}

Oliver
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have updated your inital Makefile to include USB support (attached). But still the serial communication is not working. I have no idea why...

Oliver

Edit: The screen terminal emulator (used in the Makefile) can be terminated with Ctrl-a Backslash.

* Makefile (9.04 KB - downloaded 33 times.)
« Last Edit: April 27, 2013, 01:15:08 am by olikraus » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can confirm that the led is blinking if I remove the serial output. I can also confirm the changes with -DUSBCON do not help.

Differences I can spot between the IDE and the make output:
  • -DUSB_PID=0x003e is 0x03e instead in the makefile version. It should not matter. The flags seem to be in another order, and the binary file is built in another way.
  • -nostdlib is used in the IDE but not in the makefile version
  • -g is used in in the IDE (debug)

Should I post the full output? I have done some simplification for the ide output to make it more readable.
Logged

0
Offline Offline
Full Member
***
Karma: 2
Posts: 109
ArduiYES!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

maybe a clue :
I noticed that if I used Serial.println() in an include file, I needed to add
#include <Arduino.h> in that include file

try that for your main sketch, I suspect the IDE does add this behind the scenes.
but the makefile does not (as far as I can read that makefile, I'm no guru..)

 
« Last Edit: April 27, 2013, 02:48:08 pm by raalst » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope, including arduino.h does not help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have now made a new makefile which mimics what the IDE does. It works with the example sketch in the earlier post.

Feel free to use or modify it, instructions are in the header. Feedback appreciated!


I started a repository on github to make development easier: https://github.com/pauldreik/arduino-due-makefile

* Makefile (6.73 KB - downloaded 32 times.)
« Last Edit: May 04, 2013, 03:55:59 am by pauldreik » Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Will your Makefile work with Serial.print?
If yes, any idea why my Makefile fails with Serial.print?

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Will your Makefile work with Serial.print?
If yes, any idea why my Makefile fails with Serial.print?

Oliver
Yes, the serial works.
No, not really. I suspect the linking is wrong. I tried modifying your makefile but with no luck. It also gave me linker warnings on a more complicated sketch. Eventually I made a shell script which mimicked the IDE output. After confirming it worked, I turned it into a makefile. The next step is to replace the sequential ar invocation with creating core.a in a single step, but I suspect this might be the cause of the serial port not working.

paul
« Last Edit: May 04, 2013, 01:54:29 am by pauldreik » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been wrestling with this Makefile for some time now and (finally smiley) found that
-fpack-struct
wreaks havoc with register structs.

What I think happens is that -fpack-struct removes padding/alignment spaces in structs.
Especially for hardware register structs
(e.g. see CMSIS/Device/ATMEL/sam3xa/include/component/component_pmc.h )
this means the register addresses inside the struct may get shifted downward
while the actual hardware register addresses remain the same.
The program then writes to / reads from wrong register locations.

E.g. during init(), which is called before setup(),
a write to a wrong PMC->CKGR_MOR location
makes the program stall. SystemInit() hangs here in my case.

Having this flag enabled also breaks the Timer Counters and
I'm reasonable sure it will wreak havoc in other places (Serial?), too.

Conclusion:
Remove the "-fpack-struct" compiler flag
(The Arduino ide doesn't use it either.)
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8594
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That makes sense, AFAIK all register access with CMSIS is performed through structures that mimic the physical registers, anything that packs the structs will cause havoc.


______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

Hi,
I modified Paul's Makefile to make it run on Windows. Maybe this is of some interest to someone else.
I don't see how to make it work for both Unix and Windows...
What I like most is that it is way faster then Arduino's IDE, since it compiles only files in need of that.
Have fun,
Achim

* Makefile (9.03 KB - downloaded 28 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the contribution!
I will add it as a windows branch in the repository. Do you have a github account?
I assume your changes are given under gplv2.

paul

EDIT: here is the windows branch. I have not tested it. https://github.com/pauldreik/arduino-due-makefile/tree/windows
« Last Edit: June 03, 2013, 04:07:25 am by pauldreik » Logged

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

Thanks, Paul, for putting it into your github repository.
Achim
Logged

Pages: [1]   Go Up
Jump to: