No SWD? No Problem: Erich Styger Shows How to Debug Arm Cortex-M Chips Over CAN Bus
A framework written by student Simon Kathriner makes it possible to use Arm's DebugMonitor feature for hardware debugging via CAN bus.
A student of embedded engineer and professor Erich Styger have developed a neat trick to show anyone looking to debug an Arm Cortex-M target without using the traditional Serial Wire Debug (SWD) or JTAG interfaces β by taking advantage of the CAN bus instead.
"Traditional hardware debugging requires a hardware debug probe, connected with a dedicated SWD/JTAG debug cable to the target device," Styger explains. "This needs dedicated pins on the target device plus physical access to the device itself. In many cases, this is not possible in the final product. The hardware debug probes, cables, pins and high speed signals are costly. And worse they can introduce new problems and are prone to interference. If there is a field bus like CAN connecting all the MCUs, why not use it for hardware debugging?"
The Controller Area Network (CAN) bus was originally developed for use in industrial automation, and is now a key feature of modern automotive systems β but rather than using it for communication and control during normal operation, Styger has demonstrated how it can be used to handle traditional debugging tasks that would normally take place over SWD or JTAG: flash programming, controller halting, memory inspection, and instruction stepping β thanks to "a rather unknown hardware feature" available on many models in Arm's Cortex-M microcontroller family.
"The proposed solution uses a special ARM Cortex-M feature: the ARM DebugMonitor hardware," Styger explains. "Using a special gateway, the CMSIS-DAP debug protocol gets translated between USB and the CAN network. Normal tools like gdb or VS Code are used on the host. On the target systems, a framework with the necessary hooks and code gets added, allowing hardware debugging. During debugging, the framework keeps the CAN communication going. In my opinion, the DebugMonitor feature of ARM Cortex-M is one of the most underrated features ARM has implemented. The DebugMonitor is available on all ARM Cortex-M, except for M0/M0+."
The framework β which makes it possible to link the DebugMonitor to traditional debugging tools via the CAN bus β was written by Styger's student Simon Kathriner, who has made it available under an unspecified open source license on GitLab. A detailed write-up of how it works is available on Styger's blog.