adafruit / uf2-samdx1

MSC bootloader (based on UF2) for SAMD21
Other
210 stars 182 forks source link

Lessons learned after Fuses have gone bad(=0xffffffff) #107

Closed msperl closed 4 years ago

msperl commented 4 years ago

A few comments after my expedition into feather bootloader debugging:

One of the observations that I have had after erasing and flashing the bootloader Of a feather-m0 with the jlink-flash Makefile target was that I somehow managed to set both user fuses to 0xffffffff.

The effect was that the feather in boot loader mode was resetting every second or so because of the hard enabled watchdog fuse. This was observable on Linux as disconnects on the usb bus and then a reconnect message in domestic. Just looking at the led showed a bit of dimming which was aborted and turned of and then the thing repeated.

It took me quite some time to figure this out and then a windows machine with Atmel studio to configure the fuses correctly (not to mention: research into what are the right fuse values).

So here maybe a few things for improvement:

All of this would have helped me resolve the issue quicker...

dhalbert commented 4 years ago

Thanks for your issue. There is already fuse reset code in selfmain.c, which is used by the bootloader updater, but it should probably be added to the regular bootloader main.c as well. We understand this pretty well, and I have a number of bootloader improvements and bug fixes in process. We;'ve had more trouble writing all 1's to the SAMD51, but on that chip the watchdog interval is long enough when set to all 1's that it's possible to run the updater. On the SAMD21 the interval is much shorter, but setting the flags to all 1's was much rarer, so that fuse reset code was not well tested.

msperl commented 4 years ago

Still I would recommend that all this is documented so that it can get found quickly if this is ever seen by a different user...

dhalbert commented 4 years ago

Yes, I agree, though it's hard to diagnose in some cases. I need to pinpoint the exact symptoms on different boards. That is all part of what I hope to fix and document while working on the bootloader in the ner future.

dhalbert commented 4 years ago

In the SAMD51 case, I have some short Arduino programs to print out the fuse values. For SAMD21, I'm not sure if it would be possible to load these. Hence we need bootloader fixes.

msperl commented 4 years ago

At least on the m0 feather the diagnostics of "dimming and then stop" as well as the observations on the USB bus that there are disconnects are an easy indication that something has gone bad with the fuses...

just in case setting some watchdog resets in the code should also help getting to that point...

finson commented 4 years ago

I got excited by the Zephyr - Adafruit announcement and decided to explore a little bit. Using Mac OS and the various tutorials from Adafruit and Zephyr, I got all the way to "west flash" and then ran into a series of issues actually trying to burn code to my Feather M0 Basic Proto. Long story short, I finally got Blinky running using bossac, however double click reset now drops into boot loader mode for about 500 ms, then Blinky runs again. Not bricked, but not helpful, either. I have a jlink and I expect I'll be able to restore a working boot loader once I get it configured, but I wanted to second the suggestion above that the documentation highlight the effects of corrupting the fuses and provide relatively clear help on how to fix the issue. (I'm not complaining, I recognize that I shot myself in the foot while blundering around!)

baebjr commented 4 years ago

I second that! BTW awesome work, thank you very much!

dhalbert commented 4 years ago

If the fuses get set to all 1's the watchdog ALWAYS-ON bit gets set on reset, and so we can't clear the watchdog timer programmatically. I am trying to squeeze in some fuse reset code that will detect the fuses being all 1's, and reset them to some reasonable values. But we are very close to being out of space on the SAMD21 bootloader.