Note: The mercurial server is disabled at the moment while I investigate whether it can run with an acceptably low CPU load – Mike.

Debugger connection (Digital Systems)

Copyright © 1993–2025 J. M. Spivey
Jump to navigation Jump to search

Raspberry Pi

With RPi OS bookworm, the version of PyOCD installed as the package python3-pyocd is incompatible with the system version of Python 3. The immediate symptom is a crash because of a naming conflict between thread methods isAlive and is_alive, but hacking round this just reveals other incompatibilities that I'd rather leave someone else to fix.

With OpenOCD, everything works fine.

Debian

On my laptop (the T480s, since it has less detritus), it was necessary to install a udev rule (see below). After that, pyocd-gdbserver had the same problem as on the Raspberry Pi. The version installed is really old (0.13.1) compared to the latest (0.33.0), even though that dates from January 2022.

On the other hand, openocd seems to work without problems. The command line is

openocd -f interface/cmsis-dap.cfg -f target/nrf51.cfg

OpenOCD can become detached if the micro:bit is disconnected briefly, either by unplugging it or by uploading a new program via the mass storage interface. Either action causes the USB device to be re-enumerated; OpenOCD tries to reconnect by polling at increasing intervals, but (I think) it uses the old address and never succeeds. The only solution is to end the debugging session and start a new one. An alternative way to upload a new program is to use the command load echo.elf within the debugger.

Pressing reset on the micro:bit does restart the program, but can lead to a situation where the debugger thinks the program is paused when it is actually running. Typing cont to the debugger results in an error message, but does succeed in getting program and debugger in sync again. Alternatively, you can reset the micro:bit with the debugger command monitor reset.

udev rules

The Raspberry Pi needs no extra udev rule to give access to the micro:bit for debugging.

The lab meterials have the following rule in the setup directory as 50-mbed.rules:

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0204",
  MODE="660", GROUP="plugdev"

On the software lab machines, the following rule is provided (thanks, Ian!).

# These rules allow a user to control a BBC micro:bit device plugged in to
# a USB port.  The uaccess tag will make sure that a logged-in user with a seat will be
# given read/write acess to the device via an ACL.

# serial interface
SUBSYSTEM=="tty", ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0204", TAG+="uaccess"

# /dev/bus/usb interface (for the debugger)
SUBSYSTEM=="usb", ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0204", TAG+="uaccess"