Created
June 29, 2015 18:45
-
-
Save NT7S/8302aa33279dbe3d4873 to your computer and use it in GitHub Desktop.
Revisions
-
NT7S created this gist
Jun 29, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,105 @@ Homebrew Arduino Zero Tool Setup ================================ A guide for installing the tools necessary to build up a homebrew barebones Arduino Zero (based on the Atmel SAMD21G18A microcontroller) on a Linux PC. While this guide is written for a Debian-based distribution such as Linux Mint, it should be adaptable to other distributions fairly easily. This guide also assumes that we will be using the [ATMEL-ICE](http://www.atmel.com/tools/atatmel-ice.aspx) debugger to write the Arduino bootloader to the SAMD21G18A flash memory via the Cortex Debug Connector. Install Arduino IDE ------------------- You'll need a recent version of the Arduino IDE which has support for the Arduino Zero in the Boards Manager. As of this writing, the latest stable version is 1.6.5, so be sure to use at least this version. Also as of this writing, the version of the Arduino IDE in the Linux Mint repositories is quite old, so don't use that one. Go [here](https://www.arduino.cc/en/Main/Software) to grab the latest version of the Arduino IDE, then simply uncompress the download to a convenient location and run the binary from that folder. Now navigate to the menu ```Tools > Board: > Boards Manager...``` and find the listing for "Arduino SAMD Boards (32-bits ARM Cortex-M0+)", select it, then click the Install button. ATMEL-ICE Permissions --------------------- Now we need to set up some udev rules so that the ATMEL-ICE can run without superuser priveleges. Start by creating a new udev rules file: sudo nano /etc/udev/rules.d/10-atmel-ice.rules Paste this line into the editor: SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2141", GROUP="adm", MODE="0666" Save and exit by pressing ```CTRL-O``` then ```CTRL-X```. Restart udev and then plug in your ATMEL-ICE: sudo service udev restart Connect ATMEL-ICE to Target Board and Load Bootloader ----------------------------------------------------- The ATMEL-ICE uses what is called a Cortex Debug Connector layout to do debugging and handle tasks such as writing flash memory. The standard connector size is a 10-pin (2x5) 0.05 inch header. This is what you will need to have on your target board so that you may program the Arduino bootloader into flash memory. Consult the SAMD21G18A datasheet for the wiring details of this connector. Make sure that one end of your ATMEL-ICE programming cable is connected to the ATMEL-ICE via the SAM port, then connect the 10-pin connector on the other end of the cable to the Cortex Debug Connector on the target board, following the proper orientation of the connector. The ATMEL-ICE does not provide power to the target board, so be sure to provide the 3.3 V power that the SAMD21G18A needs. You'll see the green LED on the ATMEL-ICE light up when the target board has power. Start up Arduino IDE, then go to the menu and select ```Tools > Programmer: > Atmel-ICE```. Now you should be able to choose ```Tools > Burn Bootloader```. If the bootloader was successfully written, you should see something like this in the console window (it will take a few moments to complete): Open On-Chip Debugger 0.9.0-gd4b7679 (2014-10-03-00:26) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html debug_level: 0 adapter speed: 500 kHz adapter_nsrst_delay: 100 cortex_m reset_config sysresetreq target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x81000000 pc: 0x00002304 msp: 0x20007fd0 target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x81000000 pc: 0x00000858 msp: 0x200023a0 ** Programming Started ** auto erase enabled wrote 16384 bytes from file /home/jason/.arduino15/packages/arduino/hardware/samd/1.6.0/bootloaders/zero/samd21_sam_ba.bin in 5.136203s (3.115 KiB/s) ** Programming Finished ** ** Verify Started ** verified 6328 bytes in 0.666237s (9.276 KiB/s) ** Verified OK ** ** Resetting Target ** shutdown command invoked At this point, if everything has worked correctly, your barebones board should now function as an Arduino Zero (at least as far as the Arduino IDE is concerned). Uploading Your First Program ---------------------------- I would recommend at a bare-minimum to have an LED connected to Arduino port D13 (SAMD21G18A pin 26/PA17) as is the custom in the official Arduino boards, so that you can use it for debugging purposes. Assuming that you have that, let's try to upload the Blink sketch from the Examples menu to verify that everything is working correctly. Connect your barebones board to a USB port on your PC, then fire up the Arduino IDE. Select the Blink example sketch via menu ```File > Examples > 01.Basics > Blink```. Now make sure that the proper board type is selected in the IDE. Choose ```Tools > Board: > Arduino Zero (Native USB Port)```, and then select the virtual COM port that your board enumerated under with the ```Tools > Port``` menu. Now we should be able to upload the Blink sketch using the Upload button on the toolbar. If firmware loading is successful, you should see something like this in the console: Sketch uses 11,076 bytes (4%) of program storage space. Maximum is 262,144 bytes. Atmel SMART device 0x10010005 found Device : ATSAMD21G18A Chip ID : 10010005 Version : v1.1 [Arduino:XYZ] Jun 10 2015 11:08:10 Address : 8192 Pages : 4096 Page Size : 64 bytes Total Size : 256KB Planes : 1 Lock Regions : 16 Locked : none Security : false Boot Flash : true BOD : true BOR : true Arduino : FAST_CHIP_ERASE Arduino : FAST_MULTI_PAGE_WRITE Arduino : CAN_CHECKSUM_MEMORY_BUFFER Erase flash done in 0.837 seconds Write 11124 bytes to flash (174 pages) [=========== ] 36% (64/174 pages) [====================== ] 73% (128/174 pages) [==============================] 100% (174/174 pages) done in 0.091 seconds Verify 11124 bytes of flash with checksum. Verify successful done in 0.044 seconds CPU reset. If the hardware is wired correctly, you'll see your LED toggle once per second, just like on an offical Arduino board. Congratulations!