1
\$\begingroup\$

I've recently switched over to Atmel Studio 7 (AS7) for one of my AVR projects and after a bit of fiddling around have worked out how to get the "Custom Programming Tool" to correctly upload compiled firmware to a target device using the command:

"$(SolutionDir)\avrdude\avrdude.exe" -C"$(SolutionDir)avrdude\avrdude.conf" -patmega2560 -cwiring -b115200 -D -v -Uflash:w:"$(OutputDirectory)\$(OutputFileName).hex":i -P\\.\COM5

While this works successfully, AS7 seems to think it fails every time because it outputs verbose information. If I look at the output window for the custom programming tool, I get the verbose output from avrdude as expected, but it AS7 treats it all as error messages:

ERROR:avrdude.exe: writing flash (12578 bytes):
ERROR:Writing | ################################################## | 100% 2.05s
ERROR:avrdude.exe: 12578 bytes of flash written
ERROR:avrdude.exe: verifying flash memory against ATMega2560\AstroEQ6Mega2560.hex:
ERROR:avrdude.exe: load data flash data from input file ATMega2560\AstroEQ6Mega2560.hex:
ERROR:avrdude.exe: input file ATMega2560\AstroEQ6Mega2560.hex contains 12578 bytes
ERROR:avrdude.exe: reading on-chip flash data:
ERROR:Reading | ################################################## | 100% 1.47s
ERROR:avrdude.exe: verifying ...
ERROR:avrdude.exe: 12578 bytes of flash verified
ERROR:avrdude.exe: safemode: lfuse reads as FF
ERROR:avrdude.exe: safemode: hfuse reads as D8
ERROR:avrdude.exe: safemode: efuse reads as FF
ERROR:avrdude.exe: safemode: Fuses OK (H:FF, E:D8, L:FF)
ERROR:avrdude.exe done.  Thank you.
Process exited with code 0

Clearly avrdude completes successfully, and the program is downloaded and running. However all those "ERROR:" prefixes are really annoying, especially as at the end of the process I get an error window insisting that the custom programming tool failed.

Has anyone got any experience with setting up the custom programming tool and could tell me how I need to adjust the programming tool command so that its output does not show up as errors?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Well after much head scratching, I've finally tracked down where the issue is. Basically it is because avrdude uses STDERR for all of its verbose output rather than STDOUT. Visual studio in the output window is as a result treating every line it outputs as an error.

To solve the problem requires that the output from avrdude be redirected from STDERR to STDOUT so that it can be shown in the output window without causing an error. The typical approach to this is simply to append 2>&1 to the end of the command, however Visual Studio is treating this as an argument to avrdude so it doesn't work.

The solution appears to be to basically wrap avrdude up in a batch file to do the redirection. I've built the following batch file:

@echo off

set solndir=%~1
set device=%~2
set hexfile=%~3
set port=%~4

if /I "%device%" == "ATMega2560" (
    set prog=wiring
    set baud=115200
) else (
    set prog=arduino
    set baud=57600
)

echo Running AVRDude With Command:
echo "%solndir%avrdude\avrdude.exe" -C"%solndir%avrdude\avrdude.conf" -p%device% -c%prog% -b%baud% -D -v -Uflash:w:"%hexfile%":i -P%port% 2>&1

"%solndir%avrdude\avrdude.exe" -C"%solndir%avrdude\avrdude.conf" -p%device% -c%prog% -b%baud% -D -v -Uflash:w:"%hexfile%":i -P%port% 2>&1

I can then set the custom programming tool command to:

$(SolutionDir)avrdude\avrdudeStdout.bat $(SolutionDir) $(avrdevice) "$(OutputDirectory)\$(OutputFileName).hex" "\\.\COM4"

The result is that avrdude is now correctly run and the output is now on STDOUT so is no longer causing error messages in Atmel Studio. In the event that avrdude fails, a non-zero exit code is still returned from the batch file and that correctly issues an error.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.