jpt78
January 10, 2024, 8:08pm
1
Hi,
I successfully read the original firmware from my 3d printer using:
avrdude -p atmega2560 -b115200 -P /dev/ttyUSB0 -c stk500v2 -Uflash:r:originalfirmware.hex:i
Now I try to write the new firmware which was built by platform io, but it fails.
Any idea, why?
avrdude -p atmega2560 -P /dev/ttyUSB0 -b 115200 -c stk500v2 -U flash:w:.pioenvs/megaatmega2560/firmware.hex:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9801 (probably m2560)
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 error: command failed
avrdude done. Thank you.
thank you very much.
ps. I used platformio because Arduino IDE V2 crashed with out of memory when opening Marlin sources.
Hi @jpt78 . Please run the write command again, but this time add the -v
flag to the command to enable verbose output and then post the output from the command in a reply here on the forum thread.
Hopefully the verbose output will provide some useful information about why the command failed.
jpt78
January 11, 2024, 6:07pm
3
Ah, great idea
Can you read anything from it? I don't see anything suspicious.
avrdude: Version 7.1
Copyright the AVRDUDE authors;
see https://github.com/avrdudes/avrdude/blob/main/AUTHORS
System wide configuration file is /etc/avrdude.conf
User configuration file is /home/jan/.avrduderc
User configuration file does not exist or is not a regular file, skipping
Using Port : /dev/ttyUSB0
Using Programmer : stk500v2
Overriding Baud Rate : 115200
AVR Part : ATmega2560
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 65 10 8 0 no 4096 8 0 9000 9000 0x00 0x00
flash 65 10 256 0 yes 262144 256 1024 4500 4500 0x00 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 1 1 0 0 0 0x00 0x00
Programmer Type : STK500V2
Description : Atmel STK500 version 2.x firmware
Programmer Model: AVRISP
Hardware Version: 15
Firmware Version Controller : 2.10
Vtarget : 0.0 V
SCK period : 0.1 us
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9801 (probably m2560)
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 stk500v2_command() error: command failed
avrdude done. Thank you.
The avrdude
command used when uploading sketches via Arduino IDE uses the -D
flag (Disable auto erase for flash.):
When I remove that flag, I get the same avrdude stk500v2_command() error: command failed
error as you. When I add it back, the command is successful.
From reading this discussion, it seems that the stk500v2 bootloader used by the Arduino Mega and other ATmega2560-based boards simply doesn't have support for the erase operation that is attempted by AVRDUDE when the command does not contain the -D
flag:
opened 03:29AM - 04 Jun 23 UTC
closed 06:44AM - 04 Jun 23 UTC
invalid
Reference:
* https://github.com/avrdudes/avrdude/pull/1376#issuecomment-1574982… 167
This is most likely not an avrdude issue but a Arduino STK500 V2 bootloader firmware issue.
```
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude_git -c wiring -P COM11 -p m2560 -t
avrdude_git: AVR device initialized and ready to accept instructions
avrdude_git: device signature = 0x1e9801 (probably m2560)
avrdude> dump flash 0x400 0x10
Reading | ################################################## | 100% 0.11 s
00400 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff |................|
avrdude> write flash 0x400 0xaa 0x55 0xaa 0x55 0xaa 0x55
Caching | ################################################## | 100% 0.02 s
avrdude> flush
avrdude_git: synching cache to device ...
Reading | ################################################## | 100% 35.30 s
Erasing | -------------------------------------------------- | 0% 0.01 s
avrdude_git error: command failed
avrdude_git error: chip erase failed
avrdude> quit
avrdude_git: synching cache to device ...
Reading | ################################################## | 100% 0.01 s
Erasing | -------------------------------------------------- | 0% 0.01 s
avrdude_git error: command failed
avrdude_git error: chip erase failed
avrdude_git done. Thank you.
```
So, unless you have some reason to believe the erase is required, just add a -D
flag to your command and try again.
If for some reason you do need an erase operation then there are a couple of alternative bootloaders available that might provide the missing capability. But millions of people have used the command without -D
over the last two decades when uploading to their Arduino boards so I think you should be fine with the stock bootloader.
system
Closed
July 10, 2024, 1:05am
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.