Custom avrdude with auto DTR reset and custom baud rate for Arduino boards

2013-02-14

In the context of a project involving the utilization of an ATmega2560 with a custom bootloader (predicated on the Arduino Mega bootloader using the stk500v2 protocol), it was found that the optimal baud rate for programming was 38400, given the use of an 8MHz crystal.

The default configuration of avrdude, when employing the -c stk500v2 programmer switch, does not instigate a pull down of the DTR line prior to programming. However, the specific requirements of the custom hardware necessitated the inclusion of this auto reset feature, as manual reset for each firmware update was not feasible.

To address this, the avrdude source was recompiled under MinGW, resulting in a custom build where the -c stk500v2 option now initiates a DTR/RTS pulldown.

The custom binary, inclusive of USB support via libusb, is available for download:

This custom build retains the functionality of the original avrdude, with the addition of the autoreset feature to the stk500v2 programming selection. This autoreset is not selectable, so if you might want to switch between DTR reset and the original behaviour, it might be best to keep two copies of the binary with different file names.

If you have a similar application where this might be useful, please feel free to download and use it.

The difference between the original source and the modified source is as follows:

$ diff avrdude-5.11.1 avrdude-5.11.1-stk500v2-autoreset-src
Common subdirectories: avrdude-5.11.1/doc and avrdude-5.11.1-stk500v2-autoreset-src/doc
diff avrdude-5.11.1/stk500v2.c avrdude-5.11.1-stk500v2-autoreset-src/stk500v2.c
1318a1319,1326
>   /* Clear DTR and RTS to unload the RESET capacitor
>    * (for example in Arduino) */
>   serial_set_dtr_rts(&pgm->fd, 0);
>   usleep(50*1000);
>   /* Set DTR and RTS back to high */
>   serial_set_dtr_rts(&pgm->fd, 1);
>   usleep(50*1000);
>
Common subdirectories: avrdude-5.11.1/windows and avrdude-5.11.1-stk500v2-autoreset-src/windows