Problems programming the Due


I am trying to program the Arduino Due using a Raspberry Pi. I have the arduino due connected to the raspberry pi through the programming port. I don’t want to use the Arduino IDE, I want to be able to upload *.c and *.h files using a Makefile.

I have managed to find a tutorial that explains just this(minus the raspberry pi part). Here is the link:

There is a small problem with this, however… I have not managed to make the example project.
At the end of the “fiddling script” the project is attempted to be made, this ends up failing. (picture attached below) Pretty weird looking error if you ask me, Looks like it’s looking for an ELF file.

There are a few small changes you have to make to the arduino folder to get this to work, you must rename “gcc-arm-none-eabi” to “g++_arm_none_eabi” Because this is what the fiddling script looks for. Also I had to change the usb port on the Makefile after I ran the fiddling script.

The Makefile ends up throwing a syntax error, but I have no clue where the error is found, The example main.c doesn’t have any errors. I’m thinking maybe the script is relying on an older toolchain or something of the sort.

Either way, has anyone had this problem before?

If not, but you have managed to upload to your due using native c code please share your thoughts or your setup. I am not very interested in this particular setup, I just want to be able to program my Due, through the programming port, in the native ARM c.

Any help is greatly appreciated. Thanks in advanced!

Happy Coding! :slight_smile:


From the date of the fiddling script, it was written sometime in 2013-09 and the Due library has certainly changed since then. It would be good to know which version of IDE Willy used at the time, but I can't see that written anywhere.

The file that make fails on is adc12_samu.c in libsam/source. The offending line is possibly "#if SAM3U_SERIES" if SAM3U_SERIES is not defined. (It's not good coding style).

Finding the source of the error might be rather difficult, but a workaround might be to define SAM3U_SERIES and see what happens. It would help to know what the previous IDE used was and compare the differences.

I've had similar problems with standalone Due projects that used to work with one IDE version then stop working on another, I don't think there is a way to avoid that until the IDE has stabilized.

Hmmm, thats great info!

I was looking for the ide version too, unfortunately its not there. Neither is an email to contact him and find out. But that means the compiler is calling a variable that is never defined.

So where would I place the #define SAM3U_SERIES, in the main file? Or would I have to find the tool's code, change it and re compile it? Also what would I define it as; 1?

Its a shame you can't use the same toolchain for every version of the ide.

On a side note, I've been thinking about just downloading the gcc-arm-none-eabi toolchain and using that one with the environment he has set up. Maybe that will eliminate the uninitialized defines, any ideas?

This is puzzling. I don't think that adc12_sam3u.c should even be in the build, because as the name suggests it is for SAM3U not SAM3X. adc.c is the file for the SAM3X.

Poking about in hardware\arduino\sam\system\libsam, it seems that the makefiles support SAM3U and SAM3X targets. I guess this stems from the time when they weren't sure to use SAM3U or SAM3X.

I can't see that the gcc make files would work at all, but the IAR project excludes adc12_sam3u. The implication is that Arduino must use IAR to build the due_x library?

tldr; just delete adc12_sam3u.c !

Edit: I think I was looking in the wrong place, the make files for libsam_sam3x8e_gcc_rel.a are in hardware/arduino/sam/variants/arduino_due_x. But, I still can't see how the library is built from there. I would like to figure this out, because I want to create a patch to enable the watchdog!

Hmm... so this is interesting.

The directory your talking about "hardware/arduino/sam/variants/arduino_due_x" contains some linker scripts. I am not very familiar with these at all, however I know of a good tutorial that is dealing with the same topic we are discussing;

It explains how linker scripts fit all of the proper object files into memory, wherever you specify. Hopefully this can shed some light on the subject.

Now, In regards to my toolchain, I removed the file "adc12_sam3u.c" I also attempted to build the project from install/due/sam/libsam/build_gcc. I get a similar error now, but it's interesting: I get the same error when I compile from here and when I compile from the example project. Only difference is that this one is more verbose.

(Note: There are also linker scripts in this directory)

Here is the error from the above directory:

$ make clean && make all
--- Cleaning sam3s4c release and debug
--- Cleaning __SAM3S4C__ files release_sam3s4c ../../../lib/libsam_sam3s4c_gcc_rel.a
--- Cleaning __SAM3S4C__ files debug_sam3s4c ../../../lib/libsam_sam3s4c_gcc_dbg.a
--- Cleaning sam3u4e release and debug
--- Cleaning __SAM3U4E__ files release_sam3u4e ../../../lib/libsam_sam3u4e_gcc_rel.a
--- Cleaning __SAM3U4E__ files debug_sam3u4e ../../../lib/libsam_sam3u4e_gcc_dbg.a
--- Cleaning sam3x8e release and debug
--- Cleaning __SAM3X8E__ files release_sam3x8e ../../../lib/libsam_sam3x8e_gcc_rel.a
make[1]: [clean] Error 1 (ignored)
--- Cleaning __SAM3X8E__ files debug_sam3x8e ../../../lib/libsam_sam3x8e_gcc_dbg.a
--- Cleaning sam3x8h release and debug
--- Cleaning __SAM3X8H__ files release_sam3x8h ../../../lib/libsam_sam3x8h_gcc_rel.a
--- Cleaning __SAM3X8H__ files debug_sam3x8h ../../../lib/libsam_sam3x8h_gcc_dbg.a
--- Making libsam_sam3s4c_gcc_dbg.a
--- Preparing __SAM3S4C__ files debug_sam3s4c to ../../../lib
make[1]: [create_output] Error 1 (ignored)
make[1]: [create_output] Error 1 (ignored)
../../../tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc: 1: ../../../tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc:ELF?4N: not found
../../../tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc: 2: ../../../tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc: Syntax error: word unexpected (expecting ")")
make[1]: *** [debug_sam3s4c/adc.o] Error 2
make: *** [libsam_sam3s4c_gcc_dbg.a] Error 2

And here is the error from the example project:

 $ make clean && make all
make: [clean] Error 1 (ignored)
"/media/workspace/install/due/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc" -c -Wall --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb -mlong-calls -ffunction-sections -fdata-sections -nostdlib -std=c99 -Os  -I/media/workspace/install/due/include -I/media/workspace/install/due/sam -I/media/workspace/install/due/sam/libsam -I/media/workspace/install/due/sam/CMSIS/CMSIS/Include -I/media/workspace/install/due/sam/CMSIS/Device/ATMEL main.c -o release/main.o
/media/workspace/install/due/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc: 1: /media/workspace/install/due/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc:ELF?4N: not found
/media/workspace/install/due/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc: 2: /media/workspace/install/due/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc: Syntax error: word unexpected (expecting ")")
make: *** [release/main.o] Error 2

Hope this helps, I'll keep digging and I'll post if I find anything.

I'm successfully building on Linux using a different method than yours, and I think it's simpler.

  1. Download and unpack the Arduino IDE (latest 1.5 beta). Technically you only need the hardware/tools and hardware/arduino/sam directories from it; the rest isn't used and you don't ever have to run the IDE.
  2. Put the Makefile from in your project directory.
  3. Replace "g++_arm_none_eabi" in the Makefile with "gcc-arm-none-eabi-4.8.3-2014q1" (occurs in 4 places).
  4. Set ADIR in the Makefile to the location where you unpacked the Arduino IDE, and PORT to the Arduino port (you don't need to do anything with udev, you can probably just set it to /dev/ttyACM0).

Build with "make compile", upload with "make upload". If you delete the "default:" rule, you can also build with just plain "make" like a normal project.

Paul's makefile is good, but it doesn't build libsam, it uses the one from the Arduino IDE, although it does build core.a.

I guess if you don't need to change any libsam files it's not a problem.