Here PA9 needs to be configured such that it's connected to the internal circuitry of channel 2 of the TIM1 peripheral. It can be determined from the device datasheet that pin PA9 is connected to channel 2 of the timer.This is done using the new_ch2 instance method of the PwmPin type.
I'm following along with a STM32F3DISCOVERY board so my pinout is different. Can you explain how to find in the datasheet which pin is connected to which timer and channel?
Your welcome! If you check the pin name column in table 8 in the datasheet I shared there should be all the pins listed there. There also should be a column titled “alternate functions”. These are all the functions that each pin supports. If you look up the PA9 for example, you’ll see that TIM1_CH2 is one of the functions it supports. You’ll need to find the same table for the F3 device.
Thanks! This series is really helpful. I followed this PWM tut with my STM32WLE5x board using PB3, TIM2_CH2. One thing I notice is that Delay hangs the program. A workaround is using cortex_m::delay::Delay.
Thank you for the feedback, Wang! You probably noticed that I used embassy_time::Delay to implement a blocking delay, which also required me to import embedded_hal::blocking::delay::DelayMs. My guess is that what's happening could have to do with the embedded_hal implementation for DelayMs on the particular device you are using. Either way, what you are doing is a totally valid alternative to generate a blocking delay, however, instead using the Cortex-M core crate.
Omar Hiari Finally I figured out why the embassy_time::Delay does not work. It is implemented using embassy_time::Instant, which uses TIM2(time-driver-any feature). My selected PWM pin(TIM2_CH2) also uses the TIM2 timer, so the instant value resets at each PWM cycle, resulting in an unusable Instant.
Never mind, cortex_m::delay::Delay works great.
Alexander
Hi, thanks for doing this series.
The article says:
I'm following along with a STM32F3DISCOVERY board so my pinout is different. Can you explain how to find in the datasheet which pin is connected to which timer and channel?
Thanks!