/* Code Musings */

Using BOSSA to Flash an Atmel SAMD21

I recently started working with a Cortex M0+ board from MattairTech. Their MT-D21E board hosts an Atmel SAM D/C/L21 Cortex M0+ microcontroller and is compatible with the Arduino IDE.

Now, I don’t like using the Arduino IDE. I find it clunky and lacking in all the richness an actual editor can give you. A year ago I created an Arduino makefile project so that I could avoid using the IDE (and, by extension, their bloated libraries). I wanted to do the same for this Cortex M0+ board, but ran into issues.

The Cortex M0+ board doesn’t use avrdude to flash the code onto the device; it uses BOSSA instead. The usage of bossac is fairly straight forward:

But, bossac didn’t seem to like my device most of the time. I received a range of odd behaviour failing to find the device on /dev/ttyACM0 to the device being busy.

Frustrated, I spent a few hours searching and digging through the internet. There were a good number of websites stating that the device needs to be set to 1200 baud so that it can switch into the bootloader. This voodoo should be triggered via:

But, it doesn’t quite work all the time. So, instead, I started to poke through the Arduino source code to find out exactly what they did to properly trigger the bootloader. Their solution is to open the serial, set the boad rate to 1200, disable DTR, and finally close. I’d bet that the stty command doesn’t do this exactly and, therefore, cannot always reset the serial port.

The solution was to write a quick python script to do those steps exactly:

And that’s it. Run this script before calling bossac and it should do the job. Code is also available on github.

Leave a Reply