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

Upload to Uno WiFi Rev2 fails on fuse5 verification when using AVRDUDE 7.0 #119

Open
per1234 opened this issue Jun 23, 2022 · 15 comments
Open

Comments

@per1234
Copy link
Contributor

per1234 commented Jun 23, 2022

Describe the problem

The handling of unused configuration fuse bits changed in version 6.2 of the AVRDUDE tool used for uploading to the boards of this platform:

http://savannah.nongnu.org/bugs/?46759

This change caused verification of fuses to fail when using AVRDUDE commands and configurations that were valid for previous versions of the tool:

As a workaround, a patch was made to Arduino's build of AVRDUDE which produced a warning instead of an error under these conditions:

https://github.com/arduino/avrdude-build-script/blob/master/avrdude-6.3-patches/80-Avoid-failing-fuse-check-if-different-bits-are-reserved.patch

When uploading to the Uno WiFi Rev2, the patch resulted in this warning:

avrdude: WARNING: invalid value for unused bits in fuse "fuse5", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xcd instead of 0xc9 (double check with your datasheet first).

The patch was also submitted upstream:

https://savannah.nongnu.org/patch/index.php?9110

That patch was accepted and is now part of the AVRDUDE 7.0 release. For this reason, Arduino's patch was removed from the Arduino build of AVRDUDE 7.0:

https://github.com/arduino/avrdude-packing/tree/7.0-arduino.3/patches

🐛 The upload fails during the fuse5 verification when uploading to the Uno WiFi Rev2 using AVRDUDE 7.0-arduino.3.

To reproduce

Equipment

  • Arduino Uno WiFi Rev2

Steps

  1. Replace the AVRDUDE 6.3.0-arduino17 executable in your hardware packages with the one from the downloads under the "Assets" section of this release:
    https://github.com/arduino/avrdude-packing/releases/tag/7.0-arduino.3
    • Linux: ~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude
    • Windows: %LOCALAPPDATA%\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17\bin/avrdude.exe
    • macOS: ~/Library/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude
  2. Select File > Preferences... from the Arduino IDE menus.
  3. Check the box next to "☐ Verify code after upload".
  4. Click the OK button.
  5. Select Sketch > Upload from the Arduino IDE menus.
  6. Wait for upload to finish.

🐛 The upload fails:

"C:\Users\per\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\per\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v  -patmega4809 -cxplainedmini_updi -Pusb  -b115200 -e -D "-Uflash:w:C:\Users\per\AppData\Local\Temp\arduino-sketch-95953A6B60AD3B350D9E6AEC6791BCB6/sketch_jun23a.ino.hex:i" "-Ufuse2:w:0x01:m" "-Ufuse5:w:0xC9:m" "-Ufuse8:w:0x02:m" "-Uflash:w:C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex:i"
avrdude: Version 7.0
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is "C:\Users\per\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : usb
         Using Programmer              : xplainedmini_updi
         Overriding Baud Rate          : 115200
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : ATmega4809
         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
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature               0     0     0    0 no          3    0      0     0     0 0x00 0x00
           prodsig                 0     0     0    0 no         61   61      0     0     0 0x00 0x00
           fuses                   0     0     0    0 no          9    0      0     0     0 0x00 0x00
           fuse0                   0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse1                   0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse2                   0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse4                   0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse5                   0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse6                   0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse7                   0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse8                   0     0     0    0 no          1    0      0     0     0 0x00 0x00
           lock                    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           data                    0     0     0    0 no          0    0      0     0     0 0x00 0x00
           usersig                 0     0     0    0 no         64   64      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      49152  128      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        256   64      0     0     0 0x00 0x00

         Programmer Type : JTAGICE3_UPDI
         Description     : Atmel AVR XplainedMini in UPDI mode
         ICE HW version  : 0
         ICE FW version  : 1.19 (rel. 57)
         Serial number   : B320590EEA919AFA7254
         Vtarget         : 5.00 V
avrdude: Partial Family_ID returned: "mega"
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.07s

avrdude: Device signature = 0x1e9651 (probably m4809)
avrdude: erasing chip
avrdude: reading input file "C:\Users\per\AppData\Local\Temp\arduino-sketch-95953A6B60AD3B350D9E6AEC6791BCB6/sketch_jun23a.ino.hex"
avrdude: writing flash (1726 bytes):

Writing | ################################################## | 100% 0.25s

avrdude: 1726 bytes of flash written
avrdude: verifying flash memory against C:\Users\per\AppData\Local\Temp\arduino-sketch-95953A6B60AD3B350D9E6AEC6791BCB6/sketch_jun23a.ino.hex:

Reading | ################################################## | 100% 0.20s

avrdude: 1726 bytes of flash verified
avrdude: reading input file "0x01"
avrdude: writing fuse2 (1 bytes):

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

avrdude: 1 bytes of fuse2 written
avrdude: verifying fuse2 memory against 0x01:

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

avrdude: 1 bytes of fuse2 verified
avrdude: reading input file "0xC9"
avrdude: writing fuse5 (1 bytes):

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

avrdude: 1 bytes of fuse5 written
avrdude: verifying fuse5 memory against 0xC9:

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

avrdude: verification error, first mismatch at byte 0x0000
         0xcd != 0xc9
avrdude: verification error; content mismatch
Failed uploading: uploading error: exit status 1
avrdude done.  Thank you.

Expected behavior

Upload is successful.

Additional context

This could of course be worked around by modifying Arduino's build of AVRDUDE as before, but the current goal is to maintain the fewest possible number of patches necessary for AVRDUDE to meet Arduino's requirements. So I think the best place to start the investigation is by considering whether the issue can be solved by adjusting the fuse values specified in the boards definitions of this platform:

--- a/boards.txt
+++ b/boards.txt
@@ -32,7 +32,7 @@ uno2018.build.extra_flags={build.328emulation} -DMILLIS_USE_TIMERB3
 uno2018.bootloader.tool=avrdude
 uno2018.bootloader.tool.default=avrdude
 uno2018.bootloader.file=atmega4809_uart_bl.hex
-uno2018.bootloader.SYSCFG0=0xC9
+uno2018.bootloader.SYSCFG0=0xCD
 uno2018.bootloader.BOOTEND=0x02
 uno2018.bootloader.OSCCFG=0x01
 uno2018.fuses.file=fuses_4809.bin
@@ -75,7 +75,7 @@ nona4809.build.extra_flags={build.328emulation} -DMILLIS_USE_TIMERB3 -DNO_EXTERN
 nona4809.bootloader.tool=avrdude
 nona4809.bootloader.tool.default=avrdude
 nona4809.bootloader.file=atmega4809_uart_bl.hex
-nona4809.bootloader.SYSCFG0=0xC9
+nona4809.bootloader.SYSCFG0=0xCD
 nona4809.bootloader.BOOTEND=0x00
 nona4809.bootloader.OSCCFG=0x01
 nona4809.fuses.file=fuses_4809.bin

This would have the additional benefit of removing the warning which frequently causes concern or acts as a "red herring" for new users of the Uno WiFi Rev2 (e.g., #71, #121, arduino/Arduino#9443, forum#954001)

@facchinm
Copy link
Member

I completely agree that changing FUSE5 (SYSCFG0) in the core is the right solution. Would you mind creating the PR too? Thanks!

@per1234
Copy link
Contributor Author

per1234 commented Jun 30, 2022

@facchinm I'm really struggling to understand this. AVRDUDE's recommended SYSCFG0 fuse value only changes reserved bit 2 from 0 to 1, but leaves the other reserved fuse bits 1, 4, 5 set to 0.

My understanding is that all the reserved fuse bits are intended to be changed to 1, which would mean the SYSCFG0 value should instead be 0xFF. It would also mean that OSCCFG (the current value of which AVRDUDE doesn't complain about) should be 0x7D. AVRDUDE verification passes with those new values.

I am also having a lot of confusion from the datasheets. Microchip has been flipflopping on this subject from one revision to another:

DS40002015A (02/2018)

From section 5.8:

Note: When writing the fuses write all reserved bits to ‘1’.

DS40002015B (03/2019)

From section 5.8:

Note: When writing the fuses, all reserved bits must be written to ‘0’.

From section 31.1 (revision history)

Clarifying that reserved bits within a fuse
byte must be written to ‘0’

DS40002015C (08/2019)

From section 5.8:

Note: When writing the fuses, all reserved bits must be written to ‘0’.

DS40002173A (01/2020)

From section 7.8:

Note: When writing the fuses, all reserved bits must be written to ‘0’.

DS40002173B (06/2020)

From section 7.8:

Note: When writing the fuses, all reserved bits must be written to ‘0’.

DS40002173C (02/2021)

From section section 7.8:

Note: All reserved bits must be written to ‘1’ when writing the fuses.

There is no mention of the change back to requiring 1 in the revision history. So I don't know whether it was intentional or only a regression of the erroneous information from DS40002015A.

@facchinm
Copy link
Member

facchinm commented Jul 4, 2022

@per1234 what a mess 🙂
The most sensible thing that comes to my mind is using a recent (7.0 mainline) version of avrdude to dump the fuses from an unprogrammed 4809, see if they are being read as 0 or 1, write some in both ways, read them back and see which method is "correct" (even if I think both will work)

@per1234
Copy link
Contributor Author

per1234 commented Jul 5, 2022

Unfortunately I don't have any ATmega4809 other than on my Uno WiFi Rev2 and Nano Every boards and none of the component suppliers I checked have stock. Do you happen to have access to one @facchinm?

@facchinm
Copy link
Member

facchinm commented Jul 5, 2022

Sure, I'll try to get some of them

@umbynos
Copy link

umbynos commented Sep 7, 2022

@mcuee I just tried with an Arduino WiFi rev2 and #1053 does not seem to fix this problem.
The problem seems to be related to the usage of avrdude -V flag (Do not verify). When using it, the upload is successful and the sketch is working fine. But without it, I get the same error reported by @per1234.
The -V flag is added to the command line when:

  1. Check the box next to "☐ Verify code after upload".

I guess we have to wait to have some Nano Every "virgin edition" or am I missing something?

@mcuee
Copy link

mcuee commented Sep 7, 2022

@mcuee I just tried with an Arduino WiFi rev2 and #1053 does not seem to fix this problem. The problem seems to be related to the usage of avrdude -V flag (Do not verify). When using it, the upload is successful and the sketch is working fine. But without it, I get the same error reported by @per1234. The -V flag is added to the command line when:

  1. Check the box next to "☐ Verify code after upload".

I guess we have to wait to have some Nano Every "virgin edition" or am I missing something?

Interesting that you still have issues. I am not so sure what you mean by Nano Every "virgin edition". I have the official Arduino Nano Every and I do not have issues with avrdude 7.0.

Ref: please refer to my run log. So maybe "Arduino WiFi rev2" may have some different FW version.

Edit: I see that you mean by unprogrammed blank ATmega4809, sorry I do not have that.

@mcuee
Copy link

mcuee commented Sep 7, 2022

@umbynos

In this case, maybe you want to create a new issue in avrdude. Thanks.

@umbynos
Copy link

umbynos commented Sep 7, 2022

I run some tests with the Uno WiFi Rev2 Nano Every:
With the avrdude that includes fixes from avrdudes/avrdude#1053:

result
/home/umberto/.arduino15/packages/arduino/tools/avrdude/test-PR\#1093/bin/avrdude -C /home/umberto/.arduino15/packages/arduino/tools/avrdude/test-PR\#1093/etc/avrdude.conf -v -patmega4809 -cjtag2updi -P/dev/ttyACM0  -b115200 -e -D "-Uflash:w:/tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex:i" "-Ufuse2:w:0x01:m" "-Ufuse5:w:0xC9:m" "-Ufuse8:w:0x00:m"

avrdude: Version 7.0-PR1093
        Copyright (c) Brian Dean, http://www.bdmicro.com/
        Copyright (c) Joerg Wunsch

        System wide configuration file is "/home/umberto/.arduino15/packages/arduino/tools/avrdude/test-PR#1093/etc/avrdude.conf"
        User configuration file is "/home/umberto/.avrduderc"
        User configuration file does not exist or is not a regular file, skipping

        Using Port                    : /dev/ttyACM0
        Using Programmer              : jtag2updi
        Overriding Baud Rate          : 115200
JTAG ICE mkII sign-on message:
Communications protocol version: 1
M_MCU:
  boot-loader FW version:        1
  firmware version:              1.07
  hardware version:              1
S_MCU:
  boot-loader FW version:        1
  firmware version:              6.07
  hardware version:              1
Serial number:                   00:00:00:00:00:00
Device ID:                       JTAGICE mkII
        AVR Part                      : ATmega4809
        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         64   64      0     0     0 0x00 0x00
          eeprom                  0     0     0    0 no        256   64      0     0     0 0x00 0x00
          flash                   0     0     0    0 no      49152  128      0     0     0 0x00 0x00

        Programmer Type : JTAGMKII_UPDI
        Description     : JTAGv2 to UPDI bridge
        M_MCU HW version: 1
        M_MCU FW version: 1.07
        S_MCU HW version: 1
        S_MCU FW version: 6.07
        Serial number   : 00:00:00:00:00:00
        Vtarget         : 5.0 V

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.27s

avrdude: Device signature = 0x1e9651 (probably m4809)
avrdude: erasing chip
avrdude: reading input file /tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex for flash
        with 1118 bytes in 1 section within [0, 0x45d]
        using 9 pages and 34 pad bytes
avrdude: writing 1118 bytes flash ...

Writing | ################################################## | 100% 0.84s

avrdude: 1118 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex

Reading | ################################################## | 100% 0.12s

avrdude: 1118 bytes of flash verified
avrdude: reading input file 0x01 for fuse2/osccfg
        with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse2/osccfg ...

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

avrdude: 1 byte of fuse2/osccfg written
avrdude: verifying fuse2/osccfg memory against 0x01

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

avrdude: 1 byte of fuse2/osccfg verified
avrdude: reading input file 0xC9 for fuse5/syscfg0
        with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse5/syscfg0 ...

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

avrdude: 1 byte of fuse5/syscfg0 written
avrdude: verifying fuse5/syscfg0 memory against 0xC9

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

avrdude: 1 byte of fuse5/syscfg0 verified
avrdude: reading input file 0x00 for fuse8/bootend
        with 1 byte in 1 section within [0, 0]
avrdude: writing 1 byte fuse8/bootend ...

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

avrdude: 1 byte of fuse8/bootend written
avrdude: verifying fuse8/bootend memory against 0x00

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

avrdude: 1 byte of fuse8/bootend verified

avrdude done.  Thank you.

While this is with the old avrdude 6.3.0-arduino17, the version we are currently using in the latest version of the avr core.

result
/home/umberto/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17//bin/avrdude -C /home/umberto/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cjtag2updi -P/dev/ttyACM0  -b115200 -e -D "-Uflash:w:/tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex:i" "-Ufuse2:w:0x01:m" "-Ufuse5:w:0xC9:m" "-Ufuse8:w:0x00: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 "/home/umberto/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/home/umberto/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : jtag2updi
         Overriding Baud Rate          : 115200
JTAG ICE mkII sign-on message:
Communications protocol version: 1
M_MCU:
  boot-loader FW version:        1
  firmware version:              1.07
  hardware version:              1
S_MCU:
  boot-loader FW version:        1
  firmware version:              6.07
  hardware version:              1
Serial number:                   00:00:00:00:00:00
Device ID:                       JTAGICE mkII
         AVR Part                      : ATmega4809
         Chip Erase delay              : 0 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 0
         StabDelay                     : 0
         CmdexeDelay                   : 0
         SyncLoops                     : 0
         ByteDelay                     : 0
         PollIndex                     : 0
         PollValue                     : 0x00
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           prodsig        0     0     0    0 no         61   61      0     0     0 0x00 0x00
           fuses          0     0     0    0 no          9    0      0     0     0 0x00 0x00
           fuse0          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse1          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse2          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse4          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse5          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse6          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse7          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse8          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0     0     0 0x00 0x00
           data           0     0     0    0 no          0    0      0     0     0 0x00 0x00
           usersig        0     0     0    0 no         64   64      0     0     0 0x00 0x00
           flash          0     0     0    0 no      49152  128      0     0     0 0x00 0x00
           eeprom         0     0     0    0 no        256   64      0     0     0 0x00 0x00

         Programmer Type : JTAGMKII_PDI
         Description     : JTAGv2 to UPDI bridge
         M_MCU hardware version: 1
         M_MCU firmware version: 1.07
         S_MCU hardware version: 1
         S_MCU firmware version: 6.07
         Serial number:          00:00:00:00:00:00
         Vtarget         : 5.0 V

avrdude: jtagmkII_initialize(): Cannot locate "flash" and "boot" memories in description
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.27s

avrdude: Device signature = 0x1e9651 (probably m4809)
avrdude: erasing chip
avrdude: reading input file "/tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex"
avrdude: writing flash (1118 bytes):

Writing | ################################################## | 100% 0.84s

avrdude: 1118 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex:
avrdude: load data flash data from input file /tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex:
avrdude: input file /tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex contains 1118 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.12s

avrdude: verifying ...
avrdude: 1118 bytes of flash verified
avrdude: reading input file "0x01"
avrdude: writing fuse2 (1 bytes):

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

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

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

avrdude: verifying ...
avrdude: 1 bytes of fuse2 verified
avrdude: reading input file "0xC9"
avrdude: writing fuse5 (1 bytes):

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

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

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

avrdude: verifying ...
avrdude: 1 bytes of fuse5 verified
avrdude: reading input file "0x00"
avrdude: writing fuse8 (1 bytes):

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

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

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

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

avrdude: safemode: Fuses OK (E:FF, H:FF, L:FF)

avrdude done.  Thank you.

With avrdude 7.0-arduino.3:

result
/home/umberto/.arduino15/packages/arduino/tools/avrdude/7.0-arduino.3/bin/avrdude -C /home/umberto/.arduino15/packages/arduino/tools/avrdude/7.0-arduino.3/etc/avrdude.conf -v -patmega4809 -cjtag2updi -P/dev/ttyACM0  -b115200 -e -D "-Uflash:w:/tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex:i" "-Ufuse2:w:0x01:m" "-Ufuse5:w:0xC9:m" "-Ufuse8:w:0x00:m"

avrdude: Version 7.0
         Copyright (c) Brian Dean, http://www.bdmicro.com/
         Copyright (c) Joerg Wunsch

         System wide configuration file is "/home/umberto/.arduino15/packages/arduino/tools/avrdude/7.0-arduino.3/etc/avrdude.conf"
         User configuration file is "/home/umberto/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : jtag2updi
         Overriding Baud Rate          : 115200
JTAG ICE mkII sign-on message:
Communications protocol version: 1
M_MCU:
  boot-loader FW version:        1
  firmware version:              1.07
  hardware version:              1
S_MCU:
  boot-loader FW version:        1
  firmware version:              6.07
  hardware version:              1
Serial number:                   00:00:00:00:00:00
Device ID:                       JTAGICE mkII
         AVR Part                      : ATmega4809
         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
           ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature               0     0     0    0 no          3    0      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    0      0     0     0 0x00 0x00
           osccal16                0     0     0    0 no          2    0      0     0     0 0x00 0x00
           osccal20                0     0     0    0 no          2    0      0     0     0 0x00 0x00
           tempsense               0     0     0    0 no          2    0      0     0     0 0x00 0x00
           osc16err                0     0     0    0 no          2    0      0     0     0 0x00 0x00
           osc20err                0     0     0    0 no          2    0      0     0     0 0x00 0x00
           fuses                   0     0     0    0 no          9   10      0     0     0 0x00 0x00
           fuse0       wdtcfg      0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse1       bodcfg      0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse2       osccfg      0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse4       tcd0cfg     0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse5       syscfg0     0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse6       syscfg1     0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse7       append      0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse8       bootend     0     0     0    0 no          1    0      0     0     0 0x00 0x00
           lock                    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           data                    0     0     0    0 no          0    0      0     0     0 0x00 0x00
           userrow     usersig     0     0     0    0 no         64   64      0     0     0 0x00 0x00
           flash                   0     0     0    0 no      49152  128      0     0     0 0x00 0x00
           eeprom                  0     0     0    0 no        256   64      0     0     0 0x00 0x00

         Programmer Type : JTAGMKII_PDI
         Description     : JTAGv2 to UPDI bridge
         M_MCU HW version: 1
         M_MCU FW version: 1.07
         S_MCU HW version: 1
         S_MCU FW version: 6.07
         Serial number   : 00:00:00:00:00:00
         Vtarget         : 5.0 V

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.27s

avrdude: Device signature = 0x1e9651 (probably m4809)
avrdude: erasing chip
avrdude: reading input file "/tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex"
avrdude: writing flash (1118 bytes):

Writing | ################################################## | 100% 0.84s

avrdude: 1118 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino-sketch-DA9372EC17C7CC77521592697B1C7CD7/Blink.ino.hex:

Reading | ################################################## | 100% 0.12s

avrdude: 1118 bytes of flash verified
avrdude: reading input file "0x01"
avrdude: writing fuse2/osccfg (1 bytes):

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

avrdude: 1 bytes of fuse2/osccfg written
avrdude: verifying fuse2/osccfg memory against 0x01:

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

avrdude: 1 bytes of fuse2/osccfg verified
avrdude: reading input file "0xC9"
avrdude: writing fuse5/syscfg0 (1 bytes):

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

avrdude: 1 bytes of fuse5/syscfg0 written
avrdude: verifying fuse5/syscfg0 memory against 0xC9:

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

avrdude: 1 bytes of fuse5/syscfg0 verified
avrdude: reading input file "0x00"
avrdude: writing fuse8/bootend (1 bytes):

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

avrdude: 1 bytes of fuse8/bootend written
avrdude: verifying fuse8/bootend memory against 0x00:

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

avrdude: 1 bytes of fuse8/bootend verified

avrdude done.  Thank you.

At this point I think the problem is specific to the Uno WiFi Rev2. Yes, it has the same atmega 4809 but uses a different programmer (xplainedmini_udpi, versus the nano every one: jtag2updi).

@mcuee
Copy link

mcuee commented Sep 8, 2022

I run some tests with the Uno WiFi Rev2

I think you mean to say "Arduino Nano Every".

At this point I think the problem is specific to the Uno WiFi Rev2. Yes, it has the same atmega 4809 but uses a different programmer (xplainedmini_udpi, versus the nano every one: jtag2updi).

Good to narrow down to Uno WiFi Rev2 using xplainedmini_udpi. In that case, maybe you can raise an issue with avrdude.

Unfortunately other than Uno WiFi Rev 2, I am not so sure if there are any other boards using xplainedmini_udpi with ATmega4809 or similar chips for others to reproduce the issue. There are two boards from Microchip using ATmega4809, the ATmega4809 Curiosity Nano and ATmega4809 Xplained Pro. But they are using adifferent programmers.

@MCUdude
Copy link
Contributor

MCUdude commented Aug 15, 2023

This issue has been fixed in the latest Avrdude 7.2 release. @umbynos has yet to release a statically built version at arduino/avrdude-packaging.

$ avrdude -cxplainedmini_updi -patmega4809 -Usyscfg0:w:0xc9:m
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9651 (probably m4809)

avrdude: processing -U syscfg0:w:0xc9:m
avrdude: reading input file 0xc9 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 0xc9
avrdude warning: ignoring mismatch in unused bits of syscfg0
        (device 0xcd != input 0xc9); to prevent this warning fix
        the part or programmer definition in the config file
avrdude: 1 byte of fuse5/syscfg0 verified

avrdude done.  Thank you.

@umbynos
Copy link

umbynos commented Sep 8, 2023

That is amazing news! I will try to release 7.2 static as fast as possible

@MCUdude
Copy link
Contributor

MCUdude commented Sep 8, 2023

That is amazing news! I will try to release 7.2 static as fast as possible

Excellent! The reason for all this is that the on-board mEDBG programmer on the UNO Wifi Rev2 has "fuse protection", enabled through the SUFFER register, which prevents the user from "bricking" their board when playing around with the fuse bit settings (probably intended for Xplained Nano/Mini users).

Previously you'd need a special Python tool to read and change the current value, but Avrdude 7.1 and 7.2 support reading and writing to this register (it was a fun evening project 😄). Use -c xplainedmini_updi -x suffer to read the current value, and -c xplainedmini_updi -x suffer=[value] to write to it.

I believe the UNO Wifi Rev2 SUFFER register value is 0x7F, but I've changed mine to 0x7E to play with the fuses without any constraints.

Here's what the bits represent (from Avrdude's jtag3.c file):

    // SUFFER bits
    // Bit 7 ARDUINO: Adds control of extra LEDs when set to 0
    // Bit 6..3: Reserved (must be set to 1)
    // Bit 2 EOF: Agressive power-down, sleep after 5 seconds if no USB enumeration when set to 0
    // Bit 1 LOWP: forces running at 1 MHz when bit set to 0
    // Bit 0 FUSE: Fuses are safe-masked when bit sent to 1 Fuses are unprotected when set to 0

From the Xplained Mini ATtiny817 manual:
image

@umbynos
Copy link

umbynos commented Oct 5, 2023

Released 7.2! arduino/avrdude-packing#28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants