This is a follow up from a previous question. I have one Nano working perfectly (I think) (Nano A) and another one (Nano B) which seems to be working but has no bootloader. So I am trying to use Nano-A as an ISP programmer to burn the bootloader into Nano-B. I am pretty confident with my hardware and Arduino IDE setup. See previous question for the details; Problems uploading with a new Nano
I have pasted below two screen sessions. The first shows the Arduino IDE Log when I (unsuccesfully) try to run "Burn Bootloader" - IT almost works! (but not quite). - So I beleive that there is not too much wrong with my setup.
The second session is me using running avrdude in "terminal" mode from a Windows command prompt. I have used individual "send" commands to send the ISP instructions required to programme a single word into bootloader flash memory and this all seems to work OK. So I don't understand why avrdude is not working when invoked by the IDE.
Arduino IDE Log (lengthy)
C:\Users\--\Documents\ArduinoData\packages\arduino\tools\avrdude6円.3.0-arduino17/bin/avrdude -CC:\Users\--\Documents\ArduinoData\packages\arduino\tools\avrdude6円.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM8 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m
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 "C:\Users\--\Documents\ArduinoData\packages\arduino\tools\avrdude6円.3.0-arduino17/etc/avrdude.conf"
Using Port : COM8
Using Programmer : stk500v1
Overriding Baud Rate : 19200
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 : STK500
Description : Atmel STK500 Version 1.x firmware
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
Reading | ################################################## | 100% 0.11s
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: erasing chip
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):
Writing | ################################################## | 100% 0.04s
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.04s
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xFD"
avrdude: writing efuse (1 bytes):
Writing | ################################################## | 100% 0.04s
avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFD:
avrdude: load data efuse data from input file 0xFD:
avrdude: input file 0xFD contains 1 bytes
avrdude: reading on-chip efuse data:
Reading | ################################################## | 100% 0.04s
avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xDA"
avrdude: writing hfuse (1 bytes):
Writing | ################################################## | 100% 0.04s
avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xDA:
avrdude: load data hfuse data from input file 0xDA:
avrdude: input file 0xDA contains 1 bytes
avrdude: reading on-chip hfuse data:
Reading | ################################################## | 100% 0.04s
avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):
Writing | ################################################## | 100% 0.04s
avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:
Reading | ################################################## | 100% 0.04s
avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude done. Thank you.
C:\Users\--\Documents\ArduinoData\packages\arduino\tools\avrdude6円.3.0-arduino17/bin/avrdude -CC:\Users\--\Documents\ArduinoData\packages\arduino\tools\avrdude6円.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM8 -b19200 -Uflash:w:C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex:i -Ulock:w:0x0F:m
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 "C:\Users\--\Documents\ArduinoData\packages\arduino\tools\avrdude6円.3.0-arduino17/etc/avrdude.conf"
Using Port : COM8
Using Programmer : stk500v1
Overriding Baud Rate : 19200
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 : STK500
Description : Atmel STK500 Version 1.x firmware
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
Reading | ################################################## | 100% 0.11s
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: reading input file "C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex"
avrdude: writing flash (32768 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_cmd(): programmer is out of sync
avrdude: stk500_cmd(): programmer is out of sync
avrdude: 32768 bytes of flash written
avrdude: verifying flash memory against C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex:
avrdude: load data flash data from input file C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex:
avrdude: input file C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex contains 32768 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.00s
avrdude: loadaddr(): (b) protocol error, expect=0x14, resp=0xc0
avrdude: stk500_paged_load(): (a) protocol error, expect=0x14, resp=0x10
avrdude: stk500_cmd(): protocol error
avr_read(): error reading address 0x7e00
read operation not supported for memory "flash"
avrdude: failed to read all of flash memory, rc=-2
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0xd1
avrdude done. Thank you.
Error while burning bootloader.
avrdude session (short)
Note that when writing to the bootloader flash, using the "send" instruction, you have to supply the address as a "word" - i.e. 16bit address - hence 0x3C00. When usning the "read" instruction, the address is a "byte" (8 bit) address, hence 0x7800 - this is the same address.
Update: I have now managed to upload my original sketch to the application area of flash on this Nano using the "Sketch->upload using programmer" menu option of the Arduino IDE. So I do now have a useable Nano but I have still not solved my original problem i.e. this Nano still does not have a bootloader. I would like to fix this problem becaue I am sure that I will want to update/modify my app int the future. So there is now an ancilliary question - i.e. is it possible to burn a bootloader without erasing a pre-existing application? - Answer, I think is no because maybe you have to do a chip erase before writing to the bootloader area?
-
Dear timemage - once again that is really useful I will give it a try with the addresses that you suggest. The reason why I said 0x7C00 (which I now realise is wrong anyway) is that the hfuse setting is 0xDA which is binary 10111010 - i.e. the "BOOTSZ" bits are 01 which according, to the datasheet, should give a bootloader size of 1024 words. So is the correct start address 0x3C00?Rob W– Rob W2020年12月08日 17:49:30 +00:00Commented Dec 8, 2020 at 17:49
-
Alright, so this is bizarre. I tried it here just as a sanity check. Although my setup is a bit different than yours, I don't have a normal nano to work with. I'm using an UNO as my target but programming it to be a nano. There's essentially no difference hardware-wise. I can confirm that it fuses 0xDA but puts the 512 byte optiboot program on it. Apparently is basically NOP-sliding from the configured reset vector at 0x3C00 to where the bootloader code actually begins at what would be the UNO reset vector 0x3f00. Anyway, it's stupid but it works.timemage– timemage2020年12月08日 20:57:23 +00:00Commented Dec 8, 2020 at 20:57
-
Thanks again - I have now updated my question as suggested. Now that I have got my addresses sorted out I can see that the avrdude "send" commands are able to write into the bootloader area OK. So it's beginning to like my problem has something to do with the way that arduino IDE invokes avrdude - I'll now look more carefully at this.Rob W– Rob W2020年12月09日 11:44:57 +00:00Commented Dec 9, 2020 at 11:44
-
Show the wiring I guess.timemage– timemage2020年12月09日 13:32:15 +00:00Commented Dec 9, 2020 at 13:32
-
I'm thinking that if I can get avrdude to use Nano A as an ISP programmer in terminal mode, then doesnt this prove that the wiring is OK?Rob W– Rob W2020年12月09日 17:26:25 +00:00Commented Dec 9, 2020 at 17:26
1 Answer 1
Yay! - I now have a fully working Nano with new bootloader and application loaded using this.
I have done so much that I'm not sure what the original problem was but the final change was modifying the "programmers.txt" file such that "Arduino as ISP" entry was changed as follows;
Original line;
arduinoasisp.protocol=stk500v1
Changed to;
arduinoasisp.protocol=arduino
I did this because I noticed that the menu option "Upload using programmer" (which worked) invoked avrdude with the parameter "-c arduino" whereas the "burn bootloader" option used "-c stk500v1" (which was not working).
I can't pretened that I fully understand but I'm happy that this now works and that I have now learnt enough to know where to start looking if I get similar problems in the future.
I should also add that I would never have got here without the help of @timemage - who has helped a lot - many many thanks
-
There are differences between stk500v1 and "arduino" in terms of how reset is explicitly handled and how signatures are read; otherwise they're the same. I have no idea why this would fix your problem. What is it that made you try this to begin with?timemage– timemage2020年12月11日 17:03:43 +00:00Commented Dec 11, 2020 at 17:03
-
I looked closely at the Arduino IDE logs - especially the avrdude invokations - to see what the IDE was doing differently between (1) "Upload using programmer" (which was working) and (2) "Burn bootloader" (which was not working) and noticed that the "burn bootloader" invokation had the "-c stk500v1" parameter.Rob W– Rob W2020年12月11日 19:43:41 +00:00Commented Dec 11, 2020 at 19:43
-
Well, I'm glad something is working. But I am skeptical that alone is the cause and solution. It fails and then works again consistently with changing that option back and forth?timemage– timemage2020年12月11日 20:06:45 +00:00Commented Dec 11, 2020 at 20:06
-
I suspect that the original problem was that there was something amiss in the supplied configuration of the cheap chinese nano clone that I bought on eBay. I suspect that it may have been supplied without a bootloader, but I do not know this for sure. So I cannot get back to my original starting point, unless I order another Nano from the same supplier, which I might do, just for the hell of it. At £3.00 it might be worth it just to prove my theory. I have purchased two other cheap Nano clones from other suppliers and have not had any problems. I share your skepticism.Rob W– Rob W2020年12月12日 08:06:24 +00:00Commented Dec 12, 2020 at 8:06