{"id":3397,"date":"2021-09-16T22:01:41","date_gmt":"2021-09-16T13:01:41","guid":{"rendered":"https:\/\/programresource.net\/?p=3397"},"modified":"2021-09-16T22:01:41","modified_gmt":"2021-09-16T13:01:41","slug":"network-support-for-arduino-firmware-tool-avrdude-exe-windows-version","status":"publish","type":"post","link":"https:\/\/programresource.net\/en\/2021\/09\/16\/3397.html","title":{"rendered":"Network support for Arduino firmware tool avrdude.exe (Windows version)"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/programresource.net\/images\/2021\/09\/IMG_20210916_211858-1024x471.jpg\" alt=\"\" class=\"wp-image-3385\" srcset=\"https:\/\/programresource.net\/images\/2021\/09\/IMG_20210916_211858-1024x471.jpg 1024w, https:\/\/programresource.net\/images\/2021\/09\/IMG_20210916_211858-300x138.jpg 300w, https:\/\/programresource.net\/images\/2021\/09\/IMG_20210916_211858-768x353.jpg 768w, https:\/\/programresource.net\/images\/2021\/09\/IMG_20210916_211858.jpg 1450w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>USB \/ Serial connections are usually used, but avrdude does have support for connection over network.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Command line sample is as follows.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\navrdude.exe -Cavrdude.conf -v -patmega328p -cavrisp -P net:192.168.1.100:328 -Uflash:w:somesketch.hex\n<\/pre><\/div>\n\n\n<p>IP address and port number are passed with net parameter.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\navrdude.exe: Version 6.3-20190619\n             Copyright (c) 2000-2005 Brian Dean, http:\/\/www.bdmicro.com\/\n             Copyright (c) 2007-2014 Joerg Wunsch\n\n             System wide configuration file is &quot;c:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\etc\\avrdude.conf&quot;\n\n             Using Port                    : net:192.168.1.100:328\n             Using Programmer              : arduino\navrdude.exe: ser_drain(): read error: incorrect parameter.\n\navrdude.exe: ser_drain(): read error: incorrect parameter.\n\navrdude.exe: ser_drain(): read error: incorrect paramter.\n\n             AVR Part                      : ATmega328P\n             Chip Erase delay              : 9000 us\n             PAGEL                         : PD7\n             BS2                           : PC2\n             RESET disposition             : dedicated\n             RETRY pulse                   : SCK\n             serial program mode           : yes\n             parallel program mode         : yes\n             Timeout                       : 200\n             StabDelay                     : 100\n             CmdexeDelay                   : 25\n             SyncLoops                     : 32\n             ByteDelay                     : 0\n             PollIndex                     : 3\n             PollValue                     : 0x53\n             Memory Detail                 :\n\n                                      Block Poll               Page                       Polled\n               Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack\n               ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------\n               eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff\n               flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff\n               lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00\n               hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00\n               efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00\n               lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00\n               calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00\n               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00\n\n             Programmer Type : Arduino\n             Description     : Arduino\n\navrdude.exe: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14\n\navrdude.exe: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10\n             Hardware Version: 4744608\n             Firmware Version: 0.2\n             Topcard         : STK502\n             Vtarget         : 1.8 V\n             Varef           : 0.0 V\n             Oscillator      : Off\n             SCK period      : 0.1 us\n\navrdude.exe: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x01\navrdude.exe: initialization failed, rc=-1\n             Double check connections and try again, or use -F to override\n             this check.\n\navrdude.exe: stk500_disable(): protocol error, expect=0x14, resp=0x10\n\navrdude.exe done.  Thank you.\n\n<\/pre><\/div>\n\n\n<p>You see ser_drain(): and stk500_getparm(): errors.<\/p>\n\n\n\n<p>While searching for avrdude source code, I found one with Visual Studio support. Great, and thanks to Marius Greuel.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><a href=\"https:\/\/github.com\/mariusgreuel\/avrdude\">https:\/\/github.com\/mariusgreuel\/avrdude<\/a><\/p><\/blockquote>\n\n\n\n<p>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&#8217;ve added network support in ser_drain() function and added drain (flush old data) in stk500_getparm before sending new command.<\/p>\n\n\n\n<p>Below 2 points are modified.<\/p>\n\n\n\n<p><strong>ser_win32.c<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; first-line: 645; highlight: [647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662]; title: ; notranslate\" title=\"\">\nstatic int ser_drain(union filedescriptor *fd, int display)\n{\n#ifdef HAVE_LIBWS2_32 \/\/added serial_over_ethernet 2021.9.16 nefa\n    if (serial_over_ethernet) {\n        unsigned long l;\n        unsigned char buf&#91;8];\n        while (1) {\n            ioctlsocket(fd-&gt;ifd, FIONREAD, &amp;l);\n            if (l == 0) {\n                if (display) avrdude_message(MSG_INFO, &quot;&lt;drain\\n&quot;);\n                break;\n            }\n            net_recv(fd, buf, 1);\n            if (display) avrdude_message(MSG_INFO, &quot;%02x &quot;, buf&#91;0]);\n        }\n        return 0;\n    }\n#endif\n    \/\/ int rc;\n\tunsigned char buf&#91;10];\n\tBOOL readres;\n\tDWORD read;\n\t\n<\/pre><\/div>\n\n\n<p><strong>stk500.c<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; first-line: 1090; highlight: [1102]; title: ; notranslate\" title=\"\">\nstatic int stk500_getparm(PROGRAMMER * pgm, unsigned parm, unsigned * value)\n{\n  unsigned char buf&#91;16];\n  unsigned v;\n  int tries = 0;\n\n retry:\n  tries++;\n  buf&#91;0] = Cmnd_STK_GET_PARAMETER;\n  buf&#91;1] = parm;\n  buf&#91;2] = Sync_CRC_EOP;\n\n  stk500_drain(pgm, 0); \/\/added drain 2021.9.16 nefa\n  stk500_send(pgm, buf, 3);\n\n  if (stk500_recv(pgm, buf, 1) &lt; 0)\n\n<\/pre><\/div>\n\n\n<p>Below is exe with above fix, in case it may help someone who needs.<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/programresource.net\/images\/2021\/09\/avrdude-6.3.1.1.win64net.zip\">avrdude-6.3.1.1.win64net.zip<\/a><a href=\"https:\/\/programresource.net\/images\/2021\/09\/avrdude-6.3.1.1.win64net.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. IP address and port number are passed with net parameter. However, at this point (Sept, 2021), avrdude.exe &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3386,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[868],"tags":[870,1024,1023,1026,1025],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/programresource.net\/images\/2021\/09\/IMG_20210916_211858.jpg","jetpack_shortlink":"https:\/\/wp.me\/p3pJyQ-SN","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3397"}],"collection":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/comments?post=3397"}],"version-history":[{"count":2,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3397\/revisions"}],"predecessor-version":[{"id":3401,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/posts\/3397\/revisions\/3401"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/media\/3386"}],"wp:attachment":[{"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/media?parent=3397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/categories?post=3397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programresource.net\/en\/wp-json\/wp\/v2\/tags?post=3397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}