2

I am trying to upload the arduino zero bootloader (https://github.com/arduino/ArduinoCore-samd/tree/master/bootloaders/zero) to an atsamd21g18 breakout board that I made. The breakout has a 32KHz oscillator hooked to pins 1 and 2 (with 22pF caps). I have successfully done this twice before with two other atsamd21g18's, Atmel Studio, and an Atmel ICE as the programmer. These are the steps I followed the first two times:

  1. Create a new GCC C executable project in Atmel Studio and chose ATSAMD21G18A as the device
  2. Go to Tools->Device Programming, chose Atmel-ICE as tool, and SWD as interface
  3. Go to Fuses, set USER_WORD_0.NVMCTRL_BOOTPROT to 0 Bytes, and hit Program
  4. Go to Memories, select the file ArduinoCore-samd-master\bootloaders\zero\samd21_sam_ba.bin under the Flash option, and hit Program
  5. Go back to Fuses, set USER_WORD_0.NVMCTRL_BOOTPRT to 8192 Bytes and hit Program

Then, I went to the Arduino IDE and was able to upload any sketches with Arduino Zero (programming port) chosen as the board and Atmel SAM-ICE as the programmer.

I have followed these same steps with the third samd21 chip. Eventually, all of the commands will go through. About 30% of the time when I click Program (in steps 2-5) I will get one of two errors:

Could not activate interface Unable to enter programming mode. Verify device selection, interface settings, target power, security bit, and connections to the target device.

or

Erasing device failed.

However, if I just retry clicking Program it will not give any errors.

After following those steps with no errors in Atmel Studio, I go to the Arduino IDE and try uploading a basic blink sketch (with the same board and programmer selection as before), and the upload goes through (it says Done Uploading). However, the code does not execute. This is the code I am trying to upload:

const int ledPin =  6;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}

This is the output I get after uploading the code:

Sketch uses 11444 bytes (4%) of program storage space. Maximum is 262144 bytes.
Global variables use 2188 bytes (6%) of dynamic memory, leaving 30580 bytes for local variables. Maximum is 32768 bytes.
Open On-Chip Debugger 0.10.0+dev-gf0767a31 (2018-06-11-13:36)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
none separate
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0000060c msp: 0x20007ffc
** Programming Started **
auto erase enabled
wrote 11520 bytes from file C:\Users\Michaela\AppData\Local\Temp\arduino_build_379254/blinky_samd21.ino.bin in 1.021138s (11.017 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x00000694 msp: 0x20007fdc
Error: error executing cortex_m crc algorithm
verified 11444 bytes in 0.999887s (11.177 KiB/s)
** Verified OK **
** Resetting Target **
shutdown command invoked

I have tried switching out the oscillator and led, uploading the bootloader and arduino sketch with and without the oscillator, simply hitting the Burn Bootloader command from the Arduino IDE, and even tried using openocd directly in the command line.

I do not believe this is an error with the specific samd21 chip I am using, because before I started messing with the bootloader, I uploaded a C sketch from Atmel Studio to blink the led, and it worked fine.

If anyone has any insight as to what could be going wrong, I would greatly appreciate it!

2
  • is the LED on the right pin?
    – Juraj
    Apr 30 '21 at 18:39
  • I believe so. It is on pin 29 of the samd, which correlates to pin 6 in arduino.
    – Michaela
    Apr 30 '21 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.