Merge pull request #1309 from mariusgreuel/pr-auto-reset

Change Arduino auto-reset via RTS to allow direct RTS-reset connection
This commit is contained in:
Stefan Rueger
2023-03-21 23:50:20 +00:00
committed by GitHub
4 changed files with 32 additions and 17 deletions

View File

@@ -85,13 +85,22 @@ static int arduino_open(PROGRAMMER *pgm, const char *port) {
return -1;
}
/* Clear DTR and RTS to unload the RESET capacitor
* (for example in Arduino) */
// This code assumes a negative-logic USB to TTL serial adapter
// Set RTS/DTR high to discharge the series-capacitor, if present
serial_set_dtr_rts(&pgm->fd, 0);
usleep(250*1000);
/* Set DTR and RTS back to high */
/*
* Long wait needed for optiboot: otherwise the second of two bootloader
* calls in quick succession fails:
*
* avrdude -c arduino -qqp m328p -U x.hex; avrdude -c arduino -qqp m328p -U x.hex
*/
usleep(250 * 1000);
// Pull the RTS/DTR line low to reset AVR
serial_set_dtr_rts(&pgm->fd, 1);
usleep(50*1000);
usleep(50 * 1000);
// Set the RTS/DTR line back to high
serial_set_dtr_rts(&pgm->fd, 0);
usleep(50 * 1000);
/*
* drain any extraneous input
@@ -106,7 +115,6 @@ static int arduino_open(PROGRAMMER *pgm, const char *port) {
static void arduino_close(PROGRAMMER * pgm)
{
serial_set_dtr_rts(&pgm->fd, 0);
serial_close(&pgm->fd);
pgm->fd.ifd = -1;
}

View File

@@ -97,10 +97,12 @@ int stk500_getsync(const PROGRAMMER *pgm) {
for (attempt = 0; attempt < max_sync_attempts; attempt++) {
// Restart Arduino bootloader for every sync attempt
if (strcmp(pgm->type, "Arduino") == 0 && attempt > 0) {
serial_set_dtr_rts(&pgm->fd, 0); // Set DTR and RTS low
usleep(250*1000);
serial_set_dtr_rts(&pgm->fd, 1); // Set DTR and RTS back to high
usleep(50*1000);
// This code assumes a negative-logic USB to TTL serial adapter
// Pull the RTS/DTR line low to reset AVR: it is still high from open()/last attempt
serial_set_dtr_rts(&pgm->fd, 1);
usleep(20*1000);
// Set the RTS/DTR line back to high
serial_set_dtr_rts(&pgm->fd, 0);
stk500_drain(pgm, 0);
}

View File

@@ -2237,14 +2237,18 @@ static int urclock_open(PROGRAMMER *pgm, const char *port) {
if(serial_open(port, pinfo, &pgm->fd) == -1)
return -1;
// Clear DTR and RTS to unload the RESET capacitor
// This code assumes a negative-logic USB to TTL serial adapter
// Set RTS/DTR high to discharge the series-capacitor, if present
serial_set_dtr_rts(&pgm->fd, 0);
usleep(20*1000); // 20 ms is ample for dis/charging the cap from reset to DTR/RTS
// Set DTR and RTS back to high
usleep(20*1000);
// Pull the RTS/DTR line low to reset AVR
serial_set_dtr_rts(&pgm->fd, 1);
usleep(20*1000);
// Set the RTS/DTR line back to high
serial_set_dtr_rts(&pgm->fd, 0);
if((120+ur.delay) > 0)
usleep((120+ur.delay)*1000); // Wait until board comes out of reset
if((100+ur.delay) > 0)
usleep((100+ur.delay)*1000); // Wait until board comes out of reset
pmsg_debug("%4ld ms: enter urclock_getsync()\n", avr_mstimestamp());
if(urclock_getsync(pgm) < 0)
@@ -2256,7 +2260,6 @@ static int urclock_open(PROGRAMMER *pgm, const char *port) {
static void urclock_close(PROGRAMMER *pgm) {
serial_set_dtr_rts(&pgm->fd, 0);
serial_close(&pgm->fd);
pgm->fd.ifd = -1;
if(ur.bloptiversion) // Optiboot needs a pause between two successive avrdude calls

View File

@@ -175,6 +175,9 @@ static int wiring_open(PROGRAMMER *pgm, const char *port) {
serial_set_dtr_rts(&pgm->fd, 1);
usleep(50*1000);
/* Set high, so a direct connection to reset works. */
serial_set_dtr_rts(&pgm->fd, 0);
}
/* drain any extraneous input */
@@ -188,7 +191,6 @@ static int wiring_open(PROGRAMMER *pgm, const char *port) {
static void wiring_close(PROGRAMMER * pgm)
{
serial_set_dtr_rts(&pgm->fd, 0);
serial_close(&pgm->fd);
pgm->fd.ifd = -1;
}