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.

GPIO read write

Hi All.

I spent several days trying to read/write the DM365 GPIO still with any success. From the other threads I understand that there is not an "official" driver so that everyone has to develop his own (I think almost all the developers have to deal with the gpio). I tried both to use the example provided by Bernie Thompson

http://e2e.ti.com/support/embedded/f/354/p/7633/30198.aspx#30198,

and writing my own driver from the beginning. In both cases I am able to manage the GPIO from the module (for instance reading a register from the init routine), but when I try to manage the registers from the application I am not able to open the device (e.g. the command open("/dev/user_gpio", O_RDWR) fails).

Reading the thread referenced in the link above, I see the problem is common to other users. A thing which is still obscure to me regards the creation of the /dev/user_gpio. According to Juan "it appears this should be created by the driver and you should not have to type mknod". I tried:

A) do nothing: /dev/user_gpio is not created

B) mknod /dev/user_gpio c 60 0 /dev/user_gpio is created but when I open it from my application it fails.

C)

    int devno = MKDEV(60,0);

in user_gpio_init_module () . Here, quite surprisingly, /dev/user_gpio is not created.  chmod 666 /dev does not fix this problem.

I suppose I am missing some trivial step, any hints will be greatly appreciated.

 

  • I found the problem. I have to call mknod with the right major number obtained from /proc/devices after insmod:

     

    #!/bin/sh
    module="user_gpio"
    device="user_gpio"
    mode="664"

    #unload module
    rmmod ./$module.ko 2>/dev/null
    # remove stale nodes
    rm -f /dev/$device 2>/dev/null

    insmod ./$module.ko

    if [ ! -f /dev/$device  ]
    then
        major=$(awk '$2=="user_gpio" {print $1}' /proc/devices)

        mknod /dev/$device c ${major} 0
    fi