New Nano bootloader reboots twice after upload

After burning the new bootloader on the Nano (ATmega328p) with USBasp, the Nano reboots a second time after uploading a sketch, after execution of the sketch has started.

void setup() {
	Serial.begin( 2400 );

	Serial.println( "\nBooted" );
	for( uint32_t i = 0; i<20; i++ ) {
		Serial.print( i );
		Serial.print( ' ' );
	}
}

void loop() {
}

which produces this output:


Booted
0 1 2 3 4 5 6 7 8 9⸮
Booted
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

It does not do this after pressing the reset button. Burning the old bootlooder back on it fixes the issue.
The Uno (ATmega328p) has the same problem but there I don't have the option of burning the old bootloader, at least not in the IDE.
I noticed that the fuses relating to the bootloader size changes between old and new. If I read the datasheet correctly, it looks like the boot section increases from 0.25K to 1K words.

This might be an artifact of the way Serial Monitor interacts with the upload.
The sketch is started immediately after the upload has completed, via "STK_LEAVE_PROGMODE", and starts printing characters. Shortly thereafter, the Serial Monitor notices that the upload has finished and re-opens the serial connection to the board, which also causes a hardware reset.
(To confirm this, monitor the DTR signal from the USB/Serial chip, before it becomes the RESET signal. (might be tricky, physically.))

I noticed that the fuses relating to the bootloader size changes between old and new. If I read the datasheet correctly, it looks like the boot section increases from 0.25K to 1K words.

The "Old Bootloader" was 1k words and had the fuses set for 1k.
Optiboot is 0.25k words, but for "nano" does not change the fuses, so that they're still set for 1k words. If you declare your "nano" to be an "Uno" and do a "burn bootloader", you'll get the same new bootloader AND correct fuse settings.

@westfw Thank you, that cleared things up. I got the fuse readings messed up.
I went back and read out the fuses again, taking better notes this time.

Nano old bootloader
avrdude: safemode: Fuses OK (E:FD, H:DA, L:FF)	# Boot size 0b01 = 1024 words

Nano new bootloader
avrdude: safemode: Fuses OK (E:FD, H:DA, L:FF)	# Boot size 0b01 = 1024 words

Uno bootloader
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)	# Boot size 0b11 = 256 words

Nano w. Uno bootloader
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)	# Boot size 0b11 = 256 words

It is impressive that the Optiboot reduces the boot size by 3/4!

The monitor behaves the same way but now that I know what is going on I can ignore it.
I am going to guess that this behavior has always been going on but now the bootloader finishes quicker and we can see when the monitor resets the chip.

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