Jump to content

Missing access to all PWM outputs


chrism

Recommended Posts

Armbianmonitor:

I recently uploaded Armbian_20.11_Odroidc4_focal_current 5.9.12_desktop.img.xz onto a new Odroid-C4. Booting up and getting started hasn't been a problem, but I've been interested in driving some brushless motors using a PWM control signal and started looking through the device tree. The C4 is supposed to have a total of 6 PWM outputs, spread over 3 pwmchip devices, which (I believe) should be named pwmchip0, pwmchip4, and pwmchip8. However, upon navigating to /sys/class/pwm, I'm only seeing pwmchip0. This seems a little odd, because if PWM was entirely disabled in the device tree, I wouldn't have expected that any of the chips would have appeared. Not sure if this is a board-level problem, or something I'm missing in the kernel image I downloaded. I'm planning on comparing the stock Odroid image, but the spare uSD card I ordered is taking longer to arrive than expected. I can update when it comes in, but wanted to check either way if this was expected behavior for the Armbian image and if so, there is a simple fix, since I'd prefer sticking with vanilla Armbian over whatever fork the manufacturer puts out is.
 

Thanks for your time, and please let me know if there's any add'l information I can provide to make this easier!

Link to comment
Share on other sites

I've confirmed that all three PWM outputs (pmwchip0/4/8) are present in the Odroid stock image, downloaded from https://odroid.in/ubuntu_20.04lts/c4-hc4/ , in particular the ubuntu-20.04-4.9-mate-odroid-c4-hc4-20201020.img.xz image. I think that means that the missing peripheral access is due to Armbian itself, although not sure if this is due to a kernel config that I somehow didn't enable or a bug in the build itself. Since I'd eventually like to move towards using Armbian, I'd be happy to help figure out why this is happening, since I'm sure that other folks may be interested in having access to that functionality on this board as well, if someone can point me in the right direction.

Link to comment
Share on other sites

So here I am stuck with the same problem on my c4. Even though I can enable the PWM's trough a user overlay with something like

 

    fragment@0 {
        target = <&pwm_cd>;
        __overlay__{
            status = "okay";
            pinctrl-names = "pwm_pins";
            pinctrl-0 = <&pwm_c_x5_pins &pwm_d_x3_pins>;
            clocks = <&xtal>, <&xtal>;
            clock-names = "clkin0", "clkin1";
        };
    };

 

And by by providing all the properties that are present in the hardkernel's dtb. It does not seem to work. The pwm is available in /sys/class/pwm and I can also export one of them and enable it. But when I put the scope on the pin there is simply nothing. Does anyone have a clue where to look next?

Link to comment
Share on other sites

So It seems to work on my side now. Did a lot of reading on topics that I did not and still do not understand. One of the articles mentioned a debug command.

"cat /sys/kernel/debug/pinctl/pinctl-handles". The command was kind of useful because I could see that "ff80200.pwm" was active but not my patched "ffd1a000.pwm". Which was strange because the driver was visible in "/sys/class/pwm". So the PWM controller was working, but had no pin 'attached' to it. The output or "cat /sys/kernel/debug/pinctrl/pinctrl-handles" made it more clear. I compared the code again and noticed that pwm@2000 in the dtb from armbian did use "default" for the "pinctrl-names" property unlike 'pwm_pins' in the dtb from hardkernel. I changed my overlay to use the same and finally got some output on the scope. So to enable pwm_cd the overlay should look like:

 

    fragment@0 {
        target = <&pwm_cd>;
        __overlay__{
            status = "okay";
            pinctrl-names = "default";
            pinctrl-0 = <&pwm_c_x5_pins &pwm_d_x3_pins>;
            clocks = <&xtal>, <&xtal>;
            clock-names = "clkin0", "clkin1";
        };
    };

 

Unfortunately I am now on a self build image with kernel 5.10. I'll try to go back to an *official* image and see if it still works.

Link to comment
Share on other sites

Just following up on this, I was able to get this running on the Odroid stock image (and subsequently the motor controller and external LED control, so I'm sure it's working) through the process described in the post at https://forum.odroid.com/viewtopic.php?f=207&t=41185 

However, I'm not seeing the equivalent file for Armbian to make this change. The one area that I'm looking at is the boot.cmd/.scr files, although both of those point me towards the armbianEnv.txt file, which doesn't seem to have an obvious way of calling this out similarly to the config.ini file on the Odroid image. I'd be looking for something with the overlay name, but all the files with "meson" in /boot seem to be binary and not editable by the users. @Igor, I looked at the thread that you mentioned, but it's a little beyond my ken for the momen, especially since it only seems to mention a single pwm1 channel (although it's completely possible I'm missing something). Do you potentially have any other suggestions for where to look or learning resources to understand more about what's going on in the thread you linked?

Edited by chrism
Link to comment
Share on other sites

If you just want to get PWM running do the following:

 

create a file (lets name it pwm_cd.dts) with this contents

/dts-v1/;
/plugin/;
/{
    fragment@0 {
        target = <&pwm_cd>;
        __overlay__{
            status = "okay";
            pinctrl-names = "default";
            pinctrl-0 = <&pwm_c_x5_pins &pwm_d_x3_pins>;
        };
    };
};

 

compile that file with

dtc -I dts -O dtb pwm_cd.dts -o pwm_cd.dtbo

 

create a directory for user overlays and move that file there

mkdir /boot/overlay-user
cp pwm_cd.dtbo /boot/overlay-user/

 

edit /boot/armbianEnv.txt and add the following line

user_overlays=pwm_cd

then do a reboot and you should be able to use PWM_C and PWM_D with sysfs like
 

cd /sys/class/pwm/pwmchip-2/
echo 0 > export
echo 1000000 > pwm0/period
echo 50000 > pwm0/duty_cycle
echo 1 > pwm0/enable

 

This can be done for the other PWM's as well. You'll just have to figure out which pinctrl-names you have to use by comparing the files from odroid (overlays and dtb) with the dtb from armbian.

Link to comment
Share on other sites

I'm still working on getting the other two sets of PWM outputs working using a similar approach to the one above, and just figured I'd add this link to the thread as a resource in case anyone else finds it useful (or I need to find it again). I believe this has the most recent C4 overlay .dts file from Hardkernel for pwm_ef: https://github.com/hardkernel/linux/blob/odroidg12-4.9.y/arch/arm64/boot/dts/amlogic/overlays/odroidc4/pwm_ef.dts

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines