-
Notifications
You must be signed in to change notification settings - Fork 51
Description
I'm using the PWM example with the Nucleo G431 board configuring the PA5 pin as PWM to drive the LED present on the board.
I think that there is a problem with the SetDutyCycle implementation when is used the TIM2 because for what I understood the $typ in case of TIM2 is 32bit
since
tim_hal! {
TIM1: (tim1, u16, 16, DIR: cms, BDTR: bdtr, set_bit, af1, clear_bit, clear_bit),
TIM2: (tim2, u32, 32, DIR: cms),
TIM3: (tim3, u16, 16, DIR: cms),
TIM4: (tim4, u16, 16, DIR: cms),
}
And so when is called the SetDutyCycle
fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error> {
// hal trait always has 16 bit resolution
let duty = (duty as $typ) << (8(size_of::<$typ>() - size_of::()));*
let tim = unsafe { &*$TIMX::ptr() };
Ok(tim.$ccrx().write(|w| unsafe { w.ccr().bits(duty.into()) }))
}
The duty value is wrongly shifted by 16bits on the left, creating many troubles.