0

I'm trying to upload the sketch on a Mega 2560 via the serial port 0 using another microcontroller.

To better undestand the process, I decided to first observe what avrdude is doing while it is uploading a hex file. To do this, I'm using another arduino (ESP32) with the following sketch:

void setup()
{
    Serial.begin(115200);
    Serial2.begin(115200);
}

void loop()
{
    while (Serial2.available()) {
        Serial.print(Serial2.read(), HEX);
        Serial.print(":");
    }
}

ESP32's Serial(serial0) is connected to PC via USB, and Serial2 is connected to Mega's Serial(serial0), the one connected to PC via USB, used by avrdude. enter image description here According to this answer the first things avrdude is sending over the serial interface are:

STK_GET_SYNC / CRC_EOP  (0x30/0x20)

But this is not what I receive through ESP32:

1B:1:0:1:E:1:14:1B:2:0:C:E:10:C8:64:19:20:0:53:3:AC:53:0:0:31:1B:3:0:8:E:1D:4:4:0:30:0:0:0:33:1B:4:0:8:E:1D:4:4:0:30:0:1:0:35:1B:5:0:8:E:1D:4:4:0:30:0:2:0:37:1B:6:0:8:E:1D:4:4:0:50:0:0:0:56:1B:7:0:8:E:1D:4:4:0:50:0:0:0:57:1B:8:0:8:E:1D:4:4:0:50:0:0:0:58:1B:9:0:8:E:1D:4:4:0:58:8:0:0:59:1B:A:0:8:E:1D:4:4:0:58:8:0:0:5A:1B:B:0:8:E:1D:4:4:0:58:8:0:0:5B:1B:C:0:8:E:1D:4:4:0:50:8:0:0:54:1B:D:0:8:E:1D:4:4:0:50:8:0:0:55:1B:E:0:8:E:1D:4:4:0:50:8:0:0:56:1B:F:0:5:E:6:80:0:0:0:99:1B:10:1:A:E:13:1:0:C1:A:40:4C:20:0:0:71:C0:0:0:81:C0:0:0:7F:C0:0:0:7D:C0:0:0:7B:C0:0:0:79:C0:0:0:77:C0:0:0:75:C0:0:0:73:C0:0:0:71:C0:0:0:6F:C0:0:0:6D:C0:0:0:6B:C0:0:0:69:C0:0:0:67:C0:0:0:65:C0:0:0:63:C0:0:0:61:C0:0:0:5F:C0:0:0:5D:C0:0:0:5B:C0:0:0:59:C0:0:0:57:C0:0:0:56:C0:0:0:53:C0:0:0:51:C0:0:0:4F:C0:0:0:4D:C0:0:0:4B:C0:0:0:49:C0:0:0:47:C0:0:0:45:C0:0:0:43:C0:0:0:41:C0:0:0:3F:C0:0:0:3D:C0:0:0:3B:C0:0:0:39:C0:0:0:37:C0:0:0:35:C0:0:0:33:C0:0:0:31:C0:0:0:2F:C0:0:0:2D:C0:0:0:2B:C0:0:0:29:C0:0:0:27:C0:0:0:25:C0:0:0:23:C0:0:0:21:C0:0:0:1F:C0:0:0:1D:C0:0:0:1B:C0:0:0:19:C0:0:0:17:C0:0:0:15:C0:0:0:13:C0:0:0:11:24:1F:BE:CF:EF:D1:E2:DE:BF:CD:BF:0:E0:C:BF:22:E0:A0:E0:B2:E0:1:C0:1D:92:A9:30:19:1B:11:0:5:E:6:80:0:0:80:7:1B:12:1:A:E:13:1:0:C1:A:40:4C:20:0:0:B2:7:E1:F7:4C:D0:C2:C0:7B:CF:1F:92:F:92:F:B6:F:92:11:24:2F:93:3F:93:8F:93:9F:93:AF:93:BF:93:80:91:5:2:90:91:6:2:A0:91:7:2:B0:91:8:2:30:91:4:2:23:E0:23:F:2D:37:20:F4:1:96:A1:1D:B1:1D:5:C0:26:E8:23:F:2:96:A1:1D:B1:1D:20:93:4:2:80:93:5:2:90:93:6:2:A0:93:7:2:B0:93:8:2:80:91:0:2:90:91:1:2:A0:91:2:2:B0:91:3:2:1:96:A1:1D:B1:1D:80:93:0:2:90:93:1:2:A0:93:2:2:B0:93:3:2:BF:91:AF:91:9F:91:8F:91:3F:91:2F:91:F:90:F:BE:F:90:1F:90:18:95:78:94:84:B5:82:60:84:BD:84:B5:81:60:84:BD:85:B5:82:60:85:BD:85:B5:81:60:85:BD:80:91:6E:0:81:60:80:93:6E:0:10:92:81:0:80:91:81:0:82:60:80:93:81:0:80:91:81:0:81:60:80:93:81:0:80:91:80:0:81:60:80:93:80:0:80:91:B1:0:84:60:80:93:B1:0:80:91:B0:0:81:60:1B:13:0:5:E:6:80:0:1:0:84:1B:14:1:A:E:13:1:0:C1:A:40:4C:20:0:0:91:0:80:91:91:0:81:60:80:93:91:0:80:91:90:0:81:60:80:93:90:0:80:91:A1:0:82:60:80:93:A1:0:80:91:A1:0:81:60:80:93:A1:0:80:91:A0:0:81:60:80:93:A0:0:80:91:21:1:82:60:80:93:21:1:80:91:21:1:81:60:80:93:21:1:80:91:20:1:81:7A:0:80:91:7A:0:81:60:80:93:7A:0:80:91:7A:0:80:68:80:93:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:1B:15:0:8:E:1D:4:4:0:50:0:0:0:45:1B:16:0:8:E:1D:4:4:0:50:0:0:0:46:1B:17:0:8:E:1D:4:4:0:50:0:0:0:47:1B:18:0:8:E:1D:4:4:0:58:8:0:0:48:1B:19:0:8:E:1D:4:4:0:58:8:0:0:49:1B:1A:0:8:E:1D:4:4:0:58:8:0:0:4A:1B:1B:0:8:E:1D:4:4:0:50:8:0:0:43:1B:1C:0:8:E:1D:4:4:0:50:8:0:0:44:1B:1D:0:8:E:1D:4:4:0:50:8:0:0:45:1B:1E:0:3:E:11:1:1:19:

I can't find 30:20 anywhere. What am I missing?

The baud rate is 115200 everywhere which I believe is the right one. The link is good because if I send char 'A' from PC over the serial connected to Mega, I get 41: via ESP32 on the other side, which is correct.

  • Are both ESP32's serial ports implemented in hardware? Do the research because if 1 is implemented in software the ESP32 may not be able to echo back everything it sees on the hardware serial port. – st2000 Oct 13 at 14:53
  • the bootloader responses on TX. and do you reset the board? the avrdude uses stk500 protocol, which is documented, no need to reverse engineer it – Juraj Oct 13 at 15:06
  • @st2000 According to online docs they are both hardware. It's also labeled on the board and when I send a random char from PC to Mega, I receive the correct value via ESP32, but when I look at what I receive during sketch upload, makes no sense. @Juraj I'm interested in what avrdude is sending first, which should be 0x30,0x20, not 0x1B,0x01. I don't reset the board, the usb-to-serial chip already does it. The sketch upload from PC works. I just want to confirm the the first thing it sends is 0x30,0x20 to help me going. – Chris Oct 13 at 15:12
  • Agreed, online it says the ESP32 has 3 hardware UARTs. But when the Arduino development environment was ported to the ESP processor, did it actually use the hardware UARTs? And if it did, how well implemented is the firmware? For that matter, how well is the ESP's hardware implemented? The type of problem I am concerned about occurs when many bytes are transferred rapidly. Of course the 1st byte, for such problems, should always make it through. Also, I agree with @Juraj. Use the existing documentation to develop you own programmer. Nothing says that what avrdude does is correct. – st2000 Oct 13 at 15:37
  • 1
    The answer you link to is about the Uno. The Mega uses a different bootloader and, IIRC, a different protocol. – Edgar Bonet Oct 13 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.