Hello! I have a non-standard hardware setup and would like to be able to flash programs to the bootloader using the Tx and Rx pins of one of the UARTS that is not the USB UART0. My current hardware situation looks something like this:
Parent Machine (Linux) | ATMega2560
-----------------------|-------------------
Rx pin -------------|---> Tx pin
Tx pin -------------|---> Rx pin
Reset pin -------------|---> Reset pin
Either using the Arduino-CLI or by writing my own scripts, I would like to be able to send the new program's hex file over serial to the ATMega. It looks like AVRDUDE may be able to accomplish what I need, but I have yet to find a concrete example of how it works without selecting a programmer, leading me to wonder if it is even possible.
From what I have read on other forums, you can manipulate the bootloader into being ready to receive the program by setting the RESET pin a certain way, but I have yet to find a concrete reference of this somewhere. Ultimately my question is: are there any tools/software that make this easy, and is using a non-standard UART possible for programming? Am I able to do this using the pin configuration above, or would I need to incorporate another pin/make changes? At the end of the day, I would like to be able to dump a hex file on the parent machine, run a command in which I specify: serial port/pins I am using, my new hex file, and have it upload the new code. Could it be as simple as wiring it up as shown above and hitting "go" with the Arduino-CLI? If I have to change which pins I use, and I find this out early enough, I may be able to alter the hardware design, although it is highly unlikely.
Unfortunately, while I have been absolutely loving using Arduinos for nearly everything, I have yet to even scratch the surface of bootloading and programming beyond hitting "upload," while having been given this task with limited knowledge of the subject. I am simply working with the constraints I have been given. Thank you all, for your help!
You may also be wondering:
Q: Why don't you just use an Arduino as is or program through the USB port?
A: While I would love to operate this way, this unit is being especially fabricated for a small form-factor application and I have no control over the physical layout. Ultimately I am stuck programming a custom ATMega. The good news is that the wiring of this custom ATMega2560 nearly matches the Arduino schematic, with the exception of not physically being able to access the USB once enclosed in the unit. As far as I can tell, I should just be able to copy over the Arduino Mega2560 bootloader without any problems.
Q: Just use the Arduino IDE...why do you want to use the CLI when you don't have to?
A: Due to the small form-factor I mentioned in the Q above, I am limited to programming over serial through dedicated GPIO lines on my board, and will be using a linux operating system via SSH, with no graphics or X11 capabilities. In addition to this, I would like to eventually automate the process so that, through Python, Shell, or some other language I can run a series of scripts to do all of this automatically and to multiple units at a time.
Q: What about the ICSP pins? Are those available to you?
A: Again, since the unit size is so small, the box will be a pain to tear apart, and I do not have room to have ICSP pins soldered after assembly. I will use them for the flashing of the initial bootloader using the Atmel-ICE programmer, and then will need to have the de-soldered.
Thanks again!