How to Output PWM Square Waves on OK1028A-C Development Board?

Forlinx

Apr 23, 2023
107
Joined
Apr 23, 2023
Messages
107
After checking the schematic of the OK1028A-C and the "QorIQ LS1028 AReference Manual", it is found that there are 8 FlexTimers (FTM) available by defaultLS1028on the board, with each FTM having 8 pwm channels.

file.php


The default backlight uses the pwm generated by FTM1, and we use FTM7 to do the pwm test.

As shown in the figure below:

file.php


LS1028 RCWSR12 registers 12-14 are pin multiplexed for I2C4.

As shown in the figure below:

file.php


The I2C4 pin can be multiplexed into six pin functions. The OK1028A-C sets the pins to rx and tx of can2 , you can see T6_CAN2_RX, U7_CAN2_TX in the schematic "OK1028A-C_V1.1".

We can set I2C4 to the pwm pin by modifying the rcw file.

OK1028A-C supports the pwm function by default, so we do not need to transplant the driver. All we need to do is to modify the pinmux and add the corresponding device node of pwm in the device tree. Modify packages/firmware

In the /rcw/ls1028ardb/RSQPP0x85bb/rcw1500gpu600.rcw file, the setting for IIC4_PMUX is to configure the pin as a pwm output.

Change IIC4 _ PMUX = 2 to IIC4 _ PMUX = 4

As shown in the figure below:

file.php


After completing the above settings, we need to modify the device tree code and add pwm configuration. The path of our modified file is as follows:

packages/linux/linux/arch/arm64/boot/dts/freescale/fsl-ls1028a.dtsi.

Then add the pwm7 device

Pwm7: pwm@2860000 {
                        compatible = "fsl,ls1028a-ftm-pwm";
                        reg =;
                        #pwm-cells =;
                        clock-names = "ftm_sys";
                        clocks = <&ftm_sysclk>;
                };


As shown in the figure below:

file.php



▐   Start the OK1028A-C system




root@forlinx:~#cat /sys/kernel/debug/pwm View our current pwm devices

As shown in the figure below:

file.php


We have now opened a pwm controller and can see that FTM1 supports 8 channels, with the backlight using pwm channel 1. Compile the modified device tree file and firmware, burn them intoFolinx EmbeddedLS1028A-CDevelopment Board, and boot up the system.

root@forlinx:~#cat /sys/kernel/debug/pwm View our current pwm devices.

As shown in the figure below:

file.php


At this time, although the pwm device we added is turned on, it is still different from the pwm0 device. Each channel of the newly added pwm device has no set period and duty cycle.

So in the next step, we do not need to add driver code, but use sys to set pwm parameters directly. Pwmchip8 is the pwm device we added.

file.php



▐  Enable pwm channel used


root@forlinx:~#echo 1 > /sys/class/pwm/pwmchip8/export Initialize pwm channel 1

root@forlinx:~#echo 2 > /sys/class/pwm/pwmchip8/export Initialize pwm channel 2

root@forlinx:~#cat /sys/kernel/debug/pwm CommandCheck out our current pwm devices:

file.php


If you want to cancel the corresponding pwm channel, you can use "echo 1 > /sys/class/pwm/pwmchip8/unexport".

“echo 2 > /sys/class/pwm/pwmchip8/unexport” command.

Since we can only enable pwm one way at a time, configure and turn on pwm1 first.

root@forlinx:~#echo 1000000 > /sys/class/pwm/pwmchip8/pwm1/period Configure the pwm1 period to be 1000000 in ns, which is 1kHZ.

root@forlinx:~#echo 500000 > /sys/class/pwm/pwmchip8/pwm1/duty_cycle Configure the duty_cycle to 500000, the on time in a cycle is the duty cycle, the unit is ns, and the duty cycle is 50%.

root@forlinx:~#echo 1 > /sys/class/pwm/pwmchip8/pwm1/enable Enable

root@forlinx:~#cat/sys/class/pwm/pwmchip8/pwm1/{enable,period,duty_cycle}Command to view our pwm enable status, period, and duty cycle.

As shown in the figure below:

file.php



▐  Test the 1khz square wave generated by T6_CAN2_RX with oscilloscope


Since we can only enable one pwm at a time, we need to turn off pwm1 first if we want to enable pwm2.

root@forlinx:~#echo 0 > /sys/class/pwm/pwmchip8/pwm1/enable

root@forlinx:~#echo 1000000 > /sys/class/pwm/pwmchip8/pwm2/period Configure period to 1000000

root@forlinx:~#echo 500000 > /sys/class/pwm/pwmchip8/pwm2/duty_cycle Configure duty_cycle to 500000.

root@forlinx:~#echo 1 > /sys/class/pwm/pwmchip8/pwm2/enable Enable

root@forlinx:~#cat/sys/class/pwm/pwmchip8/pwm2/{enable,period,duty_cycle}

file.php



▐  Test the 1khz square wave generated by U7_CAN2_TX with oscilloscope


When we use OK1028A-C single board computer, due to pin multiplexing, the pins of many functional modules are not led out, but the driver of the module is supported. In this case, we only need to modify the corresponding pinmux configuration and device tree file of rcw to use the corresponding function.

 

Attachments

  • IPQ9574 QCN9274.jpeg
    IPQ9574 QCN9274.jpeg
    29.3 KB · Views: 0
  • QCN9274 CARD.jpg
    QCN9274 CARD.jpg
    78.5 KB · Views: 0
  • singleband 4x4.jpg
    singleband 4x4.jpg
    80.8 KB · Views: 0
  • wallys logo wifi7.jpg
    wallys logo wifi7.jpg
    145.4 KB · Views: 0
Top