Skip to content

Arduino CLI on Windows runs AVRDUDE in safemode #844

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

Closed
per1234 opened this issue Jul 20, 2020 · 0 comments · Fixed by #897
Closed

Arduino CLI on Windows runs AVRDUDE in safemode #844

per1234 opened this issue Jul 20, 2020 · 0 comments · Fixed by #897
Labels
conclusion: resolved Issue was resolved os: windows Specific to Windows operating system topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Jul 20, 2020

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
cmaglie added a commit to cmaglie/arduino-cli that referenced this issue Aug 14, 2020
This is required because some tools detects if the program is running
from terminal by looking at the stdin/out bindings.

Fix: arduino#844
cmaglie added a commit to cmaglie/arduino-cli that referenced this issue Aug 14, 2020
This is required because some tools detects if the program is running
from terminal by looking at the stdin/out bindings.

Fix: arduino#844
cmaglie added a commit that referenced this issue Aug 18, 2020
… avrdude running in safe mode) (#897)

Some tools detects if the program is running from terminal by looking at the stdin/out bindings.
Previously stdin wasn't bound to any custom stream, this fact lead avrdude to think it was run from terminal (instead of a script) and start it in "safe-mode". This turn out to be a problem in some cases, see #844

* Removed useless stdout/err listeners

They are immediatly overwritten on the next line.

* Always pipe stdout/err/in when running tools.

This is required because some tools detects if the program is running
from terminal by looking at the stdin/out bindings.

Fix: #844

* Do not use NullWriter in executils by default.

This is not strictly required for the 'avrdude' hack.
@per1234 per1234 added conclusion: resolved Issue was resolved os: windows Specific to Windows operating system topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved os: windows Specific to Windows operating system topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant