0

I have built a custom board that has an ATmega328p connected to an ESP8266 module via UART. I am currently programming the ATmega328p using a USBtiny programmer via an SPI header. The ESP8266 module is programmed via an FTDI cable connected the the UART.

Firmware for both are created in Arduino IDE.

I have set up a webserver on the ESP that allows for files to be uploaded to the SPIFFS via FTP. I would like to be able to upload a hex file for the ATmega and then have the ESP program the ATmega via the UART connection. A GPIO on the ESP controls a transistor that can pull the reset pin on the ATmega to ground.

I know I need a bootloader on the ATmega (e.g. optiboot), but I don't know what I need to make the ESP do to trigger the bootloader and flash the ATmega. I'm thinking I need something like:

void initialiseAtmegaFlash () {
  // Trigger the bootloader to accept incoming hex over UART
}

void flashHexToAtmega (File atmegaHex) {
  for (uint32_t i = 0; i < atmegaHex.size(); ++i) {
    // Handle timing of sending byte by byte over serial... or chunk by chunk?
  }
}
5
  • You need to start by understanding the STK500 protocol. Read and digest: ww1.microchip.com/downloads/en/AppNotes/doc2591.pdf
    – Majenko
    Commented Mar 7, 2019 at 11:11
  • you can use the dfu library from here github.com/jandrassy/…
    – Juraj
    Commented Mar 7, 2019 at 12:13
  • That dfu library looks like I need to initiate the upload from Arduino IDE on the same network. The STK500 protocol documentation looks like the sort of thing I need. I was hoping there might be a neat library already, but looks like the info I need to get the functionality.
    – Pinja
    Commented Mar 7, 2019 at 15:49
  • github.com/ciminaghi/libdfu
    – Juraj
    Commented Mar 8, 2019 at 9:57
  • did u managed to do it? If yes, kindly share the details with me also and the connections. Commented Jun 29, 2020 at 10:28

1 Answer 1

1

To answer my own question in case someone else ends up here, the library Juraj suggested (https://github.com/ciminaghi/libdfu) looks like it does the job. I also found another project doing something similar (https://github.com/rene-win/esp_avr_programmer). Also the STK500 docs linked to by Majenko (http://ww1.microchip.com/downloads/en/AppNotes/doc2591.pdf) are really useful for understanding the nuts and bolts!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.