-
Notifications
You must be signed in to change notification settings - Fork 151
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
Attiny85: increase delay #983
Conversation
More details at https://forum.arduino.cc/t/usbtinyisp-from-ide/263885 Co-authored-by: Martino Facchin <[email protected]>
Well, all these proposed values look pretty arbitrary to me. The values that are currently in avrdude.conf reflect the numbers from the datasheet (or .atdf file), and they are pretty much the same (4 ms / 4.5 ms) for almost all newer AVRs. The Finally, the patch only affects the ATtiny85, but what about its smaller siblings (ATtiny45, ATtiny25)? While I have no doubt that these changes might have cured the symptoms of the person once submitting them, I think the actual issue must be somewhere else. |
For reference, delays similar to this PR are already present in the current avrdude.conf file. Here's a few: |
Maybe we can ask the users whether they also encounter issues with similar chips like ATtiny45 and ATtiny25, Probably they will have the same issue and it is just because ATtiny85 is much more popular than the other two. |
@mcuee BTW here's another report https://learn.adafruit.com/introducing-trinket/programming-with-avrdude |
Can anyone here even reproduce the problem with the ATtiny85? I can't, even using the same version of AVRDUDE and |
These are different families, which have indeed different delays described in their datasheet. As argued above, the delays in this proposal look completely arbitrary, and most of them don't even affect the programming tool used. That's why I question the complete proposal, unless someone can describe a scenario how to reproduce a problem with the ATtinyX5. Personally, I have been using these ATtinys quite a bit in the past, and never encountered problems with them. |
@ladyada would you or someone else from Adafruit mind checking whether this patch is still needed with the latest AVRDUDE from this repository to reliably upload to the Trinket and Gemma? This patch originated from Adafruit: arduino/toolchain-avr#21 |
I haven't used the ATtiny85 that much, but I've used the USBtinyISP programmer a lot with the ATtiny13, which was reported to have similar issues. I've never had any issues with the USBtinyISP when using the ATtiny13, and that's with "sensible" delay values. It may be that @ladyada knows why the original ATtiny85-based Adafruit Trinket needs such large delays, and if this somehow has later been fixed. BTW does anyone know where I can find the source code for the Trinket bootloader? |
Here it is: |
our notes say
probably this is due to USB transmission delays, we had timeout errors otherwise |
But see my analysis above: |
Hi @dl8dtl, I tried uploading to an Arduino Gemma with our patched version of the
And the uploaded code seems to work just fine on the board. By only setting
and the board does not seems to work. The interesting part is this one:
I get the exact same error. This experiment led me to think that indeed we need that delay. As @ladyada explained this is because that board do not use a programmer but instead when the mcu is powered on acts as a programmer itself for a few seconds using bit banging, after that runs the user program.
Probably you are right about this, and I don't know all the back-story since I was not part of Arduino at that point.
Probably yes, if they use the same kind of bootloader. Maybe a viable solution would be to add another entry in the |
Thanks for the feedback, it's welcome. My problem with changing any of that: these parameters are obtained from the Atmel definitions, and they are meant to apply to certain (Atmel-origin) programmers. If any particular implementation cloning that protocol needs more time, in my opinion, it's the responsibility of that implementation to adapt the timing accordingly. So if a bootloader needs 200 ms instead of the 4.5 ms defined by the datasheet, they are free to simply implement a longer timeout (and/or completely ignoring the incoming parameter). If you attach it to an Atmel/Microchip Studio, and declare it being an STK500, they are passing the exact same values down *) as AVRDUDE does. *) If not, it's indeed a bug in AVRDUDE. They are supposed to be the same. |
It seems to me the right solution is to create a new programmer type called |
Or just have the USBtiny code not use STK500 values at all, instead use fixed values inside. |
Good idea. |
Just use any larger value there. @umbynos can you give it a try whether 100000 (µs) is already sufficient, or does it really have to wait for 400 ms? |
Nope, with |
OK, then I suggest we simply change the wait time in the USBtiny implementation to 400 ms. |
@umbynos Do you want to change your PR that way, or do you want me to suggest a new one instead? |
@ladyada Is there any way to tell this bootloader apart from a real USBtiny programmer? If so, the extension of the wait time could be made dependant on that. |
Since I don't know the codebase that well, maybe it would be better if you could suggest a new one instead. |
So, the affected boards' bootloaders latch on to the Lines 636 to 639 in a5552f6
Going down the route of a computed chip erase time penalises large parts, eg, ATmega2560, when programmed with a proper usbtiny physical programmer, as the chip erase time would then be 10 s rather than the necessary 10 ms (or so). Maybe best to estimate needed delays with the target parts/boards, try them out and then use one fixed value that suits all target boards. |
And also, have a look at the proposed urprotocol #940 (comment), which is meant to help establish exactly what the bootloader is capable of. This should, if/once implemented into future AVRDUDE releases, enable boards like trinket to carry out happy bootloading with small resources (the corresponding prototype ATmega85 bootloader is 256 bytes albeit without EEPROM support). |
We now know that the ATtiny85 works with 400 ms delay, while it fails with 100 ms. Does that somewhat fit into this formula? |
128*4500 µs, so 576 ms. Considering it's an upper estimate and that the subsequent Future release fun: |
But I wouldn't just use the formula. I would cap it somehow. For an ATmega2560 this results in a 9.2 s pause that is hard to explain to users that use an actual (physical) programmer that can do the job in that many ms. |
I wish there were a method to tell a real USBtinyISP apart from a bootloader. I suggest a solution that uses extended arguments ( |
If we just need to differentiate USBtinyISP and the Arduino Gemma bootloader, then there is a simple way -- to use different USB VID/PID. USBtinyISP:
Arduino Gemma Bootloader
|
Good idea. |
BTW, if we also want to further differentiate the original Adafruit Trinket bootloader vs the USBTinyISP programmer, we can still use the USB Vendor Name and USB Device Name String. But I think this is not necessary if we use the Ref: https://github.com/adafruit/Adafruit-Trinket-Gemma-Bootloader/blob/master/usbconfig.h
USBtinyISP (it seems to me the compatible programmers all follow the
|
I don't think it's necessary to differentiate various bootloaders. So, if |
Thanks. I agree with this.
Yes. That is a good approach. |
This seems like an excellent idea |
We have a few good solutions here that each are better than increasing the part chip delay (which is for a different purpose)
Each method has advantages and disadvantages. The most general and most robust for me is 2. Implementation is not too hard and (I predict) will find good use otherwise. The slight disadvantage is a proliferation of the programmers, but not a high price to pay for a generic, clean and robust solution. @umbynos Would 2 be a suitable solution? I don't know what is involved in using different VID/PID but suspect this involves a new programmer entry in |
@stefanrueger As for the name, we can use something like |
Definitely should solve the problem
I think it should be "gemmaBoot": defined here. I don't know if VID and PID are needed but they are defined here. |
I have changed the label to enhancement -- to cater for the bootloader. And looks like Option 2 is the preferred way to go. So when @stefanrueger creates the new pull request, we can close this one. |
Just got one Tiny85 board to work with the Arduino_Gemma bootloader and I can reproduce the issue and I can confirm that 400ms delay works fine (Option 3). On the other hand, I understand that Option 2 is a better option. |
The problem with option 2 is that it would only be sufficient for a small device. As soon as someone has the idea to use that bootloader on a larger device, it will fail again. |
Just to confirm that I am queuing up work for a generic bootloader solution for all parts, large and small, in the coming weeks. |
BTW, today I got the chance to test usbasploader (based on USBAP) and it seems to work on the USBAP clones (ATmega8A version) well enough. Looks like it does not have the issues of the usbtiny based bootloader mentioned in this issue. |
Using the usbasploader bootloader to load the usbasp application:
Verified with another usbasp:
|
Closing because superseded by #1093. For further details, #1093 (comment) |
More details at https://forum.arduino.cc/t/usbtinyisp-from-ide/263885
Related conversation with @MCUdude umbynos@7c18d4b#commitcomment-73300758
Co-authored-by: Martino Facchin [email protected]