Go Down

Topic: Flash Arduino Due via UART (Read 2763 times) previous topic - next topic


I would like to write code in Arduino language, compile it in the Arduino IDE, grab the resulting binary code, and flash it to the Due via the TX/RX UART pins, bypassing both the USB Programming Port and Atmel16U2 chip. Before the UART flash, I am manually toggling the Erase and Reset pins on the Due to initiate a hard reset of the SAM3X chip, and SAM-BA now waits for the code. I would like to know: can I directly grab the binary code compiled by the Arduino IDE and give it to SAM3X via UART or is there extra code baked into that binary by the Arduino compiler that would cause this method to fail?


That's pretty much the exact process that happens when you use the programming port.
"The problem is in the code you didn't post."


While MorganS is correct, that is basically exactly what the programming port does, the answer to your question is yes. Yes, you can do that. The built-in bootloader in the SAM3X chip will respond to commands on the first serial port (that the programming port is coincidentally attached to). So, you could grab the binary image, manually trigger the reset button, and then upload the firmware over the serial port to the chip. I think both MorganS and I would have to seriously wonder why you'd want to do that but I won't let that concern me. Presumably you've got your reasons. ;)


Is there a way to do it WITHOUT touching anything else than the UART, no reset button etc?
Background: I have a given hardware featunring an ESP07-Module that is attached to an Arduino DUE, BUT the wiring is already done and only RX, TX (and gnd of course) of the DUE are being connected to TX/RX of the ESP.
So is there a way to implement a bootloader on the DUE that will accept a new binary from the ESP, check it´s integrity and programm it onto DUE?


No, you can't do it with only TX and RX, unless you have a specific set of commands you want to upload and then you write your own program to interpret those commands.

Look at how the 16U2 chip on board the Due is connected to the main processor. This will give you some idea of the minimum connections required to make the programming port work.
"The problem is in the code you didn't post."


Mar 31, 2017, 11:57 am Last Edit: Mar 31, 2017, 04:13 pm by bobcousins
So is there a way to implement a bootloader on the DUE that will accept a new binary from the ESP, check it´s integrity and programm it onto DUE?
Yes, absolutely. This is the way all AVR Arduino's work, they do not have a bootloader in ROM. They have a user bootloader, which takes up part of the Flash, and must be loaded via ISP port.

I guess the reason they did it differently for the Due is that the SAM3X has a ROM bootloader, so that saves writing one. Additionally, a virgin board can be programmed without loading a bootloader, and any board can be restored to a virgin state by the Erase-Reset sequence.

However, with a secondary bootloader in Flash you will need to change the link map for application code so it does not overlap the bootloader. Writing a bootloader is not trivial, and I don't know of any publicly available ones for SAM3X8E.   


I forget to mention that finding a lack of simple, portable and open bootloader for larger Cortex chips, I created a new one called bootem. https://github.com/bobc/bootem So far I have an LPC1768 version, and a version for NXP K64 is in progress. I guess a SAM3X port would be a useful addition.
Please ask questions in the forum so everyone can benefit. PM me for paid work.


I want to load the sketch using the UART from other device connected to TX0 and RX0 pins, is it possible to load ? In simple terms I want to bypass the conventional programming of sketch using the programming port via ATMEGA16U2.


Yes. Copy the software that's on the 16U2 chip. It's available in the Arduino Github repository.
"The problem is in the code you didn't post."


Hello shannon member,

Thanks for the reply,

Actually my requirement is to load .hex file of a sketch from another EVK board into Arduino Due using UART pins.
so Copying the software process doesn't serve my requirement.

can you help me regarding this requirement.



Once you know how the 16U2 does it, you will be able to do it yourself.
"The problem is in the code you didn't post."


May 23, 2019, 03:06 pm Last Edit: May 23, 2019, 06:16 pm by PranayGupta
Is 16U2 converting the .hex file(intel hex format) and sending the data to respective address of controller ? If so Where can I find the respective resources to conform that ?

So If I've to write the hex file of my .ino file to through Rx0,Tx0 pins as similar to how 16U2 is doing by erasing and Resetting the SAM-BA, what format I need to follow to write to it, or else will SAM-BA takes care of hex file??

I've gone through the usb-serial.c code, He is just pushing the data to which he got from USB, is that the only thing needed to do, no need of converting the hex file, thereby pushing it to respective addresses ?

Go Up