Strange pb with bootloader on ATMega2560 16U

I just started playing with a new Robodyn Mega Pro Mini:
https://idyl.io/2017/06/05/robotdyn-mega-pro-mini-embed-arduino-review/

My board doesn't have the USB connector, just the Serial headers (second pic on the page).

I was able to burn Nick Gammon's atmega2560 bootloader, and the output of his board detector are included below.
After burning the bootloader I can use a Serial to upload a sketch... once :frowning:
The uploaded sketch runs, but any subsequent attempt at using Serial to upload a new sketch fails; in fact I see the uploaded sketch running (let blinks) while the IDE is trying to start the upload.

It could be a reset pb (no DTR pin on the mega so I reset manually) however I can reset the board at the right time 100% of the time if only the bootloader is present.

This could be a pb with the boot reset vector and other fuses impacting what the mega does after resetting, I am a bit vague in that area but here is what I checked:

  • the high fuse is a 0xD8: boot reset vector enabled and boot start = 1F000
  • Nick's detector reports "Bootloader is 8192 bytes starting at 3E000" where 3E000 bytes == 1F000 words

... so I'm at a loss at what could be wrong here, any suggestions?
Is there some fuse setting that would cause the board to skip the bootloader and to go directly to the sketch when resetting? Is there a way to check whether this is what's happening?

Thanks!
Franck

Atmega chip detector.
Written by Nick Gammon.
Version 1.20
Compiled on Mar 11 2018 at 15:40:27 with Arduino IDE 10802.
Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x98 0x01 
Processor = ATmega2560
Flash memory size = 262144 bytes.
LFuse = 0xFF 
HFuse = 0xD8 
EFuse = 0xFD 
Lock byte = 0xEF 
Clock calibration = 0x8E 
Bootloader in use: Yes
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 8192 bytes starting at 3E000

Bootloader:

3E000: 0x0D 0x94 0x89 0xF1 0x0D 0x94 0xB2 0xF1 0x0D 0x94 0xB2 0xF1 0x0D 0x94 0xB2 0xF1 
...
MD5 sum of bootloader = 0x12 0xAA 0x80 0x07 0x4D 0x74 0xE3 0xDA 0xBF 0x2D 0x25 0x84 0x6D 0x99 0xF7 0x20 
Bootloader name: atmega2560_bootloader_watchdog_bug_fixed

First 256 bytes of program memory:

00: 0x06 0xC1 0x00 0x00 0x16 0xC1 0x00 0x00 0x14 0xC1 0x00 0x00 0x12 0xC1 0x00 0x00 
...

Try just doing the standard Tools > Burn bootloader instead of using that Nick Gammon chip programmer (or whatever it's called) sketch.

Also, make sure you're using a recent version of Arduino AVR Boards. The version of the avrdude tool included with older versions of that hardware package had this exact issue but the recent ones have a newer version of avrdude that solved the issue:

pert:
Try just doing the standard Tools > Burn bootloader instead of using that Nick Gammon chip programmer (or whatever it's called) sketch.

I tried that earlier, same problem.
And I do need the watchdog fixed...

Franck

Were you using avrdude 6.3 and the current ArduinoISP sketch?

Keep in mind that after you have just burned the bootloader the microcontroller stays permanently in the bootloader state so no reset is required. After you have uploaded the first sketch then the bootloader only runs for a short time after the reset and so the timing of the reset during the upload has to be fairly exact, otherwise the upload doesn't start when the bootloader is active.

franck102:
And I do need the watchdog fixed...

What do you mean by that?

pert:
Also, make sure you're using a recent version of Arduino AVR Boards. The version of the avrdude tool included with older versions of that hardware package had this exact issue but the recent ones have a newer version of avrdude that solved the issue:
Program doesn't run after Upload Using Programmer with USBasp (Mega2560) · Issue #246 · arduino/ArduinoCore-avr · GitHub

I am using avd-dude 6.3 it seems:

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
        Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
        Copyright (c) 2007-2014 Joerg Wunsch

pert:
Were you using avrdude 6.3 and the current ArduinoISP sketch?

Keep in mind that after you have just burned the bootloader the microcontroller stays permanently in the bootloader state so no reset is required. After you have uploaded the first sketch then the bootloader only runs for a short time after the reset and so the timing of the reset during the upload has to be fairly exact, otherwise the upload doesn't start when the bootloader is active.
What do you mean by that?

I am using avrdude 6.3; I will double check the ArduinoISP sketch.
Good point on the reset; I don't want to hack my Serial adapter, is there any simple circuitry I can use to turn the DTR signal into a Reset pulse?

Regarding the watchdog, this is what Nick Gammon's page mentions:
"Atmega2560 with fixes for watchdog timer problem (8192 bytes)"

I have had problems in the past with Pro Mini bootloaders and watchdog resets until I switched to Minicore, so I assumed that was something similar. I use watchdogs heavily in the sketch I want to run.

Franck

franck102:
is there any simple circuitry I can use to turn the DTR signal into a Reset pulse?

Yes, just connect the DTR pin to the reset pin on the ATmega2560 via a 0.1 uF capacitor.

franck102:
Regarding the watchdog, this is what Nick Gammon's page mentions:
"Atmega2560 with fixes for watchdog timer problem (8192 bytes)"

I have had problems in the past with Pro Mini bootloaders and watchdog resets until I switched to Minicore, so I assumed that was something similar. I use watchdogs heavily in the sketch I want to run.

Very older versions of the Mega bootloader had that same endless reset loop after watchdog reset but that was fixed a long time ago so you won't have that problem if you use the bootloader that comes with any recent version of the Arduino IDE/Arduino AVR Boards.

Not that I'm necessarily discouraging the use of Nick Gammon's sketch, it's just that I have no experience with it and I do have a ton of experience burning bootloaders using the Arduino IDE's Tools > Burn Bootloader. I see Nick Gammon's sketch as primarily being useful for making a standalone programmer that doesn't require a computer connected to burn bootloaders to microcontrollers. I really don't see any reason to use it in a situation where your microcontroller is close enough to a computer to be reached with a USB cable.

pert:
Yes, just connect the DTR pin to the reset pin on the ATmega2560 via a 0.1 uF capacitor.

Thanks, that worked like a charm! Problem solved, manual reset clearly is not the way to go...

Franck

Glad to hear! I can't imagine the days when all Arduinos had to be manually reset to upload. Even though the bootloader delays were set longer then to make it easier to get the timing, the auto reset is just so convenient.

Well I spoke too fast :frowning:

I was able to upload over the Blink sketch. But once I upload my larger sketch (25282 bytes), the sketch doesn't seem to run and I can't upload anything more through Serial afterwards.

Franck

[Edit] argh, low fuse flag left at 0xD9 from earlier attempts. Uploads work fine, the sketch doesn't but that's a different story...