Micro-RLE: Sub-300 Byte Compression Unlocks Bandwidth for Resource-Constrained MCUs
Share this article
For developers wrestling with bandwidth constraints on Cortex-M0+/M4 microcontrollers, every byte and cycle counts. CoreLathe's newly open-sourced Micro-RLE compressor delivers a startling breakthrough: lossless stream compression in just 252-264 bytes of flash and 36 bytes of RAM—smaller than most debugging headers. This isn't theoretical optimization; it's engineered specifically to halve UART transmission volumes for sensor data streams while consuming negligible resources.
Why MCUs Need Microscopic Compression
Sending raw sensor data from resource-constrained devices often bottlenecks at the UART. Traditional compression libraries demand kilobytes of memory—an impossible ask for devices with 8-32KB flash. Micro-RLE sidesteps this by combining two techniques:
- Drift-Aware XOR Delta Encoding: Compares bytes within a 32-byte sliding window (
WIN=32), encoding only the 5-bit difference from the predicted value - Run-Length Expansion (RLE): Compresses consecutive identical bytes into a 3-bit run length token
// Token format: [run:3 bits][delta:5 bits]
// Escape sequence for large deltas: [run:3][0x1F] + full 8-bit delta
The hybrid approach achieves 33-70% compression on typical telemetry streams (temperature readings, accelerometer data) by exploiting small value changes. For outliers, an escape mechanism preserves full 8-bit precision—critical for lossless operation.
Engineering for the Edge
What makes Micro-RLE revolutionary is its ruthless optimization:
- Deterministic Timing: 6-14 cycles/byte on Cortex-M0+ (enabled by bitmask modulo instead of division)
- Zero Overhead: No heap, no initialized data, sub-600µs boot at 24MHz
- Frame Sync Safety: Automatic suppression of consecutive 0x7E bytes to avoid UART framing collisions
- Tiny API Surface: Three functions replace bloated libraries:
void log_init(void); // Initialize state
void log_byte(uint8_t b); // Compress byte
void log_flush(void); // Flush pending run
Integration That Fits
Porting requires overriding just one weak function:
// In micro_rle.c
void emit(uint8_t byte) {
// Your UART/DMA/ringbuf output
}
The build flags reveal its bare-metal ethos:
arm-none-eabi-gcc -Os -mthumb -mcpu=cortex-m0plus -nostdlib \
-c micro_rle.c -o micro_rle.o
Why This Matters
For battery-powered IoT devices, Micro-RLE’s 50% bandwidth reduction translates directly to extended battery life and lower error rates. It enables new use cases—like continuous high-frequency vibration monitoring—previously choked by UART limitations. As sensor networks scale, this microscopic compressor demonstrates how algorithm-hardware co-design unlocks outsized gains.
Available under MIT license, Micro-RLE exemplifies the innovation happening at the razor’s edge of embedded systems—where every byte saved echoes across millions of devices.
Source: CoreLathe/Micro-RLE GitHub