0

trinket M0 bootloader on custom board
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

trinket M0 bootloader on custom board

by johnswenson1 on Tue May 21, 2019 8:38 pm

I'm designing a large custom board with a bunch of complex chips which require register programming to run properly. So far I've been using SPI from trinket M0 boards to do the programming. I'm now designing the final production board and will be including raw SAMD21 chips to do this (programmed with SWD). We would like customers to be able to perform updates in the field so I'm including a micro USB jack connected to the SAMD21.

The Adafruit bootloader is the coolest thing on planet for doing this, plug in a USB cable and it shows up as a pseudo drive, there is nothing easier than this. So I REALLY want to use the Adafruit bootloader. I do have some questions about using this.

My first question concerns how to get into bootloader mode. The way that I know of to do this is to double click a reset button, but this has to be done very quickly. With the trinket M0 I have found that this is very difficult to do. I have a feeling this would confound a lot of our customers. The generic SAM-BA bootloader uses a pin pulled down, I like this much better, is it possible to do this with the Adafruit bootloader? My partner says what he would like is just plugging in the USB cable goes into bootloader mode. We are not using the USB jack for anything else so there should be no conflict. The VBUS pin from the jack could be connected to a pin (with level shift of course) to signal boot loader mode. That would be ideal.

So far I have been writing my code using arduino, I presume the application is all compiled such that it works with the Adafruit bootloader so I wouldn't have to do anything for it. I will most likely be using the IBDAP you sell using OpenOCD via SWD to program the raw chip so I will need to include the bootloader and application code from arduino. I'm sure OpenOCD has a way to do this, is there a file from the arduino IDE that is what I need to use in the programming step? The manufacturing people REALLY do not want to load the bootloader THEN use USB to load the application code, they want to do it all at once.

I've read the license.txt so I presume this is all legal, there is no problem including the text of this file in our customer documentation.

Thanks,

John S.

johnswenson1
 
Posts: 8
Joined: Wed Aug 01, 2018 1:06 am

Re: trinket M0 bootloader on custom board

by adafruit_support_mike on Wed May 22, 2019 5:30 am

Props where due, the UF2 bootloader was created by an engineer at Microsoft:

https://makecode.com/blog/one-chip-to-flash-them-all

We have our own fork of the project, but praise for the awesome goes to mmoskal.

johnswenson1 wrote:My first question concerns how to get into bootloader mode.

Strictly speaking, the bootloader launches every time you click the reset button. It stores a timestamp so it can detect whether the button was single-clicked or double-clicked, but you can change that if you're up to reading & modifying the code.

The UF2 interface also supports rebooting the chip when you drop new files on the virtual filesystem. That's how CircuitPython works.

johnswenson1 wrote:The manufacturing people REALLY do not want to load the bootloader THEN use USB to load the application code, they want to do it all at once.

That's perfectly doable.

When you program a raw microcontroller, you tell it where to store the incoming data in its Flash array. The bootloader goes in a memory-protected section that can't be overwritten while uploading new code, and any non-bootloader code goes to the same blocks the bootloader will write when it uploads something new.

You'll have to work out the specific details for whatever programming toolchain you want to use.

johnswenson1 wrote:I've read the license.txt so I presume this is all legal, there is no problem including the text of this file in our customer documentation.

That's all we require, and honestly will save you some headaches down the road. When your customers start asking low-level questions about the bootloader, you can say "ne moy tsirk, ne moya obez'yana" and point them to us.

adafruit_support_mike
 
Posts: 57856
Joined: Thu Feb 11, 2010 2:51 pm

Re: trinket M0 bootloader on custom board

by johnswenson1 on Wed May 22, 2019 4:02 pm

Thanks Mike,
I took a look at the source code and this looks very easy to change to "enter bootloader monitor when USB is plugged in" behavior. The rest I should probably be able to figure out.

This looks very doable. I found an Adafruit tutorial on compiling the bootloader so that will help a lot.

I might even try the Raspberry PI as debugger tutorial, I can set one all up to do everything, give it to production and they can access it over the LAN from whatever computer they have there.

Thanks again,

John S.

johnswenson1
 
Posts: 8
Joined: Wed Aug 01, 2018 1:06 am

Please be positive and constructive with your questions and comments.