jwatte / jetson-gpio-example

Simple example of memory-mapped NVIDIA Jetson GPIO access from user space C code
MIT License
37 stars 15 forks source link

How to access GPIO in kernel space? #3

Open mintisan opened 2 years ago

mintisan commented 2 years ago

Hi, very nice tutorial, but how can we access all-40 GPIO pins in kernel space?

Thanks.

mdhardenburgh commented 2 years ago

There are two (or 3) methods, you can use userspace direct register access by directly writing to memory like with a microcontroller OR write to /sys/class/gpio. You can also try to get wriring pi to work for the jetson, however thats a python library. It is much "safer" to access the GPIOs through the kernel (with sys/class/gpio) than using a userspace program with direct register access. This is due to there being no locking method (that I am aware of) to prevent another program from clobbering your register settings. Alternatively you can also write a kernel module and driver and then access the driver's public functions through your userspace program. Hope this helps!