{"id":831,"date":"2019-03-25T22:37:04","date_gmt":"2019-03-26T05:37:04","guid":{"rendered":"http:\/\/localhost\/imagecraft\/blog\/?p=831"},"modified":"2019-03-25T22:37:04","modified_gmt":"2019-03-26T05:37:04","slug":"removing-bootloader-protection-on-the-adafruit-metro-arduino-zero-samd21","status":"publish","type":"post","link":"https:\/\/imagecraft.com\/?p=831","title":{"rendered":"Removing Bootloader Protection On The AdaFruit Metro \/ Arduino Zero \/ SAMD21"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Microchip\/Atmel SAMD21G18A is a powerful Cortex M0+ based MCU with 256K flash and 32K of SRAM. It&#8217;s used in the Arduino Zero as well as the Adafruit Metro and Feather lines of development boards, and is becoming a popular choice for users looking for a low cost powerful ARM Cortex-M MCU.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The SAMD21G18A used in the Arduino and Adafruit development boards is programmed with a bootloader. The Arduino IDE uses this feature to download programs onto the MCU. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, instead of the limited Arduino IDE, you can instead use an advanced development environment such as <a href=\"https:\/\/imagecraft.com\/products\/jumpstart-c-tools-menu\/jumpstart-cpp\">JumpStart C++<\/a>, Keil, or IAR. Besides getting the full benefit of using C\/C++, you also can use visual debuggers that are lacking in the Arduino IDE. <\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">To best utilize these environments, you need to use a <a href=\"http:\/\/localhost\/imagecraft\/blog\/2019\/03\/cortex-m-debug-pods\/\">Cortex-M Debug Pod.<\/a> The Arduino Zero has an embedded debug chip, and the Adafruit Metro board can be used with an external debug pod. Note: you will need to disable the bootloader protection, otherwise you will not be able to download programs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do that on the Adafruit Metro, you will first need to install Atmel Studio 7.x (AS7) and use the Segger JLINK. If do not have a JLINK, you can turn an embedded ST-LINK into a JLINK; see the Cortex-M Debug Pod article linked above<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> In the Arduino Zero case, you should just be able to use the embedded Atmel debug chip.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following procedure should work with both the Adafruit Metro and the Arduino Zero, although I do not have a Zero handy to try it on. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To begin, connect the hardware together. To use the JLINK with the board, you will need the 20 pin to the 10 pin &#8220;JTAG to SWD Cable Adapter Board&#8221;: see h<a href=\"https:\/\/www.adafruit.com\/product\/2094\">ttps:\/\/www.adafruit.com\/product\/2094<\/a>. (Link subject to change through the whim of Adafruit, but then use the phrase in quotation marks above as a search term ). You will also need the 10-pin cable!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Search for &#8220;Atmel Studio 7 download&#8221; to find the download link on Microchip&#8217;s site. I found that I had to download the &#8220;offline&#8221; installer version at over 800+ megabytes, as the smaller web installer version did not work for me. YMMV. Once you install AS7, invoke &#8220;Tools-&gt;Device Pack Manager&#8221;, then scroll down to the SAM21_DFP section <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/localhost\/imagecraft\/blog\/wp-content\/uploads\/2019\/03\/image-20.png\" alt=\"\" class=\"wp-image-841\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Install the 1.0.222 &#8220;Initial release&#8221; and at least the 1.3.331 &#8220;&#8230;Added fuses value-groups&#8221;. Then close AS7 and restart it. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now invoke &#8220;Tools-&gt;Device Programming&#8221;. Under Tools, select J-Link (or the Atmel Debug Chip).<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/localhost\/imagecraft\/blog\/wp-content\/uploads\/2019\/03\/image-17.png\" alt=\"\" class=\"wp-image-832\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If the boards and debug pod are connected and powered, you should be able to select the device and SWD as the Interface, and then click &#8220;Apply&#8221;. Click on the &#8220;Fuses&#8221; label on the left hand pane, then scroll down on the &#8220;Fuse Name&#8221; section until you see USER_WORD_0.NVMCTRL_BOOTPROT. It should have the value 8192 bytes. This means that the first 8K bytes of the flash is reserved for the bootloader, and cannot be overwritten.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/localhost\/imagecraft\/blog\/wp-content\/uploads\/2019\/03\/image-19.png\" alt=\"\" class=\"wp-image-835\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Click on the dropdown menu, and select &#8220;0 bytes&#8221;, then click &#8220;Program&#8221;. If all goes well, you should see the &#8220;Verify&#8230;OK&#8221; message. This process is reversible: you can find the bootloader image on the respective sites, and after you re-program in the bootloader, you can set the boot protection size back to 8192 bytes. Enjoy! <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/localhost\/imagecraft\/blog\/wp-content\/uploads\/2019\/03\/image-21.png\" alt=\"\" class=\"wp-image-842\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Microchip\/Atmel SAMD21G18A is a powerful Cortex M0+ based MCU with 256K flash and 32K of SRAM. It&#8217;s used in the Arduino Zero as well as the Adafruit Metro and Feather lines of development boards, and is becoming a popular choice for users looking for a low cost powerful ARM Cortex-M MCU. The SAMD21G18A used in the Arduino and Adafruit development boards is programmed with a bootloader. The Arduino IDE uses this feature to download programs onto the MCU. However, instead of the limited Arduino IDE, you can instead use an advanced development environment such as JumpStart C++, Keil, or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-831","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/posts\/831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imagecraft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=831"}],"version-history":[{"count":0,"href":"https:\/\/imagecraft.com\/index.php?rest_route=\/wp\/v2\/posts\/831\/revisions"}],"wp:attachment":[{"href":"https:\/\/imagecraft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imagecraft.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imagecraft.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}