Flashing firmware, serial vs spi

I have this project that has two Arduinos (Arduino pro mini 3.3v) and one esp32. I would like to flash the Arduinos from the esp32 by uploading firmware via a web interface.

But I'm struggling to understand how to do this and perhaps it's because I'm unclear what to search for. Every example I can find involves using avrdude. And then the examples can be split into two groups: using SPI or using UART.

First, is there any real differences between using UART or SPI?

Second, am I right to think that all avrdude is doing is converting the hex firmware to commands that the bootloader understands or is there something more going on?

If anyone has any advice on how to accomplish this I would love to hear it!

Thanks in advancd

most of your questions are not related to upload over an esp32.
you know the normal upload from IDE over Serial. that is upload over Serial and bootloader.
did you ever try to burn bootloader or upload sketch over the ICSP programming using other Arduino with "Arduino as ISP" sketch? that is your "SPI" way

Yes. Both approaches work differently.
UART: requires a boot loader.
SPI: requires a dedicated programmer, no bootloader needed.

So you will have to program the ESP32 to implement the protocol that is used by the bootloader (not sure which one it is) or to do what a dedicated programmer does.

There is two-way communication. The programmer sends a command to fetch the signature bytes so it can check the processor type. There are steps to erase the memory and set the programming fuses. I think avrdude converts the .hex file to a binary image for uploading. After the upload it reads the binary back to verify that it was written correctly.

Interesting reading here

Avrdude can do all kinds of things depending on the programmer & protocol selected.
Even when using the bootloader on an Arduino over serial, avrdude toggles the RTS pin to reset the board to get the board back into the bootloader for preparing for the download.
Note: Some h/w and interfaces use DTR and some use RTS to control the reset on the Arduino.
The DTR pin is set to low by the OS not the app (avrdude) when the serial port is opened. avrdude toggles RTS when the "arduino" protocol is selected.

But there is also some bit banging stuff in avrdude as well that can be done.
So it depends on the interface and the protocol being used.

If you want to use ICSP, As @Juraj mentioned,
What you want to look at and potentially start with is the "Arduino as ISP" sketch.

For serial you would need to use the stk500 protocol over serial to do the upload, and to start that you must reset the board to get it back into the bootloader so you can start talking to the bootloader.

--- bill

There is a mechanical pin connection that may affect the decision.

One unfortunate thing is that the pins needed for h/w serial port for and the ICSP SPI transfers are not the same.
There used to be a 10 pin connector that Atmel used to use in the past that had all the connections for both. (ICSP + async serial in one 10 pin connector)
But with the smaller 6 pin ICSP port, there is no access to the async serial pins.

This makes doing the physical h/w connections potentially a bit more difficult for serial downloading vs ICSP given you must have a connection to the reset pin regardless of whether doing ICPS or async serial downloading.
Everything you need is there all together at the 6 pin connector for doing ICSP programming, but if using the serial with a bootloader, then you must have connections to RX, TX, and reset and there is no connector on the board with those pins.

So from a mechanical and interconnect perspective, using ICSP is easier since you can have a 6 pin pin connector that just plugs into the board.

--- bill

Another possibility would be to use a Raspeberry Pi
Then you can actually just use avrdude.

The Raspberry Pi zero-W is very small and pretty inexpensive.
(like around $10 USD)

Here is a tutorial from Adafruit about using Raspberry Pi.

The beauty of using RaspberryPi is that it is a full fledged computer that has a real OS that was designed for development so you have all kinds of tools readily available.
i.e. avrdude, web services, python, debuggers, whatever you might need / want
which means you have less to re-invent so you can get something up and going faster with less work.

And then they have a standalone unit they developed:
https://learn.sparkfun.com/tutorials/raspberry-pi-stand-alone-programmer
which can offer something ready made.

Just me, but I'd take a serious look at going that route vs an ESP part given the very minor cost difference and the added capabilities and resources.

--- bill

Thank you everyone for your responses. It has helped a lot.

After some consideration, I think I might go with @bperrybap 's suggestion of using a pi zero w.

The pi zero w current draw is on par with the esp32 (at least if you're not using any peripherals) and it has its own sd card storage, while also having wifi and bluetooth, and that way I can leverage avrdude. This does seem like the path of least resistance at this time.

I would start with
https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266AVRISP

Serial option is
https://github.com/JAndrassy/lab/tree/master/AvrDudeTelnet

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.