Go Down

Topic: [SOLVED] Makefile for the Due (Read 3618 times) previous topic - next topic

pauldreik

Apr 26, 2013, 08:10 pm Last Edit: May 04, 2013, 10:59 am by pauldreik Reason: 1
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

olikraus

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: [Select]
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

olikraus

#2
Apr 27, 2013, 08:06 am Last Edit: Apr 27, 2013, 08:15 am by olikraus Reason: 1
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.

pauldreik

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.

raalst

#4
Apr 27, 2013, 09:41 pm Last Edit: Apr 27, 2013, 09:48 pm by raalst Reason: 1
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..)



pauldreik

Nope, including arduino.h does not help.

pauldreik

#6
May 03, 2013, 10:26 pm Last Edit: May 04, 2013, 10:55 am by pauldreik Reason: 1
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

olikraus

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

Oliver

pauldreik

#8
May 04, 2013, 08:42 am Last Edit: May 04, 2013, 08:54 am by pauldreik Reason: 1

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

SebHolt

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

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

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

pauldreik

#12
Jun 02, 2013, 10:52 am Last Edit: Jun 03, 2013, 11:07 am by pauldreik Reason: 1
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

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

Go Up