This project describes how to create a nice X-mas led strip lights based on amazing WS2811 water proof led strip and stm32 micro controller. This is a migration my previous project based on Arduino.
There is a neopixel library written for Arduino platform on github site. If you would took a look into a source code, you would see that the library is heavily used some kind of delay routine to support the neopixel strip protocol. This approach is not the one they used on stm32 platform, because there are many tools inside stm32 platform to free CPU from useless waiting.
NeoPixel protocolThe ws2811 datasheet describes the protocol used to drive the leds. In the picture below you can see how "0" and "1" signals are translated to the led strip.
T0H is 0.5 uS, T0L is 2uS
T1H is 1.2 uS, T1L is 1.3 uS
Treset is above 50 uS
The periods for "0" and for "1" codes are the same, 2.5uS. So the NeoPixel protocol is just some kind of PWM signal with the constant period, 2.5uS, the signal frequency is 400kHZ.
Every LED on the strip requires 24 bits to be sent via the bus and the data for each LED is sent consequently, To lit 100 LEDs we need to transmit 24x100 bits, then send reset signal.
Write Own NeoPixel LibraryThe main idea is to drive the led strip using PWM signal on TIM2 timer managed by the data loaded via DMA channel. The TIM2 timer clocked by 72 MHZ internal frequency and has period counter equal to 90. This generates the PWM signal of 800kHZ. To generate "0" or "1" we put "24" or "49" to the timer channel register.
To generate protocol signal the ring DMA buffer is used. The buffer length is 64 bytes because there are WRGB led strip exist that require 32 bits per led. The DMA buffer allows to store the PWM data for 2 sequential leds. As soon as the ring buffer is used, the DMA controller generates two interrupts: half-buffer and full-buffer.
First we fill the DMA buffer with the PWM data of two leds and start the DMA transfer. When half-buffer interrupt fires, we should fill the left side of the DMA buffer with next led PWM data. When full-buffer interrupt fires, we should fill up the right side of the buffer.
To send reset signal, we fill timer channel register with "0" during time of two leds signal.
LED displayThe 4 digits LED display is optional. It is used to show the current animation program or clear program number. There are 46 animation programs in the current release.
Flash The Firmware to the Controller
To flash rebuilt firmware to the controller the st link v2 programmer and ST link utility are required.
Download the STM32 ST-LINK utility from st site. Install the utility in your system. Launch the ST-LINK utility, connect the programmer to the 4pins SWD interface of BluePill board, press "connect" button. The main window should display the memory content of the BluePill board. Press flash button to write the firmaware to the BluePill board.
Building instructionsTo compile the project from the source code you have to:
- install "Workbench for STM32" and CubeMX software from openstm site.
- download your project ZIP file from the github repository
- create directory named F1-xmas_neopixel in your project directory
- extract everything from ZIP to F1-xmas_neopixel or just extract ZIP archive from GitHub then rename created top folder to F1-xmas_neopixel (name of top folder must be F1-xmas_neopixel)
- start CubeMX (just click to F1-xmas_neopixel.ioc file in F1-xmas_neopixel folder)
- CubeMX ask you to migrate to newer firmware version, answer yes to migrate.
- to start "Workbench for STM32" you can click on.project file in F1-xmas_neopixel folder
- adjust workspace to top folder of F1-xmas_neopixel folder
- add include file path for max7219 and ws2811b (Project -> Propertis ->Settings; Configuration: [All configurations], Includes => add directory.
- Convert project to C++ (Right mouse click on the project folder in the left pane)
- Add "-ffunction-sections -fdata-sections" optimization flags to make the binary code shorter. (Properties->C/C++ Build->Optimization->Other optimization flags).
- Compile and run
Comments
Please log in or sign up to comment.