arduino / arduino/ArduinoCore-megaavr
Upload to Uno WiFi Rev2 fails on fuse5 verification when using AVRDUDE 7.0
- Dominant language
- C++
- Stars
- 111
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
### 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:
- https://github.com/arduino/Arduino/issues/5175
- https://github.com/arduino/avrdude-build-script/issues/2
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](https://store.arduino.cc/products/arduino-uno-wifi-rev2), the patch resulted in this warning:
```text
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](https://github.com/avrdudes/avrdude/releases/tag/v7.0). 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](https://github.com/arduino/avrdude-packing/releases/tag/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`
1. Select **File > Preferences...** from the Arduino IDE menus.
1. Check the box next to "**☐ Verify code after upload**".
1. Click the **OK** button.
1. Select **Sketch > Upload** from the Arduino IDE menus.
1. Wait for upload to finish.
🐛 The upload fails:
```text
"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:
```diff
--- 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., https://github.com/arduino/ArduinoCore-megaavr/issues/71, https://github.com/arduino/ArduinoCore-megaavr/issues/121, https://github.com/arduino/Arduino/issues/9443, [forum#954001](https://forum.arduino.cc/t/help-please-avrdude-warning-invalid-value-for-unused-bits-in-fuse-fuse5/954001))
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Uno WiFi Rev2 and Nona4809 fuse entries in boards.txt, especially the SYSCFG0 values shown in the issue. Check the AVRDUDE 7.0 fuse verification behavior and test an upload with verification enabled. Done means the upload succeeds without a fuse5 mismatch or invalid-unused-bits warning.
Written by the indexing model from the issue text.
Assessment
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100