Skip to main content
cfilipescu
Senior
March 1, 2022
Solved

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

  • March 1, 2022
  • 2 replies
  • 2488 views

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?

This topic has been closed for replies.
Best answer by cfilipescu

I needed to remove the following line:

dma-names = "ch3";

The instructions are misleading.

2 replies

PatrickF
Technical Moderator
March 2, 2022
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.NEW ! Sidekick STM32 AI agent, see here
cfilipescu
Senior
March 2, 2022

Hi @PatrickF​ ,

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

cfilipescu
cfilipescuAuthorBest answer
Senior
March 3, 2022

I needed to remove the following line:

dma-names = "ch3";

The instructions are misleading.

PatrickF
Technical Moderator
March 4, 2022

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.NEW ! Sidekick STM32 AI agent, see here
PatrickF
Technical Moderator
March 4, 2022

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.NEW ! Sidekick STM32 AI agent, see here