Error when re burning Bootloader from 16 MHz to 8Mhz [SOLVED]

I am doing a project that requires miniaturization and due to the shortage of semiconductors I thought it would be a good idea to buy some Arduino Pro mini and remove their microcontroller.

The problem is that every time I re-burn the Bootloader I get a bunch of errors until I can't use the avr anymore. At this point I probably already bricked 3 atmega328p

The original Arduino Pro mini works at 5V, and 16MHz, Aliexpress description said that it already has the bootloader.
This is the out of the box log when uploading a sketch using an USBasp (it's succesfull)

Sketch uses 5994 bytes (19%) of program storage space. Maximum is 30720 bytes.
Global variables use 232 bytes (11%) of dynamic memory, leaving 1816 bytes for local variables. Maximum is 2048 bytes.
/Users/vn532oi/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/Users/vn532oi/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cusbasp -Pusb -Uflash:w:/var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex:i 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/vn532oi/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/Users/vn532oi/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
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: auto set sck period (because given equals null)
avrdude: reading input file "/var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex"
avrdude: writing flash (5994 bytes):

Writing | ################################################## | 100% 4.25s

avrdude: 5994 bytes of flash written
avrdude: verifying flash memory against /var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex:
avrdude: load data flash data from input file /var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex:
avrdude: input file /var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex contains 5994 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 3.81s

avrdude: verifying ...
avrdude: 5994 bytes of flash verified

avrdude done.  Thank you.

The target setup is 3.3V and 8Mhz (internal), so I've been trying to use MiniCore with the next settings:

  • Board: Atmega328
    *Clock: Internal 8 Mhz
  • BOD: BOD 2.7V
  • EEPROM: EEPROM retained
  • Compiler LTO: LTO disabled
  • Variant: 328P / 328PA
    *Bootloeader: Yes (UART0)

And this is what I get when try to burn the boot loader:

/Users/vn532oi/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/bin/avrdude -C/Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/avrdude.conf -v -patmega328p -cusbasp -Pusb -e -Ulock:w:0x3f:m -Uefuse:w:0b11111101:m -Uhfuse:w:0b11010110:m -Ulfuse:w:0xe2:m 

avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/avrdude.conf"
         User configuration file is "/Users/vn532oi/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: erasing chip
avrdude: auto set sck period (because given equals null)
avrdude: reading input file "0x3f"
avrdude: writing lock (1 bytes):

/Users/vn532oi/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/bin/avrdude -C/Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/avrdude.conf -v -patmega328p -cusbasp -Pusb -Uflash:w:/Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328p/8000000L/optiboot_flash_atmega328p_UART0_38400_8000000L_B5.hex:i -Ulock:w:0x0f:m 

avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/avrdude.conf"
         User configuration file is "/Users/vn532oi/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3f:
avrdude: load data lock data from input file 0x3f:
avrdude: input file 0x3f contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0b11111101"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0b11111101:
avrdude: load data efuse data from input file 0b11111101:
avrdude: input file 0b11111101 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0b11010110"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0b11010110:
avrdude: load data hfuse data from input file 0b11010110:
avrdude: input file 0b11010110 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xe2"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xe2:
avrdude: load data lfuse data from input file 0xe2:
avrdude: input file 0xe2 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude done.  Thank you.

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
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: auto set sck period (because given equals null)
avrdude: reading input file "/Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328p/8000000L/optiboot_flash_atmega328p_UART0_38400_8000000L_B5.hex"
avrdude: writing flash (32768 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 32768 bytes of flash written
avrdude: verifying flash memory against /Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328p/8000000L/optiboot_flash_atmega328p_UART0_38400_8000000L_B5.hex:
avrdude: load data flash data from input file /Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328p/8000000L/optiboot_flash_atmega328p_UART0_38400_8000000L_B5.hex:
avrdude: input file /Users/vn532oi/Library/Arduino15/packages/MiniCore/hardware/avr/2.1.3/bootloaders/optiboot_flash/bootloaders/atmega328p/8000000L/optiboot_flash_atmega328p_UART0_38400_8000000L_B5.hex contains 32768 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x7e00
         0x00 != 0x01
avrdude: verification error; content mismatch

avrdude done.  Thank you.

Error while burning bootloader.

Since I see that it failed in verification step (not sure if boot loader is there), I proceed to remove the 16 MHz crystal an capacitors and give it a try

Sketch uses 6100 bytes (18%) of program storage space. Maximum is 32256 bytes.
Global variables use 230 bytes (11%) of dynamic memory, leaving 1818 bytes for local variables. Maximum is 2048 bytes.
/Users/vn532oi/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/bin/avrdude -C/Users/vn532oi/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/etc/avrdude.conf -v -patmega328p -cusbasp -Pusb -Uflash:w:/var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex:i 

avrdude: Version 6.3-20201216
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/Users/vn532oi/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/etc/avrdude.conf"
         User configuration file is "/Users/vn532oi/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
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: auto set sck period (because given equals null)
avrdude: reading input file "/var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex"
avrdude: writing flash (6100 bytes):

Writing | ################################################## | 100% 4.22s

avrdude: 6100 bytes of flash written
avrdude: verifying flash memory against /var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex:
avrdude: load data flash data from input file /var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex:
avrdude: input file /var/folders/wy/ztppc8wn7ms7fmb0gxjzv21w0000gp/T/arduino_build_569259/watch.ino.hex contains 6100 bytes
avrdude: reading on-chip flash data:

Reading | ###############################################An error occurred while uploading the sketch
### | 100% 3.89s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x00 != 0x0c
avrdude: verification error; content mismatch

avrdude done.  Thank you.

If I try to use a USB/TTL I get

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

If I try to burn the boot loader without crystal I get the same error

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x7e00
         0x00 != 0x01
avrdude: verification error; content mismatch

From here the errors only get worse to the point where the device signature is 0x00000000 and I officially declare that avr dead (or just bricked)

Any suggestions?

If the fuses are so set that the MCU is expecting an external crystal, then that must be present (or a similar signal available) before you can do anything (including loading a bootloader). It appears that you may be removing the crystal prematurely.
The bootloader must match the CPU speed. The fuses must be set to match the bootloader size. This should be done automatically if you use the "burn bootloader" option in the IDE.

EDIT
If you are left with an MCU without a crystal, but which requires one because of its current fuse settings, you may find the solution here is more practical that soldering the MCU back on a board: How a crystal works and what could replace it? (post #9) :

This sets the bootloader area size to 256 bytes. A standard Arduino bootloader won't fit into that size.

That activates the internal 8MHz oscillator. As this is verified the crystal shouldn't be necessary anymore.

Thanks for your answers.
@6v6gt I can bring back the crystal, but the idea is to remove it, so I don't want to depend on it.
And the problem persists no matter if I use 16 Mhz (external) or 8 Mhz (internal). Every time I try to burn the new Bootloader, I keep getting:

avrdude: verification error, first mismatch at byte 0x7e00
         0x00 != 0x01

@pylon, that's interesting, but those fuses comes directly from GitHub - MCUdude/MiniCore: Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB specifications, should I modify it and increasing the boot loader area ?

Well, that's good, but I keep getting:

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x7e00
         0x00 != 0x01
avrdude: verification error; content mismatch

UPDATE:

I tried Nick Gammon Atmega board programmer, I was able to load the bootloader, then I can load my sketch and make it work with 8Mhz, but once I tried to load some sketch updates, the error came back

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x00 != 0x0c
avrdude: verification error, first mismatch at byte 0x0000

avrdude: verification error; content mismatch

UPDATE

Now the signature got corrupted, I guess I killed another ATmega :frowning:

avrdude: Device signature = 0x001f00
avrdude: Expected signature for ATmega328P is 1E 95 0F
         Double check chip, or use -F to override this check.

Once you successfully loaded the bootloader, how did you upload the first sketch which you say also worked? Over the UART, that is the TX and RX pins or did you use the ICSP header pins ?

It was through ICSP, I tried UART but it didn't work. I have read that UART doesn't work well with the internal oscillator.

Is it dangerous to use ICSP to repeatedly upload the sketches?

I will redesign my circuit to support an external 8Mhz crystal. I'll tell you what happens once my new PCBs arrive

It is not dangerous but if you load the bootloader then, again over the ICSP header, you load a sketch, the bootloader will be overwritten by the sketch.

Usually you load a sketch through the bootloader if there is one. For this you uses a USB/UART adaptor connected to the TX/RX pins. If there isn't a bootloader, then the fuses should be set for use without a bootloader and you upload the sketch directly using a programmer such as your USBasp via the ISCP pins.

You appear to be doing a bit of both.

If the bootloader didn't work, you should probably find out why or give up attempting to upload it. You must use a boot loader which is compiled for the target frequency. I believe it is theoretically possible that the internal oscillator is not accurate enough to support serial uploading but this is surely a rare edge case.

What I don't understand is how you could have appeared, by the process you have followed, to have irretrievably "bricked" the ATmega328P.

Why do you want a bootloader at all? If you upload sketches by ICSP you don't need a bootloader and you can use that space for your code.

Me too.

Yes, they are wrong for the 328, seems to be a copy/paste error from the 168.

I think this is correct for the high fuse (0xD6) assuming the bootloader is optiboot and fits into 512 bytes. The size units for BOOTSZ0 and BOOTSZ1 are strangely 16 bit words so this is 256 words.
If you don't use the "burn bootloader " option in the IDE you must use AVRDUDE to correct the fuse settings because the Promini has a larger bootloader. The "burn bootloader" as a side effect also sets the fuses. If you don't want a bootloader, you must explicitly change BOOTRST to 1 (unset) in that you set the high fuse to 0xD7.

Maybe this helps: Arduino / ATmega 328P fuse settings – Martyn Currey

edit
The fuse definitions for minicore can be found here: https://github.com/MCUdude/MiniCore/blob/master/avr/boards.txt

Minicore also allows the menu selection of a "no bootloader " option for mcu but to activate it you still need to use the "burn bootloader " option in order to set the fuses correctly.
When you upload sketches it is important that you use the same board configuration options as you used during the initial configuration.

Well, after some days of experimentation I was able to fix it.

  1. First, I recovered my bricked atmegas by using a high voltage programmer to reset the fuses to:

LFUSE: 0xE2
HFUSE: 0xD9
EFUSE: 0xFF

I want the Bootloader to be able to upload sketches through UART, but since it was causing me a lot o problems I stopped using it for a moment. So I disabled the Bootloader by setting the HFUSE: 0xD9, but I should try 0xD7 since that leaves BOOTSZ1 and BOOTSZ2 un-programmed, and that's probably a better state for this point.

  1. Now it's time to bring back the Bootloader. I was able to burn it as it is (minicore uses optiboot), but the key to make it work and remove this error:
avrdude: verification error, first mismatch at byte 0x0000
         0x00 != 0x0c
  • I added a 10 uf capacitor between GND and VCC, and a 10 KΩ between RST and VCC
  • I had to use slow USBasp option from minicore, which adds -B32 flag to avrdude

It worked without throwing errors!

  1. Now that I have the Bootloader, I was able to upload sketches from UART

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