c code to perform pwm in jetson nano

could you please share any c code for pwm in jetson nano,i am not able to find and code in c,once i search i got kernel level code for pwm ,need user level code using sysfs interface

hello rahul14ee,

were you like to customize through pinmux spreadsheet for configuration? may I know which pin you would like to use to control it.
you should be follow below steps to control the PWM.

  1. change the gpio pin to pwm pin in pinmux spreadsheet
  2. generate the dtsi
  3. Use this dtsi to rebuild the dtb.
  4. Use this dtb to reflash the board
  5. Use the debugfs to control the pwm.

echo [pin_vs_gpio_numer] > /sys/class/gpio/export
echo [direction] > /sys/class/gpio/gpio[pin_vs_gpio_number]/direction
echo 1 > /sys/class/gpio/gpio[pin_vs_gpio_number]/value
echo 0 > /sys/class/gpio/gpio[pin_vs_gpio_number]/value
echo [pin_vs_gpio_numer] > /sys/class/gpio/unexport

** [pin_vs_gpio_number] refer to J41 guide, the gpio_number. not equal with python module RPi.GPIO defined
** [direction] is “out” or “in” from CPU viewpoint

For me under bash, J41 pin16 is GPIO_232

echo 232 > /sys/class/gpio/export
ls /sys/class/gpio/

echo out > /sys/class/gpio/gpio232/direction
echo 1 > /sys/class/gpio/gpio232/value
echo 0 > /sys/class/gpio/gpio232/value
echo 1 > /sys/class/gpio/gpio232/value
echo 0 > /sys/class/gpio/gpio232/value
echo 232 > /sys/class/gpio/unexport

As in C

int len;
int fd;
char buf[128];

fd = open("/sys/class/gpio/export", O_WRONLY);
len = snprintf(buf, sizeof(buf), "%d", gpio);
write(fd, buf, len);