When writing sketch to Arduino, avrdude is used. Normally, Aruduino IDE is used for writing and avrdude itself is not directly used, but avrdude.exe is used from command line in case of writing hex file to flash or checking fuse setting.
USB / Serial connections are usually used, but avrdude does have support for connection over network.
Connect ESP8266 or ESP32 with Arduino via ISCP, and write sketch to ESP which relays command from network. Then connect ESP to network, and tell avrdude to connect over network.
Command line sample is as follows.
avrdude.exe -Cavrdude.conf -v -patmega328p -cavrisp -P net:192.168.1.100:328 -Uflash:w:somesketch.hex
IP address and port number are passed with net parameter.
However, at this point (Sept, 2021), avrdude.exe 6.3 included in Arduino IDE works over net in linux, but not in Windows. Trying to run in windows shows error like below.
avrdude.exe: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "c:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"
Using Port : net:192.168.1.100:328
Using Programmer : arduino
avrdude.exe: ser_drain(): read error: incorrect parameter.
avrdude.exe: ser_drain(): read error: incorrect parameter.
avrdude.exe: ser_drain(): read error: incorrect paramter.
AVR Part : ATmega328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : Arduino
Description : Arduino
avrdude.exe: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14
avrdude.exe: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10
Hardware Version: 4744608
Firmware Version: 0.2
Topcard : STK502
Vtarget : 1.8 V
Varef : 0.0 V
Oscillator : Off
SCK period : 0.1 us
avrdude.exe: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x01
avrdude.exe: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude.exe: stk500_disable(): protocol error, expect=0x14, resp=0x10
avrdude.exe done. Thank you.
You see ser_drain(): and stk500_getparm(): errors.
While searching for avrdude source code, I found one with Visual Studio support. Great, and thanks to Marius Greuel.
Debugging above source (6.3.1.1), ser_drain() was missing network processing, and stk500_getparm() seems to be failing due to handling old data left in receive buffer. So, I’ve added network support in ser_drain() function and added drain (flush old data) in stk500_getparm before sending new command.
Below 2 points are modified.
ser_win32.c
static int ser_drain(union filedescriptor *fd, int display)
{
#ifdef HAVE_LIBWS2_32 //added serial_over_ethernet 2021.9.16 nefa
if (serial_over_ethernet) {
unsigned long l;
unsigned char buf[8];
while (1) {
ioctlsocket(fd->ifd, FIONREAD, &l);
if (l == 0) {
if (display) avrdude_message(MSG_INFO, "<drain\n");
break;
}
net_recv(fd, buf, 1);
if (display) avrdude_message(MSG_INFO, "%02x ", buf[0]);
}
return 0;
}
#endif
// int rc;
unsigned char buf[10];
BOOL readres;
DWORD read;
stk500.c
static int stk500_getparm(PROGRAMMER * pgm, unsigned parm, unsigned * value)
{
unsigned char buf[16];
unsigned v;
int tries = 0;
retry:
tries++;
buf[0] = Cmnd_STK_GET_PARAMETER;
buf[1] = parm;
buf[2] = Sync_CRC_EOP;
stk500_drain(pgm, 0); //added drain 2021.9.16 nefa
stk500_send(pgm, buf, 3);
if (stk500_recv(pgm, buf, 1) < 0)
Below is exe with above fix, in case it may help someone who needs.
This post is also available in: Japanese