blackmagic-debug / blackmagic

In application debugger for ARM Cortex microcontrollers.
GNU General Public License v3.0
3.3k stars 775 forks source link

Feature: Alternate Manchester SWO implementation using DMA #1960

Open ssimek opened 1 month ago

ssimek commented 1 month ago

Fast DMA-based SWO Manchester decoding

Detailed description

The current interrupt-based SWO decoding suffers (IMO) from several issues

This PR contains a full reimplementation of the SWO Manchester decoder using DMA that makes capture a lot more efficient:

  1. all edge times of the signal are captured using a timer
  2. DMA is used to record the timings into a circular buffer
  3. the buffer is periodically processed in batches, transformig the edge stream into a byte stream for sending in another circular buffer, resulting in effective processing time per sample on the order of several clock cycles
  4. the output buffer is processed in a lower-priority ISR as time permits

The result is the ability to process SWO signal up to ~3 MHz with the probe being more resilient against higher frequency signals (it just fails to decode it properly). Continuous streaming at these speeds obviously makes USB a bottleneck (1.5 Mbit = ~180 kB/s, with the USB controller seemingly being able to handle up to about 70 kB/s without double buffering). But for reasonably intermittent flows, one big benefit is the lightened load on the target.

Your checklist for this pull request

Closing issues

None that I'm aware of

dragonmux commented 1 month ago

Note: We are aware of the breakage on the lint pass from GitHub's deployment of Ubuntu 24.04 LTS, we will get this fixed in the mean time.

Edit: This has now been fixed, when you rebase this PR on main next, that fix will automatically get pulled in and used.