Atmel Studio 7 and SAMD21 – ARM Cortex M0+

Having used the Atmel Studio IDE for some years for the AVR 8 bit microcontrollers, it was time to migrate to ARM 32 bit, so I bought a low-cost ARM M0 board from Ebay, the WeMos (RobotDyn) M0-mini ( Atmel SAMD21G18A ARM M0+ ). Many SAMD21G18A based boards without the EDBG chip will work OK with the following description, including Sparkfun samd21 mini breakout, Arduino MKRZero, Adafruit Feather M0, Seeeduino M0+, Seeeduino Xaio. The RobotDyn M0-mini board shown below is close to a 1:1 copy of the Sparkfun samd21 mini breakout board. Schematics for both boards is in this .zip file: Board_schematics

This Robotdyn/WeMos type of SAMD21 board holds the 10 pin SWD header (Cortex debug) to be seen next to the reset button at the right side of the picture above. To flash the SAMD21G18A, I used the J-Link EDU mini , that is used for non-commercial purposes only. The software for the J-Link EDU mini integrates nicely with Atmel Studio 7, so connecting the J-Link EDU mini to the onboard SWD header makes it possible to flash output files from Atmel Studio 7. To use the SAMD21 board directly off the Atmel Studio IDE with just an USB cable, a suitable bootloader must be inside the MCU.I made a custom bootloader version from the Arduino MKRZero board to be used with the Robotdyn/WeMos board. The description on how to make a customized Arduino compatible SAMD21 bootloader can be found here:  SAMD21 bootloader.  The following steps apply to Win10 x64 as the PC OS.!

Steps needed to flash the bootloader and to set up Atmel Studio to use the bootloader to do the flashing:

  1. Connect the SAMD21 board to the PC via the USB cable. At this point the type of boot-loader installed, if any ! , can be tested.
  2. Go to Control Panel -> Device manager -> Ports ( COM and LPT )
  3. Press the board Reset button twice ( double tap ) to see if a new COM port shows up.
  4. If you see a new COM port, keep the COM port number in mind, and the steps 5-10 can be skipped.!
  5. A bootloader need to be programmed due to the missing COM port from step 1..3.  As mentioned above, my customized bootloader is used, here it is as a zipped file: SAMD21 customized bootloader.
  6. Download and install Atmel Studio IDE ( I used version 7.0.2397 ) from here:  Atmel Studio download
  7. Connect the J-Link EDU mini to the SAMD21 board 10 pin SWD header:
  8. Add power to the board via the USB connector. In Atmel Studio, select Tools -> Device Programming . Tool as J-Link . Device as SAMD21G18A . Click Apply . Choose Memories and use the bootloader .hex file from step 5. Click Program to flash the bootloader:
  9. Disconnect the J-Link EDU mini after flashing the bootloader. The next steps show how to set up Atmel Studio to transfer output files to the bootloader via the USB connection. During the file transfer, the bootloader flashes memory.
  10. Repeat the steps 1, 2 and 3 to get the virtual USB COM port number from Windows Device Manager.
  11. The flash program BOSSA for SAMD21 is needed to flash off from Atmel Studio directly, in this case, the installer file bossa-x64-1.9.1.msi . Download and install BOSSA from here: BOSSA download
  12. In Atmel Studio, create a new GCC C Executable project for SAMD21G18A.
  13. As a demo program for main.c , I use this simple Blink program: Blink test
  14. As the Arduino bootloader expects the application from the IDE to start at address 0x2000, the Atmel Studio gcc Linker must be set up accordingly. Select Project -> (your project name) Properties ->Toolchain and add the string: -Wl,–section-start=.text=0x2000 into the position shown below, and save the file:
  15. Select Build -> Build Solution to build the project
  16. To flash the SAMD21 with the program from Atmel Studio, some parameters to invoke the installed BOSSA flash program from step 11 must be defined.
  17. In Atmel Studio, select Tools -> External Tools:
  18. Choose a Title in the settings window, I named it Samd21_prog. Set the Command to: C:\Program Files (x86)\BOSSA\bossac.exe  , check the path of the installed bossac.exe .
  19. For the Arguments insert the following parameters to define the program address offset ( to load the code above the bootloader address space ): COM port and filename.:
  20. Arguments: –offset=0x2000 -p COM4 -i -e -w -v -R “$(ProjectDir)Debug\$(TargetName).bin” , BUT change COM4 to the COM port number you got earlier at step 4. Note –offset is with 2 minus signs. ! Uncheck the “Close on exit” and click Apply:
  21. Now select Tools -> External Tools -> SAMD21G18_prog to flash the Blink program.
  22. In case everything works out OK, the Bossa output window will show: 
  23. And the board leds LEDs TX_LED and RX_LED start to blink.

Remarks: A newer bootloader that exposes the user program area as a Windows USB-stick, the UF2 type of bootloader can be used. It is described here: UF2 info . For the actual SAMD21 board, the UF2 bootloader for the Sparkfun SAMD21 mini breakout board works out of the box: Sparkfun UF2 bootldr.