Skip to content

[AVR] Fix problems with USB CDC auto-reset #6055

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

Closed
wants to merge 4 commits into from

Conversation

MLXXXp
Copy link

@MLXXXp MLXXXp commented Mar 10, 2017

Address a problem where the bootloader magic key location could be restored before it was saved, and other issues, with a bootloader auto-reset invoked by USB CDC.

Discussed in issue #6033

MLXXXp added 4 commits March 10, 2017 16:34
In the USB CDC code to invoke an auto-reset, the magic key location could be
restored before it had actually been saved. The sketch would then have a
corrupted value at this location. This fix prevents the value from being
restored if it hasn't previously been saved.
The state of the watchdog timer is saved during a USB auto-reset and then
restored if the reset is aborted, in case the sketch is using the watchdog.
Instead of checking for the NEW_LUFA_SIGNATURE once in program memory and then
setting a flag which is used for further checks, a function is used that always
checks program memory directly.

If a flag is used, there's a slight chance that its location in RAM could fall
on MAGIC_KEY_POS. In this case, an aborted USB auto-reset sequence may fail.
An auto-reset invoked using USB CDC is triggered by the port closing
(when set to 1200 baud). Closing of the port is indicated by DTR going inactive.
There is no need to have auto-reset invoked by a CDC_SET_LINE_CODING command.
Only the CDC_SET_CONTROL_LINE_STATE command, which indicates a change in the
state of DTR, should be used.
@mastrolinux mastrolinux added the in progress Work on this item is in progress label Mar 10, 2017
@facchinm
Copy link
Member

@ArduinoBot build this please

@facchinm facchinm added Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer labels Mar 13, 2017
@facchinm facchinm added this to the Release 1.8.3 milestone Mar 20, 2017
@az0uz
Copy link

az0uz commented Mar 21, 2017

I like the Idea of having the possibility to use Watchdog with 32u4 based arduino.

This patch doesn't work if you call wdt_reset() in the user code faster than one time every > 120ms (reset time in the CDC driver).
If you do so, the mcu will never reset to let you upload a new sketch.

@MLXXXp
Copy link
Author

MLXXXp commented Mar 21, 2017

@az0uz

This patch doesn't work if you call wdt_reset() in the user code faster than one time every > 120ms

This is being discussed in PR #6064.

@facchinm
Copy link
Member

Closing as merged in https://github.com/arduino/ArduinoCore-avr

@facchinm facchinm closed this Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) in progress Work on this item is in progress USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants