Programming the ATSAMD11C14 with Black Magic Probe

16 January 2022

About a 1-minute read

I’m working on a new tail light for my bike, to get back into electronics. It’s a custom circuit board design with a microntroller. There’s still a global chip shortage, but I managed to find some ATSAMD11 microcontrollers to base my design on.

The SAMD11 is the small sibling of the popular SAMD21 and SAMD51 chips, and it seems less popular among hobbyists based on how thin the documentation is. I had trouble finding straightforward information on how to program it, especially because I am using the Black Magic Probe instead of OpenOCD to do so.

Here’s my simple “blink” sketch that toggles Arduino pin 4 (which happens to be pin 14 of this chip) to prove that something is happening:

const unsigned int LED_PIN = 4;
void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  delay(10);
  digitalWrite(LED_PIN, LOW);
  delay(10);
}

I’m observing the pin with an oscilloscope, but you could increase those delay times to make it blink at a more human-readable pace if you use an LED.

Here are the steps I used to get this first LED-blinking program on to the chip:

  1. Install the Mattairtech SAMD cores for Arduino. These include the pin definitions and SAMD standard library so we can call Arduino functions.
  2. Install gdb-multiarch. The Black Magic Probe hosts a GDB server, so we’ll program and debug the circuit with GDB.
  3. Build the sketch with these options & note the path of the created ELF file:
    • Board: “Generic D11C14A”
    • Clock source: “Internal USB-Calibrated Oscillator”
    • USB Config: “CDC Only”
    • Serial Config: “One UART, No Wire, One SPI” (probably not important right now)
    • Bootloader size: “No Bootloader” (this part is important until we have a bootloader)
  4. Program the chip using the Black Magic Probe and GDB, using the path of the compiled ELF file:
    gdb-multiarch \
      -ex "target extended-remote /dev/ttyACM0" \
      -ex "monitor swdp_scan" -ex "attach 1" \
      -ex "monitor erase mass" \
      -ex "load /tmp/arduino_build_520906/tail-light.ino.elf"

If all of that works, the output looks something like the following:

Remote debugging using /dev/ttyACM0
Target voltage: 3.2V
Available Targets:
No. Att Driver
 1      Atmel SAMD11D14A (rev B)
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x00000250 in ?? ()
Erase successful!
Loading section .text, size 0x2300 lma 0x0
Loading section .data, size 0x160 lma 0x2300
Start address 0x00000184, load size 9312
Transfer rate: 18 KB/sec, 846 bytes/write.

That programming step will drop you in to the GDB prompt. Next, we need to start the program. These commands go into the GDB prompt:

  1. Tell GDB which file we’re running: file /tmp/arduino_build_520906/tail-light.ino.elf
  2. start
  3. continue

With that, the program will start and move past the temporary initial breakpoint. The pin should start to blink!

Up next, I will be combining these steps into a single command so I can add it to the Arduino IDE. After that, I will progam a bootloader to this chip so I can upload things over USB.

Comments