2025-04-21 4:32 AM
Hello All,
I wonder if someone here can help me out. I have spend a large number of hours over a few days on and off trying to drive a bitstream into a WS2812B using DMA. I have proven the hardware by bit-banging into the LED and it works as expected. I have the DIN pin of the WS2812B to PA3 configured for TIM2_CH4, this is a clean project with nothing else in the way. Clocks are configured to the point where I can get the expected frequency/duty cycle I need, and I have 24 bytes of static data that I want to send to the PWM CCP to create a bitstream.
The code is below, I have gotten this far be reading, seeing examples, even chatting with Chat GPT, and I just cannot get this to work. The code below yields nothing out, its just always low. If I enable the PWM by uncommenting lines 102 and 103 I get the expected 803Khz at 50% mark/space.
In my main loop I am trying to trigger a DMA transfer once ever 500ms... but it does not work, and I am at a loss as where to go now, have followed lots of examples and tried lots of poking around with things, but I just cant seem to make this work.
Can anyone help or offer me any pointers please?
Gerry
2025-04-21 4:42 AM - edited 2025-04-21 4:42 AM
Lots of examples out there on driving WS2812 with STM32. Here is one of them:
How to Interface WS2812 with STM32 using Timer PWM
2025-04-21 5:03 AM
@TDK thanks for the pointer, thats one of the many examples I came across and tried. The problem I have is not so much driving the Ws2812B (although thats what I am trying to do), the problem is, I cannot get the DMA transfer to work. That being said, I just added the following from the above example, and I can see that the something is happening, my main loop runs, and once ever 500ms I clear the variable, initiate the DMA transfer and then check this value, and, it gets reset to 1 by the callback function, so that suggests the DMA is running.
However, what I see on the scope is a fast rising edge and a slow decay of about 1ms, no actual data. Keeping in mind that if instead of doing any DMA transfer I just start the PWM by uncommenting those two lines, I get the 803khs output as expected.
I am really quite lost here, it should work, the change I made appears to show that the DMA peripheral is being started, and is signaling a stop, I am just not seeing the PWM data stream on the output pin.
I am obviously doing something ***, but I really cannot figure out what :(
2025-04-21 5:09 AM
And for comepleteness, this is the TIM4 output when I enable PWM by uncommenting those two lines, this is really just to prove the hardware setup and timer confiuration.
2025-04-21 5:41 AM
@TDK I am not sure if this helps, for me its very frustrating, I just switched the code to use TIM4 CH1 instead, and configured that in the exact same way, and that works. So its something to do with the way TIM2 CH4 works specifically it would seem... which is as I say very frustrating when there is nothing that seems to describe this anywhere.
The timers definitely have different options when configuring them in CubeMX so there is something I am not understanding. The problem is, the hardware is already designed, and that PA6 is already in use, I just hacked the hardware do do this test.
How might I go about getting some assistance from ST?