-
Notifications
You must be signed in to change notification settings - Fork 141
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
wiring: set reset discharge time to 80ms #1504
Conversation
Geeetech GT2560 boards [1] use 1uF capacitors in their DTR/RESET line and 50ms seem to be a tad too short. 80ms works well (here). fixes avrdudes#1503 [1] https://www.geeetech.com/wiki/images/d/d3/Hardware_GT2560_RevA%2B.pdf
Great to know this fixes comms with your board, and thanks for the PR! @dl8dtl @MCUdude @mcuee @mariusgreuel What do we do about other boards with a 2 µF, 10 µF, ... 1 mF cap between DTR and Reset?! OK, I realise there has to be a limit in what board design AVRDUDE can support (and to which waiting times we can subject applications to). Is it worth our while to introduce an |
100nF is the norm, but some boards have apparently used 1uF, as this worked with older versions of Avrdude.
That would be a good idea. Perhaps name the flag so it's a little more self-explanatory, like |
Since this is a per-board setting, how about introducing a config file parameter that can be adjusted per board definition? |
You guys are quick to respond :) As I mentioned in #1503 I haven't thought this through at all and just posted this PR to show what works for me. To answer the question of @stefanrueger about errors I've seen, it was plain "timeout error"s right at the first recv in getsync(). For another thing, would you mind explaining or pointing me somewhere how that reset with serial cap stuff works. I can't quite understand it... |
Technically, we only have
Plus: keeps the command line clean (use |
@diresi These reset circuits are not for the faint-hearted, and some hardware people I have spoken to roundly reject the plucking-a-cap method to create a reset pulse. Have a look at this simulation or get some popcorn and read the discussion in #1262 and #1309. |
I thought about it in the past minutes and think I might get the idea, which also would explain the positive spike when setting DTS again (my board apparently doesn't have any diodes there and it shows). Thanks! |
Thanks, so it would be this line? Line 717 in 8ed9615
The reason I ask is that it is all well and good if we have a mechanism to cater for various boards, but we should have a mechanism to tell a user who experiences problems what they might try to counter them. So, if we can give some hint in the right error message that would be useful. |
@diresi BTW, it will not be the cap alone that delays the board coming out of reset. Some fuse settings delay the MCU coming out of reset for a large start-up time (more than 65 ms) to give the oscillators time to settle down. For a list type
If SUT is large then AVRDUDE's first synch command won't be picked up by the MCU (still effectively in reset) and the expected response won't be coming forth. Hence, the timeout. @dl8dtl Given that it's a combination of board hardware and SUT fuse setting, I now tend towards a |
Thinking a bit more about this, I predict this PR won't help in case the cap C9 was bridged, ie, DTR directly connected to RESET. Originally, #1309 wanted to support programming boards with such a direct connection. For that one would need a (variable?) Lines 182 to 186 in 8ed9615
@mcuee @diresi Could you test that? @mcuee you might need a large SUT fuse setting, eg, |
You still need a small Now, if you had had a direct DTR/RESET connection (bridge C9), then you'd need a bit more than |
I don't know if the wiring bootloader reads the fuses (a bootloader defo cannot write them), but if it does, then you'd see your fuse settings via |
I still had the 50ms usleep in line 183 and also added 80ms in line 187, if that's what you mean. The
|
Good, so assuming a 16 MHz external quartz the MCU's SUT is 65 ms + 1 ms (for 16k extra cycles). This means the MCU will jump to the bootloader 66 ms after the reset signal is no longer active, which is around 10-11 ms after line 182, ie, when DTR physically pulled low, which means setting it to 1 as it's an active low logic. So makes sense that you'd have to wait at least these 77 ms after line 182. What I don't understand, is why it matters when DTR is released again. That, in my mind, could be anytime after the code has waited an initial 20 ms after line 182 (your scope vividly shows RESET is no longer active then). I cannot explain why keeping 50 ms in line 183 and adding 80 ms in line 187 does not work. Additional sleep in line 187 (within reason) should not matter. Or does it? Hmm, that might depend on the receive timeout setting. What happens if the code sleeps 30 ms in line 187 and keeps 50 ms in line 183? |
I think this is what I tried earlier, isn't it? avrdude was sleeping for 50ms in line 183 and some additional 80ms after setting DTR high again in line 186. Do you think changing the latter to only 30ms would make a difference? I just tried that again to make sure I didn't mess up earlier, but what can I say ... doesn't work :) |
In case the receive timeout is set to a short time, yes. Other than this, it should not matter if the code sleeps 80 ms after plucking DTR (initiating reset) and then releasing DTR or to sleep 50 ms, release DTR and then sleep 30 ms. If it does, I would not know why. Another idea: What's Vcc? If > 5.5 V then the > 11 V peak might trigger HV programming. |
Good point, but isn't this risk an arduino HW issue and not an avrdude SW topic. |
Sure! This PR wants to change a timing, which helps one specific board, and I'd like to understand what the actual cause for the underlying issue is and exactly what the ramifications for other boards are. Worst case for this PR is that it works for one board, but all hell breaks loose for a gazillion of other boards. @mcuee does a great job in testing some m2560 boards with wiring bootloader against regression, and I want to have some credible understanding of what happens... Trouble is, I don't! I just checked that |
Sorry for the delay, I can't play around all day, can I? :-) I had a quick Vcc measurement and it really is 5.6V. It's attached to a RPi3 via USB but also has its own power supply, idk how that mixes together in detail. I'll try adding surge(?) diodes later to confirm or not. |
And yes, timeout errors are reported after several seconds each, 5s sounds pretty realistic. |
I always use a BAT54S diode connected to VCC and GND, to prevent positive or negative voltage doubling. A design without a clamping diode of some sort is something I'd consider "unsafe", as you might accidentally trigger high-voltage programming mode, as pointed out earlier in this thread. Here's a snippet of the USB to serial part of this ATtiny board I've designed (for ATtiny13/25/45/85), where VCC can be either 3.3 or 5V depending on the on-board target voltage switch. |
Any simple clamp diode will do, see recommended AVR reset circuit |
Should be taken care of by the internal clamp diode |
That's not great in terms of user experience. |
I can now confirm that it is HV programming mode. Adding a random clamp diode (that I had lying around) makes RESET max out at some 6.5V or so and fixes the whole problem, vanilla avrdude 7.2 works well then. I understand that this leaves open the whole discussion about what and how to fix but I trust that you'll take it from there (and I'm sure I'm way out of my league already). Thanks everyone and especially @stefanrueger for the help so far, I had a fun day, learned quite something and fixed my problem all at the same time! And finally have some justifications for having bought a scope in the first place :) |
Sounds good to me. Allows for a per-programmer default value that can be overridden on the commandline for pathological cases. |
du-oh, I never thought about that :-/ |
Implemented in PR #1505 | I can now confirm that it is HV programming mode. @diresi That's interesting to know. I believe Vcc = 5.6 V is out-of-specs for the ATmega2560, and putting a board briefly into HVPP through plucking the DTR/RTS lines is not something that AVRDUDE can do a lot about. I actually do not know why increasing the |
Standard AVR reset circuits deploy a connection from the DTR/RTS line of a USB-to-serial chip to the AVR via a small capacitor, see https://onlinedocs.microchip.com/pr/GUID-F626284A-58F0-4C25-A6F3-0EA5054F3E2B-en-US-6/index.html?GUID-B80B25FF-E9D7-4766-B562-DA197B8B938C Setting DTR/RTS low once will issue a reset. Setting this signal high again after a short time ensures that a direct connection DTR/RTS to reset also works. The duration of pulling DTR/RTS low must be relatively short, say RC/10, in order to avoid a reset spike above Vcc. If Vcc exceeds 5.5 V then a full 2 Vcc reset spike can potentially trigger HV programming. See also - avrdudes#1504 (comment) - avrdudes#1505 (comment)
Geeetech GT2560 boards [1] use 1uF capacitors in their DTR/RESET line and 50ms seem to be a tad too short. 80ms works well (here).
fixes #1503
[1]
https://www.geeetech.com/wiki/images/d/d3/Hardware_GT2560_RevA%2B.pdf