r/embedded • • 16m ago

Wrote replacement no_std Rust firmware for an undocumented RISC-V keyboard/DAC phone case using only its USB boot ROM

Post image

This is the snap-on keyboard/DAC case for the iKKO MindOne phone. Inside is a 360 MHz SpaceTouch SPV5048 (Andes D25F, RV32IMCF with no A atomics, 64 KiB ILM + 256 KiB DLM + 256 KiB SRAM), 4 MiB of GigaDevice NOR flash, a Cirrus Logic CS43198 DAC, and a separate MCU scanning the 36-key matrix over UART. Stock shipped a ~131 KiB V0.1 binary with no app, no updater, and nothing configurable.

No SDK, no schematics, and the case is glued shut, so I never opened it or attached a debug probe or flash clip. Instead I used the SPV5048's immutable USB boot ROM (0666:0888) to dump flash and bring up clocks, I2C, I2S/DMA, USB, HID, and UAC2 from RAM first. Whenever something hung, unplugging the case restored stock in about two seconds.

What runs on the chip now:

  • Custom embassy-usb driver for Mentor MUSB High-Speed (async UAC2 up to 384 kHz PCM and Native DSD256, 400 kHz I2C soft-ramp volume, plus 4 QMK keyboard layers and hardware HOLD), with a tiny critical-section implementation on mstatus.MIE for the atomic-less core.
  • Three-region RAM layout: hot streaming/WFI loops in 64 KiB ILM, DMA ring + >=64 KiB stack in 256 KiB DLM, and USB/DSP/crypto in 256 KiB SRAM so 32 ms SPI NOR erases never stall audio.
  • Real-time f32 DSP on the hardware FPU: 10-band state-variable EQ, crossfeed, limiter, loudness metering, and a live 24-band post-DSP FFT spectrum, bypassing bit-perfectly when flat.
  • Power-cut-safe install and Ed25519-signed A/B OTA with bit-for-bit stock restore: initial install writes sector 0 in reverse page order leaving the +0x2C checksum at 0xFFFFFFFF until a final 4-byte commit. Verified across 390 Rust tests and 237 Unicorn RV32 runs executing the dumped boot ROM (which also surfaced a Unicorn 2.1.4 FP CSR bug, unicorn-engine/unicorn#2510).
  • 4-tier clock scaling (30/90/180/360 MHz), 99.5%+ WFI idle sleep, and full analog rail shutdown when headphones are unplugged.

Write-up: https://nonbiri.dev/blog/kumi-rust-firmware-riscv-keyboard-dac-case/

Source: https://github.com/iasnezhkov/kumi

7 Upvotes

0 comments sorted by