RobotDyn Uno WiFi – flash Atmega328P over ESP8266

I have met some problem with flashing Atmega over ESP on RobotDyn Uno WiFi board with these two chips embedded. The problem is that I have flashing process working when use separately Arduino Uno board and ESP-01 module connected. But it doesn’t work on combined board.

For the flashing I use OTA principles and STK500 protocol from GitHub - DIYOSEPP/EspUnoWiFi: WiFi Serial and OTA bridge for UNO.
First, I send new firmware hex file over TCP to SPIFFS of ESP. Secondly, trying to flash Atmega with this file.

When use separately - board and module connected as follows: ESP-01s– Uno, RX–TX, TX–RX, 3V3–3v3, GND–GND, IO2–reset. To reproduce scheme for RobotDyn Uno WiFi I do next:

  1. Dip switches 1-2 ON (to connect Atmega-ESP RX-TX).
  2. Connect IO2 to board reset.
    As I understand VCC and GND are already set for embedded ESP.

And so RobotDyn Uno WiFi flashing doesn’t work.
It turned out to me that RobotDyn Uno WiFi board has reset pin connected to both of their chips. And when in send signal to it the entire board is reset. While I need to reset only Atmega in order to enter optiboot.

Could anybody explain how reset at RobotDyn board is set up? Is there a way to reset only Atmega?

I have checked that both chips work well. And combination RobotDyn board + ESP-01 module also works for flashing.
P.S. I do programming in that way because I need to make system that can be flashed from mobile (Android and iOS) and may be used from different locations (so we use AP mode for WiFi). Approach with separate Arduino Uno board and ESP-01 module is fine but I want to make less wirings for the system.

Here is the main part of the code.

int handleHex(WiFiClient client, int hexlen) // writes hex to Atmega 
{
    while (client.connected() && client.available() == 0) {
        delay(1);
    }
    if (client.read() != ':') return 0; // client holds hex code text
    int totalLen = 0;
    address = -1;
    baseaddr = 0;
    dity = 0;
    total_write = 0;
    memset(read_page_buff, 0xff, sizeof(read_page_buff));
    memset(write_page_buff, 0xff, sizeof(write_page_buff));
    if (!entryBootloader())
        if (!entryBootloader())
            if (!entryBootloader()) return -1;
    while (client.connected()) {
        int rl = client.readBytesUntil(
            ':', lineBuff,
            min((int)sizeof(lineBuff) - 1, hexlen - totalLen - 1));
        int dlen = rl;
        if (dlen < 10) break;
        if (lineBuff[rl - 1] == '\n') dlen--;
        if (lineBuff[rl - 2] == '\r') dlen--;
        if (dlen < 10) break;
        if (dlen & 1) break;
        totalLen += rl + 1;
        if (sigleRecord(lineBuff, dlen)) break;
    }
    return totalLen;
}

int entryBootloader() // check Atmega bootloader state
 {
    Serial.begin(115200);
    resetTarget();
    delay(500);
    int i = 0;
    while (1) {
        while (Serial.available()) 
        Serial.read();
        Serial.write(0x30);
        Serial.write(0x20);
        delay(50);
        i++;
        if (i > 500 /10 ) {
            return 0;
        }
        if (Serial.available() > 1) {
            if (Serial.read() != 0x14) continue;
            if (Serial.read() != 0x10) continue;
            return 1;
        }
    }
}

const int resetPin = 2;  // GPIO2-->UNO reset pin
void resetTarget() {
    pinMode(resetPin, OUTPUT_OPEN_DRAIN);
    digitalWrite(resetPin, LOW);
    delay(10);
    digitalWrite(resetPin, HIGH);
}

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