[Solved] Programming a SAMD21 with the ATMEL-ICE from the IDE


I've seen some posts about issues with the Atmel-ICE, but they are not exactly the same as the issue that I'm facing, and I'm wondering if somebody out there could help me.

I have some boards that I made that are based around the same SAMD21 that is being used in the Zero. So far, I've been successful in burning code through the IDE via a USB connector I had in my development boards, but I would like to get rid of it and use the ATMEL-ICE and program the boards via SWD. The way that I do it right now is I burn a sketch on a dev board via USB, then read the flash with Atmel Studio, and use that image to flash the other boards This is a bit a pain in the ass, as I changed the footprint of my programming socket in the board, and I have to fiddle with wires everytime I switch boards.

I tried the "burn with a programmer" from the IDE, but the code won't start to execute, and I tried to open the sketch on the Atmel Studio, but it only works with basic sketches (blink, for example), but not with the one I'm working in right now (Atmel Studio returns the error "failed to import Arduino sketch. 'NoneType' object has no attribute 'token_type', but I guess this one is a question for the Atmel guys).

I guess the error will have something to do with bootloaders and start programming addresses. But I can't figure this one out. Has somebody been successful using the IDE and the ATMEL-ICE to flash SAMD21 chips?

Hi, you need to compile your code using a different linker script : https://github.com/arduino/ArduinoCore-samd/blob/master/variants/arduino_zero/linker_scripts/gcc/flash_without_bootloader.ld Then, use the Atmel ICE to upload the resulting binary.


Thanks for your quick reply. I've been reading a bit, as this is the first time I use a linking script. What I did is modify boards.txt, and add a "no bootloader" entry, copying the Arduino Zero Native programming port config and changing the linking script there, and nothing else. I managed to flash a board that way, but I don't know if I'm still flashing the firmware or what, as there is a couple of lines related to it


Is that change all that is needed? Is that the correct way of proceeding?

Yep, you did well. The line in the platform.txt about the bootloader are used when you use the "Burn bootloader" function.

Thanks for your help. I've been using it for a while and as you said, it works as a charm.

For future reference, and for less experienced people that might stumble upon this, the process consist on editing your SAMD boards.txt, that in windows and in my current version (1.6.8) is located at


Copy one of the boards (for example, all the lines that start with arduino_zero_native), and change the bits before the first period to something else (for example, arduino_zero_native_nobl).

Then you need to change the contents of the first line to the name you want it to have on the boards menu, for example:

arduino_zero_native_nobl.name=Arduino Zero No Bootloader (Native USB Port)
arduino_zero_native_nobl.name=Arduino Zero No Bootloader (Native USB Port)

And change the scripter link


I am onto the same task.

Do you know if it is possible to program another SAMD21 version with the Arduiono IDE and Atmel ICe. For example the 32 pin version with lower RAM and flash . i.e. SAMD21E16.


I'm not an expert on the matter, but I think it would be problematic to move to a version with a different pinout, as there might be stuff on the IDE libraries that is different. I guess it would be easier on a different SAMD21G, where you would only have to tweak the memory sizes.

I think I remember reading on a hackaday.io project that I studied before working on my board about a minimal SAMD21 board, and I think the guy modified the bootloader to work on a different chip, so you might be lucky with that. I've searched a bit but I couldn't find it, sorry.

Hopefully, somebody with more knowledge might guide you. :confused:

I think it is this post you are talking about where he changes the bootloader to the larger 64 pin version.


Yes I think it should not be that much of a problem just changing the registers, but wandering if someone that had done it could confirm.

Will keep looking into it and will post if solved

Hi solar82,

I've produced a custom board using the larger 64-pin SAMD21J18A. As the ARM core and memory map (256kB flash, 32kB RAM) are identical to the Arduino Zero (SAMD21G18A), it's possible to just upload the Zero's bootloader over the SWD port and thereafter use the native USB port to upload Arduino sketches.

For the SAMD21J all I had to do was to make a small change to the "boards.txt" file and alter the "variant.cpp" file to account for the extra pins. However, it looks like the Arduino team accounted for the SAMD21J in their core code, so you may have to edit some files to comment out or add #defines to code that references peripherals that don't exist on the smaller SAMD21E.

If you're using the Arduino IDE, it's possible to add a new entry for your board. I wrote up a small guide here: https://forum.arduino.cc/index.php?topic=409715.0.


jsantosrico: Thanks for your help. I've been using it for a while and as you said, it works as a charm.

For future reference, and for less experienced people that might stumble upon this, the process consist on editing your SAMD boards.txt, that in windows and in my current version (1.6.8) is located at

Many thanks for your post and how to edit the boards files that worked great for me with the ATMEL-ICE however it then gave me the error, possible due to the board I was using.

Error: SAMD: NVM lock error

So for anyone else seeing this, using ATMEL Studio with the ICE connected to the board, from Tools select device programming, select the Tool as Atmel-ICE, device (in my case ATSAMD21G18A, interface SWD then click Apply. First thing is under memory do an erase, you can't clear the NVM protection until after a full erase. Then click on Fuses, in the list at the top find "USER_WORD_0.NVMCTRL_BOOTPROT" and set this to 0x07 to disable the NVM protection. Then click Program to update the chip.

Hope that helps someone in the future.