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.

DM388: Using GPIOs in DM388 from application(user space)( (IPNC RDK 3.9.0)

Part Number: DM388

In Source/ti_tools/ipnc_psp_arago/u_boot/board/ti/dm38x/evm.c

In the function 'static void gpio_init(void)' , code for glowing BB_Led2 in CSK was added. Thus on power on the led glows.

Now a new function 'void led_glow(void)' is written and declared the same in evm.h

I was trying to call this function in a .c file at Source/ipnc_rdk/ipnc_app/...

By including evm.h(with path)  in that .c file which I want the led glow function to be called.

But on building it shows an error of No files found for ../evm.h

Can this be done by including headers in makefile ?

What is the correct procedure to achieve this? Please assist.

Thanks n regards.

  • Hi Nithin,

    From what I understand you want to call u-boot function from user space application. I do not think this is possible. You can call linux kernel function (driver) from user space application through some API (i.e. ALSA Audio API), see below wiki for more info:

    processors.wiki.ti.com/.../TI81XX_PSP_AUDIO_Driver_User_Guide

    You can also use u-boot stand alone application, where linux kernel and filesystem are not involved.

    Regards,
    Pavel
  • Hi Pavel,

    So we cannot call u-boot function from user application part? Can't we achieve this by including header files with proper makefile for that?

    Regards.
  • Hi Nithin,

    Adding on to Pavel's reply, by just going by building code, we can resolve the dependency by adding the dependent C file and H file and we may even build the code. But the point to note is, Linux is not a single binary, it has kernel to do the administration work. So if there is a piece of code, which needs to access the Hardware, the proper way is to go through the kernel framework(though you can mmap the GPIO registers from user space and get the work done, that would deviate from kernel framework). So please explore the GPIO sysfs feature : www.kernel.org/.../sysfs.txt

    Export the GPIO(to which LED is connected) to the user space using sysfs and then write the code to access this sysfs entry.
  • Nithin Dominic said:
    So we cannot call u-boot function from user application part? Can't we achieve this by including header files with proper makefile for that?

    No, you can not use u-boot.

    As Dwarakesh states, you should use GPIO sysfs for user space access. See below wiki pages for more info:

    http://processors.wiki.ti.com/index.php/Processor_SDK_Linux_GPIO_Driver_Overview

    http://processors.wiki.ti.com/index.php/Linux_PSP_GPIO_Driver_Guide

    Regards,
    Pavel

  • Thank you Dwarakesh and Pavel,

    I was going through the documents and tried as mentioned by Dwarakesh " Export the GPIO(to which LED is connected) to the user space using sysfs and then write the code to access this sysfs entry."

    to export the GPIO pin to glow led;

    $ echo 56 > /sys/class/gpio/export

    $ echo "out" > /sys/class/gpio/gpio56/direction

    $ echo 1 > /sys/class/gpio/gpio56/value

    Here the LED turns ON.

    Then you have mentioned "write the code to access this sysfs entry", where I should write the code? Please explain

    How to write the LED glow code anywhere In the code as required?

     

    Regards.

  • Nithin,

    You can use shell script or C application to access sys/class/gpio from user space. Please have a look in the below links for more info:

    linux-kernel/Documentation/gpio/sysfs.txt

    developer.ridgerun.com/.../How_to_use_GPIO_signals - see gpio.sh for example shell script, gpio-int-test.c for exmaple C application

    e2e.ti.com/.../495550
    e2e.ti.com/.../370560
    e2e.ti.com/.../156496

    Regards,
    Pavel
  • Thank you Pavel,

    From following link,

    http://processors.wiki.ti.com/index.php/Linux_PSP_GPIO_Driver_Guide#User_Space_-_Sysfs_control

    In Driver Usage/ Kernel Level..

    I can add the following code in user space:

    err = gpio_request(56, LED2);
    gpio_direction_output(56, 1);
    gpio_export(56, true);

    As mentioned in:

    please tell me which header file i have to include in my GPIO APIs applications. - Processors forum ...

    e2e.ti.com
    Other Parts Discussed in Thread: AM1808 , OMAPL138 Hi, I used gpio uaer APIs, writen this below code its getting error what is the problem which header file



    I was getting similar errors, here the posts suggest to make changes in the makefile
    to get rid of the errors. But I got a confusion to make changes in:

    ../ti/ipnc_rdk-3.9.0/Source/ti_tools/ipnc_psp_arago/kernel/drivers/gpio/Makefile

    or the place where I'm trying to use GPIO funtion

    ../ti/ipnc_rdk-3.9.0/Source/ipnc_rdk/ipnc_app/network/dhcpcd/Makefile



  • Nithin Dominic said:
    ../ti/ipnc_rdk-3.9.0/Source/ti_tools/ipnc_psp_arago/kernel/drivers/gpio/Makefile

    Nithin Dominic said:
    ../ti/ipnc_rdk-3.9.0/Source/ipnc_rdk/ipnc_app/network/dhcpcd/Makefile

    None of both. You can not use C application with these functions (gpio_request(), gpio_direction_output(), gpio_export()), you should use external kernel module (.ko file) which should be loaded (with insmod/modprobe) from user space.

    You should create your own directory (gpio test directory), where you should place your C code (structured as kernel module, not as user space application) and create your own Makefile, fill it and place it in that directory.

    Regards,
    Pavel

  • Thank you Pavel,
    So you are saying I cannot call the functions in:

    /ti/ipnc_rdk-3.9.0/Source/ti_tools/ipnc_psp_arago/kernel/drivers/gpio/gpiolib-sysfs.c
    where we have;
    gpiod_export(struct gpio_desc *desc, bool direction_may_change), etc

    into my application?
    So I should use external kernel module loaded from user space. How can I create .ko files

    To access GPIO pins, I should develop a new GPIO C code?
    Where I should place the code, in kernel?

    Is it possible to call gpio function into application if I write desperate GPIO code?
  • Nithin Dominic said:
    So you are saying I cannot call the functions in:

    /ti/ipnc_rdk-3.9.0/Source/ti_tools/ipnc_psp_arago/kernel/drivers/gpio/gpiolib-sysfs.c
    where we have;
    gpiod_export(struct gpio_desc *desc, bool direction_may_change), etc

    into my application?

    Yes

    You can also use C application, but you should export the GPIO functions to user space. All this explained in details in my previous replies.

    Nithin Dominic said:
    So I should use external kernel module loaded from user space

    Yes

    Nithin Dominic said:
    How can I create .ko files

    There is nothing TI specific in this. You might search in google how to create and use external kernel modules. Example tutorial you can find in the below link:

    Nithin Dominic said:
    To access GPIO pins, I should develop a new GPIO C code?
    Where I should place the code, in kernel?

    Is it possible to call gpio function into application if I write desperate GPIO code?

    I am not able to understand these question, hence I can not provide answers.

    Regards,
    Pavel

  • Thank you Pavel,
    As you mentioned in your previous post;
    developer.ridgerun.com/.../How_to_use_GPIO_signals

    I can use C application to access sys/class/gpio from user space.
    Create a directory, place the c code, create necessary make file..

    So in this case I don't want to create any external kernel module. Is my understanding correct?

    regards.
  • Nithin,

    Yes, you can use C application to access sys/class/gpio from user space. In this case you do not need external kernel module. You can also check below e2e thread:

    e2e.ti.com/.../495550



    Regards,
    Pavel
  • Thank you Pavel,

    Now, I'm trying to use C application to access sys/class/gpio from user space.

    Let me make the steps to be followed clear;

    •    I must use a similar C code available here: 'https://e2e.ti.com/support/embedded/linux/f/354/t/495550'  to access sys/class/gpio from user space
    •    Place the code in User Space? or in kernel ? and I can access the GPIOs.
    •    So if I'm able to access the gpios from user space what are the APIs or something to set the GPIO pin direction and value (like gpiod_direction_output( ,etc..))?

    Can I use the same C code mentioned in the above post, it contains a while(1), I can modify that and use the same for my purpose?

    Please help with the proper steps and clear my doubts.

    Regards

  • Nithin,

    When writing C/C++ application, you should place your code in user space. You can use the standard POSIX APIs such as open, read, write, etc on gpiox/value files to control your GPIO from C code.

    For how to request, export, set direction, etc through the POSIX APIs, refer to the below links:

    developer.ridgerun.com/.../How_to_use_GPIO_signals
    falsinsoft.blogspot.bg/.../access-gpio-from-linux-user-space.html
    www.kernel.org/.../sysfs.txt
    e2e.ti.com/.../495550

    Regards,
    Pavel
  • Hello Pavel,

    First of all I thank you for your patience in helping me out.

    This document helped: falsinsoft.blogspot.bg/.../access-gpio-from-linux-user-space.html

    ../Manage GPIO from application

    Everything was clear with code to be used, to export and control. Now I am able use GPIOs from my application. :-)

    Thank you and Regards