Programming the Zero via native USB in Atmel Studio?

I'm considering using the SAMD21G18A in a new design, and got an arduino.cc Zero to learn more and evaluate it. It's up and running in the Arduino IDE (v 1.6.6), bootloader is functioning, and I'm able to program via both the native and debug interfaces. For continuing development, what I'd like to do is use Atmel Studio (I'm running v 7.0.634) and program the Zero through the native USB. It seems like a toolchain that would work well for building small quantities of custom boards - burn the bootloader into a new chip with an ICE via the 10-pin SWD interface, then use native USB to program/update from there on out.

This seems simple enough, yet I can't seem to figure out how to program a device via a bootloader/COM port in Atmel Studio. If I go to Tools -> Device Programming, the COM port doesn't show up.

(Side note: the debug USB does show up as the EDBG, but since that chip won't be on my custom board, it's not a long-term solution. Also, Atmel Studio wants to update the EDBG's firmware from 2.01 to 2.10 and I haven't been brave enough to open that potential can of worms yet).

I've also tried using BOSSA (gui version), and though the COM port is selectable, it can't connect to the device. SAM-BA seems to be out because I'm running 64 bit Windows 7 (README indicates it only works on 32 bit systems).

Uploading via native USB in Atmel Studio with the Visual Micro plug-in works, but only with "Arduino Projects" (sketches).

Thank you for any help!

You should maybe take a look in the documentation of the Atmel development kit with SAMD chip (SAMD21 Xplained). Maybe there is a project with Usb CDC bootloader or something.
I've tried the Visual Micro plugin once, but with a lot of trouble so I can't really help. Have you tried to see where the plugin takes the compiled code? maybe you could put your compiled plain C code there...

Hi, AloyseTech. I did read through quite a bit of documentation before posting - there's a lot on burning a bootloader, and even creating a bootloader, not so much on then using one with Atmel Studio.

I kept at it and am getting somewhere....I ended up creating an "External Tool" that linked to bossac.exe with the following arguments (taken from the output of Visual Micro and Arduino IDE, as you suggested):

-i -d --port=COM14 -U true -i -e -w -v $(TargetDir)$(TargetName).bin -R

Here's also the full BOSSA syntax.

I wasn't able to get the Arduino to go into bootloader mode via pulling PA15 low (as detailed in Atmel's app note on SAM-BA Bootloader for SAMD21). But I was able to get it into bootloader mode by opening the native USB COM port at 1200 baud as outlined in the Zero's Getting Started Guide.

Then I selected the new tool I created, and....something happened. The output indicates it read and wrote successfully (I think):

Set binary mode
readWord(addr=0)=0x200023a0
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010205
version()=v1.1 [Arduino:XYZ] Jun 10 2015 11:08:10
chipId=0x10010005
Connected at 921600 baud
readWord(addr=0)=0x200023a0
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010205
Atmel SMART device 0x10010005 found
write(addr=0x20004000,size=0x34)
writeWord(addr=0x20004030,value=0x10)
writeWord(addr=0x20004020,value=0x20008000)
Device       : ATSAMD21G18A
readWord(addr=0)=0x200023a0
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010205
Chip ID      : 10010005
version()=v1.1 [Arduino:XYZ] Jun 10 2015 11:08:10
Version      : v1.1 [Arduino:XYZ] Jun 10 2015 11:08:10
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
readWord(addr=0x41004020)=0xffff
none
readWord(addr=0x41004018)=0
Security     : false
Boot Flash   : true
readWord(addr=0x40000834)=0x7000a
BOD          : true
readWord(addr=0x40000834)=0x7000a
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
chipErase(addr=0x2000)
done in 0.821 seconds

Write 1924 bytes to flash (31 pages)
write(addr=0x20005000,size=0x7c0)
writeBuffer(scr_addr=0x20005000, dst_addr=0x2000, size=0x7c0)

[==============================] 100% (31/31 pages)
done in 0.020 seconds

Verify 1924 bytes of flash with checksum.
checksumBuffer(start_addr=0x2000, size=0x784) = 187e
Verify successful
done in 0.009 seconds
CPU reset.
readWord(addr=0)=0x200023a0
readWord(addr=0xe000ed00)=0x410cc601
readWord(addr=0x41002018)=0x10010205
writeWord(addr=0xe000ed0c,value=0x5fa0004)

But of course my LED doesn't blink. :frowning: It's likely that I don't have the SAM initialized properly for the Zero board, the template I started with was the bare-bones Atmel Studio default. Seeing exactly what system_init() does and digging through clock settings is next on my list.

Also, I wasn't able to get the SAM back into bootloader mode after "programming". I was able to re-burn the bootloader through the EDBG port and upload working blink code through the Arduino IDE again. So at least I'm back to where I started.

Hey Super interested in the outcomes, did you ever get an answer or managed to get it to work? I am in the same situation.

Custom board, I am using Atmel ICE for development but for deploying it later on my custom PCB I would like to use the native USB and AS7...

Thanks

I tried Atmel Studio with Visual Micro plugin for bootloading and FW development for MKR Zero using the native USB and gave up. Too much trouble, too complicated, too buggy. Atmel studio is kind of nice for code editing and debugging because it's based on the MS Visual Studio IDE. But other than that naghhh.

I'm now back to Arduino IDE and I can do everything I need: bootload and program through native USB port with Atmel ICE with no problems, easy and straighforward. Unless you need to use the Atmel ASF libraries you can do everything else in Arduino IDE including direct accessing and manipulating all SAMD21 registers.

I did eventually get it to work with my custom board, but ended up using the Arduino IDE instead. The reason was twofold - 1) I didn't want to mess with creating my own USB drivers (or using ASF which is just as bloated as Arduino and way more obfuscated IMO). Since I was still essentially married to Arduino...it was just easier to use the IDE. 2) I think you have to put your board into bootloader mode in order to get the below to work. I didn't want to have to press a button to do that, and there didn't seem to be an obvious way to do the baud rate toggle in Atmel Studio.

Anyway, the way I did it in Atmel Studio was to do put the board in bootloader mode (long press on the reset button since I was using an Adafruit Feather bootloader), then use an External Tool that links to bossa. I believe my final syntax was this:

Command:
C:(your path to bossac.exe)

Arguments:
-i -d --port=COMX -U true -i -e -w -v C:(your path to compiled .bin here) -R

Enter your own paths and COM port #.
Make sure "Use Output Window" is checked so you can keep an eye on it.

I haven't looked at the Visual Micro plugin in a while, so don't know if there have been any recent developments there, though from evi7538's comment, sounds like no.

There has been work done to the bossa gui, more recently than I've even looked, so you might want to check that out too.

I know it's a bit late to post in this topic but thought to give it a try.
I was trying to integrate a SAMD21 Mini from sparkfun into Atmel studio & by far,i have done it successfully & I can program the SAMD21 using a single click on a external tool that I configured,which will eventually call a batch file to send the chip to bootloader mode & program by calling bossac.exe.

But there is a small problem.

Normally when i attach the SAMD21 to PC,it shows up as a virtual com port(COM29 in my case).We know that Arduino IDE sends the SAMD chip to bootloader mode by opening & closing the CDC serial port @1200 baud(In my case here,COM29).Now when programming from Arduino IDE,when in bootloader mode during programming,the SAMD21 changes the port from COM29 to COM28(as i can see from Arduino o/p window).
As soon as the programming is done,the COM29 gets back.
Although,I burn a blank sketch,the COM port shows up after burning the sketch.
So that clearly means that the Arduino configures some sort of USB CDC driver & adds it before the main program(invisible in the IDE though),so that the COM port always shows up so that the Arduino IDE can detect it & send it to bootloader mode(by open & close the port @1200 baud) for the next round of programming.

But

When programming from Atmel studio,everything remains fine for the first time(SAMD21 loaded with fresh Sparkfun Bootloader from Arduino using Atmel ICE) until the programming is completed.Now the COM29 gets vanished.So clearly in case of Arduino,it adds some sort of USB CDC driver so that the COM port shows up & in case of Atmel studio,it doesnt show up at the end of programming as the code is not there.
So i have to double tap reset button for the next round of programming.

Before any kind of experiment,every time I had to burn the Arduino Sparkfun bootloader using Atmel ICE to the board.

I also tried to add a USB CDC program(That i got from an example) & initialized the USB.Now the COM port(now COM30) shows up after burning program but sending the SAMD to bootloader by opening & closing the port@1200 baud gets fail in the next round of programming & so on.
Clearly,i have to write something in the USB CDC driver that can sense the opening/closing of the port @1200 baud & resets the chip to send it into bootloader mode.Unfortunately,I can't do that as i don't know the register level programming of SAMD boards(I purchased the board to learn :wink: )
Can anybody help?I can provide the files what i've done so far......Please reply!!