Description
Bug Report
Current behavior
I use Bash-style syntax below to provide a procedure that can be run on both Windows (git-bash) and Linux, but I have also tested this using cmd and PowerShell with the same results.
$ export ARDUINO_BOARD_MANAGER_ADDITIONAL_URLS=https://mcudude.github.io/MightyCore/package_MCUdude_MightyCore_index.json
$ arduino-cli core update-index
$ arduino-cli core install MightyCore:avr
$ mkdir /tmp/Foo
$ printf "void setup() {}\nvoid loop() {}\n" > /tmp/Foo/Foo.ino
$ arduino-cli compile -b MightyCore:avr:32 -u -p COM23 -v /tmp/Foo/Foo.ino
AVRDUDE has an odd behavior where it is in "safemode" by default, but when it is "run from a script" (whatever that means), "safemode" is automatically disabled:
$ avrdude --help
...
-u Disable safemode, default when running from a script.
The manual provides different information on the subject, which makes things more clear:
https://www.nongnu.org/avrdude/user-manual/avrdude_4.html
-u
Disables the default behaviour of reading out the fuses three times before programming, then verifying at the end of programming that the fuses have not changed.
When you do an upload in the Arduino IDE, regardless of OS, apparently AVRDUDE considers this as being "run from a script", so safemode is never used.
With other AVR microcontrollers, it really isn't a big deal whether safemode is on or off, but the safemode fuse check fails when uploading to the ATmega32A because of a workaround done to allow it to work with the same the same tools.avrdude.erase.pattern
as the other boards, despite it having no extended fuse.
It was necessary to add a "fake" efuse
to avrdude.conf:
https://github.com/MCUdude/MightyCore/blob/v2.0.5/avr/avrdude.conf#L1651-L1653
This was also done by Arduino for the ATmega8 (arduino/Arduino#3446), so I'm guessing the same error will occur when uploading to arduino:avr:atmegang:cpu=atmega8
using Arduino CLI on Windows.
In the IDE, that's no problem because safemode is disabled. If you're running the AVRDUDE command directly it's no problem because you can just add the -u
option. The problem is that, only on Windows, when Arduino CLI runs AVRDUDE, it doesn't happen to meet whatever AVRDUDE considers to be "run from a script", so you get an ugly error message:
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9502 (probably m32)
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: Fuse reading not support by programmer.
Safemode disabled.
avrdude: reading input file "C:\Users\per\AppData\Local\Temp\Foo\build\MightyCore.avr.32/Foo.ino.hex"
avrdude: writing flash (388 bytes):
Writing | ################################################## | 100% 0.19s
avrdude: 388 bytes of flash written
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode
avrdude done. Thank you.
Error during Upload: uploading error: uploading error: exit status 1
If you do the same process with the Arduino IDE on any OS or Arduino CLI on Linux, it is successful.
If you run the identical upload command from the command line on Linux or Windows, you get the same failure shown above.
Expected behavior
AVRDUDE should not run in safemode when using Arduino CLI from any OS.
Environment
- CLI version (output of
arduino-cli version
): 0.11.0-rc1-62-g72c9655f Commit: a2f63fb - OS and platform: Windows 10, Ubuntu 20.04