Driving 16 WS2812B Strips With GPIOs And DMA

[Martin Hubáček] wrote in with his WS2812 LED library for the STM32F3 series processors. [Martin]’s library takes the same approach as [Paul Stoffregen]’s OctoWS2811 for the Teensy, and [Erich Styger]’s for the Freescale FRDM-K64F board. That is, it uses three DMA channels to get the signal out as fast as possible.

ws2812b-dma-timing-diagramHe has a good overview of the method that you can check out for details, but it goes something like this. The WS2812 uses a PWM-like encoding to transfer data. If the signal is high for 1/3 of the time, it’s a zero, and if it’s high for 2/3 of the time, it’s a one.

The first DMA signal sends the start of a bit, setting all outputs high. The second DMA channel sends out a low signal for all of the zeros, and the third DMA channel sends out a low signal for the ones. Each of these three DMAs are clocked at just the right times to make the pulse timing work out.

The advantage of this GPIO/DMA setup over other methods is that it can drive a whole bank of pins — up to 16 strips simultaneously for the STM32F10x chips. It also loops the graphic buffer around so that you can drive repeating patterns without using much memory. And all the CPU has to do is load up the DMA buffer when it’s (half) empty, which means that even with a full load of LEDs, it’s still got most of its time left for number crunching.

ws2812b-mixing-colors-with-and_or-gates-urwhqbio1qemkv-shot0006_whiteFinally, to show off, [Martin] pulled a sweet trick and captured it on video. Since the digital signals are on/off encoded for the red, green, and blue channels, he decided to experiment with digital color mixing. He ands and ors two simultaneous signals together and demonstrates that it works just as you’d expect. Check it out in the video below.

8 thoughts on “Driving 16 WS2812B Strips With GPIOs And DMA

  1. Love that TESLA 74x series chip on that breadboard! That thing has to be at least 30 years old if not more. TESLA stopped producing chips (mostly ceased to exist as a company) after the fall of communism in 1989. Childhood memories of playing with 7400 gates which were extremely precious, because components were hard to get unless you knew the right people or lived in a large city where there was a relatively stocked store …

  2. Hello, I’m the author of the library. Just wanted to clarify that this lib is different. It don’t allocate big uint16_t buffer with bit combinations to just throw to GPIO, but thanks to circular DMA and quick bit-banding in DMA’s IRQ it uses only small buffer for two LEDs and updates it on-the-fly from the efficient RGB framebuffer.

  3. If you want to see a *hack* check out my up-to-4-strips WS2811 library for the poor little Atmegas, a modification of the original ws2811 library to take advantage of every clock cycle available.

    If you really wanted you can drive about 16 strips with an Atmega but your pixel data would need to be preprocessed instead of using the normal RGB buffers.

Leave a Reply to Jan Ciger (@janoc200)Cancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.