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 arduino.org <http://arduino.org/> variant of the Zero (which is now handled by arduino.cc <http://arduino.cc/>). 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
filename
   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/openocd.sh flash
### Flashing Target ###
Open On-Chip Debugger 0.9.0 (2016-09-05-11:06)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
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: ***
[/home/flrn/workbench/RIOT/examples/hello-world/../../Makefile.include:330:
flash] Error 1

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

Florian

[1] http://www.arduino.org/blog/m0-pro-vs-zero

Looks like your NVM has the security lock enabled:

   http://www.atmel.com/Images/Atmel-42114-SAM-Non-Volatile-Memory-Driver-NVM_Application%20Note_AT03247.pdf

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

    https://github.com/ataradov/edbg

HTH,

Antonio

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
~/workbench/RIOT/examples/hello-world/bin/arduino-zero/hello-world.elf
Debugger: ATMEL EDBG CMSIS-DAP FFFFFFFFFFFFFFFFFFFF 01.1F.0118 (SJ)
Target: SAM D21G18A
Erasing...  done.
Verification...
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 ihex.py (https://github.com/ant9000/IHex/):

  python ihex.py file.hex > file.bin

Antonio

Did as suggested using IHex. Output:

$ edbg -b -t atmel_cm0p -e -p -v -f hello-world.bin
Debugger: ATMEL EDBG CMSIS-DAP FFFFFFFFFFFFFFFFFFFF 01.1F.0118 (SJ)
Target: SAM D21G18A
Erasing...  done.
Programming..................................... done.
Verification...
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:

   http://www.avrfreaks.net/forum/fuses-samd21-xplained

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.

Antonio

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.

Tobias