QT Py SAMD21 Bootloader Protection

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py SAMD21 Bootloader Protection

Post by danhalbert »

I looked at the fuses on some other small SAMD21 boards, specifically a couple of Trinkeys. The last hex digit is "A", so the BOOTPROT setting is 0x2, which is 8kB, which is expected.

Could you take a picture of the label on the bag of the brand new QT Py M0 you just checked the fuse values on? You didn't load anything on this at all ever, is that right? It is fresh out of the bag?

User avatar
leafon
 
Posts: 32
Joined: Thu Sep 22, 2022 12:40 am

Re: QT Py SAMD21 Bootloader Protection

Post by leafon »

Hi Dan,

Here's a picture of the label of the batch of QT Py M0 we received:
QT_Py_M0.png
QT_Py_M0.png (980.39 KiB) Viewed 239 times
We didn't reprogram the boards. All we did was adding the headers on them. All the ones I checked has BOOTPROT = 0x7.
I ran https://github.com/adafruit/uf2-samdx1/ ... 3.14.0.uf2 on on one my QT Py's, and after running, the fuses are:
CODE: SELECT ALL
D800C772
FFFF005D
Perhaps my understanding of the BOOTPROT isn't correct. Since your QT Py already has BOOTPROT = 0x2, you wouldn't be able to program them with a new bootloader right?

After I updated the QT Py M0 using the file you linked "update-bootloader-feather_m0_express-v3.14.0.uf2", and read the flash using a J-Link, I still get the following fuses value:
fuses[0] = 0xD8E0C7FF;
fuses[1] = 0xFFFFFC5D;
Is this a wrong file intended for Feather M0? On the reflashed QT Py M0, I don't see the Neopixel changing colors or able to put the QT Py into bootloader mode by double clicking the reset button.

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py SAMD21 Bootloader Protection

Post by danhalbert »

Ack, very sorry, that was the wrong UF2. Use this one: https://github.com/adafruit/uf2-samdx1/ ... 3.14.0.uf2. You should still be able to double-click reset. If not I will figure out what to do here. I will put the wrong one on a QT Py M0 and see how to recover.
Perhaps my understanding of the BOOTPROT isn't correct. Since your QT Py already has BOOTPROT = 0x2, you wouldn't be able to program them with a new bootloader right?
BOOTPROT protects the bootloader area from casual overwrites. However, it's possible to override BOOTPROT programmatically and re-program the bootloader, and that is what the updater program does.

In the long run, you might consider switching to the QT Py RP2040, which has a UF2 bootloader in unchangeable ROM, and is a better board in most ways (except no DAC).

User avatar
leafon
 
Posts: 32
Joined: Thu Sep 22, 2022 12:40 am

Re: QT Py SAMD21 Bootloader Protection

Post by leafon »

Hi Dan,

No problem. I was able to recover the board by flashing it with the bootloader-QTPy_m0-v3.14.0.bin file located here: https://github.com/adafruit/uf2-samdx1/releases

However, after updating the board with the .UF2 file you provided: https://github.com/adafruit/uf2-samdx1/ ... 3.14.0.uf2
BOOTPROT.png
BOOTPROT.png (38.64 KiB) Viewed 234 times
I still see BOOTPROT = 0x7.

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py SAMD21 Bootloader Protection

Post by danhalbert »

What is in INFO_UF2.TXT in QTPYBOOT? It should show the latest version number.

I repeated what you did, and I see the fuse set to the correct value. I compiled my own test versions of update-bootloader and set BOOTPROT to various other values to make sure it was getting written properly (e.g. I set it to 0x5, and saw that in the fuses).

I am not using the J-Link to read the fuses. I have had problems with J-Link caching fuse values, which was extremely confusing. It was not clear whether it was gdb's or the J-Link software's fault, but it caused me considerable grief.

Could you try the update UF2 again? Make sure that QTPYBOOT reappears before you do anything else, to ensure it is finished. Then use this .uf2, which is just a (better) version of the Arduino sketch above; it prints the fuse values every two seconds. Don't rely on the J-Link to report the fuse values.
print_samd21_fuses.uf2
(512 KiB) Downloaded 2 times

User avatar
leafon
 
Posts: 32
Joined: Thu Sep 22, 2022 12:40 am

Re: QT Py SAMD21 Bootloader Protection

Post by leafon »

Thank you Dan.

Here's the content of the INFO_UF2.TXT:
UF2 Bootloader v3.14.0 SFHWRO
Model: QT Py M0
Board-ID: SAMD21E18A-QTPy-v0

Here's the serial output after updating with the UF2 file you provided:
NVM Serial.png
NVM Serial.png (92.37 KiB) Viewed 225 times

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py SAMD21 Bootloader Protection

Post by danhalbert »

I did the following:

1. Ran a hacked update-bootloader to set the fuses to exactly what your board is showing.
2. Verified that the fuses values matched yours (including BOOTPROT 0x7) using print_samd21_fuses.uf2
3. Ran the stock https://github.com/adafruit/uf2-samdx1/ ... 3.14.0.uf2.
4. Verified that BOOTPROT was reset to 0x2 after step 3.

So when you do 3 and 4, it appears BOOTPROT does not change and remains and 0x7. That is very mysterious. My QT Py M0's are all from an older batch, and yours are newer, per the bag label. I will inquire about this.

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py SAMD21 Bootloader Protection

Post by danhalbert »

One more thing: I would be interested in knowing if you ran the v3.13 updater whether INFO_UF2.TXT changed to show the previous version.

Run v3.13.0 update:
https://github.com/adafruit/uf2-samdx1/ ... 3.13.0.uf2
Look at Bootloader version reported in INFO_UF2.TXT. It should say: UF2 Bootloader v3.13.0 SFHWRO

Run v3.14.0 update:
https://github.com/adafruit/uf2-samdx1/ ... 3.14.0.uf2
Look at Bootloader version reported in INFO_UF2.TXT. It should say: UF2 Bootloader v3.14.0 SFHWRO

If it does not change, then something is strange.

User avatar
leafon
 
Posts: 32
Joined: Thu Sep 22, 2022 12:40 am

Re: QT Py SAMD21 Bootloader Protection

Post by leafon »

Hi Dan,

After I updated the board with https://github.com/adafruit/uf2-samdx1/ ... 3.13.0.uf2

The INFO_UF2.TXT says: UF2 Bootloader v3.13.0 SFHWRO

User avatar
leafon
 
Posts: 32
Joined: Thu Sep 22, 2022 12:40 am

Re: QT Py SAMD21 Bootloader Protection

Post by leafon »

Hi Dan,

I can ship you couple of the brand new QT Py M0 boards if you like.

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py SAMD21 Bootloader Protection

Post by danhalbert »

Thanks - could you contact [email protected], and arrange to return to NYC a couple of the QT Py's that are acting up? Ask them to do an RMA "FORPHIL". This is will be an actual RMA so that they get sent back to the engineering staff, and you'll get a refund. Send them the URL of this thread post as an authorization.

They are completely out of stock from the Adafruit factory -- otherwise we would do a check on the stock. I have ordered a couple from Mouser that hopefully will correspond to your bag label.

We know of nothing special about the chips on these boards that would cause this problem. Mine that work are vintage 2021. We would like to track this down.

Have you seen this on your oldest QT Py's, or did you only start buying them recently anyway?

We appreciate your help with this!

User avatar
leafon
 
Posts: 32
Joined: Thu Sep 22, 2022 12:40 am

Re: QT Py SAMD21 Bootloader Protection

Post by leafon »

Thanks Dan.

All the QT Py M0 boards we have were delivered in one batch on Aug 8th, 2022.

User avatar
leafon
 
Posts: 32
Joined: Thu Sep 22, 2022 12:40 am

Re: QT Py SAMD21 Bootloader Protection

Post by leafon »

Hi Dan,

Here are more details.

I made a board to connect the SWD interface on the bottom of the QT Py M0 to a 10-pin SWD connector.
QT Py Rescue.jpg
QT Py Rescue.jpg (242.07 KiB) Viewed 161 times
Using this adapter board, I can see on a "failed" QT Py M0, a section of the bootloader was over-written as "FF".
Bad Bootloader.png
Bad Bootloader.png (669.04 KiB) Viewed 161 times

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py SAMD21 Bootloader Protection

Post by danhalbert »

We saw this kind of thing on SAMD51, as I mentioned, but not on SAMD21. However, I think the fix is to add brownout checking to the bootloader, as was done for the SAMD51. It is bad, of course, because it does brick the board for anyone without programming hardware.

Can you describe the situation where you see this in more detail? Is it just plugging the boards into a host computer, or are the boards externally powered? What's the power-on sequence? For instance, do you have the board plugged into an adapter, and then you plug it into the wall, or otherwise power it up? Does it happen if you bobble the plugging in? I would like to try to reproduce this as consistently as possible, which may be difficult, or at least increase the probability of it happening.

We have seen some 5V adapters that have a noticeable hiccup in voltage when plugged in.

User avatar
leafon
 
Posts: 32
Joined: Thu Sep 22, 2022 12:40 am

Re: QT Py SAMD21 Bootloader Protection

Post by leafon »

In my case, the QT Py M0 is connected to another board using the headers. Both boards are powered with the 5V from a host computer. The SAMD21 itself is powered by the 3.3V regulator on the QT Py M0 board. So far, on 3 out of 200+ boards, the bootloader spontaneously became corrupted during power up.

Could you please update the bootloader FW to enable the brown out detector for SAMD21 in addition to enable the bootloader protection by default?

Thea described this problem clearly in this blog:

https://blog.thea.codes/sam-d21-brown-out-detector/

"The last stress test I wanted to put the hardware through was power cycling. I connected five units up to my bench supply and switched the power on and off at various intervals. After about 50 cycles, one of the modules stopped working. It's a weird feeling when you're happy that something you made has died!"

https://github.com/adafruit/uf2-samdx1/issues/170

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”