Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AVRDUDE flashing eeprom with error using "Arduino as ISP" for ATMEGA128 #1337

Closed
Topper69 opened this issue Apr 7, 2023 · 34 comments
Closed
Labels
bug Something isn't working

Comments

@Topper69
Copy link

Topper69 commented Apr 7, 2023

Hi,

When i try to burn a complete eeprom dump with AVRDUDE 7.1 (ARM64) on my rasp4 64b os, on the verification it show some errors (corrupt data) which is confirmed when i dump back the eeprom.
I tried the debian version

When i do the same on WIN10, it's complete without any error. 100% working. (same board, same programmer, same dump).

uC : ATMEGA128
programmer : arduino uno with ISP sketch loaded.

AVRDUDE on ARM64 (with error) log file:

pi@Rasp4:~/Documents/avrdude $ ./avrdude -p m128 -P /dev/ttyACM0 -c avrisp -b 19200 -U eeprom:w:/home/pi/Documents/avrdude/firmwarem128ok.eep:i -v

avrdude: Version 7.1
Copyright the AVRDUDE authors;
see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

     System wide configuration file is /home/pi/Documents/avrdude/avrdude.conf
     User configuration file is /home/pi/.avrduderc
     User configuration file does not exist or is not a regular file, skipping

     Using Port                    : /dev/ttyACM0
     Using Programmer              : avrisp
     Overriding Baud Rate          : 19200
     AVR Part                      : ATmega128
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PA0
     RESET disposition             : possible i/o
     RETRY pulse                   : SCK
     Serial program mode           : yes
     Parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                                       Block Poll               Page                       Polled
       Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom                  4    20    64    0 no       4096    8      0  9000  9000 0xff 0xff
       flash                  33    10   128    0 yes    131072  256    512  4500  4500 0xff 0x00
       lfuse                   0     0     0    0 no          1    1      0  9000  9000 0x00 0x00
       hfuse                   0     0     0    0 no          1    1      0  9000  9000 0x00 0x00
       efuse                   0     0     0    0 no          1    1      0  9000  9000 0x00 0x00
       lock                    0     0     0    0 no          1    1      0  9000  9000 0x00 0x00
       signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
       calibration             0     0     0    0 no          4    1      0     0     0 0x00 0x00

     Programmer Type : STK500
     Description     : Atmel AVR ISP
     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 = 0x1e9702 (probably m128)
avrdude: reading input file /home/pi/Documents/avrdude/firmwarem128ok.eep for eeprom
with 4096 bytes in 1 section within [0, 0xfff]
using 512 pages and 0 pad bytes
avrdude: writing 4096 bytes eeprom ...

Writing | ################################################## | 100% 192.94 s

avrdude: 4096 bytes of eeprom written
avrdude: verifying eeprom memory against /home/pi/Documents/avrdude/firmwarem128ok.eep

Reading | ################################################## | 100% 6.49 s

avrdude avr_verify() warning: verification mismatch
device 0x00 != input 0xff at addr 0x0339 (error)
device 0x72 != input 0xff at addr 0x033a (error)
device 0x73 != input 0xff at addr 0x033b (error)
device 0x74 != input 0xff at addr 0x033c (error)
device 0x75 != input 0xff at addr 0x033d (error)
device 0x76 != input 0xff at addr 0x033e (error)
device 0x77 != input 0xff at addr 0x033f (error)
device 0x80 != input 0xff at addr 0x0340 (error)
device 0x81 != input 0xff at addr 0x0341 (error)
device 0x82 != input 0xff at addr 0x0342 (error)
suppressing further verification errors
avrdude do_op() error: verification mismatch

avrdude done. Thank you.

On WIN10: (working)

./avrdude -p m128 -P COM21 -c arduino -b 19200 -U eeprom:w:firmwarem128ok.eep:i -v

avrdude: Version 7.1
Copyright the AVRDUDE authors;
see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

     System wide configuration file is avrdude.conf

     Using Port                    : COM21
     Using Programmer              : arduino
     Overriding Baud Rate          : 19200
     AVR Part                      : ATmega128
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PA0
     RESET disposition             : possible i/o
     RETRY pulse                   : SCK
     Serial program mode           : yes
     Parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                                       Block Poll               Page                       Polled
       Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom                  4    12    64    0 no       4096    8      0  9000  9000 0xff 0xff
       flash                  33     6   128    0 yes    131072  256    512  4500  4500 0xff 0xff
       lfuse                   0     0     0    0 no          1    1      0  9000  9000 0x00 0x00
       hfuse                   0     0     0    0 no          1    1      0  9000  9000 0x00 0x00
       efuse                   0     0     0    0 no          1    1      0  9000  9000 0x00 0x00
       lock                    0     0     0    0 no          1    1      0  9000  9000 0x00 0x00
       signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
       calibration             0     0     0    0 no          4    1      0     0     0 0x00 0x00

     Programmer Type : Arduino
     Description     : Arduino for bootloader using STK500 v1 protocol
     Hardware Version: 2
     Firmware Version: 1.18
     Topcard         : Unknown

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9702 (probably m128)
avrdude: reading input file firmwarem128ok.eep for eeprom
with 4096 bytes in 1 section within [0, 0xfff]
using 512 pages and 0 pad bytes
avrdude: writing 4096 bytes eeprom ...

Writing | ################################################## | 100% 193.02 s

avrdude: 4096 bytes of eeprom written
avrdude: verifying eeprom memory against firmwarem128ok.eep

Reading | ################################################## | 100% 7.77 s

avrdude: 4096 bytes of eeprom verified

avrdude done. Thank you.

I have only issue with EEPROM, with FLASH it's fine (no corrupt data).

Best regards

@mcuee mcuee added the unconfirmed Maybe a bug, needs to be reproduced by someone else label Apr 7, 2023
@mcuee
Copy link
Collaborator

mcuee commented Apr 7, 2023

@Topper69

What if you try the latest git version? You can either build from source, or use github action version.

@mcuee
Copy link
Collaborator

mcuee commented Apr 7, 2023

BTW, if you use Arduino as ISP as your main programmer, I will highly recommend buying an AVR ISP Shield from online stores (pretty cheap from places like AliExpress).

Before I got the shield I used ribbon cables and I often had connection issues. After I got the shield, it becomes much more stable.

One example of the AVR ISP Shield. There are other versions.
Screenshot 2023-04-07 154516

BTW, you can also boost the ISP speed to 57600 bps by optimizing the "Arduino as ISP" sketch. You can also use the ScratchMonkey to use -c stk500v2.

Ref: #1088

@Topper69
Copy link
Author

Topper69 commented Apr 7, 2023

@Topper69

What if you try the latest git version? You can either build from source, or use github action version.

I use the nightly build from : https://github.com/avrdudes/avrdude/wiki/Getting-Nightly-Builds-for-AVRDUDE
(the aarch64 version)

About the bad connection, it's unlikly because i works fine in windows (i keep the same board / link / wires). In my case i have soldered some wire to the uC.

@mcuee
Copy link
Collaborator

mcuee commented Apr 7, 2023

I see. No problem. I can check on myside as well to see if I can reproduce the issue or not.

@stefanrueger
Copy link
Collaborator

Do all .eep hex files trigger this error? Does the error only appear on sections with 0xff? If it's only specific files, please share a problematic one. Please share a log with higher verbosity (-vv, -vvv, ...). This so that one of us (@mcuee?) can reproduce the problem.

@Topper69
Copy link
Author

Hi,

Yes all files (not empty) triggers the issue.
Find attached logs from my raspberry pi 4 (linux) & from win with the same eep file.
The dump is a fully random file that fill all eeprom memory of the Atmega128.

randval.zip
log_linux.txt
log_windows.txt

@mcuee
Copy link
Collaborator

mcuee commented Apr 12, 2023

I should be able to test this over the weekend on my Raspberry Pi 400.

@mcuee
Copy link
Collaborator

mcuee commented Apr 24, 2023

Sorry I can not find my ATmega128A breakout board so this will be delayed.

I will leave this issue as unconfirmed for now. Hopefully somebody else can test it.

@Topper69
Copy link
Author

I have switch to my pickit4 now without issues (drop to use my ardunio uno as programmer).

@mcuee
Copy link
Collaborator

mcuee commented Apr 24, 2023

I have switch to my pickit4 now without issues (drop to use my ardunio uno as programmer).

That is certainly a much better choice than Arduino as ISP using the Uno or Nano, even though the price is higher.

@Tim666
Copy link

Tim666 commented May 27, 2023

I have identical problem. I use Arduino Nano as Arduino ISP programmer for ATmega328P. It correctly writes flash but has problem with eeprom. It loos like it can write eeprom only from address 0x013C.
image
Read/write log comparation
image

@mcuee
Copy link
Collaborator

mcuee commented May 30, 2023

I have identical problem. I use Arduino Nano as Arduino ISP programmer for ATmega328P. It correctly writes flash but has problem with eeprom. It loos like it can write eeprom only from address 0x013C.

What is the host (as well as OS version)? Is this a normal Intel/AMD Windows PC or Windoes on ARM?

Take note the original report shows that there is no issue on Windows PC, but only on Raspberry Pi 64.

What kind of setup do you use? "Arduino as ISP" can be not so stable if you use wires to connect to the target.

@Tim666
Copy link

Tim666 commented Jun 2, 2023

I use Intel Windows 10 PC. Command for writing eeprom:
avrdude -c stk500v1 -p m328p -P com7 -b 19200 -v -U eeprom:w:mega328.eep:a
I do not understand how is possible "not stable" successfully write flash and incorrectly write half eeprom.
And this situation reproduces every time identically.
It look like the writing protection the part of memory in ArduinoISP or chip.

@stefanrueger
Copy link
Collaborator

@Tim666 Try -c arduino instead of -c stk500v1

@Tim666
Copy link

Tim666 commented Jun 3, 2023

@stefanrueger Thanks a lot!!!!
I tried -c arduino before but without success, then possible after different experiments I fixed hardware issue.
Command avrdude -c arduino -p m328p -P com7 -b 57600 -v -U eeprom:w:mega328.eep:a correctly upload flash.
I found out my problem was the stk500v1 incorrectly read data from address below 0x013C. It writes correctly but the reading incorrect and verification after writing does not match. So the command avrdude -c stk500v1 -p m328p -P com7 -b 19200 -v -U eeprom:w:mega328.eep:a do the same thing but impossible to check if eeprom uploaded correctly.

@stefanrueger
Copy link
Collaborator

@Tim666 If -c arduino works then -c urclock should too, but -c stk500v1 no longer works for Arduino as ISP b/c it has been changed to work for STK500 v1 programmers writing EEPROM. If you use an ArduinoISP programmer (note the difference to Arduino as ISP) then -c arduinoisp is your friend.

@Tim666
Copy link

Tim666 commented Jun 3, 2023

@stefanrueger As I understand... now... the command -c arduino writes firmware to connected Arduino Nano. But I want to use Arduino Nano as ArduinoISP programmer for uploading firmware to another ATmega328P chip. And command -c arduino rewrites my Arduino Nano only, but not target ATmega328P :-(
I remembered why I used -c stk500v1 because Arduino IDE uses it for "Arduino as ISP" programmer:
avrdude -CC:[PATH]avrdude.conf -v -patmega328p -cstk500v1 -PCOM7 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m

@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

@Tim666

Just wondering which "Arduino as ISP" sketch do you use? Are you using the version comes as an Example from Arduino IDE?

Last time there is a report of using the Adfruit version which does not work with EEPROM.

@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

No issues here under Windows 11.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c stk500v1 -P COM11 -b 19200 -p m328p -U eeprom:w:entest.hex:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)
avrdude: reading input file entest.hex for eeprom
         with 512 bytes in 1 section within [0, 0x1ff]
         using 128 pages and 0 pad bytes
avrdude: writing 512 bytes eeprom ...
Writing | ################################################## | 100% 25.80 s
avrdude: 512 bytes of eeprom written
avrdude: verifying eeprom memory against entest.hex
Reading | ################################################## | 100% 2.38 s
avrdude: 512 bytes of eeprom verified

avrdude done.  Thank you.

As mentioned before, the "Arduino as ISP" sketech is a bit fragile and you need good connections.

Here is my setup.

swtup

@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

All in all "Arduino as ISP" should not be used as a regular programmer, rather you can use it occassionally. I will recommend getting a more proper programmer.

For hobbist, usbasp is a good one to use. usbtinyisp can be used as well but it is not as good as usbasp. You can also get clones of STK500v2 and AVRIP mkii.

If you are interested in modern UPDI AVR chip as well, then Microchip SNAP or PICKit 4 is a good investment. But if there is a budget constraint, then you can use things like serialupdi.

If you still want to use the Uno/Nano as a programmer, you may want to check out this discussion.

@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

I have found my ATmgea128A breakout board.

  1. Writing 512Bytes hex file to the EEPROM seems to be stable
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c stk500v1 -P COM11 -b 19200 -p m128a -U eeprom:w:entest.hex:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9702 (probably m128a)
avrdude: reading input file entest.hex for eeprom
         with 512 bytes in 1 section within [0, 0x1ff]
         using 64 pages and 0 pad bytes
avrdude: writing 512 bytes eeprom ...
Writing | ################################################## | 100% 24.73 s
avrdude: 512 bytes of eeprom written
avrdude: verifying eeprom memory against entest.hex
Reading | ################################################## | 100% 1.39 s
avrdude: 512 bytes of eeprom verified

avrdude done.  Thank you.
  1. Writing the big hex file (4096Bytes) as mentioned in the original report is not successful.
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c stk500v1 -P COM11 -b 19200 -p m128a -U eeprom:w:randval.eep:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9702 (probably m128a)
avrdude warning: no end of file record found for Intel Hex file randval.eep
avrdude: reading input file randval.eep for eeprom
         with 4096 bytes in 1 section within [0, 0xfff]
         using 512 pages and 0 pad bytes
avrdude: writing 4096 bytes eeprom ...
Writing | ################################################## | 100% 194.83 s
avrdude: 4096 bytes of eeprom written
avrdude: verifying eeprom memory against randval.eep
Reading | ################################################## | 100% 9.66 s
avrdude warning: verification mismatch
        device 0x1b != input 0x41 at addr 0x0000 (error)
avrdude error: verification mismatch

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c stk500v1 -P COM11 -b 19200 -p m128a -U eeprom:w:entest_4096B.eep:i

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9702 (probably m128a)
avrdude: reading input file entest_4096B.eep for eeprom
         with 4096 bytes in 1 section within [0, 0xfff]
         using 512 pages and 0 pad bytes
avrdude: writing 4096 bytes eeprom ...
Writing | ################################################## | 100% 194.76 s
avrdude: 4096 bytes of eeprom written
avrdude: verifying eeprom memory against entest_4096B.eep
Reading | ################################################## | 100% 9.65 s
avrdude warning: verification mismatch
        device 0x73 != input 0x54 at addr 0x0000 (error)
avrdude error: verification mismatch

avrdude done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

1024B and 2048B are okay.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c stk500v1 -P COM11 -b 19200 -p m128a -U eeprom:w:entest_1024B.eep:i

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9702 (probably m128a)
avrdude: reading input file entest_1024B.eep for eeprom
         with 1024 bytes in 1 section within [0, 0x3ff]
         using 128 pages and 0 pad bytes
avrdude: writing 1024 bytes eeprom ...
Writing | ################################################## | 100% 49.24 s
avrdude: 1024 bytes of eeprom written
avrdude: verifying eeprom memory against entest_1024B.eep
Reading | ################################################## | 100% 2.79 s
avrdude: 1024 bytes of eeprom verified

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c stk500v1 -P COM11 -b 19200 -p m128a -U eeprom:w:entest_2048B.eep:i

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9702 (probably m128a)
avrdude: reading input file entest_2048B.eep for eeprom
         with 2048 bytes in 1 section within [0, 0x7ff]
         using 256 pages and 0 pad bytes
avrdude: writing 2048 bytes eeprom ...
Writing | ################################################## | 100% 97.73 s
avrdude: 2048 bytes of eeprom written
avrdude: verifying eeprom memory against entest_2048B.eep
Reading | ################################################## | 100% 5.11 s
avrdude: 2048 bytes of eeprom verified

avrdude done.  Thank you.

3072B failed.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c stk500v1 -P COM11 -b 19200 -p m128a -U eeprom:w:entest_3072B.eep:i

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9702 (probably m128a)
avrdude: reading input file entest_3072B.eep for eeprom
         with 3072 bytes in 1 section within [0, 0xbff]
         using 384 pages and 0 pad bytes
avrdude: writing 3072 bytes eeprom ...
Writing | ################################################## | 100% 146.36 s
avrdude: 3072 bytes of eeprom written
avrdude: verifying eeprom memory against entest_3072B.eep
Reading | ################################################## | 100% 7.53 s
avrdude warning: verification mismatch
        device 0x73 != input 0x54 at addr 0x0000 (error)
avrdude error: verification mismatch

avrdude done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

All in all, I do not consider this to be an avrdude problem. Rather this Arduino as ISP sketech is fragile.

@mcuee mcuee added invalid This doesn't seem right wontfix This will not be worked on and removed unconfirmed Maybe a bug, needs to be reproduced by someone else labels Jun 4, 2023
@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

I will close this issue now.

@Tim666
You can continue to post your findings here but I recommend to switch to better programmers like usbasp.

@mcuee mcuee closed this as completed Jun 4, 2023
@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

BTW, I can reproduce the issue under Linux as well.

mcuee@UbuntuSwift3:~/build/avr/avrdude_bin$ ./avrdude -c stk500v1 -P /dev/ttyUSB0 -b 19200 -p m128a -U eeprom:w:randval.eep:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9702 (probably m128a)
avrdude warning: no end of file record found for Intel Hex file randval.eep
avrdude: reading input file randval.eep for eeprom
         with 4096 bytes in 1 section within [0, 0xfff]
         using 512 pages and 0 pad bytes
avrdude: writing 4096 bytes eeprom ...
Writing | ################################################## | 100% 194.05 s 
avrdude: 4096 bytes of eeprom written
avrdude: verifying eeprom memory against randval.eep
Reading | ################################################## | 100% 8.90 s 
avrdude warning: verification mismatch
        device 0x1b != input 0x41 at addr 0x0000 (error)
avrdude error: verification mismatch

avrdude done.  Thank you.

Same for ATmega328PB, 512B EEPROM write is okay but not 1024B.

cuee@UbuntuSwift3:~/build/avr/avrdude_bin$ ./avrdude -c stk500v1 -P /dev/ttyUSB0 -b 19200 -p m328pb -U eeprom:w:entest_1024B.eep:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9516 (probably m328pb)
avrdude: reading input file entest_1024B.eep for eeprom
         with 1024 bytes in 1 section within [0, 0x3ff]
         using 256 pages and 0 pad bytes
avrdude: writing 1024 bytes eeprom ...
Writing | ################################################## | 100% 50.15 s 
avrdude: 1024 bytes of eeprom written
avrdude: verifying eeprom memory against entest_1024B.eep
Reading | ################################################## | 100% 3.91 s 
avrdude warning: verification mismatch
        device 0x65 != input 0x54 at addr 0x0000 (error)
avrdude error: verification mismatch

avrdude done.  Thank you.

mcuee@UbuntuSwift3:~/build/avr/avrdude_bin$ ./avrdude -c stk500v1 -P /dev/ttyUSB0 -b 19200 -p m328pb -U eeprom:w:entest_512B.eep:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9516 (probably m328pb)
avrdude: reading input file entest_512B.eep for eeprom
         with 512 bytes in 1 section within [0, 0x1ff]
         using 128 pages and 0 pad bytes
avrdude: writing 512 bytes eeprom ...
Writing | ################################################## | 100% 25.07 s 
avrdude: 512 bytes of eeprom written
avrdude: verifying eeprom memory against entest_512B.eep
Reading | ################################################## | 100% 1.95 s 
avrdude: 512 bytes of eeprom verified

avrdude done.  Thank you.

Same for another ATmega16U2+ATmega328P Uno Clone (previous tests using CH340G based clone).

mcuee@UbuntuSwift3:~/build/avr/avrdude_bin$ ./avrdude -c stk500v1 -P /dev/ttyACM0 -b 19200 -p m328pb -U eeprom:w:entest_1024B.eep:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9516 (probably m328pb)
avrdude: reading input file entest_1024B.eep for eeprom
         with 1024 bytes in 1 section within [0, 0x3ff]
         using 256 pages and 0 pad bytes
avrdude: writing 1024 bytes eeprom ...
Writing | ################################################## | 100% 48.99 s 
avrdude: 1024 bytes of eeprom written
avrdude: verifying eeprom memory against entest_1024B.eep
Reading | ################################################## | 100% 2.67 s 
avrdude warning: verification mismatch
        device 0x65 != input 0x54 at addr 0x0000 (error)
avrdude error: verification mismatch

avrdude done.  Thank you.

mcuee@UbuntuSwift3:~/build/avr/avrdude_bin$ ./avrdude -c stk500v1 -P /dev/ttyACM0 -b 19200 -p m328pb -U eeprom:w:entest_512B.eep:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9516 (probably m328pb)
avrdude: reading input file entest_512B.eep for eeprom
         with 512 bytes in 1 section within [0, 0x1ff]
         using 128 pages and 0 pad bytes
avrdude: writing 512 bytes eeprom ...
Writing | ################################################## | 100% 24.49 s 
avrdude: 512 bytes of eeprom written
avrdude: verifying eeprom memory against entest_512B.eep
Reading | ################################################## | 100% 1.33 s 
avrdude: 512 bytes of eeprom verified

avrdude done.  Thank you.

@mcuee
Copy link
Collaborator

mcuee commented Jun 4, 2023

Please take note Arduino does not really care about EEPROM uploading at all from their AVR bootloaders.

  1. The AVR code optiboot is of very old 4.x version and does not support EEPROM at all.
  1. The STK500v2 bootloader for ATmega2560 has a long standing EEPROM bug which they also do not want to fix.

Therefore I will not feel surprised that this "Arduino as ISP" does not work with EEPROM very well.

Reference:

@stefanrueger
Copy link
Collaborator

the command -c arduino writes firmware to connected Arduino Nano

@Tim666 Only because -c arduino resets the connected target and the Nano has a bootloader that will intercept the upload mechanism. You can try removing the Bootloader on the Nano (or, simpler, change the BOOTRST configuration of the Nano to jump to addr 0 on reset, not the bootloader); you can try preventing the Nano be reset by the host PC that runs avrdude: is there a jumper on the Nano board that prevents reset from the host?

Basically -c arduino and -c stk500v1 are the same except -c arduino tries to reset the connected board and EEPROM treatment of -c arduino is compatible with Arduino as ISP, whilst EEPROM treatment of -c stk500v1 is compatible with the STK500 programmer with v1 firmware.

Maybe we should give -c arduino and the (better) alternative -c urclock an option -xnoreset...

@stefanrueger
Copy link
Collaborator

@Tim666 and @mcuee: Give PR #1383 a try to see whether -c avrduinoAsISP solves this.

@mcuee mcuee reopened this Jun 5, 2023
@mcuee mcuee added bug Something isn't working and removed invalid This doesn't seem right wontfix This will not be worked on labels Jun 5, 2023
@mcuee
Copy link
Collaborator

mcuee commented Jun 5, 2023

I thought there is a bug in the Arduino as ISP sketech, but I am wrong. I have changed the label to bug. I think technically it is a bug in the Arduino As ISP sketch but it has been there for so long so we have to work around it if we can. And in this case, we can thanks to the great job by @stefanrueger.

PR #1383 works well and fixed my issues with ATmega328P and ATmega128A when programming higher amount of EEPROM.

@mcuee
Copy link
Collaborator

mcuee commented Jun 5, 2023

@Topper69

You may want to try PR #1383 as well. I tested ATmega128A using your hex file and it works.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_pr1383 -C .\avrdude_pr1383.conf -c arduinoAsISP -P COM11 -b 19200 -p m128a -U eeprom:w:randval.eep:i
avrdude_pr1383: AVR device initialized and ready to accept instructions
avrdude_pr1383: device signature = 0x1e9702 (probably m128a)

avrdude_pr1383: processing -U eeprom:w:randval.eep:i
avrdude_pr1383: reading input file randval.eep for eeprom
                with 4096 bytes in 1 section within [0, 0xfff]
                using 512 pages and 0 pad bytes
avrdude_pr1383: writing 4096 bytes eeprom ...
Writing | ################################################## | 100% 195.00 s
avrdude_pr1383: 4096 bytes of eeprom written
avrdude_pr1383: verifying eeprom memory against randval.eep
Reading | ################################################## | 100% 9.82 s
avrdude_pr1383: 4096 bytes of eeprom verified

avrdude_pr1383 done.  Thank you.

@mcuee mcuee changed the title AVRDUDE flashing eeprom with error on ARM64 on ATMEGA128 uC // Corrupt data AVRDUDE flashing eeprom with error using "Arduino as ISP" for ATMEGA128 Jun 9, 2023
@mcuee
Copy link
Collaborator

mcuee commented Jun 11, 2023

Close this one as #1383 has been merged.

@mcuee mcuee closed this as completed Jun 11, 2023
@Ho-Ro
Copy link
Contributor

Ho-Ro commented Sep 15, 2023

Basically -c arduino and -c stk500v1 are the same except -c arduino tries to reset the connected board and EEPROM treatment of -c arduino is compatible with Arduino as ISP, whilst EEPROM treatment of -c stk500v1 is compatible with the STK500 programmer with v1 firmware.

Looking at the logfiles for EEPROM reading shows the difference:

This is part of the log for stk500v1 protocol, the sent address cmd U is increased in steps of four (U [55] . [00] . [00] [20], U [55] . [04] . [00] [20], ...) and four bytes are read by cmd t:

avrdude -p m328p -vvvv -c stk500v1 -U eeprom:r:/dev/null:r -l read_eeprom_stk500v1.log
avrdude: Version 7.1
...
avrdude: reading eeprom memory ...

Reading | avrdude: send: U [55] . [00] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
avrdude: send: t [74] . [00] . [04] E [45]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [00] . [00] . [00] . [00] 
avrdude: recv: . [10] 
avrdude: send: U [55] . [04] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
avrdude: send: t [74] . [00] . [04] E [45]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [00] . [00] . [00] . [00] 
avrdude: recv: . [10] 
avrdude: send: U [55] . [08] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
avrdude: send: t [74] . [00] . [04] E [45]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [00] . [00] . [00] . [00] 
avrdude: recv: . [10] 
avrdude: send: U [55] . [0c] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
avrdude: send: t [74] . [00] . [04] E [45]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [00] . [00] . [00] . [00] 
avrdude: recv: . [10]
...

And this is part of the log for arduino protocol, the sent address (cmd U) is increased in steps of two (U [55] . [00] . [00] [20], U [55] . [02] . [00] [20], ...) but also four bytes are read by cmd t:

avrdude -p m328p -vvvv -c arduino -U eeprom:r:/dev/null:r -l read_eeprom_arduino.log
avrdude: Version 7.1
...
avrdude: reading eeprom memory ...

Reading | avrdude: send: U [55] . [00] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
avrdude: send: t [74] . [00] . [04] E [45]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [00] . [00] . [00] . [00] 
avrdude: recv: . [10] 
avrdude: send: U [55] . [02] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
avrdude: send: t [74] . [00] . [04] E [45]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [00] . [00] . [00] . [00] 
avrdude: recv: . [10] 
avrdude: send: U [55] . [04] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
avrdude: send: t [74] . [00] . [04] E [45]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [00] . [00] . [00] . [00] 
avrdude: recv: . [10] 
avrdude: send: U [55] . [06] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
avrdude: send: t [74] . [00] . [04] E [45]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [00] . [00] . [00] . [00] 
avrdude: recv: . [10] 
avrdude: send: U [55] . [08] . [00]   [20] 
avrdude: recv: . [14] 
avrdude: recv: . [10] 
...

Reason:
The stk500v1 protocol inside the e.g. STK500 with v1 interprets the EEPROM address as the byte address where to read or write while the arduino protocol takes a word address also for the EEPROM and the bootloader or the "Arduino as an ISP" device doubles the address value before sending the command to the AVR.
And if you use the wrong protocol with the programmer then you'll get EEPROM read/write errors.

@mcuee
Copy link
Collaborator

mcuee commented Sep 17, 2023

Please use avrdude 7.2 release or latest git main. Thanks.

@Ho-Ro
Copy link
Contributor

Ho-Ro commented Sep 17, 2023

Please use avrdude 7.2 release or latest git main. Thanks.

As expected nothing has changed from my reported 7.1 logging.
I get the same correct behaviour with latest github as well as with 7.2:

  • with -c arduino avrdude increments the EEPROM address be two and reads four bytes.
  • with -c stk500v1 it increments the EEPROM address be four and reads four bytes.

This is the correct behaviour because the stk500v1 protocol expects byte addresses and the modified arduino protocol expects word addresses.

Remark:
My Arduino Nano as ISP hardware uses my improved firmware that automatically detects the used protocol (arduino protocol uses one Cmnd_STK_READ_SIGN call to read the signature while stk500v1 protocol uses three Cmnd_STK_UNIVERSAL calls for this purpose).

EDIT:
This cock-up comes once again from the Arduino people, who cannot stick to conditions that have lasted for years and decades, but have had to reinvent the wheel, even if it is once again only square instead of round ("Shield" instead of PCB, the unspeakable "Sketch" instead of the program, etc.). In our case, the same code sequence was used in the bootloader for the extension to EEPROM access that was originally intended for the flash (there it is correctly word addressing), but for the EEPROM it should be byte addresses. And as a consequence, the protocol based on stk500v1 was then named arduino.

EDIT_2:
I just discovered the long discussion in #967 - sorry for my redundancy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants