-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Arduino auto-reset via RTS to allow direct RTS-reset connection #1309
Conversation
Only when directly connected!! When connected via a cap, the magic starts less than a ms after Line 2245. See Typical C is 100 nF, typical R is 10k, so we are talking t = RC ~ 1 ms. Really no need to spend 50 ms each! Why the sleep in Line 2249? Time will march on regardless. Can I suggest // 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);
// 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((100+ur.delay) > 0)
usleep((100+ur.delay)*1000); // Wait until board comes out of reset Similar in stk500.c If you insist on changing the original 250 ms wait in arduino.c in Line 91 to 50 ms, I predict there will be trouble when executing two uploads to optiboot in quick succession $ avrdude -c arduino -qqp m328p -U blink.hex; avrdude -c arduino -qqp m328p -U blink.hex; Leave that 250 ms be. (Urclock deals with this by sleeping at exit for 200 ms if it had served optiboot). See my comment on this |
Actually, we know DTR/RTS has been set 0 (ie, high voltage) earlier, all we need to do is // 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); The sleep after that won't be necessary as draining input itself sleeps and getsync spends time ... And should we not also improve the other two serial programmers that reset the MCU board by plugging DTR/RTS?
|
I will say I am not so sure whether it is a good idea to change
|
Last weekend I played with the Falstad simulator. It corroborates my sketch above: below graph pulls DTR low for 20 ms (The circuit misses external clamp diode protection to Vcc. The chip doesn't have internal protection on the reset pin to allow High Voltage programming. The graph above neatly shows the spike to 2*Vcc when switching the DTR signal to Vcc again. With Vcc > 5V one needs the diode to prevent accidentally entering the HV mode.) |
Anyway, I pushed my suggested changes onto your PR, @mariusgreuel, so we can try them out. If things work out, I'd be keen to integrate this into avrdude because this is great to be able to use DRT/RTS directly on the reset pin! Your idea, @mariusgreuel, is a great improvement. |
I have tested some direct short cases using ATmega2560 and ATmega13A. I will carry out more tests for this to see if there are regressions for STK500 v1 related programmers later. |
No regressions for Arduino optiboot bootloader.
|
No regression for "Arduino as ISP" either.
|
Made the change for wiring.c as well, so STK500 v2 bootloaders should work with direct reset, too. Earmarked for the next mergefest (probably in the next days) so any objection speak up now |
Closes #1262
@stefanrueger Here is something to look at. I have not grasped the timing logic in urclock, but assuming the magic starts with releasing the reset line in line 2247, I figured 120 minus 50 for the extra wait?