RIOT on the Arduino M0 Pro

Hello RIOT dev community,

I’m trying to get RIOT up and running on the Arduino M0 Pro, which is the <> variant of the Zero (which is now handled by <>). It is largely the same as the Zero in terms of hardware [1] but doesn’t work with the Makefiles provided for the Zero nor with any other of the arduino Makefile sets or variants thereof created/damaged by yours truly in a trial-and-error process.

When trying to compile with the Zero Makefiles (I copied the arduino-zero directory to arduino-m0 for my trials, so don't be confused by that - in the following output it's still the original copy), the following is my output:

$ make flash BOARD=arduino-m0
Building application "hello-world" for "arduino-m0" with MCU "samd21".

"make" -C /home/flrn/workbench/RIOT/boards/arduino-m0
"make" -C /home/flrn/workbench/RIOT/core
"make" -C /home/flrn/workbench/RIOT/cpu/samd21
"make" -C /home/flrn/workbench/RIOT/cpu/cortexm_common
"make" -C /home/flrn/workbench/RIOT/cpu/sam21_common
"make" -C /home/flrn/workbench/RIOT/cpu/sam21_common/periph
"make" -C /home/flrn/workbench/RIOT/cpu/samd21/periph
"make" -C /home/flrn/workbench/RIOT/drivers
"make" -C /home/flrn/workbench/RIOT/drivers/periph_common
"make" -C /home/flrn/workbench/RIOT/sys
"make" -C /home/flrn/workbench/RIOT/sys/auto_init
"make" -C /home/flrn/workbench/RIOT/sys/newlib
"make" -C /home/flrn/workbench/RIOT/sys/tsrb
"make" -C /home/flrn/workbench/RIOT/sys/uart_stdio
   text	   data	    bss	    dec	    hex
   8448	    128	   2752	  11328
2c40	/home/flrn/workbench/RIOT/examples/hello-world/bin/arduino-m0/hello-world.elf
/home/flrn/workbench/RIOT/dist/tools/openocd/ flash
### Flashing Target ###
Open On-Chip Debugger 0.9.0 (2016-09-05-11:06)
Licensed under GNU GPL v2
For bug reports, read
Info : only one transport option; autoselect 'swd'
adapter speed: 500 kHz
adapter_nsrst_delay: 100
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 01.1F.0118
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : SWD IDCODE 0x0bc11477
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* at91samd21g18.cpu  cortex_m   little at91samd21g18.cpu  running
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x81000000 pc: 0x000028f4 msp: 0x20002c00
auto erase enabled
Info : SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
Error: SAMD: NVM lock error
Error: Failed to erase row containing 00000000
Error: SAMD: failed to erase sector 0
Error: failed erasing sectors 0 to 0

make: ***
flash] Error 1

Has anyone gotten this to work and/or is interested in helping me with this? Either would be greatly appreciated.



Looks like your NVM has the security lock enabled:

You might want to try a full erase first, that should solve. You can do it with edbg:



Hello Antonio,

thank you very much for your time. I tried with edbg, as suggested, and I am getting

$ edbg -bv -t atmel_cm0p -e -f
Target: SAM D21G18A
Erasing...  done.
at address 0x0 expected 0x7f, read 0xff
Error: verification failed

Now it seems to me that at least the erase was successful, but the error for `BOARD=arduino-zero make flash` remains unchanged.

Regards Florian

Try like this:

  edbg -b -t atmel_cm0p -e -p -v -f filename.bin

in order to do a full erase/program/verify cycle. To produce a .BIN file, you need to convert the .hex - for instance with (

  python file.hex > file.bin


Did as suggested using IHex. Output:

$ edbg -b -t atmel_cm0p -e -p -v -f hello-world.bin
Target: SAM D21G18A
Erasing...  done.
Programming..................................... done.
at address 0x0 expected 0x00, read 0xff
Error: verification failed

Regards Florian

Mh, then my best bet is that your CPU has the fises bits set to protect the first pages - see for instance:

If you have a copy of Atmel Studio, you can change the fuses in a snap. It might be possibile to do that with OpenOCD, but frankly I don't know how.


In case anyone else has this issue: It was basically what Antonio said, the USER_WORD_0 was set wrong by Arduino. The factory setting is 0xD8E0C7F9, but it needs to be set to 0xD8E0C7FF. In Atmel Studio one can do that by changing the fuse-setting USER_WORD_0.NVMCTRL_BOOTPROT from 0x01 to 0x07.

If we find a way to do that automatically with openocd we'll post it.