Article thumbnail

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

14 February, 2013Arduino, Electronics

I’ve been working on a project where I have been using a ATmega2560 with a custom bootloader (based on the Arduino Mega bootloader using the stk500v2 protocol). As I was using a 8MHz crystal, it was best that I used a baud rate of 38400 for programming.

By default with avrdude, when using the -c stk500v2 programmer switch, it does not pull down the DTR line prior to programming, however for my custom hardware, I was needing this auto reset feature as it was not possible to keep pressing the reset button for a firmware update.

As a result, I have recompiled the avrdude source under MinGW, for a custom build where the -c stk500v2 option now performs a DTR/RTS pulldown.

You can download the custom binary here (includes USB support via libusb):

This should have the same functionality as the original avrdude, but with just the autoreset feature added 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.

Difference between orignal source and modified source:

$ 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
© Andy Gock 2009−2023