[SOLVED] Makefile for the Due

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: GitHub - pauldreik/arduino-due-makefile: Arduino Due Makefile

Makefile (8.85 KB)

makefile.ino (462 Bytes)


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:

enum constants {
void setup() {
  // put your setup code here, to run once:
    // initialize the digital pin as an output.
  pinMode(ledpin, OUTPUT);    
  //Serial.println("Configuration complete");

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


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


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

Makefile (9.04 KB)

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.

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…)

Nope, including arduino.h does not help.

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: GitHub - pauldreik/arduino-due-makefile: Arduino Due Makefile

Makefile (6.73 KB)

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


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


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.


I've been wrestling with this Makefile for some time now and (finally :)) 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.)

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.


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,

Makefile (9.03 KB)

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.


EDIT: here is the windows branch. I have not tested it. https://github.com/pauldreik/arduino-due-makefile/tree/windows

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