avrdudes / avrdude

AVRDUDE is a utility to program AVR microcontrollers
GNU General Public License v2.0
696 stars 136 forks source link

megaTinyCore optiboot_x issue with avrdude git main -- FALSE ALARM #1166

Closed mcuee closed 1 year ago

mcuee commented 1 year ago

I can not get avrdude git main to work with megaTinyCore optiboot_x using ATtiny1627 Curiosity Nano board.

More details here.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -pattiny1627 -carduino -PCOM21 -b115200 -D 
-U .\Blink.ino.t1627opti.20c0.mB1.v261.hex -qq && echo OK
avrdude error: verification mismatch, first encountered at addr 0x0200
        device 0xff != input 0x3b
avrdude error: verification mismatch

avrdude 7.0 also does not work.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude7 -C .\avrdude7.conf -pattiny1627 -carduino -PCOM21 
-b115200 -D -U .\Blink.ino.t1627opti.20c0.mB1.v261.hex -qq && echo OK
avrdude7.exe: verification error, first mismatch at byte 0x0200
              0xff != 0x3b
avrdude7.exe: verification error; content mismatch

But avrdude 6.3 from megaTinyCore works fine, verified with the on-board pkobn_updi programmer as well.

C:\work\avr\avrdude_test\avrdude_bin>
C:\Users\xfchen\AppData\Local\Arduino15\packages\DxCore\tools\avrdude\6.3.0-arduino17or18/bin/avrdude 
-CC:\Users\xfchen\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1/avrdude.conf 
-pattiny1627 -ccuriosity_updi -Pusb -D -U .\Blink.ino.t1627opti.20c0.mB1.v261.hex -qq && echo OK
OK

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -qq -pattiny1627 -cpkobn_updi -D
 -U flash:v:.\Blink.ino.t1627opti.20c0.mB1.v261.hex:i && echo OK
OK
mcuee commented 1 year ago

Now we need to revisit the following two, or avrdude.conf for the ATTiny1627 and other ATtiny 0/1/2 devices.

Parts | memory | size | a_div -- | -- | -- | -- UPDI-chips (optiboot_x megaTinyCore) | flash | <=64k | 1 UPDI-chips (optiboot_x MegaCoreX) | flash | <=64k | 1
mcuee commented 1 year ago

@MCUdude

Just wondering if you can help checking on megaTinyCore and MegaCoreX. Thanks.

MCUdude commented 1 year ago

@mcuee sure! I'm currently on vacation, and didn't brought the right hardware with me. I'm pretty sure optiboot_x for MegaCoreX works without any problems, but I can double-check when I'm back on Monday next week.

@mcuee meanwhile, can you try to change a_div back to 2 on line 770 and re-compile?

https://github.com/avrdudes/avrdude/blob/b5699663c4ebdb185c21f2f1ca02610cd078ed77/src/stk500.c#L762-L772

It is strange that it doesn't work with Avrdude 7.0, since no major changes to stk500.c was done after the project was migrated over to Github. Can you try with Avrdude 6.4? The follwing commit is present in Avrdude 6.4 and later, but not in 6.3. Can you try to revert this as well?

If this doesn't help, please try to roll even further back to see if you can narrow it down to a single commit: https://github.com/avrdudes/avrdude/commits/main/src/stk500.c

MCUdude commented 1 year ago

@mcuee from the output you provided, It doesn't look like you actually tested -carduino with Avrdude 6.3:

C:\Users\xfchen\AppData\Local\Arduino15\packages\DxCore\tools\avrdude\6.3.0-arduino17or18/bin/avrdude 
-CC:\Users\xfchen\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1/avrdude.conf 
-pattiny1627 -ccuriosity_updi -Pusb -D -U .\Blink.ino.t1627opti.20c0.mB1.v261.hex -qq && echo OK
OK

Also, you shouldn't use the -D flag with non-bootloader based programmers, since the -D flag prevents a page/chip erase, and may leave the previous flash content intact.

mcuee commented 1 year ago

Looks like a megaTinyCore issue to me now.

I use Arduino IDE 2.0.1 and now it okay to burn the bootloader (no need to manually using avrdude) and upload the sketch. Take note I am using avrdude git master and not avrdude 6.3.

"C:\Users\xiaof\AppData\Local\Arduino15\packages\DxCore\tools\avrdude\6.3.0-arduino17or18/bin/avrdude" "-CC:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1/avrdude.conf" -v -pattiny1627 -cpkobn_updi -Pusb -e "-Ufuse0:w:0x00:m" "-Ufuse1:w:0b00000101:m" "-Ufuse5:w:0b11110110:m" "-Ufuse6:w:0x04:m" "-Ufuse8:w:0x00:m" "-Ufuse7:w:0x00:m" "-Uflash:w:C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1/bootloaders/hex/optiboot_Curiosity1627.hex:i"

avrdude: Version avrdude-main-test-libusb-compat
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1\avrdude.conf

         Using Port                    : usb
         Using Programmer              : pkobn_updi
avrdude: found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : ATtiny1627
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         Serial program mode           : yes
         Parallel program mode         : yes
         Memory Detail                 :

                                           Block Poll               Page                       Polled
           Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           fuse0       wdtcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse1       bodcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse2       osccfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse4       tcd0cfg     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse5       syscfg0     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse6       syscfg1     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse7       append      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse8       bootend     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuses                   0     0     0    0 no          9   10      0     0     0 0x00 0x00
           lock                    0     0     0    0 no          1    1      0     0     0 0x00 0x00
           tempsense               0     0     0    0 no          2    1      0     0     0 0x00 0x00
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           prodsig                 0     0     0    0 no         61   61      0     0     0 0x00 0x00
           sernum                  0     0     0    0 no         10    1      0     0     0 0x00 0x00
           osccal16                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osccal20                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osc16err                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osc20err                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           data                    0     0     0    0 no          0    1      0     0     0 0x00 0x00
           userrow     usersig     0     0     0    0 no         32   32      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        256   32      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      16384   64      0     0     0 0x00 0x00

         Programmer Type : JTAGICE3_UPDI
         Description     : Curiosity nano (nEDBG) in UPDI mode
         ICE HW version  : 0
         ICE FW version  : 1.21 (rel. 37)
         Serial number   : MCHP3258021800000382
         Vtarget         : 3.31 V
         PDI/UPDI clock Xmega/megaAVR : 100 kHz
avrdude: partial Family_ID returned: "tiny"
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9428 (probably t1627)
erasing chip
avrdude: reading input file 0x00 for fuse0/wdtcfg
         with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse0/wdtcfg ...
avrdude: 1 byte of fuse0/wdtcfg written
avrdude: verifying fuse0/wdtcfg memory against 0x00
avrdude: 1 byte of fuse0/wdtcfg verified
avrdude: reading input file 0b00000101 for fuse1/bodcfg
         with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse1/bodcfg ...
avrdude: 1 byte of fuse1/bodcfg written
avrdude: verifying fuse1/bodcfg memory against 0b00000101
avrdude: 1 byte of fuse1/bodcfg verified
avrdude: reading input file 0b11110110 for fuse5/syscfg0
         with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse5/syscfg0 ...
avrdude: 1 byte of fuse5/syscfg0 written
avrdude: verifying fuse5/syscfg0 memory against 0b11110110
avrdude: 1 byte of fuse5/syscfg0 verified
avrdude: reading input file 0x04 for fuse6/syscfg1
         with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse6/syscfg1 ...
avrdude: 1 byte of fuse6/syscfg1 written
avrdude: verifying fuse6/syscfg1 memory against 0x04
avrdude: 1 byte of fuse6/syscfg1 verified
avrdude: reading input file 0x00 for fuse8/bootend
         with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse8/bootend ...
avrdude: 1 byte of fuse8/bootend written
avrdude: verifying fuse8/bootend memory against 0x00
avrdude: 1 byte of fuse8/bootend verified
avrdude: reading input file 0x00 for fuse7/append
         with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse7/append ...
avrdude: 1 byte of fuse7/append written
avrdude: verifying fuse7/append memory against 0x00
avrdude: 1 byte of fuse7/append verified
avrdude: reading input file C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1/bootloaders/hex/optiboot_Curiosity1627.hex for flash
         with 466 bytes in 2 sections within [0, 0x1ff]
         using 8 pages and 46 pad bytes
avrdude: writing 466 bytes flash ...

Writing | ################################################## | 100% 0.24s

avrdude: 466 bytes of flash written
avrdude: verifying flash memory against C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1/bootloaders/hex/optiboot_Curiosity1627.hex

Reading | ################################################## | 100% 0.11s

avrdude: 466 bytes of flash verified

avrdude done.  Thank you.

Using board 'microchipo' from platform in folder: C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1
Using core 'megatinycore' from platform in folder: C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1
Detecting libraries used...
"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-g++" -c -g -Os -Wall -std=gnu++17 -fpermissive -Wno-sized-deallocation -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -mrelax -w -x c++ -E -CC -mmcu=attiny1627 -DF_CPU=20000000L -DCLOCK_SOURCE=0 -DTWI_MORS -DMILLIS_USE_TIMERB1 -DCORE_ATTACH_ALL -DARDUINO=10607 -DARDUINO_AVR_CuriosityNano1627 -DARDUINO_ARCH_MEGAAVR "-DMEGATINYCORE=\"2.6.1\"" -DMEGATINYCORE_MAJOR=2UL -DMEGATINYCORE_MINOR=6UL -DMEGATINYCORE_PATCH=1UL -DMEGATINYCORE_RELEASED=1 -DARDUINO_attinyxy7 -DLED_BUILTIN=PIN_PB4 -DPIN_BUTTON_BUILTIN=PIN_PB7 -DCLOCK_TUNE_INTERNAL "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\cores\\megatinycore/api/deprecated" "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\cores\\megatinycore" "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\variants\\txy7" "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984\\sketch\\Blink.ino.cpp" -o nul
Generating function prototypes...
"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-g++" -c -g -Os -Wall -std=gnu++17 -fpermissive -Wno-sized-deallocation -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -mrelax -w -x c++ -E -CC -mmcu=attiny1627 -DF_CPU=20000000L -DCLOCK_SOURCE=0 -DTWI_MORS -DMILLIS_USE_TIMERB1 -DCORE_ATTACH_ALL -DARDUINO=10607 -DARDUINO_AVR_CuriosityNano1627 -DARDUINO_ARCH_MEGAAVR "-DMEGATINYCORE=\"2.6.1\"" -DMEGATINYCORE_MAJOR=2UL -DMEGATINYCORE_MINOR=6UL -DMEGATINYCORE_PATCH=1UL -DMEGATINYCORE_RELEASED=1 -DARDUINO_attinyxy7 -DLED_BUILTIN=PIN_PB4 -DPIN_BUTTON_BUILTIN=PIN_PB7 -DCLOCK_TUNE_INTERNAL "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\cores\\megatinycore/api/deprecated" "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\cores\\megatinycore" "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\variants\\txy7" "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984\\sketch\\Blink.ino.cpp" -o "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\builtin\\tools\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-g++" -c -g -Os -Wall -std=gnu++17 -fpermissive -Wno-sized-deallocation -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mrelax -mmcu=attiny1627 -DF_CPU=20000000L -DCLOCK_SOURCE=0 -DTWI_MORS -DMILLIS_USE_TIMERB1 -DCORE_ATTACH_ALL -DARDUINO=10607 -DARDUINO_AVR_CuriosityNano1627 -DARDUINO_ARCH_MEGAAVR "-DMEGATINYCORE=\"2.6.1\"" -DMEGATINYCORE_MAJOR=2UL -DMEGATINYCORE_MINOR=6UL -DMEGATINYCORE_PATCH=1UL -DMEGATINYCORE_RELEASED=1 -DARDUINO_attinyxy7 -DLED_BUILTIN=PIN_PB4 -DPIN_BUTTON_BUILTIN=PIN_PB7 -DCLOCK_TUNE_INTERNAL "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\cores\\megatinycore/api/deprecated" "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\cores\\megatinycore" "-IC:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\megaTinyCore\\hardware\\megaavr\\2.6.1\\variants\\txy7" "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984\\sketch\\Blink.ino.cpp" -o "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984\\sketch\\Blink.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\xiaof\AppData\Local\Temp\arduino-core-cache\core_6561b52f8f4a97bfc7553cd8ed4fd0f9.a
Linking everything together...
"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-gcc" -Wall -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -Wl,--section-start=.text=0x200 -mrelax -mmcu=attiny1627 -o "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.elf" "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984\\sketch\\Blink.ino.cpp.o" "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/..\\arduino-core-cache\\core_6561b52f8f4a97bfc7553cd8ed4fd0f9.a" "-LC:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984" -lm
"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-objcopy" -O binary -R .eeprom "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.elf" "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.bin"
"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.elf" "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.eep"
"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.elf" "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.hex"
cmd /C echo. && "C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-objdump" --disassemble --source --line-numbers --demangle --section=.text "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.elf" > "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.lst"

Bootloader file specified but missing: C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1\bootloaders\optiboot_Curiosity1627.hex
cmd /C echo. && "C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-nm" --numeric-sort --line-numbers --demangle --print-size --format=s "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.elf" > "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.map"

"C:\\Users\\xiaof\\AppData\\Local\\Arduino15\\packages\\DxCore\\tools\\avr-gcc\\7.3.0-atmel3.6.1-azduino6/bin/avr-size" -A "C:\\Users\\xiaof\\AppData\\Local\\Temp\\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.elf"
Sketch uses 722 bytes (4%) of program storage space. Maximum is 15972 bytes.
Global variables use 4 bytes (0%) of dynamic memory, leaving 2044 bytes for local variables. Maximum is 2048 bytes.
"C:\Users\xiaof\AppData\Local\Arduino15\packages\DxCore\tools\avrdude\6.3.0-arduino17or18/bin/avrdude" "-CC:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1/avrdude.conf" -v -V -pattiny1627 -carduino -D -PCOM20 -PCOM20 -b115200 "-Uflash:w:C:\Users\xiaof\AppData\Local\Temp\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.hex:i"

avrdude: Version avrdude-main-test-libusb-compat
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.1\avrdude.conf

         Using Port                    : COM20
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATtiny1627
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         Serial program mode           : yes
         Parallel program mode         : yes
         Memory Detail                 :

                                           Block Poll               Page                       Polled
           Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           fuse0       wdtcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse1       bodcfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse2       osccfg      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse4       tcd0cfg     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse5       syscfg0     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse6       syscfg1     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse7       append      0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuse8       bootend     0     0     0    0 no          1    1      0     0     0 0x00 0x00
           fuses                   0     0     0    0 no          9   10      0     0     0 0x00 0x00
           lock                    0     0     0    0 no          1    1      0     0     0 0x00 0x00
           tempsense               0     0     0    0 no          2    1      0     0     0 0x00 0x00
           signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
           prodsig                 0     0     0    0 no         61   61      0     0     0 0x00 0x00
           sernum                  0     0     0    0 no         10    1      0     0     0 0x00 0x00
           osccal16                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osccal20                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osc16err                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           osc20err                0     0     0    0 no          2    1      0     0     0 0x00 0x00
           data                    0     0     0    0 no          0    1      0     0     0 0x00 0x00
           userrow     usersig     0     0     0    0 no         32   32      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        256   32      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      16384   64      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino for bootloader using STK500 v1 protocol
         Hardware Version: 3
         Firmware Version: 9.1

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9428 (probably t1627)
avrdude: reading input file C:\Users\xiaof\AppData\Local\Temp\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.hex for flash
         with 722 bytes in 1 section within [0x200, 0x4d1]
         using 12 pages and 46 pad bytes
avrdude: writing 722 bytes flash ...

Writing | ################################################## | 100% 0.10s

avrdude: 722 bytes of flash written

avrdude done.  Thank you.
mcuee commented 1 year ago

Howver, it is actually not working if I verify using the on-board pkobn_updi programmer.

PS C:\work\avr\avrdude_test\avrdude_bin> cp C:\Users\xiaof\AppData\Local\Temp\arduino-sketch-CFD7186EB0E645E355FF22678D2A1984/Blink.ino.hex blink_attiny1627_optiboot.hex

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c pkobn_updi -p attiny1627 -U flash:v:.\blink_attiny1627_optiboot.hex

         Vtarget                      : 3.31 V
         PDI/UPDI clock Xmega/megaAVR : 100 kHz
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9428 (probably t1627)
avrdude: verifying flash memory against .\blink_attiny1627_optiboot.hex

Reading | ################################################## | 100% 0.08 s

avrdude error: verification mismatch, first encountered at addr 0x0200
        device 0xff != input 0x3b
avrdude error: verification mismatch

avrdude done.  Thank you.
mcuee commented 1 year ago

I am going to close this one as invalid for now as the bootloader does not seem to work at all for the ATtiny1627 Curiosity Nano board.

Arduino IDE 2.0.1 somehow can not display the menu option for UPDI/Reset pin function and use the default UPDI (no reset pin) option and that is why it is successful writing the bootloader.

I am using the other option UPDI with reset on PB4 (2-series only) with Arduino 1.8.19 and that is why the bootloader buring works. When I use the default option under Arduino 1.8.19, then the bootloader buring will work.

However, sketch upload still fails.

For Arduino 2.0.1, sketch uploading appears to pass but then verify using the on_board programmer shows that it fails in reality.

MCUdude commented 1 year ago

I find it hard to believe that Optiboot doesn't work on the ATtiny1627. I believe Spence would have tested this. To narrow things down, we should also leave out as much "noise" as possible and only focus on Avrdude and the optiboot_x bootloader. Arduino IDE/megaTinyCore may have bugs, but we don't care about that since what we really care about is if we can upload a binary (with start address 0x200) using optiboot_x and Avrdude.

Since I don't have the correct hardware at hand, can you test this @mcuee?

Here's an srec_cat command for generating 256 byte large hex file that starts from 0x200. If head -c256 doesn't work, try head -256c instead:

yes "hello, world" | head -c256 | srec_cat - -bin -offset 0x200 -o hello_world_256B_offset_0x200.hex -Intel
mcuee commented 1 year ago

@MCUdude Good advice. I will try later. I have multiple issues with megaTinyCore and I think the issues may have already been fixed in megaTinyCore git master. But you are right, I should focus on avrdude and optiboot_x.

The Tiny2 series is supposed to be easier with optiboot_x and it indeed seem to be so (to configure PB4 as the alternative reset pin). I do not really need to use the 8s trick. The only problem is that it does not seem to write to the flash. https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/Ref_Reset.md#the-reset-pin

Edit to add: Still I tend to think there is no issue with avrdude, rather the problem may be more with the specific optiboot_curiosity1627.hex file.

mcuee commented 1 year ago

@MCUdude

Thanks for the advice, I think the issue is with optiboot_curiosity1627.hex. I choose to go with /optiboot_tx2z_rst.hex (default UART0 pins, UPDI on RA0, Reset on the alternative PB4 pin) so that I can still use the on-board USB to Serial port.

And it works fine. I verified with the on-board pkobn_updi as well.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -qq -pattiny1627 -cpkobn_updi -Pusb -e 
-Ufuse0:w:0x00:m -Ufuse1:w:0x00:m -Ufuse5:w:0b11111110:m -Ufuse6:w:0x04:m 
-Ufuse8:w:0x02:m -Ufuse7:w:0x00:m -Uflash:w:optiboot_tx2z_rst.hex:i && echo OK
OK

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c arduino -P COM20 -b 115200 -p t1627 -D 
-U .\hello_world_256B_offset_0x200.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9428 (probably t1627)
avrdude: reading input file .\hello_world_256B_offset_0x200.hex for flash
         with 256 bytes in 1 section within [0x200, 0x2ff]
         using 4 pages and 0 pad bytes
avrdude: writing 256 bytes flash ...

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

avrdude: 256 bytes of flash written
avrdude: verifying flash memory against .\hello_world_256B_offset_0x200.hex

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

avrdude: 256 bytes of flash verified

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c pkobn_updi -p t1627 
-U flash:v:.\hello_world_256B_offset_0x200.hex:i -qq && echo OK
OK
mcuee commented 1 year ago

@MCUdude

I'd like to see the possibility of using optiboot_x on the ATmega4808 based Nano 4808 board. I understand that you do not support it with optiboot_x in MegaCoreX. Just wondering what is the reason. Thanks.

If I am willing to use PICKit 4 HV UPDI with the board (I have two boards now and another on-order, so I can sacrifice one just in case), is it possible to use optiboot_x?

I see that you also do not support optiboot_x for Arduino Nano Every (ATmega4809), I believe it is based on the same reason. I have one official board.

What about Microchip ATmega4809 Curiosity Nano board? I do not have the board but I may be able to get one in the future (out of stock as of now from local onlone shops).

MCUdude commented 1 year ago

Thanks for the advice, I think the issue is with optiboot_curiosity1627.hex. I choose to go with /optiboot_tx2z_rst.hex (default UART0 pins, UPDI on RA0, Reset on the alternative PB4 pin) so that I can still use the onboard USB to Serial port.

Thank you @mcuee for carrying out the test, even if it's a little boring and kinda time-consuming. Now we know that the upstream version of Avrdude works with optiboot_x for ATtinys, and that's a good thing! I'll perform the same tests on different ATtiny hardware when I'm back home, just to back your conclusion.

I'd like to see the possibility of using optiboot_x on the ATmega4808-based Nano 4808 board. I understand that you do not support it with optiboot_x in MegaCoreX. Just wondering what is the reason. Thanks.

My "3rd party Arduino core philosophy" has always been to greatly extend the original Arduino AVR core in terms of features, performance, and hardware compatibility, but not to give the user a bunch of choices in the Arduino Tools menu that 99.9% of the users wouldn't really care about. I believe this is the reason most of my Arduino cores have become quite popular, while the number of reported issues/questions is quite low. This can be niche things like brown-out sample rate or start-up time.

Optiboot on the Nano 4808/4809 is on paper a good idea since the upload speed would be greatly improved. However, the last time I had a look at this, the IDE had a few quirks that made it difficult to implement bootloader upload while still maintaining a user interface the average user could make sense of.

From the top of my head, here's one of the main obstacles I stumbled across:

However, I've compiled a bootloader binary with an 8-second timeout on power-on that you could use for Nano 4808/4809 optiboot testing. But I don't find the Nano 4808/4809 board to be convenient enough for bootloader use that I would give MegaCoreX users this option.

(Suitable for the Nano Every 4809) Optiboot_mega0_UART3_ALT_115200_E2.hex.zip

(Suitable for the Nano 4808) Optiboot_mega0_UART2_DEF_115200_C2.hex.zip

mcuee commented 1 year ago

@MCUdude I agree with your rational not to offer the bootloader to the general MegaCoreX users. Just one minor correction, Nano 4808 does not require the 1200bps touch (only Arduino Nano Every needs the 1200bps touch).

Thanks a lot for the bootloaders. The one for Arduino Nano Every seems to work fine.

PS C:\work\avr\avrdude_test\avrdude_bin> mode COM12 baud=12 dtr=on > nul && mode COM12 baud=12 dtr=off > nul 
&& .\avrdude -c jtag2updi -P COM12 -p m4809 -U .\Optiboot_mega0_UART3_ALT_115200_E2.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9651 (probably m4809)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
erasing chip
avrdude: reading input file .\Optiboot_mega0_UART3_ALT_115200_E2.hex for flash
         with 468 bytes in 2 sections within [0, 0x1ff]
         using 4 pages and 44 pad bytes
avrdude: writing 468 bytes flash ...

Writing | ################################################## | 100% 0.40 s

avrdude: 468 bytes of flash written
avrdude: verifying flash memory against .\Optiboot_mega0_UART3_ALT_115200_E2.hex

Reading | ################################################## | 100% 0.10 s

avrdude: 468 bytes of flash verified

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c arduino -P COM12 -b 115200 -p m4809 -D 
-U .\hello_world_256B_offset_0x200.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9651 (probably m4809)
avrdude: reading input file .\hello_world_256B_offset_0x200.hex for flash
         with 256 bytes in 1 section within [0x200, 0x2ff]
         using 2 pages and 0 pad bytes
avrdude: writing 256 bytes flash ...

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

avrdude: 256 bytes of flash written
avrdude: verifying flash memory against .\hello_world_256B_offset_0x200.hex

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

avrdude: 256 bytes of flash verified

avrdude done.  Thank you.
mcuee commented 1 year ago

@MCUdude

But the one for Mega4808 does not seem to work. I will need to double check if the fuse settings play a part or not. Edit -- indeed it was due to wrong fuse8 setting.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c arduino -P COM13 -b 115200 -p m4808 -D
 -U .\hello_world_256B_offset_0x200.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9650 (probably m4808)
avrdude: reading input file .\hello_world_256B_offset_0x200.hex for flash
         with 256 bytes in 1 section within [0x200, 0x2ff]
         using 2 pages and 0 pad bytes
avrdude: writing 256 bytes flash ...

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

avrdude: 256 bytes of flash written
avrdude: verifying flash memory against .\hello_world_256B_offset_0x200.hex

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

avrdude error: verification mismatch, first encountered at addr 0x0200
        device 0xff != input 0x68
avrdude error: verification mismatch

avrdude done.  Thank you.
mcuee commented 1 year ago

@MCUdude

But the one for Mega4808 does not seem to work. I will need to double check if the fuse settings play a part or not.

In the end, it is due to the wrong fuse8 setting. Once I fixed the fuse8 setting, it works fine.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c jtag2updi -P COM6 -p 115200 -p m4808 -t

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9650 (probably m4808)
avrdude> dump fuses
>>> dump fuses

Reading | ################################################## | 100% 0.08 s

0000  00 54 01 ff 00 c9 06 00  00                       |.T.......       |

avrdude> write fuse8 0x0 0x02
>>> write fuse8 0x0 0x02

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

avrdude> flush
>>> flush
avrdude> dump fuses
>>> dump fuses

Reading | ################################################## | 100% 0.08 s

0000  00 54 01 ff 00 c9 06 00  02                       |.T.......       |

avrdude> quit
>>> quit
avrdude>
avrdude done.  Thank you.

C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c arduino -P COM6 -p 115200 -p m4808 -D 
-U .\hello_world_256B_offset_0x200.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9650 (probably m4808)
avrdude: reading input file .\hello_world_256B_offset_0x200.hex for flash
         with 256 bytes in 1 section within [0x200, 0x2ff]
         using 2 pages and 0 pad bytes
avrdude: writing 256 bytes flash ...

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

avrdude: 256 bytes of flash written
avrdude: verifying flash memory against .\hello_world_256B_offset_0x200.hex

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

avrdude: 256 bytes of flash verified

avrdude done.  Thank you.
mcuee commented 1 year ago

I have learned to choose the right hex file (optiboot_txyz.hex, UART pins as PB2/PB3, UPDI/RESET pin as UPDI, 8 seconds delay) for ATtiny817 Xplained Mini and ATtiny817 XPlained Pro from megaTinyCore, and I can confirm that avrdude git main works with optiboot_x for ATtiny817.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -p attiny817 -c arduino -P COM7 -b 115200 -p t817 -D
 -U .\hello_world_256B_offset_0x200.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9320 (probably t817)
avrdude: reading input file .\hello_world_256B_offset_0x200.hex for flash
         with 256 bytes in 1 section within [0x200, 0x2ff]
         using 4 pages and 0 pad bytes
avrdude: writing 256 bytes flash ...

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

avrdude: 256 bytes of flash written
avrdude: verifying flash memory against .\hello_world_256B_offset_0x200.hex

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

avrdude: 256 bytes of flash verified

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -p attiny817 -c arduino -P COM7 -b 115200 -p t817 -D
 -U .\Blink.ino.t817opti.20c0.mD0.v261.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9320 (probably t817)
avrdude: reading input file .\Blink.ino.t817opti.20c0.mD0.v261.hex for flash
         with 512 bytes in 1 section within [0x200, 0x3ff]
         using 8 pages and 0 pad bytes
avrdude: writing 512 bytes flash ...

Writing | ################################################## | 100% 0.02 s

avrdude: 512 bytes of flash written
avrdude: verifying flash memory against .\Blink.ino.t817opti.20c0.mD0.v261.hex

Reading | ################################################## | 100% 0.02 s

avrdude: 512 bytes of flash verified

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c xplainedpro_updi -p t817 -qqt
avrdude> dump fuses
>>> dump fuses
0000  00 00 02 ff 00 c4 04 00  02                       |.........       |

avrdude> quit
>>> quit
avrdude>

Ref:

Basically just choose generic ATtiny817 board with optiboot and do not choose Microchip official board with optiboot. UART pins for the bootloader are PB2/PB3.

C:\Users\xiaof\AppData\Local\Arduino15\packages\DxCore\tools\avrdude\6.3.0-arduino17or18/bin/avrdude 
-CC:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.4/avrdude.conf
 -v -pattiny817 -cxplainedpro_updi -Pusb -e 
-Ufuse0:w:0x00:m -Ufuse1:w:0x00:m -Ufuse2:w:0x02:m 
-Ufuse5:w:0b11000100:m -Ufuse6:w:0x04:m -Ufuse8:w:0x02:m -Ufuse7:w:0x00:m 
-Uflash:w:C:\Users\xiaof\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.6.4/bootloaders/hex/optiboot_txyz.hex:i 

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c xplainedpro_updi -p t817 -qqt
avrdude> dump fuses
>>> dump fuses
0000  00 00 02 ff 00 c4 04 00  02                       |.........       |

avrdude> quit
>>> quit
avrdude>
mcuee commented 1 year ago

Interestingly I got a Nano4808 clone where the on-board jtag2updi does not work (only work once to upload the optiboot hex file and then can not talk the board). Luckily I used the PICkit4 to change the fuse settings and now it works okay.

mcuee commented 1 year ago

@MCUdude

Could you also tell me how to build the hex file for ATmega4809 Curiosity Nano? I just got the board.

The following command generated a bootloader (8s delay, UART3, LED is B5) which works only one time. After uploading the blink hex file it no longer works. The fuse should be correct.

make mega0 UARTTX=B0 TIMEOUT=8 LED=B5 BAUD_RATE=115200 SKIP_BOOTLOADER_ON_POR=1

Run log:

PS C:\Users\xiaof> cd c:\work\avr\avrdude_test\avrdude_bin\
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c pkobn_updi -p m4809 -qqt
avrdude> dump fuses
0000  00 54 01 ff 00 c9 06 00  02                       |.T.......       |

avrdude> quit
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c pkobn_updi -p m4809 -U .\Optiboot_mega0_UART3_DEF_115200_B5_8s.hex

         Vtarget         : 3.31 V
         PDI/UPDI clk    : 100 kHz

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9651 (probably m4809)
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 .\Optiboot_mega0_UART3_DEF_115200_B5_8s.hex for flash
         with 466 bytes in 2 sections within [0, 0x1ff]
         using 4 pages and 46 pad bytes
avrdude: writing 466 bytes flash ...

Writing | ################################################## | 100% 0.24 s

avrdude: 466 bytes of flash written
avrdude: verifying flash memory against .\Optiboot_mega0_UART3_DEF_115200_B5_8s.hex

Reading | ################################################## | 100% 0.11 s

avrdude: 466 bytes of flash verified

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c urclock -P COM25 -p m4809 -xshowall -xbootsize=512

avrdude: AVR device initialized and ready to accept instructions
0 0000-00-00 00.00  application 0 store 0 meta 0 boot 512 x0.0 ......... vector 0 (RESET) ATmega4809
PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c urclock -P COM25 -p m4809 -U .\BlinkCu.ino_atmega4809_16000000L.hex -xbootsize=512

avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9651 (probably m4809)
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 .\BlinkCu.ino_atmega4809_16000000L.hex for flash
         with 764 bytes in 1 section within [0x200, 0x4fb]
         using 6 pages and 4 pad bytes
avrdude: preparing flash input for device bootloader
avrdude: writing 764 bytes flash ...

Writing | ################################################## | 100% 0.12 s

avrdude: 764 bytes of flash written
avrdude: verifying flash memory against .\BlinkCu.ino_atmega4809_16000000L.hex

Reading | ################################################## | 100% 0.08 s

avrdude: 764 bytes of flash verified

avrdude done.  Thank you.

(unplug and plug)

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c urclock -P COM25 -p m4809 -xshowall -xbootsize=512
avrdude warning: attempt 1 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 2 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 3 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 4 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 5 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 6 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 7 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 8 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 9 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude warning: attempt 10 of 10: not in sync
avrdude error: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude error: unable to open programmer urclock on port COM25