cancel
Showing results for 
Search instead for 
Did you mean: 

Configuring PWM on stm32f405

sb_st
Associate II

Hi there;

I'm extremely new to the world of ST, and trying to get my feet under me with it, coming from a few years' experience developing for esp32 microcontrollers using the esp-idf framework. 

I have an Adafruit stm32f405 feather; I understand this isn't the same as a proper ST development board, but I am trying to learn with it nevertheless. The board has an onboard neopixel - out of the box, the board can be plugged into USB and the neopixel begins cycling through colors. I *think* it comes configured with circuitPython, but I am interested in getting it working using ST's tools and workflows, and so I'm trying to figure out how to get that neopixel working in cubeIDE. 

Studying the schematic, I can see the neopixel is connected via pin PC0. This is where I'm getting a bit lost - I *think* what I need to do is configure PWM using some timer settings somewhere (?), then connect this pin PC0 to that timer/pwm generator. But it's not clear to me how to do this in the cubeMX/visual configuration side of things. 

I can see, when I click on some of the pins in the Pinout & Configuration settings, that some have timer options listed among the available settings. But PC0 does not:

Screen Shot 2024-09-15 at 7.47.40 PM.png

So it's not quite clear to me how to proceed (and, again, I am VERY new to this, so just understanding the relationship between the timers and pins and all the configuration settings has put me in a bit of an overwhelmed state). How was it that this neopixel might have worked initially? 

From Adafruit's documentation about the board:

The NeoPixel is connected to pin #8 in Arduino, so just use our NeoPixel library and set it up as a single-LED strand on pin 8.

CircuitPython, the NeoPixel is board.NEOPIXEL and the library for it is here and in the bundle. The NeoPixel is powered by the 3.3V power supply but that hasn't shown to make a big difference in brightness or color. The NeoPixel is not used by the built in STM32 bootloader! 

 

I don't really know what it means for the neopixel "not to be used by the bootloader" though...

Thank you for entertaining this question!

 

1 ACCEPTED SOLUTION

Accepted Solutions

For this link: https://github.com/MaJerle/stm32-ws2811-ws2812-ws2812b-ws281x-tim-pwm-dma-timer

Read the readme file:

SofLit_0-1726585846872.png

As you are new in the STM32 world, not easy to explain you all the mechanism. You need to start somewhere. I think you need to start some STM32 courses to understand the environment and tools and how STM32 are working.

I suggest you so start with this wiki: https://wiki.st.com/stm32mcu/wiki/Category:Getting_started_with_STM32_:_STM32_step_by_step

See also this thread.

https://community.st.com/t5/stm32-mcus-products/for-better-learning-stm32-programming-and-debugging/m-p/721123

Hope it helps.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

7 REPLIES 7
SofLit
ST Employee

Hello @sb_st,


@sb_st wrote:

I can see, when I click on some of the pins in the Pinout & Configuration settings, that some have timer options listed among the available settings. But PC0 does not:

Screen Shot 2024-09-15 at 7.47.40 PM.png

So it's not quite clear to me how to proceed (and, again, I am VERY new to this, so just understanding the relationship between the timers and pins and all the configuration settings has put me in a bit of an overwhelmed state).


To check, your first entry point is always the documentation.

Regarding the pinout, you need to refer to the datasheet DS8626 / Table 7. STM32F40xxx pin and ball definitions:

SofLit_0-1726477900122.png

As you can see PC0 doesn't have any TIM alternate function. So I think the Neopixel in your board is managed by GPIO and (maybe) driven by a timer.

 

As your LEDs have the part number WS2812B, I suggest you to refer to these links:

https://github.com/MaJerle/stm32-ws2811-ws2812-ws2812b-ws281x-tim-pwm-dma-timer

https://community.st.com/t5/power-management/controlling-ws2812b-led-strip-with-stm32/td-p/73747

https://controllerstech.com/interface-ws2812-with-stm32/

Hope it helps.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Thanks for the response!

To check, your first entry point is always the documentation.

 

 Agreed, I have read both the datasheet and and skimmed the reference manual. I struggle with these as learning materials in that I don't really know what terms I should be looking for. 

In the event that anyone of similar (in)experience comes across this thread, here are some clues I found:

  • It's theoretically possible to communicate with a neopixel via either pwm or spi - we want to send a strictly-timed stream of 0's and 1's to the neopixel, and these two 'languages' allow for some degree of control over timing. PWM is often used to simulate analog voltages, so it's easy to conflate PWM's use for dimming a regular ol' LED with its use speaking to a neopixel - in the latter case, we can use it as a digital signal, rather than as an analog approximation. 

    The problem is that this particular board, the Adafruit STM32f405, has the neopixel connected to pin PC0, which lacks the ability to do either SPI or PWM, if I understand things correctly. (this strikes me as kind of an odd design choice).

  • Stumped by this, I hunched that whatever code this board ships with from Adafruit probably uses Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel. Reading through this code, I think I understand that it achieves speaking to neopixels mostly-irrespective of hardware through the use of assembly code. 

Much of the examples I found online presupposed I am using a Nucleo board, or at least have some amount of control as to which pin I connect a neopixel to. The difficulty in this case is that I do not - the neopixel on the Adafruit Feather board is an SMD component physically wired to PC0, so I don't really have any choice about which pin to use. And this seems to affect what options I have to communicate with the neopixel. 

 

 


@sb_st wrote:
  •  

Much of the examples I found online presupposed I am using a Nucleo board, or at least have some amount of control as to which pin I connect a neopixel 

 


NUCLEO or not, it's an STM32 MCU used. So need to adapt the code from any platform (Nucleo or something else) to you specific board, for example need to use PC0 in your case.  But in your case you are using stm32f405 on which PC0 is not having any Timer output function. So may be you need to control the timing using a Timer while setting the GPIO. 

I've already provided some links. I think, the last link I provided is using TIM2/PWM. 

Otherwise you need to contact https://www.adafruit.com/product/4382 to have answer about how they control these LEDs.

I don't have any idea how these LEDs are controlled. I'm trying to provide you some tips.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Thank you! Your tone suggests I should apologize - it's not my intent to seem ungrateful. I'm reading the links you provide and trying to understand them. Most specifically, it is this thing you say:

 

But in your case you are using stm32f405 on which PC0 is not having any Timer output function. So may be you need to control the timing using a Timer while setting the GPIO. 

This part, I'm sorry, I don't understand. "Use a timer while setting the GPIO". So, looking at this link you provided:

https://controllerstech.com/interface-ws2812-with-stm32/

(this guy's youtube channel is quite helpful, by the way, thanks for pointing me indirectly to that). Anyway, I can see he configures a timer, and I can see he configures DMA (I don't fully understand DMA, am still learning about it; my understanding is that this DMA is 'piping' the value of a variable representing my LED colors to...'a peripheral'. Is this peripheral a GPIO? I can't quite wrap my head around where the DMA is 'going to', and if it's being connected to an arbitrary GPIO, I can't see where that's happening in his code). 

This other link you provided:

https://github.com/MaJerle/stm32-ws2811-ws2812-ws2812b-ws281x-tim-pwm-dma-timer

 

does something that seems similar - it seems to be 'routing memory to a peripheral'...is this peripheral a GPIO? Is that what that means? 

It feels like these links you provide are indeed quite helpful, it's just this one part that is not clear to me. Or, to restate: it is not clear to me how to 'connect a timer to an arbitrary GPIO' (I don't know if I'm phrasing this question the right way), if we are saying "PC0 does not have any Timer output function"?

 

For this link: https://github.com/MaJerle/stm32-ws2811-ws2812-ws2812b-ws281x-tim-pwm-dma-timer

Read the readme file:

SofLit_0-1726585846872.png

As you are new in the STM32 world, not easy to explain you all the mechanism. You need to start somewhere. I think you need to start some STM32 courses to understand the environment and tools and how STM32 are working.

I suggest you so start with this wiki: https://wiki.st.com/stm32mcu/wiki/Category:Getting_started_with_STM32_:_STM32_step_by_step

See also this thread.

https://community.st.com/t5/stm32-mcus-products/for-better-learning-stm32-programming-and-debugging/m-p/721123

Hope it helps.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Thanks for suggesting I read the read me, very helpful advice and one I hadn’t considered. Thanks also for not being condescending at all to someone new to this development environment. 

You're welcome and we are here to help the professionals as well as beginners  :) ..

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.