Issue with uploading program after burning bootloader

I am trying to burn my bootloader on my ATMEGA 2560 board, there appear; to be no issues when I actually burn the bootloader; rather the issues surface when I try to actually upload my program onto the board. Really stuck with this one and not sure how to proceed as the error is not that descriptive for me

There are the commands I am running

'avrdude -v -p atmega2560 -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0xFF:m -U efuse:w:0xFD:m -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m'

'avrdude -v -p atmega2560 -c stk500v1 -P /dev/ttyACM0 -b 19200 -U flash:w:bootloaders/stk500boot_v2_mega2560.hex:i -U lock:w:0xCF:m'

message I receive when I try to upload the sketch after burning the bootloader on the board

10678 bytes
avrdude: reading on-chip flash data:Reading | ###############################################An error occurred while uploading the sketch

| 100% 2.31savrdude: verifying ...

avrdude: verification error, first mismatch at byte 0x0000
0xff != 0x7c
avrdude: verification error; content mismatchavrdude done. Thank you

cross-post reference here

Did you try with a different sketch ?. Post whole error code

A different sketch? no, so the order in which I need to do these is (1) bootloader (2) init tool sketch (3) final sketch and currently, right now number 2 is failing.

Here is the bootloader verbose output when I am actually burning the bootloader

BOOTLOADER BURNING OUTPUT

avrdude: Recv: . [c1] ] [5d] . [de] O [4f] . [08] . [81] . [cf] R [52] . [d1] @ [40] . [0f] _ [5f] . [c1] ] [5d] . [de] O [4f] . [08] . [83] . [cf] R [52] . [d1] @ [40] . [90] . [e0] . [a0] . [e0] . [b0] . [e0] . [0d] . [94] . [1a] . [f4] ' [27] . [98] / [2f] . [98] . [80] . [e0] . [90] . [e0]   [20] . [ed] 7 [37] . [e0] . [f9] . [01] 1 [31] . [97] . [f1] . [f7] . [01] . [96] . [84] 6 [36] . [91] . [05] . [c9] . [f7] . [00] . [00] . [80] . [91] . [c0] . [00] . [8d] . [7f] . [80] . [93] . [c0] . [00] . [81] . [e1] . [80] . [93] W [57] . [00] . [e8] . [95] . [ee] ' [27] . [ff] ' [27] . [09] . [94] . [ff] . [cf] . [90] . [e0] . [0d] . [94] . [1a] . [f4] . [97] . [fb] . [09] . [2e] . [07] & [26] . [0a] . [d0] w [77] . [fd] . [04] . [d0] . [2e] . [d0] . [06] . [d0] . [00]   [20] . [1a] . [f4] p [70] . [95] a [61] . [95] . [7f] O [4f] . [08] . [95] . [f6] . [f7] . [90] . [95] . [81] . [95] . [9f] O [4f] . [08] . [95] . [a1] . [e2] . [1a] . [2e] . [aa] . [1b] . [bb] . [1b] . [fd] . [01] . [0d] . [c0] . [aa] . [1f] . [bb] . [1f] . [ee] . [1f] . [ff] . [1f] . [a2] . [17] . [b3] . [07] . [e4] . [07] . [f5] . [07]   [20] . [f0] . [a2] . [1b] . [b3] . [0b] . [e4] . [0b] . [f5] . [0b] f [66] . [1f] w [77] . [1f] . [88] . [1f] . [99] . [1f] . [1a] . [94] i [69] . [f7] ` [60] . [95] p [70] . [95] . [80] . [95] . [90] . [95] . [9b] . [01] . [ac] . [01] . [bd] . [01] . [cf] . [01] . [08] . [95] . [aa] . [1b] . [bb] . [1b] Q [51] . [e1] . [07] . [c0] . [aa] . [1f] . [bb] . [1f] . [a6] . [17] . [b7] . [07] . [10] . [f0] . [a6] . [1b] . [b7] . [0b] . [88] . [1f] . [99] . [1f] Z [5a] . [95] . [a9] . [f7] . [80] . [95] . [90] . [95] . [bc] . [01] . [cd] . [01] . [08] . [95] . [f9] . [99] . [fe] . [cf] . [92] . [bd] . [81] . [bd] . [f8] . [9a] . [99] ' [27] . [80] . [b5] . [08] . [95] & [26] / [2f] 
avrdude: Recv: . [10] 
avrdude: Send: U [55] . [80] . [fe]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Send: t [74] . [01] . [00] F [46]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [f9] . [99] . [fe] . [cf] . [1f] . [ba] . [92] . [bd] . [81] . [bd]   [20] . [bd] . [0f] . [b6] . [f8] . [94] . [fa] . [9a] . [f9] . [9a] . [0f] . [be] . [01] . [96] . [08] . [95] . [f8] . [94] . [ff] . [cf] . [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] . [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] . [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] . [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] . [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] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] 
avrdude: Recv: . [10] 
avrdude: avr_read(): skipping page 1022: no interesting data
avrdude: avr_read(): skipping page 1023: no interesting data
avrdude: verifying ...
avrdude: 261406 bytes of flash verified
avrdude: reading input file "0xCF"
avrdude: writing lock (1 bytes):

Writing |                                                    | 0% 0.00savrdude: Send: V [56] X [58] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [ff] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] . [ac] . [e0] . [00] . [cf]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] X [58] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [cf] 
avrdude: Recv: . [10] 
Writing | ################################################## | 100% 0.03s

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

Reading |                                                    | 0% 0.00savrdude: Send: V [56] X [58] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [cf] 
avrdude: Recv: . [10] 
Reading | ################################################## | 100% 0.01s

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

avrdude: Send: V [56] P [50] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [ff] 
avrdude: Recv: . [10] 
avrdude: safemode read 1, lfuse value: ff
avrdude: Send: V [56] P [50] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [ff] 
avrdude: Recv: . [10] 
avrdude: safemode read 2, lfuse value: ff
avrdude: Send: V [56] P [50] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [ff] 
avrdude: Recv: . [10] 
avrdude: safemode read 3, lfuse value: ff
avrdude: safemode: lfuse reads as FF
avrdude: Send: V [56] X [58] . [08] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [de] 
avrdude: Recv: . [10] 
avrdude: safemode read 1, hfuse value: de
avrdude: Send: V [56] X [58] . [08] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [de] 
avrdude: Recv: . [10] 
avrdude: safemode read 2, hfuse value: de
avrdude: Send: V [56] X [58] . [08] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [de] 
avrdude: Recv: . [10] 
avrdude: safemode read 3, hfuse value: de
avrdude: safemode: hfuse reads as DE
avrdude: Send: V [56] P [50] . [08] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [fd] 
avrdude: Recv: . [10] 
avrdude: safemode read 1, efuse value: fd
avrdude: Send: V [56] P [50] . [08] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [fd] 
avrdude: Recv: . [10] 
avrdude: safemode read 2, efuse value: fd
avrdude: Send: V [56] P [50] . [08] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [fd] 
avrdude: Recv: . [10] 
avrdude: safemode read 3, efuse value: fd
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:DE, L:FF)
avrdude: Send: Q [51]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 

avrdude done.  Thank you.

UPLOADING THE SKETCH OUTPUT

Please see the link below as it's a bit easier to read ( interesting stuff at the bottom but included the complete output)

'avrdude -v -p atmega2560 -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0xFF:m -U efuse:w:0xFD:m -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m'

'avrdude -v -p atmega2560 -c stk500v1 -P /dev/ttyACM0 -b 19200 -U flash:w:bootloaders/stk500boot_v2_mega2560.hex:i -U lock:w:0xCF:m'

Just a guess, but I think your fuse bits say you are using a 512 size bootloader and you are cramming a 4048 size into your chip.

Try MegaCore for your setup.

Could you add to that please? what needs to be swapped here I am not super familiar with the Arduino are you referring to the addresses or another area?

avrdude -v -patmega2560 -cstk500v1 -P/dev/ttyUSB0 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m

Change your hfuse to 0xD8 if you are going to use the stk500boot_v2_mega2560.hex bootloader.

This will work if you want the standard bootloader used by the Arduino IDE for the Arduino Mega or
Mega 2560.

If you want to use different speeds , then MegaCore is real handy.

Awesome excited to run this tonight, could you tell me please what the H fuse here is actually doing and why the way I had it was wrong? my understanding from a high-level perspective is the first avrdude command I run here is erasing the chip and defining a segment of memory in which the bootloader file will live is that correct?

Yes.

This will get you started. Select your chip and play with the fuse values.

https://www.engbedded.com/fusecalc/

The safest way for somebody like me is to use MegaCore, MIniCore and MightyCore. Everything is already figured out and ready to go.

May I add a problem with same category but different symptom here? If this is not OK, please let me know. I will create another thread.

I try to enable the fuse of CLKOUT in Arduino Nano, so I setup ArduinoISP with an Uno with Arduino IDE and change the board.txt of low fuses of arduino nano from 0xFF to 0x3F (divided by 8 clock out from PB0), then program the new bootloader into the arduino nano. I saw the 2MHz clock out from PB0. (This part is correct.)

But I used to program the arduino nano with the following command in Windows

avrdude -c arduino -p atmega328p -C ../avrdude.conf -b 115200 -P COM6 -U flash:w:blink.hex

now it doesn't work. The error messages are

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x12
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x12
.
.
.

If I change the low fuses back to 0xFF, everything is working again (except no CLKOUT).

If I change the low fuses back to 0xFF, everything is working again (except no CLKOUT).

I was hoping one of the experts would answer this. I am mostly cut and paste. :slight_smile:

Check this out.

@kprims - i'm still having a hard time with this I have implemented your suggestions

avrdude -v -p atmega2560 -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0xFF:m -U efuse:w:0xFD:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m

avrdude -v -patmega2560 -cstk500v1 -P/dev/ttyACM0 -b19200 -U flash:w:bootloaders/stk500boot_v2_mega2560.hex:i -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m

But am receiving a similar error

avrdude: verifying ...
avrdude: 261406 bytes of flash verified
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

Writing | | 0% 0.00s ***failed;
Writing | ################################################## | 100% 0.09s

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.01s

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

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:D8, L:FF)

avrdude done. Thank you.

#################################
256

I'm going to upload the links here, there are the output products of running the commands

avrdude -v -p atmega2560 -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0xFF:m -U efuse:w:0xFD:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m

OUTPUT:
https://www.pastiebin.com/5efa2376a9f44

avrdude -v -patmega2560 -cstk500v1 -P/dev/ttyACM0 -b19200 -U flash:w:bootloaders/stk500boot_v2_mega2560.hex:i -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m

OUTPUT:
https://www.pastiebin.com/5efa272d34290

avrdude -v -p atmega2560 -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0xFF:m -U efuse:w:0xFD:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m

Change "-e -U lock:w:0xFF:m" to "-e -U lock:w:0x3F:m"

avrdude -v -p atmega2560  -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0x3F:m -U efuse:w:0xFD:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m

avrdude -v -p atmega2560 -c stk500v1 -P /dev/ttyACM0 -b 19200 -e -U lock:w:0x3F:m -U efuse:w:0xFD:m -U hfuse:w:0xD8:m -U lfuse:w:0xFF:m

I'm still getting an error from this it looks like its those two fuse values we pass in

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD
avrdude: erasing chip
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

Writing | | 0% 0.00s ***failed;
Writing | ################################################## | 100% 0.11s

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.01s

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

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:D8, L:FF)

avrdude done. Thank you.

Well I worked myself into a hole. :confused:

Using the Arduino IDE 1.8.12, I have no problem with the Lock byte 0x3F, however, using avrdude version 6.3-20171130 I have the same problem as you are showing.

avrdude.conf for m2560 is different between the two versions.

My advice would be to use the .arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 that comes with IDE 1.8.12. or whatever comes with IDE1.8.13.

You should try to load your sketch now, your fuses look OK.

@kprims thanks for the help; and just to clarify the last bit .arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 that comes with IDE 1.8.12. or whatever comes with IDE1.8.13. you're referring the path to the avrdude conf ?

Also were you able to try to see if a sketch could be uploaded after you ran the command with avrdude while still receiving that address mismatch error ?

No, you would need both /bin/avrdude and /etc/avrdude.conf, like this. Easier to just use the IDE.

/home/kprims/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/kprims/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega2560 -cstk500v1 -P/dev/ttyUSB0 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m  -Uflash:w:/home/kprims/.arduino15/packages/arduino/hardware/avr/1.8.3/bootloaders/stk500v2/stk500boot_v2_mega2560.hex:i -Ulock:w:0x0F:m

Today, I couldn’t change fuses or upload a sketch with the address mismatch error.

Just some further info. I replaced arduino.conf at /etc/arduino.conf with the one used bye IDE 1.8.12 and nothing worked.
Then I overwrote the original /etc/arduino.conf ,two bits at location 10591,47 and 10591,49 from o to x and this worked for the m2560 chip.

memory "lock"
        size            = 1;
        read            = "0 1 0 1  1 0 0 0   0 0 0 0  0 0 0 0",
                          "x x x x  x x x x   o o o o  o o o o";

Change to this.

 memory "lock"
        size            = 1;
        read            = "0 1 0 1  1 0 0 0   0 0 0 0  0 0 0 0",
                          "x x x x  x x x x   x x o o  o o o o";

You know what... if I ignore the the xx != xx it will still allow me to upload! it's very annoying since im using the error codes to trigger lights when it successfully flashed but I mean it works!

Could you show me the avrdude command you are using now?