Program SAMD21G18A MCU using ATMEL ICE

I am trying to program the ATSAMD21G18A MCU using ATMEL ICE to run a sample Arduino code to test my Bluetooth module. I tried to import the Arduino project to ATMEL Studio 7 by creating an Arduino sketch in AS7 but I am facing various library issues when I try to build the code. I also tried to program the MCU through Arduino IDE using Upload using programmer option. But I am facing the following error.

Error: at91samd21g18.cpu -- clearing lockup after double fault

What is the best way to program an Arduino code to ATSAMD21G18A MCU?

I used the Arduino IDE to program the Arduino MKR Zero with Atmel ICE. Here is the procedure:

  1. Connect the Atmel-ICE programmer to the computer through USB cable
  2. Connect the MKR Zero to the computer through another USB cable, or connect the MKR Zero board supply pins to 5V supply
  3. Make sure the middle LED on the Atmel-ICE is RED and the left LED is GREEN
  4. Open Arduino IDE, load the sketch
  5. make sure the “Tools-> Board” is set to “Arduino MKRZERO” and the “Tools->Port” is connected to the corresponding COM port
  6. Make sure the “Tools->Programmer” is set to “Atmel SAM-ICE”
  7. Select “Tools-> Burn bootloader”
  8. Make sure the bootloading was successful: the message in the Arduino IDE should be “Done burning bootloader”

I assume programming the Zero would be similar

I'm facing the same issue,
Here some other details:
bootloader burns flawlessly
uploading with programmer gives that error and MCU halts
but reburning the bootloader the MCU start executing the program that previously gave error.
So the program uploads but it is unable to clear lockup.
Any suggestions?

I have the same issue, programing Arduino MKR 1010, through the isp connector on the bottom side of board.
After charging the program, it doesn't start, but if I recharge the bootloader it starts.
Someone have seen same problem after this procedure? Or I can program bords in this way without problems?