[SOLVED] Inconsistencies in wiki regarding pwm

Post Reply
paulcrawford
Posts: 134
Joined: Tue May 10, 2016 11:51 am
languages_spoken: english
ODROIDs: c2 and n2
Has thanked: 9 times
Been thanked: 1 time
Contact:

[SOLVED] Inconsistencies in wiki regarding pwm

Unread post by paulcrawford » Tue May 21, 2019 10:59 am

I am in the midst of upgrading from a C2 to an N2 and need to implement a pwm pin. I am following the wiki here:https://wiki.odroid.com/odroid-n2/appli ... e/gpio/pwm

When I list the pwmchips I get:

Code: Select all

root@no:/sys/class/pwm# ls
pwmchip0  pwmchip12  pwmchip16  pwmchip4  pwmchip8
but the wiki only shows four:

Code: Select all

root@odroid:/sys/class/pwm# ls
pwmchip0  pwmchip12  pwmchip4  pwmchip8
Is pwmchip16 real?

When I look at the reference to the Expansion Connectors https://wiki.odroid.com/odroid-n2/hardw ... connectors I see PWM_C, PWM_D, PWM_E, and PWM_F on their respective pins 33, 35, 12, and 15 but I also see in the diagram PWM_B on pin 15 and pin 36 and PWM_D on pin 11. Are these other three actually available?

The section on "Various SYSFS Attributes" seems to be OK for export and unexport (now similar to gpio pins).

Having exported pwmchip4 to "0" if I go into pwm0 I get:

Code: Select all

root@no:/sys/class/pwm# echo 0 > pwmchip4/export
root@no:/sys/class/pwm# cd pwmchip4
root@no:/sys/class/pwm/pwmchip4# ls
device  export  npwm  power  pwm0  subsystem  uevent  unexport
root@no:/sys/class/pwm/pwmchip4# ls pwm0
capture  duty_cycle  enable  period  polarity  power  uevent


So that makes the "enable" section incorrect as it should be:

Code: Select all

root@no:/sys/class/pwm/pwmchip4/pwm0# echo 1 > enable
root@no:/sys/class/pwm/pwmchip4/pwm0# cat enable
1
root@no:/sys/class/pwm/pwmchip4/pwm0# echo 0 > enable
root@no:/sys/class/pwm/pwmchip4/pwm0# cat enable
0
rather than:

Code: Select all

echo 1 > enable0
as shown in the wiki.

Finally "polarity" is all lower case while the wiki shows "Polarity". Also if you cat polarity you get:

Code: Select all

root@no:/sys/class/pwm/pwmchip4/pwm0# cat polarity
normal
while the wiki shows either 1 or 0 as values but if you do those you get:

Code: Select all

root@no:/sys/class/pwm/pwmchip4/pwm0# echo 1 > polarity
bash: echo: write error: Invalid argument
and

Code: Select all

root@no:/sys/class/pwm/pwmchip4/pwm0# echo 0 > polarity
bash: echo: write error: Invalid argument
I would like to know what the valid arguments for polarity are, other than "normal", the default. Also is there an example of what polarity means on a pwm?

I have updated my n2 kernel to the latest:

Code: Select all

root@no:/sys/class/pwm/pwmchip4/pwm0# uname -a
Linux no 4.9.177-28 #1 SMP PREEMPT Thu May 16 23:10:54 -03 2019 aarch64 aarch64 aarch64 GNU/Linux

User avatar
odroid
Site Admin
Posts: 32137
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Has thanked: 119 times
Been thanked: 293 times
Contact:

Re: Inconsistencies in wiki regarding pwm

Unread post by odroid » Tue May 21, 2019 11:26 am

Recent Kernel updates might change the PWM drivers.
We will check it with the latest kernel 4.9.177 and edit the WiKi page for clarification.

cap00k
Posts: 87
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 9 times
Contact:

Re: Inconsistencies in wiki regarding pwm

Unread post by cap00k » Tue May 21, 2019 6:40 pm

Hi,
Thank you for your feedback.
Is pwmchip16 real?
pwmchip16 has been added for active cooling(pwm-fan).
When I look at the reference to the Expansion Connectors https://wiki.odroid.com/odroid-n2/hardw ... connectors I see PWM_C, PWM_D, PWM_E, and PWM_F on their respective pins 33, 35, 12, and 15 but I also see in the diagram PWM_B on pin 15 and pin 36 and PWM_D on pin 11. Are these other three actually available?
That's because all possible pin-functions are recorded in the diagram.
In the case of PWM_B, the pwm_ab block is used in the VDDCPU regulator and can not be enabled.
For PWM_D, you can also edit the devicetree to operate on pin11.
However, the possible pwm are PWM_C, PWM_D, PWM_E, and PWM_F.
In the device tree, four PWMs(C, D, E, F) are mapped to four pins (33, 35, 12, 15).

In addition, an error in the wiki page due to the kernel update has been fixed.
https://wiki.odroid.com/odroid-n2/appli ... e/gpio/pwm

Let me know if there are any errors.
Thank you.
These users thanked the author cap00k for the post:
paulcrawford (Wed May 22, 2019 10:29 am)

paulcrawford
Posts: 134
Joined: Tue May 10, 2016 11:51 am
languages_spoken: english
ODROIDs: c2 and n2
Has thanked: 9 times
Been thanked: 1 time
Contact:

Re: Inconsistencies in wiki regarding pwm

Unread post by paulcrawford » Wed May 22, 2019 10:45 am

@cap00k, I think everything is OK except the polarity, which I will not likely use anyway. The wiki still shows it capitalized (Polarity) which will definitely not work:

Code: Select all

root@no:/sys/class/pwm/pwmchip8/pwm0# cat Polarity
cat: Polarity: No such file or directory
I did try to change the polarity just to see what would happen. I took care not to enable the pwm but I could still not change the property from "normal" to "inversed":

Code: Select all

root@no:/sys/class/pwm# echo 0 > pwmchip8/export
root@no:/sys/class/pwm# cd pwmchip8
root@no:/sys/class/pwm/pwmchip8# ls pwm0
capture  duty_cycle  enable  period  polarity  power  uevent
root@no:/sys/class/pwm/pwmchip8# cd pwm0
root@no:/sys/class/pwm/pwmchip8/pwm0# cat polarity
normal
root@no:/sys/class/pwm/pwmchip8/pwm0# echo 1 > polarity
bash: echo: write error: Invalid argument
root@no:/sys/class/pwm/pwmchip8/pwm0# echo 0 > polarity
bash: echo: write error: Invalid argument
root@no:/sys/class/pwm/pwmchip8/pwm0# echo "normal" > polarity
bash: echo: write error: Invalid argument
root@no:/sys/class/pwm/pwmchip8/pwm0# echo inversed > polarity
bash: echo: write error: Invalid argument
root@no:/sys/class/pwm/pwmchip8/pwm0# echo "inversed" > polarity
bash: echo: write error: Invalid argument
root@no:/sys/class/pwm/pwmchip8/pwm0# echo 'normal' > polarity
bash: echo: write error: Invalid argument
The wiki states that "Writes to this property only work if the PWM chip supports changing the polarity." I cannot determine whether my writes did not work because pwmchip8 (and pwmchip4, which I tested before) does not support changing the property or the form of the argument is wrong.

If it is because the change is not supported, which pwm chips do support the change?

Thanks for your help.

cap00k
Posts: 87
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 9 times
Contact:

Re: Inconsistencies in wiki regarding pwm

Unread post by cap00k » Wed May 22, 2019 12:28 pm

@paulcrawford,
I modified the wiki.
"The polarity can only be changed if the PWM is not enabled or period is not be zero."

Thank you
These users thanked the author cap00k for the post:
paulcrawford (Wed May 22, 2019 8:06 pm)

paulcrawford
Posts: 134
Joined: Tue May 10, 2016 11:51 am
languages_spoken: english
ODROIDs: c2 and n2
Has thanked: 9 times
Been thanked: 1 time
Contact:

Re: Inconsistencies in wiki regarding pwm

Unread post by paulcrawford » Wed May 22, 2019 8:10 pm

@cap00k, I can confirm that both the wiki and the actual pwm are now correct:

Code: Select all

root@no:/sys/class/pwm/pwmchip8/pwm0# ls
capture  duty_cycle  enable  period  polarity  power  uevent
root@no:/sys/class/pwm/pwmchip8/pwm0# echo 10000000 > period
root@no:/sys/class/pwm/pwmchip8/pwm0# echo "normal" > polarity
root@no:/sys/class/pwm/pwmchip8/pwm0# cat polarity
normal
root@no:/sys/class/pwm/pwmchip8/pwm0# echo "inversed" > polarity
root@no:/sys/class/pwm/pwmchip8/pwm0# cat polarity
inversed
root@no:/sys/class/pwm/pwmchip8/pwm0# echo normal > polarity
root@no:/sys/class/pwm/pwmchip8/pwm0# cat polarity
normal
root@no:/sys/class/pwm/pwmchip8/pwm0# echo inversed > polarity
root@no:/sys/class/pwm/pwmchip8/pwm0# cat polarity
inversed
Thanks again.
These users thanked the author paulcrawford for the post:
odroid (Thu May 23, 2019 10:09 am)

Post Reply

Return to “General Topics”

Who is online

Users browsing this forum: CaptManiac and 0 guests