[A20 Lime2] PWM on vanilla 5.6 mainline kernel

Started by jhuge, September 25, 2020, 07:36:21 PM

Previous topic - Next topic

jhuge

Hello,

I have a A20 OLinuXino Lime2 board running vanilla 5.6 kernel with PREEMPT_RT patch, and I'm not sure how I should go about to get hardware PWM output on a GPIO pin.

This guide doesn't seem to apply to my case since I don't have the pwm-sunxi driver config available when compiling the kernel, and I'm not sure how to add it, and if it would work with 5.6 kernel.
I only have pwm_sun4i driver, but my /sys/class/pwm is empty. The pwm entry in the dts tree is disabled, so maybe I would need to add dtoverlay boot parameters, but I'm not sure what command to use.

I would prefer not to use software PWM because I already have hard real time tasks running.

Can anyone help me ?

LubOlimex

#1
In our official images we use PWM for the LCD backlight. Look at our overlays, this is olinuxino-overlay, it might give you some ideas

https://github.com/OLIMEX/olinuxino-overlays/blob/upstream/sun7i-a20/sun7i-a20-pwm.dts

https://github.com/OLIMEX/olinuxino-overlays/blob/master/sun7i-a20/sun7i-a20-pwm.dts

~#olinuxino-overlay – provides easy way to enable or disable different hardware assignments – different I2C, SPI, UART, CAN, PWM, etc;
Technical support and documentation manager at Olimex

Danrancan

Quote from: LubOlimex on September 28, 2020, 04:12:05 PMIn our official images we use PWM for the LCD backlight. Look at our overlays, this is olinuxino-overlay, it might give you some ideas

https://github.com/OLIMEX/olinuxino-overlays/blob/upstream/sun7i-a20/sun7i-a20-pwm.dts

~#olinuxino-overlay – provides easy way to enable or disable different hardware assignments – different I2C, SPI, UART, CAN, PWM, etc;

Thats a broken link like 87% of the other links on this forum and your site. Might want to remove it or fix it if you can.

LubOlimex

Hello,

Thanks for the notice. This happened because that upstream branch was merged to the master branch on October 7th 2020. Dead links are expected - the software and hardware work are in continuous development. You can find the same link now here:

https://github.com/OLIMEX/olinuxino-overlays/blob/master/sun7i-a20/sun7i-a20-pwm.dts

Also edited the original link.
Technical support and documentation manager at Olimex

Danrancan

Quote from: LubOlimex on December 14, 2020, 10:51:22 AMHello,

Thanks for the notice. This happened because that upstream branch was merged to the master branch on October 7th 2020. Dead links are expected

- By whom? Professionals? I don't think dead links are "expected" on any support forum from any company that takes their product support seriously enough to consider themselves professionals, and their products/services, of high enterprise quality.

I'm not attempting to be an meanie or anything here, but I belong to over 30 different support forums for different products, and not one of them is even remotely close to being so poorly maintained and updated. I point this out not to be crude or insulting, but to give you some solid customer feedback, to let you know that it reflects very poorly on olimex, when you cannot properly maintain and update your website/support forums. I am a devops guy myself, and live amongst a community of developers, and one consistency amongst them, is that coders and developers are excellent at what they do (code), but usually they don't share dual strongpoints of being able to code, AND develop/maintain/document things properly for the end users.

So, If I may suggest, you most certainly might want to try hiring someone to keep all of your documentation, forum posts, links, etc. top-notch up to date, so it feel exceptionally professional.

I'm a huge fan of your products and you guys being one of the few open source hardware vendors around. So you have my loyalty because of that. However, I can't give any sort of strong recommendations to any of my associates about your products or your product support, while the attitude of Olimex is that "Dead Links should be expected". It is an unprofessional standard to have, and casts a stigma towards your company, as people start to unintentionally associate the lackluster website maintainence, with you products themselves. So, again, out of pure constructive criticism in good conscience to help you improve your company, I would seriously suggest hiring someone who can maintain and update your site and forum on a regular daily basis.

Quote from: LubOlimex on December 14, 2020, 10:51:22 AMthe software and hardware work are in continuous development. You can find the same link now here:

https://github.com/OLIMEX/olinuxino-overlays/blob/master/sun7i-a20/sun7i-a20-pwm.dts
Also edited the original link.

After spending hours trying to gather all of the information from so many different locations, I finally DO realize, that you guys most certainly are hard at work with continuous development, and I appreciate that.

Thank you for the new link, and your update of the original link is also appreciated! Also, thank you, in general, just for your help and for your responses. They are much appreciated!

Danrancan

faraz

Hey,

I want to confirm when we enable pwm through overlay, only PB2 gets enabled?(https://github.com/OLIMEX/olinuxino-overlays/blob/master/sun7i-a20/sun7i-a20-pwm.dts)

As per https://github.com/torvalds/linux/blob/master/arch/arm/boot/dts/sun7i-a20.dtsi
I want to enable PWM on PI3 as well.

Could you please share how can that be done?
Or can I get PWM on any GPIO by modifying the dts?

regards
Faraz

faraz

#6
Also,

could you please tell if we can use https://developer.ridgerun.com/wiki/index.php/Edit_device_tree_at_run_time this instead of building the dts?

if we can, could you please provide a quick walkthrough?

I disabled the LCD from overlay and was successfully able to use PWM0 to control a servo motor.
However, I would like to use PI3, via shield. PI3 on shield is delivered at pin 12 of GPIO5.

faraz

When PWM controller is enabled via Olinuxino-Overlays.
Only 1 PWM which is PWM0 at pin PB2 is enabled.
Below is how I enabled both PWMs. PWM0 at PB2 and PWM1 at PI3. Hope this can help someone.

First I installed device tree compiler using
sudo apt-get install device-tree-compilerThen I modified the code at https://github.com/OLIMEX/olinuxino-overlays/blob/master/sun7i-a20/sun7i-a20-pwm.dts to look like below

/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun7i-a20";
description = "Enable PWM controller";

fragment@0 {
target = <&pio>;
__overlay__ {
pwm0_pin: pwm0-pin {
pins = "PB2";
function = "pwm";
};
};
};

        fragment@1 {
                target = <&pio>;
                __overlay__ {
                        pwm1_pin: pwm1-pin {
                                pins = "PI3";
                                function = "pwm";
                        };
                };
        };

fragment@2 {
target = <&pwm>;
__overlay__ {
pinctrl-names = "default";
pinctrl-0 = <&pwm0_pin>, <&pwm1_pin>;
status = "okay";
};
};
};

Then I compiled the .dts file into a .dtb file.
Code to compile
dtc -I dts -O dtb -o /home/sun7i-a20-pwm.dtbo /*path to the DTS file*/sun7i-a20-pwm.dts
Above code should compile the .dts file to a .dtbo file and place it in home.

Then I moved the .dtbo to /usr/lib/olinuxino-overlays/sun7i-a20/
It should replace the existing sun7i-a20-pwm.dtbo file
Then I rebooted the board and was able to generate PWM on both pins using below
From bash:
# cd /sys/class/pwm/pwmchip0/
# ls
device    export    npwm      power      subsystem  uevent    unexport
# echo 0 > export
The above enables pwm0, which should be at pin PB2
# cd pwm0
#ls
duty_cycle  enable      period      polarity    power      uevent
# echo 10000 > period
# echo 1000 > duty_cycle
# echo 1 > enable
# echo 0 > enable
# cd ../
# echo 1 > export
The above enables pwm1, which should be at pin PI3
# cd pwm1
#ls
duty_cycle  enable      period      polarity    power      uevent
# echo 10000 > period
# echo 1000 > duty_cycle
# echo 1 > enable
# echo 0 > enable

There might be typos in the code, so please double check.