Building your own Custom ARDUINO DUE and Programming Firmware onto it

When designing a custom microprocessor-based electronic circuit, it can be convenient to program it using the super friendly ArduinoIDE, by incorporating the Arduino DUE circuitry. Or maybe you just want to build an Arduino DUE from scratch.
Draw the schematic of your special interfaces, combine it with the Arduino DUE schematic, do the printed circuit board layout, send it to the fab, buy the components, solder them onto your PCB, and you are done. Well, almost: you have two processors on your custom board, but unlike those on an original bought Arduino DUE, the firmware has not been loaded yet, and until you do, they cannot do anything, not even communicate with ArduinoIDE.

This is when you discover that there is no easy guide showing how to do this. Google suggests the article Upgrading Firmware of the Arduino Due Programming Port 16U2 . While this works for an original Arduino DUE (one that is already loaded with firmware), it does not work for a newly assembled Arduino DUE-like PCB. Your Arduino clone will throw an error if you try to upload a sketch from ArduinoIDE, and you will spend hours trying to find the problem. This is because for a newly built board, you also need to program the 16U2 fuses, not just its Flash memory.

This article is about how I got a brand new board working, with the hope that I may save you a lot of time. I will also cover some of the Arduino-DUE basics, which might help add your application-specific circuitry to the Arduino DUE schematic.

WHAT IS AN ARDUINO DUE (skip if you already know)

Let us first understand what the two processors do on the Arduino DUE.

The SAM3X8 processor (the large chip) is the main processor : all your sketches get uploaded to this processor, and all IO connections come from it. The processor itself contains a bootloader that is permanently stored in ROM, amd allows uploading code to the chip either via its USB port (the one closest to the Reset button, referred to as Native USB port, micro-AB connector), or via its serial port. Since we want to keep the native USB port available for our application's peripherals, either as host or client, the standard way to program the processor is via the serial (UART) port, which is connected to the 16U2 chip.

The 16U2 processor (the small chip) is programmed with code that makes it act as an ISP (in-system programmer) for the main processor. It is like having an ISP permanently incorporated on board. It converts its USB port (the one closest to the DC jack, referred to as a USB Programming Port, connector type micro-B) to a serial port (RX, TX) plus it provides ERASE and RESET commands to the main processor. These four connections are the only ones between the two processors. Additionally, this USB port can be used to communicate with the main SAM3X8 processor using the "Serial" object.

Once the 16U2 is flashed to act as ISP (you do that by using ... another ISP! See below...), here is what happens when you upload a sketch from the ArduinoIDE to the Arduino DUE:
a) the IDE sends over the USB port a starting slow pattern at 1200 baud that signals to the 16U2 the start of an upload.
b) the 16U2 asserts the ERASE line for 250 ms, erasing the Flash memory of the SAM3X8.
c) then the 16U2 sends two 200 ms RESET pulses to the SAM3X8 and waits 600 ms.
d) the programming starts by sending Flash data to the UART port of the SAM3X8, via the TX RX lines at 115200 baud.

HOW TO GET STARTED USING AN ORIGINAL ARDUINO DUE (skip if you already know)

If you have not done so already, read the Getting Started article

  1. Connect Arduino DUE to your PC using a USB A-to-microB cable, using the USB Programming Port (closest to DC jack).
  2. On your PC, launch Device Manager, look in the Ports section. you should see it as "Arduino DUE Programming Port" with its assigned COM port number (typically COM3)
  3. Install Arduino IDE on your PC. The IDE should find the Arduino DUE, and automatically install SAM drivers and all drivers needed.
  4. Launch ArduinoIDE. On the main green toolbar, under Select Board, you should see and select the Arduino Due Programming Port.
  5. Select an example program (they are called "sketches" in Arduino-speak). Under the File Menu, select Examples, select 01.Basics, select Blink.
  6. press the green -> button to upload the blink sketch to the Arduino DUE (or select Sketch then select Upload).
  7. the L LED next to the ON LED should blink.

If you run Linux instead of Windows, follow a similar procedure as found in the Getting Started article cited.

A NOTE ABOUT HARDWARE (skip if your hardware is already made)

The schematic in PDF and the schematics and layout in Eagle PCB are in the official Arduino docs site.

A few comments on the hardware.

  1. The schematic is reasonably clear.
  2. Parts marked NM should not be populated - in English one would normally mark DNP (do not populate), so I guess NM comes from Italian "non montare".
  3. There is confusion to the top left of the ATSAM3X8, where zero-ohm resistors are used to select the source of voltage AVREF. Unless you want to provide a separate analog voltage reference on pin AREF, you should install the JR1 zero-ohm resistor (the one drawn as a rectangle, European style), and omit the other two (drawn as a zigzag, American style).
  4. Under the USB AB connector, there are wire remnants of an Ethernet connection that has been removed and should be ignored. Hence ports PB0 to PB9 on the ATSAM3X8 are unused and should be left not connected.
  5. Some of the parts are obsolete. NX1117CE33Z should be replaced by identical TLV1117-33IDCYR.
  6. Some of the parts have no part number. For the LEDs you can use APT2012YC (TX, RX, TX1, RX1, L), APT2012SGC (ON).
  7. If you are doing your own soldering, it might be easier to replace all 0402 size resistors and capacitors with 0603 size.
  8. If you are doing your own soldering, it might be easier to use the ATMega16U2-AU, which is in a slightly larger TQFP-32 package with more accessible pins.
  9. If you are doing your own soldering, it might be easier to replace the two MPM3610 voltage regulators and associated glue components. I replaced them with easier to find and easier to solder TPS56339DDCR, with the circuit given in Fig. 17 of the datasheet, omitting R1 and R2 and leaving the EN pin not connected. For the inductor, I used IHLP3232DZER5R6M11 by Vishay/Dale.
  10. For the crystals I used model 12.60383 for the 16 MHz crystal on the 16U2 chip, 12.88662 for the 12 MHz crystal, and ABS07-32.768KHZ-T for the 32 kHz crystal.
  11. Consider replacing all the polarized 22 uF capacitors with 25 V MLCC caps in size 0805.
  12. Careful, there is a mistake in the JFET symbol, you should change it so that the gate is pin 1 and the drain is pin 3. If you omit to do this, the op amp driving the first JFET will overheat, and when you press reset the 3.3 V line will rise above 4 V.

The layout deserves some comment. The layout files given are for a 2-layer board. This saves money but I would not recommend it for pro applications, since there are no ground planes. I was very surprised that Arduino DUE is a 2-layer board. I chose to move up to 4 layers, thus incorporating a full GND ground plane on one of the new layers, and mainly +3V3 on the other new layer (but also +5V and VIN). This also allowed creating a ground plane ara on the bottom layer under the SAM3X8 chip for VDDOUT.

Moving to a 4-layer layout allowed me to do changes 6, 7 and 8 above while maintaining the same size and shape as the original Arduino DUE, including the 3 large connectors for the IO signals, in case I needed to add Arduino-DUE compatible expansion boards in the future.

LOADING FIRMWARE ONTO YOUR FRESHLY ASSEMBLED ARDUINO DUE CLONE

Here is the information you were waiting for, including the parts about programming fuses that you will not find anywhere else on the web, and without which your board will not be programmable or usable with Arduino IDE.

The following procedure loads the firmware required on your board, in order to make it behave like an Arduino DUE and thus allowing it to be used with ArduinoIDE to upload sketches.

  1. Do a basic smoke test on your freshly assembled Arduino clone: connect the DC jack to a lab power supply set to 12 V with a current limit of 100 mA. The board should draw no more than about 40 mA. The L and ON LEDs should be on. Check the 5 V and 3.3 V outputs coming from the voltage regulators. If you have a thermal camera, even a cheap one for your cell phone, check that there are no hot spots. No components should be over 50 degrees C.
  2. Buy an original Arduino DUE; it will be useful for comparison to your Arduino DUE clone.
  3. If you don't have a compatible ISP (in-system programmer), buy one. I recommend Atmel's AVRISP Mk II, which is no longer available in its original form, but clones are cheap and easy to find. Another possibility is to use an Arduino UNO as suggested in the article cited at the beginning of this one.
  4. Connect your AVRISP Mk II to your PC using a USB cable.
  5. Install the Zadig utility and use it to change the AVRISP driver to libusb (or libusbK).
  6. Install AVRDUDESS. This is a friendly GUI around the avrdude command. A GUI is easier to use than command lines and avoids mistakes, particularly when there are many options and long file names.
  7. Locate the installation of Arduino on your PC. Typically at:
    C:\Users\USERNAME\AppData\Local\Arduino15.
  8. Locate the ATmega16U2 firmware. These are .hex files typically located at:
    C:\Users\USERNAME\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\firmwares\atmega16u2\
  9. The hex files will have names like:
    Arduino-DUE-usbserial-prod-firmware-2013-02-05.hex
  10. Locate the avrdude.exe and avrdude.conf files, typically at:
    C:\Users\mike\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin\
  11. Copy files avrdude.exe and avrdude.conf into the directory where you found the .hex files.
  12. Test your AVRISP Mk II on a genuine Arduino DUE, by reading the Flash memory and fuses by using avrdude through the AVRDUDESS GUI:
    a - connect the AVRISP Mk II probe to a genuine original Arduino DUE; the header is not polarized so careful to install it the correct way, with the red wire on the side of the cylindrical electrolytic capacitor.
    b - start AVRDUDESS.
    c - under Programmer, find AVRISP Mk II, and set the port to usb (ignore baud rate and Bit clock).
    d - on the upper right press the Detect button to set the MCU, it should read ATmega16U2 an show a signature like 1E9489. If you cannot detect a MCU, check your AVRISP connections.
    e - in the Flash section, select the Read checkbox, select Format Intel HEX, then press the button with three dots to set the filename, call it something like original.hex in the same directory as the hex files located in step 7. Careful not to overwrite the files already there.
    f - press the Go button in the Flash section, this should read the Flash on the Arduino DUE and create a new file with the name you chose (original.hex). Check that the read operation succeeds.
    g - ignore the EEPROM section
    h - under Fuses and Lock Bits, press the Read button next to the L box to read the L, H and E fuses. These should read L=0xEF, H=0xD9, E=0XF4. Write them down.
    i - under Fuses and Lock Bits, press the Read button next to the LB box to read the LB lock bits. This should read LB=0xCF. Write it down.
  13. If the AVRISP Mk II worked in the previous section on an original Arduino DUE, you can now program you own Arduino DUE clone:
    a - connect the AVRISP Mk II probe to your clone of Arduino DUE (straight off your assembly line and unprogrammed). Again plug the connector in the right orientation.
    b - If it is not still running, start AVRDUDESS again.
    c - under Programmer, if not set, again find AVRISP Mk II, and set the port to usb (ignore baud rate and Bit clock).
    d - on the upper right press the Detect button again to set the MCU, it should read the same as before in step 11.
    e - in the Flash section, select the Write checkbox, select Format Intel HEX, then press the button with three dots to select the filename of the HEX file you intend to upload to your board. Either use the latest version of the hex file you found in the directory (typically Arduino-DUE-usbserial-prod-firmware-2013-02-05.hex), or use the file you read from the original Arduino DUE that you called original.hex.
    f - press the Go button in the Flash section, this should write the chosen hex file into Flash memory on your Arduino DUE. Check that the write operation succeeds.
    g - ignore the EEPROM section
    h - under Fuses and Lock Bits, press Read button next to the L box to read the L, H and E fuses. These will probably read in their default setting L=0x5E, H=0xD9, E=0XF4 (only L has changed). Change the L box back to 0xEF and press the Write button. Check that the write operation succeeds.
    i - under Fuses and Lock Bits, press the Read button next to the LB box to read the LB lock bits. This should read the default value LB=0xFF. Change the LB box back to 0xCF and press the Write button. Check that the write operation succeeds.

RUNNING YOUR ARDUINO DUE CLONE UNDER ArduinoIDE

If the above procedure was successful, you should now have a fully functional Arduino DUE clone.

Power up the board, connect the USB Programmer Port (the one closest to the DC jack on the ortiginal Arduino DUE) to your PC.

  1. Connect the DC jack of your Arduino DUE clone board to a 12 V power supply. Check current consumption as in previous section.
  2. Connect your Arduino DUE clone to your PC using a USB A-to-microB cable, using the USB Programming Port (closest to DC jack).
  3. On your PC, launch Device Manager, look in the Ports section. you should see it as "Arduino DUE Programming Port" with its assigned COM port number.
  4. Install Arduino IDE on your PC. The ArduinoIDE installer should find your Arduino DUE, and automatically install SAM drivers and all drivers needed.
  5. Launch ArduinoIDE. On the main green toolbar, under Select Board, you should see and select the Arduino Due Programming Port.
  6. Select an example program (they are called "sketches" in Arduino-speak). Under the File Menu, select Examples, select 01.Basics, select Blink.
  7. press the green arrow -> button to upload the blink sketch to your Arduino DUE clone (or select Sketch then select Upload).
  8. the L LED (next to the ON LED) should blink.
  9. now you can write code for your application.

That's it!

1 Like

Hi there!
thank you for sharing these information! I was wondering what you're referring to in point 12 talking about JFET symbol because I was not able to identify it into the schematic.
Luca

mtommasi was saying that there is a discrepancy between the pin numbering systems used by Eagle and NXP for the type PMV48XP MOSFET.

Eagle pin numbering:

NXP pin numbering from their datasheet:

Comparison:

1 Like

Now I always double check both transistors and diodes. Diodes are even more prone to errors, not only on Eagle but also on Kicad and Altium. Amazing how sometimes the errors come from the library (diode pins marked A K, sometimes mapped 1 2 and sometimes 2 1), but sometimes the manufacturers themselves make changes to pin numbering.

Can the small USB Interface processor (16U2) be substituted by CH340? If yes, then we need only to store "Loader Program" into DUE.