Unable to load code to SAMD21G18A via USB after loading hex file, Atmel Studio 7


I have done my development in arduino IDE. I am importing the code into Atmel Studio 7, using their “Create Project from Arduino Sketch”. This loads and builds fine. I can then use Atmel Studio 7 and my atmel ICE to load the HEX file (produced from imported arduino sketch) to the ATSAMD21G18A chip. The code runs great.

My problem is that I want to double check that in the future, when I dont have access to the SWD pins, that I can load updates to the code via USB. I am testing loading the code via USB using the arduino IDE. I set my board to Arduino Zero (Native USB Port) and I can see the board on COM 3 in the IDE. I click to upload and it compiles but I get an error saying it cant see the board and when I look again, the IDE cant see anything on its ports.

If I load code in the first place from arduino IDE using the atmel ICE and then try and load code via the USB I can get it to work. The issue is if I do the initial programming with the HEX file from Atmel Studio 7.

When I import the arduino file into Atmel Studio I use the settings in the attached picture.

Any help would be much appreciated.


After AS7 has corrupted your SAMD21 burn bootloader before uploading sketch in the Arduino IDE.

Unfortunately that wont work in my case. I wont have access to the SWD pins.

I need a hex file that I can send to the chip manufacturer such that when I get the boards back I can load code via usb and usb only. This would be for a program update.

I saw that arduino creates a ino.with_bootloader.hex. Can I send this file to the chip manufacturer? If I do, would I be able to load code via the USB when I get it?

I like testing things out before hand and I have an atmel ICE programmer but I cant get Atmel Studio to load ino.with_bootloader.hex, it has a parsing error.

Is there any way for me to send a hex file such that I will be able to load code via USB with out using a programmer?

I've deleted your other cross-posts @aehrlich54.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Sorry for cross posting. I looked for a way to delete the original post but I couldn't find a way to do it. Not trying to waste peoples time.

I have gathered some more info and some solutions. Full disclosure, I am not an expert and there may be other ways to do this but I have tested these methods and they work.

The easiest way I found to get a hex file that you can load over Atmel Studio 7 or send to a chip manufacturer and still be able to load code updates over USB is to essentially read the code off your chip into a hex file after you have used Arduino IDE to get it into the proper state. To do this:

  1. Using the Arduino IDE load the "Arduino Zero (Native USB)" bootloader.
  2. Using the Arduino IDE load your full code.
  3. Open Atmel Studio 7 and open the Device Programming Screen.
  4. Connect your programmer to the Arduino and Select the Tool, Device, interface and hit apply.
  5. On the left select memories and in the Flash section click Read. Name it and press ok.

When it is done you will have a Hex file of the entire system memory including the bootloader and it will be in a format that AS7 or a chip manufacturer will be able to load.

More info.

Second Method: You can do something similar where you get the "Arduino Zero (Native USB)" bootloader and open it as a text file. You can then open your hex file of your full code (as compiled by arduino. Google how to find these on your computer) and then splice the two hex files together. You have to be careful with some of the end and start lines, which is why I liked the method above.

Loading code over USB without Arduino IDE, Untested: If you want to make your code updates via USB without the Arduino IDE, it looks like you can use the BOSSA exe from the command line with some arguments. See this post: https://forum.arduino.cc/index.php?topic=365219.0

The difficulty, which is listed in that post, is the Zero needs to somehow use the USB to reset the chip two times quickly to boot it into programming mode. It also seems like there is some shuffling with com ports.

If anyone knows how, using the command line (no Arduino IDE), to reset the chip with USB, please post. That would awesome.