Troubleshooting UART Selection for Arduino Mega using MegaCore

Issue Overview:

I'm encountering difficulties when attempting to use UART other than UART 0 and UART 1 for uploading programs to the Arduino Mega using MegaCore (Idea came from: Uploading sketch to Mega 2560 through serial2 or serial3?). Specifically, I suspect the problem lies with the autobaud rate detection, as mentioned in the readme of MegaCore.

Relevant Information from MegaCore Readme:

The readme for MegaCore states:

Make sure you connect an ISP programmer, and select the correct one in the "Programmers" menu. For time-critical operations, an external crystal/oscillator is recommended. The Urboot bootloader has automatic baud rate detection (except when using UART2 and UART3 on ATmega640/1280/2560), so UART uploads should work fine even though the oscillator is a little too fast or too slow.

Detailed Log Comparison:

Here's a comparison of the log for selecting UART 0 vs. UART 3:

UART 0:

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9801 (probably m2560)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip

avrdude: processing -U flash:w:~/Library/Arduino15/packages/MegaCore/hardware/avr/3.0.1/bootloaders/urboot/atmega2560/watchdog_1_s/autobaud/uart0_rxe0_txe1/led+b7/urboot_atmega2560_pr_ee_ce.hex:i
avrdude: reading input file ~/Library/Arduino15/packages/MegaCore/hardware/avr/3.0.1/bootloaders/urboot/atmega2560/watchdog_1_s/autobaud/uart0_rxe0_txe1/led+b7/urboot_atmega2560_pr_ee_ce.hex for flash
         with 396 bytes in 2 sections within [0x3fe00, 0x3ffff]
         using 2 pages and 116 pad bytes
avrdude: writing 396 bytes flash ...
Writing | ################################################## | 100% 0.16s
avrdude: 396 bytes of flash written
avrdude: verifying flash memory against ~/Library/Arduino15/packages/MegaCore/hardware/avr/3.0.1/bootloaders/urboot/atmega2560/watchdog_1_s/autobaud/uart0_rxe0_txe1/led+b7/urboot_atmega2560_pr_ee_ce.hex
Reading | ################################################## | 100% 0.00s
avrdude: 396 bytes of flash verified

avrdude: processing -U lock:w:0xff:m
avrdude: reading input file 0xff for lock
         with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte lock ...
avrdude: 1 byte of lock written
avrdude: verifying lock memory against 0xff
avrdude: 1 byte of lock verified

avrdude done.  Thank you.

UART 3:

       Programmer Type : STK500
         Description     : Atmel STK500 version 1.x firmware
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9801 (probably m2560)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip

avrdude: processing -U flash:w:~/Library/Arduino15/packages/MegaCore/hardware/avr/3.0.1/bootloaders/urboot/atmega2560/watchdog_1_s/external_oscillator/16000000_hz/115200/uart3_rxj0_txj1/led+b7/urboot_atmega2560_pr_ee_ce.hex:i
avrdude fileio_segments_normalise() OS error: cannot open input file ~/Library/Arduino15/packages/MegaCore/hardware/avr/3.0.1/bootloaders/urboot/atmega2560/watchdog_1_s/external_oscillator/16000000_hz/115200/uart3_rxj0_txj1/led+b7/urboot_atmega2560_pr_ee_ce.hex: No such file or directory
avrdude do_op() error: read from file ~/Library/Arduino15/packages/MegaCore/hardware/avr/3.0.1/bootloaders/urboot/atmega2560/watchdog_1_s/external_oscillator/16000000_hz/115200/uart3_rxj0_txj1/led+b7/urboot_atmega2560_pr_ee_ce.hex failed

avrdude done.  Thank you.

Failed to burn bootloader: uploading error: exit status 1

Error Encountered with UART 3:

avrdude ioerror() OS error: file ~/Library/Arduino15/packages/MegaCore/hardware/avr/3.0.1/bootloaders/urboot/atmega2560/watchdog_1_s/external_oscillator/16000000_hz/115200/uart3_rxj0_txj1/led+b7/urboot_atmega2560_pr_ee_ce.hex is not readable: No such file or directory

Is there anything I can do to resolve the issue?

Hi @agingwarrior. This is caused by a bug in the MegaCore boards platform configuration. This particular bootloader file is at a different path than the path specified in the platform's configuration

I submitted a fix for it:

I think the easiest workaround for the bug will be to move the bootloader file to the path where the platform is configured to look when performing a "Burn Bootloader" operation:

  1. Use macOS Finder to navigate to the following path:
    /Users/foo/Library/Arduino15/packages/MegaCore/hardware/avr/3.0.1/bootloaders/urboot/atmega2560/watchdog_1_s/external_oscillator/16000000_hz/
    
    :exclamation: The Library folder is hidden by default. You can make it visible by pressing the Command+Shift+. keyboard shortcut.
  2. Rename the 115200_baud folder to 115200.

Now try performing a "Burn Bootloader" operation in Arduino IDE just as you did before. Hopefully this time it will be successful.

Thank you so much. I've been able to get it working now.

You are welcome. I'm glad it is working now.

Regards,
Per

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