This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OMAP l-138 LCDK - GPIO and PWM

Hi experts,

I have an OMAP l-138 LCDK board running the linux kernel 3.3.0. So far, i already made and execute on the target board an hello world program using a text editor and the ti-sdk-omapl138-lcdk-01.00.00 on Ubuntu.

I would like to develop a small graphic application to control one LED with the board, and i would like to ask you for some guidance... I am completely lost, i have spend the hole day searching for examples, trying to create and execute a project in code composer, trying to compile some examples, but i haven't no success at all...

There's any example showing how to manipulate a GPIO pin? (I already have activated the GPIO option on the linux kernel menuconfig, under sys/classe/gpio i can see some of these pins)

And for PWM? (i have activated the corresponding option on the kernel menuconfig, but i cannot see any node under /sys/classes/pwm... the pwm modules shouldn't be there?)


If you could show me an example it will be great.


Thanks,
Pedro

  • Please refer to the below TI wiki pages.
    processors.wiki.ti.com/.../Linux_PSP_GPIO_Driver_Guide
    processors.wiki.ti.com/.../Configuring_GPIO_Interrupts

    To control the LED, please do the below commands.
    If the GPIO no is 30,
    echo 30 > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio30/direction
    echo 1 > /sys/class/gpio/gpio30/value (glow the LED)
    echo 0 > /sys/class/gpio/gpio30/value (OFF the LED)

    For PWM support, please do make sure that you have the entry for PWM in board file.
  • Hi, 

    Thanks for your answer.

    I already have configured the kernel's menuconfig in order to activate the GPIO and PWM functions.

    GPIO:

    I was able to teste the commands that you wrote for some pins. In order to test another pins i also modified the da850.c file, and here i have a question... I would like to activate the pin GP8[2], but when i tried to add the command MUX_CFG(DA850, GPIO8_2, 3, 24, 15, 4, false), the compiler says that  GPIO8_2 is undeclared... It's impossible to select this pin?

    I tried to create a program to use the gpio driver commands on a C program, but the compiler doesn't recognise the include <linux/gpio.h>, do i need to install something on my linux host machine?

    PWM:


    I couldn't get any pwm node under /sys/class/pwm... 

    Thanks a lot,

    Pedro


  • GPIO:

    I was able to teste the commands that you wrote for some pins. In order to test another pins i also modified the da850.c file, and here i have a question... I would like to activate the pin GP8[2], but when i tried to add the command MUX_CFG(DA850, GPIO8_2, 3, 24, 15, 4, false), the compiler says that GPIO8_2 is undeclared... It's impossible to select this pin?

    You have to add the entry in "arch/arm/mach-davinic/include/mach/mux.h

    Append into this enum structure.
    enum davinci_da850_index {
    ...........
    ...........
    DA850_GPIO8_2,
    };
  • Thanks for your answer :)

    Do you know why i am not getting anything under /sys/class/pwm? I saw some posts describing that problem but didn't find any solution :/

    Thanks,
    Pedro
  • Can you please attach your linux boot log (dmesg) ?

    Regards,
    Titus S.
  • Hi Titus,


    Thanks! I already wrote a kernel module to configure some GPIO pins.

    I was trying to configure also the eHRPWM in this kernel module but i am not understanding which driver i should use... Could you please give me some ideas or some example?

    Thanks,

    Pedro

  • Please refer to the below TI eHRPWM and eCAP drivers.
    linux-kernel/drivers/pwm
  • Thanks, i was there yesterday trying to understand the code of the driver ehrpwm...

    I am not understanding how to create this parameter: struct pwm_device *p

    The structure of the parameter:
    struct ehrpwm_pwm {
    struct pwm_device pwm[NCHAN]; --->> Theres any documentation explaining all these parameters?
    struct pwm_device_ops ops;
    spinlock_t lock;
    struct clk *clk;
    void __iomem *mmio_base;
    unsigned short prescale_val;
    int irq[2];
    struct et_int st_etint;
    struct tz_int st_tzint;
    };

    The function that i need to call at first:
    static int ehrpwm_pwm_request(struct pwm_device *p)
    {
    struct ehrpwm_pwm *ehrpwm = to_ehrpwm_pwm(p);
    int chan;

    chan = p - &ehrpwm->pwm[0];

    p->tick_hz = clk_get_rate(ehrpwm->clk);
    debug("\n The clk freq is %lu", p->tick_hz);
    clk_enable(ehrpwm->clk);
    ehrpwm_pwm_stop(p);

    return 0;
    }

    Thanks,
    Pedro
  • I really don't understand how to use those drivers... :(

  • Maybe it could be useful to someone, so here's how i did it with the linux/pwm/pwm.h driver of kernel 3.3.0:

    struct pwm_device *pwm_dev;

    ...

    /* Config PWM */
    pwm_dev = pwm_request_byname("ehrpwm.1\:0","pwm_device");

    int requested = pwm_is_requested(pwm_dev);
    if(requested){
    printk(KERN_INFO "PWM Requested!\n");
    }

    int error = pwm_set_period_ns(pwm_dev, period);
    if(error){
    printk(KERN_INFO "---Not possible to set period!\n");
    }

    error = pwm_set_duty_percent(pwm_dev, dutyCycle);
    if(error){
    printk(KERN_INFO "---Not possible to set duty cycle!\n");
    }

    error = pwm_start(pwm_dev);