MaJerle / stm32-ws2811-ws2812-ws2812b-ws281x-tim-pwm-dma-timer

WS2811, WS2812, WS2812B or compatible leds driver with STM32, TIM, PWM and DMA with minimum RAM required
192 stars 43 forks source link

St32f072c8t - usart #10

Closed gaucho1978 closed 2 months ago

gaucho1978 commented 2 months ago

I’m on St32f072c8t. I can use only one of these 2 pin to control a ws2812 led strip: PA14 (Alternate functions Usart2_tx and swclk) or PA12 (Alternate functions can_tx, usart_rts, tim1_etr, comp2_out, tsc_g4_io4, eventout, usb_dp) Can I use this library? I suppose no, but I’m a newbie 😁 Any hint for a beginner?

MaJerle commented 2 months ago

Sure you can. You will need to select another timer and adjust DMA for another timer (different channel) but concept will of course work.

gaucho1978 commented 2 months ago

Sure you can. You will need to select another timer and adjust DMA for another timer (different channel) but concept will of course work.

Thank you for reply. I don’t understand: this library uses timer to generate pwm. But timer can be used only with specific gpio. No one of the alternate functions of my gpio are related to timer output, then I suppose I can not use this approach. Where am I wrong?

MaJerle commented 2 months ago

But you can always change the timer, which is available in your GPIO. Sadly, if there is no timer alternate function on your pin, then you cannot use this pin for signal generation.

gaucho1978 commented 2 months ago

Yes, my pin doesn’t have timer as alternate function.

Is it possible to generate custom interrupts at fixed periods and toggle gpio inside that interrupts? Sorry for newbie question.

will it result in a too slow update rate for a 2 meters led strip?

MaJerle commented 2 months ago

Alternatively you may use SPI if you have MOSI on your pin? Otherwise you will need bitbanging, that will slow your CPU :)

gaucho1978 commented 2 months ago

Alternatively you may use SPI if you have MOSI on your pin? Otherwise you will need bitbanging, that will slow your CPU :)

Thank you. Meanwhile I found the way to use another pin with AF timer. Now I’m reading your code to find the way to integrate it in to my code.

gaucho1978 commented 2 months ago

unfortunately this library is using LL driver and not HAL. I find too difficult to convert it to STM32F0xx uP, since some functions are using different number of parameters, and I obtain a lot of errors. Can I use some other github repo as starting point?

MaJerle commented 2 months ago

Driving LEDs with SPI or timer is very advanced topic and not a typical application use case with these IPs. For this reason, HAL drivers don't necessary support all the features in the every neat way. This is then when LL drivers come to play.

I do not have any other repo.

Maybe this can help you if you have access to SPI on your led pin: https://www.newinnovations.nl/post/controlling-ws2812-and-ws2812b-using-only-stm32-spi/

gaucho1978 commented 2 months ago

I have no SPI in my free pins. Meanwhile i compiled with success this: https://github.com/Cpt-Quantum/STM32F0-Timer-WS2812 I made some adjustments and I need to double check everything before to try it. I hope I can do it today.

gaucho1978 commented 2 months ago

Anyway this repo was really useful to understand the best approach to use, the protocol, and to get support on my problem. At the end I implemented with success the same approach on stm32cube ide. Thank you very much.