

After PWM transfer, send 50us pulse again ( 40 periods at 800kHz).There is no dead-time between end of first led and beginning of second led!.Transfer 24 bits for each led of 33% (logical 0) or 67% (logical 1) duty-cycle on PWM.Before you start PWM sequence for all leds, 50us reset pulse (pulse low) is required ( 40 periods at 800kHz).To transfer data for 1 LED, you need 30us PWM signal must be 800kHz, or 1.25us per bit.I will not go deep into control sequence, to set color you basically need to respect rules below: To have information for all leds, we need 3 * leds_count big array with R0,G0,B0, R1,G1,B1, R2,G2,B2,… color structure.

LED memory footprintĮach LED has RGB format for color, which represents 24 bits of data (or 3 bytes). We will use this feature for our raw data for PWM for each LED. DMA in STM32 also supports circular mode, which basically means that once we are at the end of block transfer, DMA will start from the beginning of memory and will transfer more data (this is visible on picture below with left arrow). Since we are receiving 2 events in the middle/end of block, we can use single buffer DMA mode but interact with it as double buffer data. receive Transfer Complete event ( TC event) after all elements were transferred.receive Half-Transfer Complete event ( HT event) after 24 elements were transferred,.If we configure DMA to transfer 48 elements we will: They are called at the end of block transfer and in the middle of block transfer, respectively. Second option we have is to use single buffer mode and rely on DMA Transfer-Complete and Half-Transfer Complete events.

64BIT STM32 DRIVER CODE
Handling this may add some additional code in our project. In this mode, you have 2 memory addresses and DMA will switch between memories at the end of block transaction. Double buffering DMAĭMA hardware in all STM32 families allows you double buffering mode. All together we need 3 * LEDS_Count + 24 * sizeof(uint32) bytes.

STM32 hardware allows you good way to scale down this ram usage to 3 bytes per LED, which is 300 bytes at 100 leds = 32x more efficient! In addition to this memory, we also need temporary buffer to store 2 LED raw PWM data, used for DMA hardware. If you have 100 leds, that’s almost 10k of RAM. It uses 24 words of RAM for each LED, which is 96 bytes per LED. It is very well written, but it has one major issue. If you have no experience with WS2812B leds, I strongly recommend you to read the blog post. There is a good explanation, already available on the web.
64BIT STM32 DRIVER HOW TO
In this tutorial I will explain how to drive WS2812B with STM32 using TIM PWM and DMA peripherals in the most efficient way by using minimum amount of RAM, required to process all leds.
