cancel
Showing results for 
Search instead for 
Did you mean: 

How can I set PWM to input capture mode in Linux for EV1 board?

cfilipescu
Senior

I am trying to configure the TIM2_CH4 to capture mode on EV1 board so I can sense a fan speed from a PWM fan but I keep getting

cat: read error: Connection timed out

I have configured the timer as follows:

&timers2{
        pinctrl-names = "default", "sleep";
        pinctrl-0 = <&tim2_pins_mx>;
        pinctrl-1 = <&tim2_sleep_pins_mx>;
        status = "okay";
 
        /* USER CODE BEGIN timers2 */
    dma-names = "ch3";
    pwm {
        /* enable PWM on TIM2 */
        status = "okay";
    };
        /* USER CODE END timers2 */
};
        tim2_pins_mx: tim2_mx-0 {
                pins {
                        pinmux = <STM32_PINMUX('A', 3, AF1)>; /* TIM2_CH4 */
                        bias-disable;
                        drive-push-pull;
                        slew-rate = <0>;
                };
        };
 
        tim2_sleep_pins_mx: tim2_sleep_mx-0 {
                pins {
                        pinmux = <STM32_PINMUX('A', 3, ANALOG)>; /* TIM2_CH4 */
                };
        };

I am using TIM12_CH1 to generate a pulse and I have shorted the two pins on the board.

What am I doing wrong? Is there a better way to detect the sense on a PWM fan?

1 ACCEPTED SOLUTION

Accepted Solutions
cfilipescu
Senior

I needed to remove the following line:

dma-names = "ch3";

The instructions are misleading.

View solution in original post

6 REPLIES 6
PatrickF
ST Employee

Hi,

this wiki page could help you:

https://wiki.st.com/stm32mpu/wiki/PWM_overview#How_to_use_PWM_capture_with_sysfs_interface

Regards.

In order 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.

Hi @PatrickF​ ,

That is the link I used but it doesn't seem to work, is there any other helpful material or example?

cfilipescu
Senior

I needed to remove the following line:

dma-names = "ch3";

The instructions are misleading.

Hi @cfilipescu​ ,

I agree Wiki is misleading or most probably outdated.

Looking at DTS, for timer2 CH4, it should have been

    dma-names = "ch4";

to use DMAMUX channel TIM2_CH4

We will ask for a wiki update/clarification.

Regards.

In order 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.

I got confirmation that wiki is OK.

In fact, PWM capture will use two timer channels (e.g. timer capture 1+2 for CH1 or CH2 pins and timer capture 3+4 for CH3 or CH4 pins) but one single DMA request to get period and duty-cycle ("ch1" DMA for timer capture 1+2 and "ch3" DMA for timer capture 3+4),

In your DT, you probably missed to enable the relevant DMAMUX channel, e.g.

        /* Enable DMA "ch3" for PWM input on TIM2_CH4 */
	dmas = <&dmamux1 20 0x400 0x5>;
        dma-names = "ch3";

but I have not tested it.

Regards.

Regards,

Patrick

In order 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.

@PatrickF​ 

I did test adding the dmas line as well and it did not solve the problem.

The reason is the proper dmas and dma-names are specific in the following file: https://github.com/STMicroelectronics/linux/blob/v5.10-stm32mp/arch/arm/boot/dts/stm32mp151.dtsi

So there is no need to specify them in my custom device tree.

I still think the wiki is wrong and should differentiate between what is already specified in the generic file (stm32mp151.dtsi) and what should be put in the custom device tree.

In my case, all I had to add was the status = "okay" since everything else was defined in the include file.