Accessing specific PWM channel in Linux

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing specific PWM channel in Linux

Jump to solution
169 Views
Tony-FM-Eng
Contributor II

Hi, I am trying to access a specific channel, channel 5 of the PWM1 output from flex_timer_1 on the S32G274. I am not sure what values to use on the command line or settings in the dts file in order to obtain an output?

In my dts file, I have the following:

myboard.dts
 
&pwm1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pwm1_out_pins>;
    status = "okay";
};
 
&pinctrl {
     pwm1_out_pins: pwm1_out_pins {
          pwm1_out_grp {
              pinmux = <S32CC_PINMUX(80, FUNC3)>;
              output-low;
              output-enable;
              slew-rate = <S32_COMPAT_SLEW_83MHZ>;   // Is this needed?
         };
    };
};
 
Then, when I run the following commands on the Linux command line:
 
echo 1 > /sys/class/pwm/pwmchip0/export
echo 10000000 > /sys/class/pwm/pwmchip0/pwm1/period
echo 5000000 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
echo 'normal' > /sys/class/pwm/pwmchip0/pwm1/polarity
echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable
 
I don't receive any errors, but I do not see an output on PF_00, pin for PWM1, channel 5. I'm not sure if the /sys/class/pwm/pwmchip0/export file controls the output channel? I did try 
 
echo 4 > /sys/class/pwm/pwmchip0/export
 
but received an error.
 
Is there something I need to add in the dts file in order to access channel 5 of flex_timer_1 for PWM1? Or is there a command I need to execute on the command line to provide the PWM output?
 
Thanks for any assistance.
 
0 Kudos
1 Solution
60 Views
Tony-FM-Eng
Contributor II

Thank you for the assistance so far. After reviewing the examples and delving into the links, I saw that I am doing pretty much the same thing as the example for imx8mmn-nitrogen8mm.dtsi example. I did notice that if I do the following command, "echo 4 > /sys/class/pwm/pwmchip0/export," I do see "/sys/class/pwm/pwmchip0/pwm4."  But I am still not sure how to set the channel in the dts file? 

Also, with pin 80 set for PWM5 output through the dts file pinmux, I still do not see any PWM on the output pin either. 

Do I have to create a "PWM5" entry in the dts file for channel 5 of the PWM? If so, would I have to clone parameters from PWM1 in the s32cc.dtsi file? Is there an example of this? I could not find anything is my extensive search online.

Thanks again.

View solution in original post

0 Kudos
5 Replies
61 Views
Tony-FM-Eng
Contributor II

Thank you for the assistance so far. After reviewing the examples and delving into the links, I saw that I am doing pretty much the same thing as the example for imx8mmn-nitrogen8mm.dtsi example. I did notice that if I do the following command, "echo 4 > /sys/class/pwm/pwmchip0/export," I do see "/sys/class/pwm/pwmchip0/pwm4."  But I am still not sure how to set the channel in the dts file? 

Also, with pin 80 set for PWM5 output through the dts file pinmux, I still do not see any PWM on the output pin either. 

Do I have to create a "PWM5" entry in the dts file for channel 5 of the PWM? If so, would I have to clone parameters from PWM1 in the s32cc.dtsi file? Is there an example of this? I could not find anything is my extensive search online.

Thanks again.

0 Kudos
52 Views
Tony-FM-Eng
Contributor II

I found the problem. It was the wrong channel assignment. Note, for channel PWM5, use:

echo 5 > /sys/class/pwm/pwmchipio/export. I was using channel 4 since the PWM starts with one apparently and not with zero.

If in your kernel driver, the setting would be pwm_device = pwm_request(<channel number>, <pwm_chip>). So, for example, to obtain channel 5 with PWM0 enabled, it would be:

struct pwm_device *my_pwm_device;

my_pwm_device = pwm_request(5, pwmchip0);

 

 

Thanks for the help.

0 Kudos
124 Views
brian14
NXP TechSupport
NXP TechSupport

Hi @Tony-FM-Eng

Thank you for contacting NXP Support.

It seems that the configurations are correct.

Could you please share the output of the following commands?

ls /sys/class/pwm/
ls /sys/class/pwm/pwmchip0/
ls /sys/class/pwm/pwmchip0/pwm1

Please try it and send me the outputs.

Have a great day!

0 Kudos
105 Views
Tony-FM-Eng
Contributor II

Thanks for the reply. Here are the following outputs to the commds:

# ls /sys/class/pwm
pwmchip0

# ls /sys/class/pwm/pwmchip0
device export npwm power pwm1 subsystem uevent unexport

# ls /sys/class/pwm/pwmchip0/pwm1
capture duty_cycle enable period polarity power uevent

 

Let me know if you require any additional information.

0 Kudos
70 Views
brian14
NXP TechSupport
NXP TechSupport

Hi @Tony-FM-Eng

Thank you very much for your response.

Based on your reply and your steps described on your question, Linux can interface correctly PWM driver.
However, it seems that you are missing a Kernel configuration to properly set up the PWM.
I couldn't find any specific manual for the S32G to enable PWM but please have a look to the following community thread of i.MX8MM Solved: Q: What is the preocedure to Enable PWM on imx8mm-evk? - NXP Community.

Please check and tell me if you have any questions or comments.

0 Kudos