cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32 drive 32 strips of ws2812

Akargarelc
Associate II

Hello. 

I have connected 32 strips of ws2812 connected separately to 32 gpio of stm32f407vgt6, each strip has 30 chips in series, how can I drive all of them? Dma, pwm, uart and spi modes doesn't support this number of strips separately.

Thank you

10 REPLIES 10
Danish1
Lead II

I think you should be able to DMA all the devices on a single port (e.g. GPIOA) in one hit. You can do 32-bit DMA to the BSRR register, with each DMA transfer being driven off a timer clocking with a period around 0.35 microseconds.

Looking at the data-sheet for the devices, I think it would take 4 words of DMA to write one bit to each of those devices. And as each device in the chain wants 24 bits, and you have 30 chips in series, that's 4 x 24 x 30 = 2880 32-bit words (11520 bytes) of DMA for all the devices connected to a single port.

I suspect you could also include the reset code as well - that's 50 microseconds so maybe equivalent to two more chips in series.

Working out the bit-pattern to write into that bank to send to the LEDs is not trivial. You want to DMA a waveform that does 1000 to send a bit zero; 1100 to send a bit 1 (total time for all 4 DMA transfers about 1.4 microseconds).

If the chains are spread across two ports e.g. GPIOA and GPIOB then you'd need to set up two DMA transfers. If you use the same DMA channel then you'd need to wait for one transfer to complete before starting the other.

Thank you that's very useful, I'm working on it, how can I change dma port after a transfer is completed? Just restart dma setting every time?

If I assign a port to dma, can I use some of pins of that port for another command? 

gbm
Lead III

Driving 30 strips is close to impossible. It's much easier to drive 3 strips of 300 WS2812. With F4 series, you may only use SPI peripherals and timers for that task.

Any modern series of STM32, starting with STM32F0, will be better and easier to use for controlling WS2812 than F4 - the slightly enhanced UART present in F0, L0, L4, L5, G0, C0 series may be used. Search for a microcontroller with many UARTs (like STM32F091).

See these threads:

https://community.st.com/t5/stm32-mcus-products/stm32103-bluepill-bare-metal-ws2812b-neopixel-driver-no/m-p/622687#M230914

https://community.st.com/t5/stm32-mcus-products/ws2812-library-does-not-work-on-stm32f40/td-p/603041

 

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

Thank you, there is many company's built this project with same conditions as I said, I checked they boards, all of them connected 32 strips to stm32f107vct6

Probably, but it's not optimal.

One GPIO bank using all 16 pins would be easier to drive with a pattern buffer via DMA.

With a circular buffer getting HT and TC interrupts you could update the inactive half whilst the other half paints.

For 32-bit, I'd perhaps consider the FMC data bus with some latches or gates, and DMA into that memory space.

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

As regards restarting the DMA, it depends what library you're using (many people here use the ST-written HAL libraries). But I don't like them; I write my own.

----

You can use other pins of that port for other things. But you need to be slightly careful to avoid "read-modify-write" issues while the DMA is running. If you read from e.g. GPIOA->IDR or GPIOA->ODR, the DMA might have changed one of it's bits before you write back to GPIOA->ODR. So your write-back could upset things.

If you only write to GPIOA->BSRR, then only the bits you want to set or reset will be changed.

If in doubt, consult the Reference Manual for your stm32.

Could look for 2 DMA driven via different channels of the same TIM, perhaps with staggered phase settings.

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

Thanks for helps

I'll check it

I think another way is to use logical gates to control infinit strips with just 1 gpio (for example uart or spi), what do you think? 

No logic gates are needed if you control WS2812 from SPI MOSI. An inverter is needed on F4 UART TX, F0 or any newer UART may simply invert the TX under software control.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice