No description
  • HTML 80.2%
  • C 10.9%
  • C++ 6.7%
  • Python 2.2%
Find a file
vratk0529-arch-desktop fc1b763602 Give the case standoffs real walls around the screw counterbores
The 3 mm head counterbore went 1 mm past the 2 mm floor into the 7 mm
standoffs, leaving a 0.25 mm wall that slicers drop, so the standoffs
started in mid-air. Widen the standoff base to 9.5 mm, taper it back,
and step the counterbore ceiling (slot, then square) so it bridges
without support.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 10:47:52 +01:00
3d Give the case standoffs real walls around the screw counterbores 2026-11-21 10:47:52 +01:00
docs Add README, board photo and KiCad project 2026-11-11 22:44:58 +01:00
hardware Resave the PCB in KiCad 10, export the STEP to 3d/ 2026-11-21 00:18:19 +01:00
include Process audio in the SAI DMA interrupts to cut latency to ~1.5 ms 2026-11-13 21:00:09 +01:00
lib Initial commit, not working, resample enabled 2026-01-18 20:55:35 +01:00
LICENSES Add licenses: MIT for firmware, CERN-OHL-P v2 for hardware 2026-11-11 23:00:29 +01:00
scripts Make the project build on a stock PlatformIO install 2026-11-11 22:44:58 +01:00
src Use SW2 to switch the mic AGC on and off 2026-11-13 21:05:20 +01:00
test Initial commit, not working, resample enabled 2026-01-18 20:55:35 +01:00
.gitignore Make the project build on a stock PlatformIO install 2026-11-11 22:44:58 +01:00
.gitleaksignore Add README, board photo and KiCad project 2026-11-11 22:44:58 +01:00
LICENSE Add licenses: MIT for firmware, CERN-OHL-P v2 for hardware 2026-11-11 23:00:29 +01:00
platformio.ini Replace the FIR crossover with LR4 biquads, back to 240 MHz 2026-11-13 20:47:33 +01:00
README.md Use SW2 to switch the mic AGC on and off 2026-11-13 21:05:20 +01:00

STM32 DSP Test Board

A USB sound card + 2.1 class-D amplifier built around an STM32H743. It shows up on the PC as a standard USB Audio device (stereo speakers + mono microphone, no drivers needed), splits the audio into left / right / subwoofer with FIR filters and drives the speakers directly. The microphone input gets a noise gate and AGC before it goes back to the PC.

The board

The one-day board

I designed the schematic and the PCB in a single day, as a sort of challenge. It works well - it's my primary audio amp and I use it all the time with my PC - but it shows. Some of the dumber decisions:

  • The integrated Black Magic Probe. Why did I put a whole debugger (an STM32F103 + USB hub) on the board? It's just annoying.
  • The wrong ADC. I picked the hardware-controlled PCM1861 instead of one of its I2C-controlled siblings, so the microphone gain is fixed in hardware.
  • +30 dB of mic gain. That was WAY too much, and changing it to 0 dB required some horrendous bodges.
  • No protection on USB-C power. The internal 5 V rail is connected straight to the USB-C port, without a diode or anything. When the board runs from the DC jack, it can back-feed 5 V into whatever it's plugged into. Don't copy this part.

Hardware

Block Part
MCU STM32H743VIT6, 8 MHz HSE
Audio clock 12.288 MHz oscillator, fed in as the SAI master clock
DACs 2× PCM5102A (left/right, subwoofer)
Amplifiers 2× TPA3118D2 (stereo + subwoofer)
Mic ADC PCM1861
USB CH334R hub → STM32H743 (audio) + STM32F103 (Black Magic Probe)
Power DC jack → TPS54302 5 V buck, AMS1117 / LP5907 3.3 V LDOs
Front panel 4 pots, 2 toggle switches, status LEDs
Extras TOSLINK in/out footprints - unpopulated, I couldn't find the parts in stock on LCSC

The KiCad 9 project is in hardware/. The schematic is also available as a PDF, and hardware/bom/ibom.html is an interactive BOM. hardware/production/ has the gerbers, BOM and placement files (LCSC part numbers included) as exported for JLCPCB. Some 3D models came from easyeda2kicad and aren't included, so a few parts are missing in the 3D view.

Firmware

Signal path

PC ──USB──► resampler ──┬─► LR4 high-pass (100 Hz) ──► PCM5102A ──► TPA3118 ──► L / R
                        └─► mono → LR4 low-pass (100 Hz) ─► PCM5102A ──► TPA3118 ──► Sub

Mic ──► PCM1861 ──► high-pass ──► noise gate ──► AGC ──► soft limiter ──► resampler ──USB──► PC
  • USB Audio Class 1, 48 kHz / 16-bit, stereo out and mono in.
  • The USB host and the board's audio clock are never exactly in sync, so both directions go through a fractional resampler whose rate is steered by a control loop that keeps the buffers at a fixed fill level.
  • The crossover is a 4th-order Linkwitz-Riley at 100 Hz (two cascaded Butterworth biquads per output, double precision): 24 dB/octave on both sides, and sub + satellites sum back to a flat response. Change it with -D CROSSOVER_HZ=....
  • The amplifiers are muted and shut down automatically when there's only silence on the outputs.
  • All audio is processed in the SAI DMA interrupts, 16 frames (1/3 ms) at a time, straight into the DMA buffers. The only buffering is the USB ring in each direction, so the board adds about 1.5 ms of latency for playback and about 2.5 ms for the mic (USB packets are 1 ms). The main loop only reads the pots and drives the LEDs, and the CPU sleeps the rest of the time.

Controls

Control Function
POT1 (rightmost) Main volume (−90 to 0 dB, on top of the PC volume)
POT2 Subwoofer level (−6 to +20 dB relative to main)
POT3 Mic noise gate threshold (−60 to −20 dBFS)
POT4 (leftmost) Mic AGC maximum gain (0 to +30 dB)
SW1 Amplifiers on / off
SW2 Mic AGC on / off (off = fixed 0 dB, gate stays on)
LED1 Amplifiers on
LED2 Output clipping
LED3 Mic gate open (mic is transmitting)
LED4 Amplifier fault / unexpected amplifier state

Building

It's a PlatformIO project:

pio run                 # build
pio run -t upload       # flash through the on-board Black Magic Probe
pio device monitor      # debug UART (1 Mbaud)

The platform version is pinned in platformio.ini; PlatformIO downloads the right toolchain and framework on the first build. The upload and monitor ports (/dev/ttyBmpGdb, /dev/ttyBmpTarg) come from my udev rules - change them to your probe's ports (usually /dev/ttyACM0 and /dev/ttyACM1).

Optional build flags (uncomment in platformio.ini):

  • -D CPU_LOAD_REPORT=1 prints the CPU load once a second on the debug UART, plus glitch counters: speaker underruns / dropped frames / sub DMA sync errors, and mic buffer overflows / underruns / missed ISO IN packets.
  • -D CPU_CLOCK_480MHZ=1 runs the core at 480 MHz instead of 240 MHz.
  • -D CROSSOVER_HZ=80.0 moves the crossover (default 100 Hz).

The STM32duino core only builds its USB device stack for CDC/HID, so scripts/usb_device_core.py pulls the generic parts of it in for the custom audio class.

The USB VID/PID (0xEEEE:0x0529) are made up, fine for personal use but not registered.

Repository layout

src/, include/   firmware
scripts/         PlatformIO build helper
hardware/        KiCad project, schematic PDF, production files, interactive BOM
docs/            pictures
LICENSES/        third-party licenses

License

  • Firmware (src/, include/, scripts/): MIT.
  • Hardware (hardware/): CERN-OHL-P v2.
  • src/usbd_audio.c, include/usbd_audio.h and src/usbd_desc.c are modified versions of STMicroelectronics code and keep ST's license terms, as stated in their headers. The license of ST's USB Device Library (SLA0044) is in LICENSES/.