finds.dev← search

// the find

nicokorn/STM32F1XX_WS2812B

★ 10 · C · MIT · updated Sep 2022

This is an example code of controlling an ws2812b led stripe, with 18 leds thus the used library is configured as 1 row with 18 cols. You can change row and col in the ws2812b header file. You can connect up to 16 led stripes. Data is written in parallel to the stripes from a GPIO Bank (GPIO A in this example) This is why up to 16 stripes can be controlled in parallel. A Timer is used in which 3 DMA transfer are triggered used to write data to the gpio's on which the stripes are connected to. These 3 DMA transfers are triggered as following: First trigger is on each period. It sets all gpios to high. Second trigger is on the first capture compare event on the 8th tick/pulse. The GPIOS are set accordingly if the bit for the ws2812b shall be a 1 or a 0 in the output buffer "WS2812_Buffer". The third trigger is the second capture compare event an sets all gpio's always to 0 through a dma transfer. It doesn't matter if the pins are already set to 0 by the first capture compare event. Please read the ws2812b datasheet to understand the communication protocol with the ws2812b led chips. This example is programmed in the IAR Embedded Workbench IDE for a stm32f103 and tested on the famous Blue-Pill. But you can use this library for any other IDE or stm32 microcontroller. Just be sure to set the correct DMA streams/channels, otherwise it won't work.

A DMA-driven WS2812B LED driver for STM32F1 (Blue Pill) that controls up to 16 LED strips in parallel using a single GPIO bank. The three-DMA-transfer trick — set-all-high, set-data-bits, set-all-low — is a well-known but tricky technique that offloads all the 800kHz timing from the CPU. For an embedded developer who wants to drive multiple WS2812B strips without bit-banging or per-strip timers, this is a working reference.

The parallel GPIO bank approach is genuinely clever: all 16 strips share one timer and three DMA channels, so adding a strip costs zero CPU and no extra peripherals. The timing diagrams in the docs folder show exactly which timer ticks trigger each DMA event, which makes porting to a different STM32 family straightforward. The code is self-contained — no HAL dependency spaghetti, just CMSIS and the STM32F1 peripheral library, so it compiles cleanly across toolchains. The README honestly tells you what to change (DMA channels/streams) when you move to a different chip.

The repo ships the entire CMSIS DSP test suite as dead weight — nothing in the WS2812B driver uses any of it, and it balloons the repository with hundreds of files that have nothing to do with the stated purpose. There is no API: you get one hardcoded example for 18 LEDs on GPIO A; gamma correction, HSV helpers, or any abstraction above raw RGB bytes are left entirely to you. The IAR project files are included but no Makefile or CMakeLists.txt, so users on GCC/arm-none-eabi have to wire up their own build. Last touched in 2022, 10 stars, zero forks — it works, but it is abandoned and you own it from day one.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →