cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L432 – WS2812 LEDs not working reliably (no external crystal)

Martin42
Associate III

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!

23 REPLIES 23

Pretty sure it's not critical to use a crystal or XO. More likely a fumble at the DMA HT/TC or IRQ processing, or how the TIM is using shadow register or not (Pre/AutoLoad?)

The SW2812 will be unforgiving, but you need to look at the mechanics, the L4 and F4 should be more than capable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@Martin42 wrote:

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


Usually the target MCU is clocked from the ST-Link - which does have a crystal ...

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@Martin42 wrote:

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.


That's not due to your clock drifting - that's an error in your pattern generation.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Hi, I have it running on a L4 (STM32L431). 256 (16x16 module) WS2812B (4 Pin version). Via DMA and Timer.

  1. You should use a 3V3 to 5V level converter for the signal. 3V3 is out of spec. In my case,  (without a level converter), some modules work and some not. Since that, I always using a level converter. I expect you Arduino in powered by 5V. Therefore it is working. Regarding to dataset, you need min. 5V * 0.7 = 3V5. To confirm this, you can lower the supply to 4V (4V * 0.7 = 2V8), then 3V3 signal is in spec.
  2. In case you have a long cables, check that the voltage drop and reflexion are ok.

@FKaes.1 wrote:
  1. 3V3 is out of spec. .

While this is true, I very much doubt that it's the issue here.

Look at the scope plots @Martin42 posted earlier - the sequence is clearly wrong in the "bad" case.

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Kraal
Lead

As@FKaes.1 said, I also think it is related to the voltage level of DIN on the first LED.

@Andrew Neilwe don't know where @Martin42 probed the signal in his 2 plots. It can be at DOUT of the first LED, since I count 5 vertical divs for the signal.

In my experience 3V3 is not high enough, I also got wrong colors, or even wrong LEDs being lit. Once I put a level converter everything was back on track.

@Martin42in my view it is simpler to add a level converter before the first LED and see if the results are good or not.

Andrew Neil
Super User

@Martin42 wrote:
  • Using an Arduino, the same strip works immediately and reliably.


What Arduino - 3V or 5V ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

@Kraal wrote:

@Martin42in my view it is simpler to add a level converter before the first LED and see if the results are good or not.


Fair point: eliminate sources of doubt & uncertainty!

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Martin42
Associate III

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!

5V Arduino Mega 2560