1. WS2812 Overview:
WS2812 integrates a processing chip and 3 LED lights of different colors (red, green, and blue). The brightness of the three lights is controlled by a single bus protocol to achieve a full-color effect.
1. Data transmission time:

2. Timing waveform:

3. 24-bit data structure:
Each light requires 8 bits (1 byte) of data (8 1s are brightest, 8 0s are off), so a ws2812 requires a total of 24 bits (3 bytes) **(24 1s are brightest, 24 0s are off)** of data.
Note: The high bit is sent first, and the data is sent in the order of GRB .

2. Several ways to drive WS2812
1. Use the delay function
to directly flip the IO port to generate timing. This method is the simplest and easiest to use. You only need to control the delay time to generate 0 and 1 codes. It needs to occupy system resources. 2.
Use SPI data transmission to generate timing through SPI control. You only need to control the baud rate to generate the required 0 and 1 codes when transmitting different data. This method is equivalent to using an SPI device. 3. Use DMA+Timer to generate timing.
This method requires a timer, in which one channel generates a fixed PWM with a period of 1.25us and a duty cycle of 2/3. Then another channel is needed to move data to the IO port at 1/3 of the period. If it is 1, PWM remains unchanged. If it is 0, PWM is 0 code. This method has greater limitations. Since DMA can only move at least one byte, the high and low levels of 8 IO ports will be changed at the same time each time. Perhaps using bit-band operations can solve this problem. 4. Use Timer+PWM+DMA to generate timing.
This article discusses the implementation scheme. There are two driving methods for this scheme. One is to directly establish a large array to store the data of all lamp beads, and then start DMA transmission. The second is to establish an array of the size of 2 lamp group data. When DMA transmits the data of a lamp bead, change the data of another lamp group. By constantly changing the array, memory is saved. In comparison, the first method is more intuitive, and the second method can solve the situation where there are more lamp beads. This article discusses the principle of the first method and the implementation of the program.
3. TIM+PWM+DMA drive WS2812 timer TIM is used to generate a fixed cycle PWM, and DMA is used to change the duty cycle of PWM:

As shown in the figure, DMA realizes the generation of ws2812 timing by continuously transferring data to the CCR register of the timer to adjust the duty cycle. In STM32, it can be realized by configuring the peripherals: every time the timer generates an overflow event (that is, the count is completed), it requests DMA to transfer a data (length: byte/half word/word optional), so the user only needs to arrange the data in the array to generate the required timing. 4. Schematic diagram introduction
1. Main control circuit:

Use the STM32F103C8T6 microcontroller, add the necessary filter capacitor to prevent the waveform from being unstable.
2. Crystal oscillator circuit:

Use the 8MHz crystal oscillator of the chip to save space.
3. Reset circuit:

4. Power supply circuit:

Use AMS117-3.3, which is very friendly to wide voltage input. Add filter capacitors to make the waveform smoother, and provide a 3.3V regulated power supply to power the microcontroller.
5. Indicator light circuit:

The indicator light is added to indicate whether the PCB board has power input, in order to better see whether the PCB board is in working condition.
6. Download circuit:

This interface is introduced for the convenience of debugging. After debugging is completed, the pin can be removed, which affects the aesthetics of the finished product.
7. Power interface:

This interface provides a battery power supply for the PCB board to power the entire PCB board.
8. RGB light circuit:

Compared with direct-drive RGB lights, this built-in chip integrated WS2812 light occupies fewer pins, which is convenient for wiring on crowded PCB boards and can increase its expandability.
V. PCB introduction
1. Top layer:

2. Bottom layer:

3. Overall:

6. 3D simulation diagram