Configure pin 66 as pwm verdin am62

Hello,

As part of the development of a custom board, I would like to use pin 66 of the Verdin AM62 board as a PWM. Despite several attempts, I have been unable to obtain /sys/class/pwm/pwmchip1 to export the desired PWM.

I am attaching the device tree configuration we are using. It is based on the “k3-am62-verdin.dtsi” file. Could you help me with the declaration of pin 66?

Best regards,

Arthur

recipes-kernel.tar.xz (48.5 KB)

tdx-info :

Software summary

Bootloader: U-Boot
Kernel version: 6.1.83-6.9.0-devel+git.dd30c7ec04b8 #1 SMP PREEMPT We4
Kernel command line: root=PARTUUID=c6111a11-02 ro rootwait console=tty1 co0
Distro name: NAME=“TDX Wayland with XWayland”
Distro version: VERSION_ID=6.9.0-devel-20241115074444-build.0
Distro variant: -
Hostname: verdin-am62-15478787

Hardware info

HW model: Toradex Verdin AM62 WB on Verdin Development Board
Toradex version: 0075 V1.2A
Serial number: 15478787
Processor arch: aarch64

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello Arthur,

Thank you for reaching out with your question about configuring pin 66 as a PWM on the Verdin AM62. Let’s go through the steps to ensure your device tree is set up correctly for this purpose.

  1. Identify the Correct PWM Controller and Pin Mapping:

    • First, confirm which PWM controller is associated with pin 66. This information is typically available in the SoC’s reference manual or pinmuxing guide.
    • Ensure that pin 66 can be configured as a PWM output.
  2. Modify the Device Tree:

    • Open the device tree source file, such as k3-am62-verdin.dtsi, where the pin configuration is defined.
    • Add or modify the node for the PWM controller to include pin 66. This involves setting the correct pin function and muxing options.
    • Here is an example snippet for a PWM node in the device tree:
      &pwm1 {
          status = "okay";
          pinctrl-names = "default";
          pinctrl-0 = <&pinctrl_pwm1>;
      };
      
      &pinctrl_pwm1 {
          pinmux = <PIN_66_MUX_OPTION>;
          /* Replace PIN_66_MUX_OPTION with the actual mux option for PWM */
      };
      
    • Ensure the status property is set to “okay” to enable the PWM controller.
  3. Recompile and Deploy the Device Tree:

    • After making the necessary changes, recompile the device tree to generate the updated device tree blob (DTB).
    • Deploy the new DTB to your Verdin AM62 board.
  4. Verify PWM Interface in Sysfs:

    • Once the board is booted with the updated device tree, check for the PWM interface in /sys/class/pwm/.
    • You should see directories like pwmchipX where you can export and configure the PWM channels.
  5. Troubleshooting:

    • If the PWM interface is still not visible, double-check your device tree modifications for any errors.
    • Ensure that the kernel has PWM support enabled for your specific SoC.

By following these steps, you should be able to configure pin 66 as a PWM on the Verdin AM62. If you encounter any issues, reviewing the pinmuxing options and ensuring the correct PWM controller is targeted will be crucial.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Verdin AM62 Lower PWM Frequency Needed.

Hello,

I tried what the Toradex AI Assistant suggested :

&epwm1 {
	status = "okay";
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_epwm1_a>, <&pinctrl_epwm1_b>;
};

&main_pmx0 {
	[......]
	pinctrl_epwm1_b: main-epwm1b-pins-default {
		pinctrl-single,pins = <
			AM62X_IOPAD(0x01c0, PIN_OUTPUT, 2) /* (B13) SPI0_D0.GPIO1_18 */ /* SODIMM 66 */
		>;
	};
	[......]
};

Without success.

ls /sys/class/pwm/pwmchip*
/sys/class/pwm/pwmchip0

Another suggestion?

Best regards,

Arthur

Hello @aforey,

Your changes from the original post appear to be correct.
I will double-check and test this here.

Once there is more information, I will send it here.

Best Regards,
Bruno

Hello @aforey,

1: Check if any overlays are being applied: Ensure that no overlays are affecting the configuration of pin 66.

2: Verify alternate functions: According to the Verdin AM62 datasheet, pin 66 has alternate functions like SPI0 and CP_GEMAC_CPTS0_HW1TSPUSH. These alternate functions need to be disabled in your Device Tree Source (DTS) file. Make sure they are not enabled by any overlay.

Hello @aforey,

Please check if the pwm is available by checking the output of:

cat /sys/kernel/debug/pwm

By default, it should only show the following:

platform/23000000.pwm, 2 PWM devices
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

If you have epwm1 properly enabled on the device tree, it will show the following:

platform/23010000.pwm, 2 PWM devices
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/23000000.pwm, 2 PWM devices
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

If this is not what you see, please try to compare your device tree changes with the following snippet, which was enough to enable PWM on SODIMM_66 on my tests:

#include "k3-pinctrl.h"

/ {
	compatible = "toradex,verdin-am62";
};

&epwm1 {
	pinctrl-0 = <&pinctrl_epwm1_a>, <&pinctrl_qspi1_dqs_gpio>;
	status = "okay";
};

&pinctrl_qspi1_dqs_gpio {
    pinctrl-single,pins = <
        AM62X_IOPAD(0x01c0, PIN_OUTPUT, 2) /* (B13) SPI0_D0.EHRPWM1_B */ /* SODIMM 66 */
    >;
};

If you have both PWM controllers available, then your device tree should be correct.
To then use PWM, the pin needs to be exported. Please check the following documentation for more information: How to Use PWM on Torizon OS | Toradex Developer Center
You can skip the docker run command as it is Torizon OS-specific.

Best Regards,
Bruno

Hello,

Indeed, an overlay was blocking access to the PWM. After removing it, I now have access to PWM pin 66. I can export it, set the parameters, and enable it.

Here are the commands I used:

echo 1 > /sys/class/pwm/pwmchip2/export
echo 45000 > /sys/class/pwm/pwmchip2/pwm1/period
echo 200 > /sys/class/pwm/pwmchip2/pwm1/duty_cycle
echo 1 > /sys/class/pwm/pwmchip2/pwm1/enable

However, from an electrical standpoint, nothing happens on pin 66. No pulse is generated. Any idea how to solve this issue?

root@verdin-am62-15478787:~# cat /sys/kernel/debug/pwm
platform/23010000.pwm, 2 PWM devices
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1   (sysfs               ): requested enabled period: 45000 ns duty: 200 ns polarity: normal

platform/23000000.pwm, 2 PWM devices
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

With another BSP, everything works correctly, so it is not an electrical issue.

Best regards,

Arthur

Hello @aforey,

I was able to get an output when testing this here.

How are you measuring pin 66?

Have you tested with other periods and duty cycles?
Can you also test with PWM_1 (SODIMM_15)? This pin is pwm-0 under pwmchip0.

Best Regards,
Bruno

Hello,

Thank you for all your responses. I tried with pins 66, 15, and 16. Same result.

echo 0 > /sys/class/pwm/pwmchip0/export
echo 45000 > /sys/class/pwm/pwmchip0/pwm0/period
echo 200 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
echo 500 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle

echo 1 > /sys/class/pwm/pwmchip0/export
echo 45000 > /sys/class/pwm/pwmchip0/pwm1/period
echo 200 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle
echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable
echo 500 > /sys/class/pwm/pwmchip0/pwm1/duty_cycle

echo 1 > /sys/class/pwm/pwmchip2/export
echo 45000 > /sys/class/pwm/pwmchip2/pwm1/period
echo 200 > /sys/class/pwm/pwmchip2/pwm1/duty_cycle
echo 1 > /sys/class/pwm/pwmchip2/pwm1/enable
echo 500 > /sys/class/pwm/pwmchip2/pwm1/duty_cycle

I’m checking the signals with an oscilloscope. All PWM outputs are at 0V.

Best regards,

Arthur

Hello @aforey,

Please double-check your oscilloscope configuration, maybe the trigger level is incorrect.
These are 1.8V signals.
I tested this here with PWM_1 (SODIMM_15) and it worked as expected.
The following examples are always using a period of 45000.

  • Duty-cycle 200:

  • Duty-cycle 500:

  • Duty-cycle 22500:


Can you try to reproduce these results with PWM_1 in a Verdin Development Board using the Toradex Reference Multimedia Image 6.8.1?
This way we can confirm that the measurement of the signal is correct and try to investigate what may be causing the problem.

Best Regards,
Bruno

Hello @bruno.tx ,

Thank you for your help. Following our discussions, I started from scratch and took great inspiration from the various Toradex meta layers.

Everything is now working.

Best regards,
Arthur

Hello @aforey,

That is good to know, thanks for the update!

Best Regards,
Bruno