stm32f4xx-hal icon indicating copy to clipboard operation
stm32f4xx-hal copied to clipboard

pwm-input setting for TI2 is wrong

Open ceigel opened this issue 3 years ago • 4 comments

I haven't checked whether this is really not working, I was just reviewing the code when I discovered this.

This is the code for setting the active polarity for capture in CCR2 the Timer::pwm_input function:

https://github.com/stm32-rs/stm32f4xx-hal/blob/aaa10963802b98990a24112b646c32690a038a79/src/pwm_input.rs#L118-L122

From documentation (chapter 18.3.6 of the Reference manual RM0090): Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P bit to ‘1’ and the CC2NP bit to ’0’(active on falling edge).

I believe the code is not according to documentation, at least for STM32F405/415, STM32F407/417, STM32F427/437 and STM32F429/439 which are referenced in RM0090 from STM

ceigel avatar Oct 27 '21 08:10 ceigel

I don't know if it's the intention of the code, but both set, I believe, is capture on both edges.

jkristell avatar Oct 27 '21 09:10 jkristell

yes, that is correct, it means capture on both edges, but I still think that is incorrect. cc1np/cc1p are 00

ceigel avatar Oct 27 '21 12:10 ceigel

Looks like original comments from RM0368/RM0383 (F401), chapter 12.3.7 or something

burrbull avatar Oct 27 '21 12:10 burrbull

I believe you refer to this statement in RM0368:

Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P and CC2NP bits to ‘1’ (active on falling edge).

The equivalent statement in RM090 is this:

Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P bit to ‘1’ and the CC2NP bit to ’0’(active on falling edge).

ceigel avatar Oct 27 '21 12:10 ceigel