platformio / platform-atmelavr

Atmel AVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelavr
Apache License 2.0
136 stars 104 forks source link

Fixed the avrdude upload process #246

Closed snake-4 closed 3 years ago

snake-4 commented 3 years ago

Scons 4.1.0 escapes the values of construction variable lists before adding them to the command line in the execute function as it can be seen here https://scons.org/doc/4.1.0/HTML/scons-api/_modules/SCons/Action/#CommandAction.execute . This leads to the avrdude not being able to open the serial port on windows as the quotes get escaped and passed to the avrdude. So I've removed the quotes that were getting passed to the Append functions as it already escapes the serial port argument's value. I can confirm that this problem exists on platform-atmelavr 3.2.0 on Windows 10 20H2.

valeros commented 3 years ago

Hi @SnakePin ! Thanks for the PR. Strange, but I cannot reproduce the issue, tried on both Win 8, Win 10 and it seems that you're the first to complain about it in years. IIRC, the upload port is explicitly wrapped as there were issues on Unix OSes that can contain whitespaces in device names a few years ago. Could you please share here the entire log of the upload command in verbose mode. Also, please run pio system info in the terminal and attach the output here. Thanks!

snake-4 commented 3 years ago

Log after the fix is applied Log before the fix is applied System info log

snake-4 commented 3 years ago

Besides, if I edit the code to pass /dev/tty S0 (notice the space) without any quotes, Scons automatically adds quotes as required. I've printed the command line string right after it gets escaped in Scons and here's the output: avrdude -V -v -p atmega2560 -C C:\Users\SnakePin\.platformio\packages\tool-avrdude\avrdude.conf -c wiring -b 115200 -D -P "/dev/tty S0" -U flash:w:.pio\build\mega2560\firmware.hex:i Scons uses the SCons.Subst.escape_list function to escape the cmd_line list and it should have the same behavior on Unix OSes.

valeros commented 3 years ago

Thanks for the logs. In both cases avrdude correctly recognized the upload port COM9 and even though the quotes might seem like an apparent reason to explain the failed uploading, I still have some doubts as the error "\\.\COM9": Access is denied is not that obvious. Is there any chance that you're monitoring the output from COM9 while uploading the binary?

cc @ivankravets any thoughts?

snake-4 commented 3 years ago

Nope, I'm not monitoring the port and no other program is using the port. No matter how many times I try, it still fails unless I remove the quotes.

valeros commented 3 years ago

Merged, thanks for the PR.