Leonardo auto-reset problem
I found a design flaw in how the Leonardo auto-reset works. A sketch can affect how the bootloader behaviors. This flaw can cause the bootloader to jump to the sketch and therefore never go into a mode where it can be reprogrammed using the auto-reset feature. For more information, see my linked thread below on the Arduino Forum.
I noticed that the code was based on the LUFA codebase, so I checked the latest release of LUFA to see if they had a similar problem. In my opinion they do, but the LUFA group doesn't think so. They recognized that the Arduino codebase had this problem but not the LUFA codebase. See the linked thread below for that correspondence.
http://arduino.cc/forum/index.php/topic,141812.0.html
https://groups.google.com/d/topic/lufa-support/hg_mO61G0mM/discussion
Still not fixed? https://github.com/arduino/Arduino/commit/344897301c486d569e6032a73faf4792ca5bcedf
More discussion https://github.com/arduino/Arduino/issues/2474
Please try HoodLoader2 for 32u4 and report your problems.
It'd also be useful if you post the OS you are using. I noticed linux sometimes opens the port at 1200 baud rate which makes it reboot. Then we have the modem manager etc. And on Windows we have other problems.
I think we can close this issue and move to the one you linked, because it describes the issue better and is most up to date.
@NicoHood the problem is that a patched bootloader is not compatible with the current bootloader and we have a lot of Leonardo boards in the wild.
I see:
#if MAGIC_KEY_POS != (RAMEND-1)
*(uint16_t *)(RAMEND-1) = *(uint16_t *)MAGIC_KEY_POS;
*(uint16_t *)MAGIC_KEY_POS = MAGIC_KEY;
#else
// for future boards save the key in the inproblematic RAMEND
// which is reserved for the main() return value (which will never return)
*(uint16_t *)MAGIC_KEY_POS = MAGIC_KEY;
#endif
how the IDE should determine the MAGIC_KEY_POS value?
Or maybe there are no compatibility issues and I'm missing something?
Its simple:
- Fix the bootloader (not only this issue, a lot of other bootloader issues as well).
- Make the bootloader also accept the old address, so new Addresses and old are both supported
- Add a submenu for leonardo aka "BootLoader" with v1.0 and 1.1
- As an alternative you could detect the bootloader with a special PID
Patching the bootloader isnt the problem. The patched bootloader is just better and accept both methods. The "confusion" could only happen in the IDE side, where you need to select "new bootloader" somewhere, do explicite fix this issue. However as described the old option would still work if you patch the bootloader correct.
Closing as duplicate of #2474 , continuing there