edbg build failure in Vagrant VM due to missing libudev-devpackage + problems flashing Atmel samr21-xpro board

Dear RIOT development team,

Attempting to flash with the edbg driver instead of OpenOCD results in an error when using the Vagrant VM as building edbg requires the libudev-dev package, which is not included in the image and cannot be found in the configured package repositories either.

gcc -W -Wall -Wextra -O2 -std=gnu99 dap.c edbg.c target.c target_atmel_cm0p.c target_atmel_cm3.c target_atmel_cm4.c target_atmel_cm7.c dbg_lin.c -ludev -o edbg

dbg_lin.c:42:21: fatal error: libudev.h: No such file or directory

#include <libudev.h>

^

compilation terminated.

Makefile:43: recipe for target ‘edbg’ failed

make[2]: *** [edbg] Error 1

Makefile:10: recipe for target ‘all’ failed

make[1]: *** [all] Error 2

/home/vagrant/RIOT/makefiles/tools/targets.inc.mk:14: recipe for target ‘/home/vagrant/RIOT/dist/tools/edbg/edbg’ failed

make: *** [/home/vagrant/RIOT/dist/tools/edbg/edbg] Error 2

A possible workaround would be switching to OpenOCD but I’m getting the following error when trying to flash applications on my Atmel samr21-xpro board with OpenOCD:

Error: at91samr21g18.cpu – clearing lockup after double fault

Polling target at91samr21g18.cpu failed, trying to reexamine

Info : at91samr21g18.cpu: hardware has 4 breakpoints, 2 watchpoints

TargetName Type Endian TapName State


0* at91samr21g18.cpu cortex_m little at91samr21g18.cpu halted

target state: halted

target halted due to debug-request, current mode: Thread

xPSR: 0x61000000 pc: 0x000003ec msp: 0x20000200

auto erase enabled

Info : SAMD MCU: SAMR21G18A (256KB Flash, 32KB RAM)

Error: error writing data: (null)

Info : SWD IDCODE 0x0bc11477

Error: Failed to write memory at 0x41004006

Error: Failed to erase row containing 0000af00

Error: SAMD: failed to erase sector 2

Error: failed erasing sectors 0 to 3

…/…/Makefile.include:364: recipe for target ‘flash’ failed

make: *** [flash] Error 1

As such, I have resorted to building edbg myself outside of Vagrant (in lxss), however, I get another error message then:

Error: unknown target device (DSU_DID = 0x10010319)

Apparently I’m using an unconsidered revision of the Atmel samr21-xpro board. I could fix this by adding the following line to static device_t devices[] in /dist/tools/edbg/bin/target_atmel_cm0p.c:

{ 0x10010319, “SAM R21G18A”, 0, 256*1024, 64, 4096, 256 },

Flashing now works, though very inconsistently. Very often, the flashing will fail with a connection timeout that can happen both during the programming and verification phases. The larger the binary file to flash, the more likely the connection is to timeout. I’ve been able to flash smaller binaries with OpenOCD so I suspect a similar or the same problem is at fault when using OpenOCD, causing the error message above. Unfortunately, I don’t know where the root of the problem is. At least with OpenOCD I have tried different boards and different USB cables to no avail. I can try other boards with edbg on Monday but I expect them to fail as well, in which case a problem with the particular board shouldn’t be the root cause (this is reinforced by the fact that somebody else tried to flash larger binaries on my board via OpenOCD, which did work, albeit not using a VM but directly on Linux). Other possible root causes could be a problem with either Vagrant (less likely in my opinion), Oracle VM VirtualBox, my host OS (Windows 10 version 1703) or even my particular PC hardware (Surface Pro 3) but I don’t know how I could proceed further to identify the cause.

If you’d like I can create a pull request for the change to /dist/tools/edbg/bin/target_atmel_cm0p.c and/or add issues to the repo for the problems described.

Best regards,

Adrian (student of Freie Universität Berlin)