ROC-RK3328-CC Buy Specs

Firefly first ultra-small open-source main board, unique USB3.0 and DDR4 to make its performance faster and more stable. The ultra-affordable ROC-RK3328-CC is your first choice for exploring the programming world.

PWM

Update time:2018-04-13 Views:2497

Introduction

ROC-RK3328-CC development board has 4 PWMs, namely PWM0 ~ PWM3. 4 PWMs use for eDP backlight, MIPI backlight, VDD logic , IR . This article describes how to configure and use PWM.

The PWM driver of RK3328 is in file kernel/drivers/pwm/pwm-rockchip.c

Configure DTS

Configuring PWM has the following three major steps: configuring PWM DTS nodes, configuring PWM kernel drivers, and controlling PWM devices.

Configure pwm driver

Add code below to turn on pwm demo in kernel/arch/arm64/boot/dts/rk3328-roc-cc-port.dtsi

pwm_demo: pwm_demo {   
                        status = "okay";   
                        compatible = "rockchip,rk-pwm";   
                        pwm_id = <1>;   
                        min_period = <0>;   
                        max_period = <10000>;   
                        duty_ns = <5000>;   
                    };

pwm_id:The number of PWM channels that need to be applied.

min_period:Period length minimum。
max_period:The maximum value of the long period.

duty_ns:The duty cycle of PWM is longer than that of the unit ns.

Configure pwm driver

Modify the code as shown below:

(1)、Include the pwm.h file  

#include <linux/pwm.h>


This file includes the API functions of PWM.  

(2)、Request PWM.

struct pwm_device *pwm_request(int pwm_id, const char *label);

You can use the pwm_request function to request the PWM device. For example:

struct pwm_device * pwm1 = NULL;
pwm0 = pwm_request(1, “firefly-pwm”);


(3)、Set PWM configuration 

int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns);

You can use the function pwm_config to set the PWM configuration. For example:

pwm_config(pwm0, 500000, 1000000);

(4)、Enable PWM Function

int pwm_enable(struct pwm_device *pwm);

enable PWM,For example:

pwm_enable(pwm0);


(6)、Release the applied PWM

void pwm_free(struct pwm_device *pwm);


(7)、Prohibit PWM

void pwm_disable(struct pwm_device *pwm);

Debug

cat  /sys/kernel/debug/pwm  ---success or not,check the address of register

FAQs

Cannot register pwm:

  1. Set dts pwm configuration is "okay"

      2.Check the io of pwm if it was used by other source .According to the return to figure out the error.