Load Firmware

The SAMD21 MicroPython port is currently in an experimental / beta state for early testing. Not all MicroPython modules are implemented and there are likely bugs or other issues!

Download Firmware

To get started you'll need to download a release of the SAMD21 MicroPython firmware from its home on GitHub.  Alternatively you can build the firmware from scratch, but if you just want to get started quickly use the prebuilt firmware from a GitHub release.

Go to the SAMD21 MicroPython releases page and download the latest .bin file for your board.  Currently the Arduino Zero and Feather M0 boards are supported and have prebuilt firmware images.

As of the time of this guide's writing the current SAMD21 MicroPython port version is: v1.8.4-20161014

Download BOSSA

Once you have a firmware image you'll need to download a special version of the BOSSA tool that can load firmware on SAMD21 boards.  This tool is actually used internally by the Arduino IDE when it programs these boards, however you can use it yourself to load custom firmware like the SAMD21 MicroPython port.

Be aware you must use this special 1.7.0 or higher version of BOSSA to program SAMD21 boards!  If you find an older version of BOSSA it won't work because it doesn't support the SAMD21 chip.

Go to the BOSSA GitHub releases page and download the latest release for your platform (for Windows you want the mingw32 version).  You might need a tool like 7zip to open the .tar.gz archive.  Once unarchived you should find a bossac command line executable tool.

Open a terminal and navigate to the folder with the bossac tool.  Then check the tool runs by running it with the --help option:

bossac --help

Or if you're using Linux or Mac OSX you'll need to add a ./ to specify that bossac is run from the current directory like:

./bossac --help

Make sure you see BOSSA version 1.7.0 or higher!  If you see a lower version then you accidentally downloaded an older version of the tool and it won't work to flash SAMD21 chips.  Go back and grab the latest release from this BOSSA GitHub repository as mentioned above.

Flash Board

Once you have the firmware and BOSSA tool you're ready to flash the firmware onto the board.  Follow the steps below to flash the firmware for an Arduino Zero or Feather M0 board.

Feather M0

For a Feather M0 board (including all variants like Feather M0 proto, AdaLogger, Bluefruit, RFM69, etc.) you need to put the board in a special bootloader mode before flashing firmware.  Plug in the board and 'double click' the reset button.  You should see the pin #13 LED start to fade on and off to signal that the bootloader is running.  Once you see the bootloader running skip down to the BOSSA flash command below.

Also be sure you've followed the learn guide for your Feather M0 board to setup the Arduino IDE and install any necessary drivers.  In particular Windows will need drivers installed before you can flash the Feather M0.  Linux and Mac OSX should be usable without any extra driver install.  Be sure you can use and program your Feather M0 with Arduino before diving into loading MicroPython--this will help you make sure the board is working as expected before complicating things with custom firmware.

Arduino Zero

For the Arduino Zero you don't need to do anything special to enter the bootloader.  However make sure you've plugged in the board using the native USB port and not the programming port.

One special note, if you're using the Arduino M0 Pro from Arduino.org you'll need to replace its bootloader with the Arduino Zero bootloader so it can work with BOSSA.  To do this install the Arduino/Genuino Zero board in the Arduino IDE board manager and then follow these steps to burn the Arduino Zero bootloader (using the programming port on the board).  Once you've loaded the Arduino Zero bootloader you should be able to use the M0 Pro with BOSSAC as described below.

BOSSA Flash Command

With your board plugged in and running the bootloader (for Feather M0 boards as mentioned above) you're ready to flash the SAMD21 MicroPython firmware onto the board.  Copy the firmware .bin file to the same directory as the bossac tool, then in a terminal navigate to that location and run the following command:

Flashing new MicroPython firmware will delete all files on the board's filesystem! Backup files you wish to keep and restore them after the flash.
bossac -e -w -v -R -p PORT_NAME firmware.bin

Remember on Linux & Mac OSX you need to add the ./ to the front of the bossac command!

Change PORT_NAME to the name of the serial port for your board.  On Windows this will be something like COM4, COM5, etc. (look in Device Manager for the list of all serial ports).  On Mac OSX this will be something like tty.usbmodem143411 (run ls -l /dev/tty.usbmodem* to list all the serial ports).  On Linux this will be something like ttyACM0, ttyACM1, etc. (run ls -l /dev/ttyACM* to list all the ports).  Note that on Mac OSX and Linux you don't specify the full /dev/tty... name of the device, instead you just specify the name after the /dev/ part of the path.

Also change firmware.bin to the name of the firmware .bin file you downloaded.

If you're using the Vagrant VM described later to build SAMD21 MicroPython firmware be sure the VM is halted and not running or else it might 'steal' the serial port from your host machine!

Finally note on Linux you might need to run as root with the sudo command if your user doesn't have access to the serial port.  If you see an error like the device can't be found then try running with sudo in from of the ./bossac command.

After BOSSA loads the firmware you should see output similar to the following:

Access REPL

Once the firmware is loaded you're ready to access the serial REPL to run MicroPython code.  Note that on Windows you might need to install this CDC serial driver from PJRC to make the board accessible as a COM port.  For Linux and Mac OSX no driver is necessary to install.

Using the serial REPL with SAMD21 MicroPython is just like using it with other MicroPython boards.  See this MicroPython serial REPL guide for details on using tools like screen and putty to access the REPL.  SAMD21 MicroPython uses the same 115200 baud rate for the REPL as other MicroPython boards.

For example on Linux or Mac OSX you can use the screen command to open the REPL:

screen PORT_NAME 115200

Where PORT_NAME is the name of the serial port for the board (see the BOSSA flash command section above for how to list the serial ports).

Screen should open the port and if you press enter you should see the Python >>> REPL prompt.  Try typing in a print('Hello world!') command and pressing enter to see MicroPython working on the SAMD21!

On Windows use the putty program as mentioned in the MicroPython serial REPL guide.

Woo hoo, that's all there is to loading SAMD21 MicroPython on a board!  Once you see MicroPython running you can start using it just like other MicroPython boards.  Tools like ampy can load files on the board's file system and even run scripts.

Be sure to read the quick start guide on supported modules so you know what is currently supported by SAMD21 MicroPython!

Revert Back to Arduino Sketches

If you'd like to revert back to using your SAMD21 board with Arduino it's as easy as using the Arduino IDE to program the board again.  For Feather M0 boards you might need to 'double click' the reset button to manually start the bootloader, then program the board from Arduino.  For Arduino Zero boards the programming port and Atmel EDBG programmer type are guaranteed ways to always reprogram a board regardless of what it was previously running.

Should you ever want to go back to MicroPython just follow the steps on this page again!

Last updated on 2017-01-05 at 05.23.07 PM Published on 2016-10-17 at 05.28.02 PM