STM32L432 – WS2812 LEDs not working reliably (no external crystal)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 9:01 AM - edited 2025-05-12 9:02 AM
Hi everyone,
I'm trying to drive a WS2812 LED strip (20 LEDs - Strip has 60 LEDs) using an STM32L432KCUx, but so far without success.
I've tested multiple approaches — PWM with DMA, SPI-based encoding, and bit-banging via GPIO — but none of them produce stable or correct results. Sometimes up to 22 LEDs light up instead of 20, and the colors are often wrong or appear white.
Occasionally, the first LED doesn’t light up at all, which seems to indicate timing jitter or inaccurate bit timing.
Setup:
Microcontroller: STM32L432KCUx
No external HSE crystal or LSE available
SYSCLK = 48 MHz, tested using both MSI via PLL and HSI via PLL
Output pins used:
PA12 for SPI and bit-banging
PA9 for PWM (TIM1_CH2)
SPI clock set to 2.4 MHz (used for encoded WS2812 bitstream) SYSCLK = 38MHz
3.3 V logic level used for WS2812 data line (no level shifter)
LED strip powered with 5 V USB - GND connected
Additional info:
I confirmed the LED strip and wiring are working:
Using an Arduino, the same strip works immediately and reliably.
Questions:
Has anyone successfully driven WS2812 LEDs using an STM32L4 without an external crystal?
Could the issue be due to clock accuracy (MSI/HSI) or the 3.3 V logic level?
Does anyone have a working example project (PWM, SPI, or bit-banging) for this or a similar STM32 without HSE?
I'd really appreciate any tips, example code, or experience on this topic!
Solved! Go to Solution.
- Labels:
-
STM32L4 series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-13 3:37 AM
After many attempts and small mistakes with sometimes big consequences, I’ve now powered the LED strip with 4 volts and am using https://github.com/nimaltd/ws28xx library.
Of course, it didn’t work perfectly right away, but now everything is running smoothly.
Many thanks for the quick and helpful support!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 9:17 AM
Solved: Re: Controlling WS2812B LED Strip With STM32 - STMicroelectronics Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 9:18 AM
You haven't said what hardware you're using - see: How to write your question to maximize your chances to find a solution.
Have you used a scope or logic analyser to verify your drive signal?
@Martin42 wrote:
- Could the issue be due to clock accuracy (MSI/HSI) or the 3.3 V logic level?
Could even be both!
Start by eliminating some unknowns - does it work if you do use a crystal HSE ?
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 9:22 AM
Hi, thanks for your reply. I already found it, but I thought it was an STM32F4 controller, which I believe is faster than the L4. Am I right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 9:35 AM
I don’t have an external HSE crystal available on my custom hardware, and adding one would require a fairly involved soldering modification — so I’m trying to avoid that unless it’s absolutely necessary.
That’s why I’m particularly interested to know if anyone has successfully driven WS2812 LEDs using an STM32L4 series MCU without an external crystal. I'm currently using internal oscillators (MSI or HSI via PLL), but the timing doesn't seem reliable enough.
Your comment actually reminded me that I do have an STM32 Nucleo-32 board (STM32L432KC), which includes an on-board 24 MHz crystal oscillator. This allows me to test the exact same WS2812 setup with a stable HSE-based clock configuration. If it works reliably on the Nucleo board, that would strongly suggest the problems on my custom board are due to clock inaccuracy or jitter caused by the internal MSI/HSI oscillators.
I'll test this setup next to confirm whether the internal clock is indeed the root cause.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 10:02 AM
@Martin42 wrote:I don’t have an external HSE crystal available on my custom hardware, and adding one would require a fairly involved soldering modification.
So test on a Dev Board - eg, your Nucleo board.
A key use of dev boards is, after all, to prove this sort of unknown before committing to custom hardware ...
@Martin42 wrote:clock inaccuracy or jitter caused by the internal MSI/HSI oscillators.
They are certainly less accurate than a crystal, but jitter shouldn't be a problem.
The timing tolerances on the WS LEDs are pretty wide - they are designed as cheap consumer parts - so it should be doable.
AIUI, they regenerate their own timing on the data that they pass-through - and they certainly don't have a crystal with each LED!
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 10:18 AM
I don't think speed is an issue here. Adjust the timer period based on your clock settings. It's a one line change.
The accuracy difference between HSE and HSI is not an issue for the WS2812.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 11:30 AM
I tested a single LED with red color using PWM and DMA. The signal was mostly correct, but occasionally the LED displayed white instead of red.
Bad signal.
Do you have an idea what could be causing this issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 1:07 PM
After further attempts to get the crystal working on my NUCLEO-L432KC evaluation board, I discovered that there isn't one installed on the STM32L4, only on the STM32F4. That's a bummer.
The L4 has a 32K LSE mounted on X1. Of course, that doesn't work as a HSE.
Do you think I really don't need an external crystal to control the SW2812?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2025-05-12 3:25 PM - edited 2025-05-12 5:33 PM
> Do you think I really don't need an external crystal to control the SW2812?
Required timings seem pretty generous, don't they?
