> For the complete documentation index, see [llms.txt](https://theiotlearninginitiative.gitbook.io/minnowboardmax/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://theiotlearninginitiative.gitbook.io/minnowboardmax/linux/subsystems/general-purpose-input-output.md).

# General Purpose Input Output

## General Purpose Input Output

### GPIO, Kernel Driver Tests

Let's find if GPIOs are found under Sysfs

```
user@Minnowboard:~$ ls /sys/kernel/gpio
ls: cannot access /sys/kernel/gpio: No such file or directory
```

### GPIO, Kernel Drivers Enablement

One way to enable GPIOs is to follow [ELinux MinnowMax Linux Kernel](http://www.elinux.org/Minnowboard:MinnowMaxLinuxKernel)

Compile your kernel, once compiled we enable all needed drivers via menuconfig:

```
user@Minnowboard:~$ cd linux
user@Minnowboard:~$ make menuconfig

Processor type and features  --->

  [*] Intel Low Power Subsystem Support
      Symbol: X86_INTEL_LPSS [=y]
      Prompt: Intel Low Power Subsystem Support

Device Drivers  --->
  Pin controllers  --->

[*] Intel Baytrail GPIO pin control
Symbol: PINCTRL_BAYTRAIL [=y]
Prompt: Intel Baytrail GPIO pin control

Device Drivers  --->
  -*- GPIO Support  --->
  Symbol: GPIOLIB [=y]
  Prompt: GPIO Support

[*]   Debug GPIO calls
Symbol: DEBUG_GPIO [=y]
Prompt: Debug GPIO calls

[*]   /sys/class/gpio/... (sysfs interface)
Symbol: GPIO_SYSFS [=y]
Prompt: /sys/class/gpio/... (sysfs interface)
```

Once configured, we save the changes, compile and reboot

### GPIO, Kernel Modules Tests

Ready! We test that our GPIOs are enabled in dmesg, sysfs y debugfs

```
user@Minnowboard:~$ dmesg | grep gpio
[    0.222366] gpiochip_find_base: found new base at 410
[    0.222466] gpiochip_add: registered GPIOs 410 to 511 on device: INT33FC:00
[    0.223202] gpiochip_find_base: found new base at 382
[    0.223285] gpiochip_add: registered GPIOs 382 to 409 on device: INT33FC:01
[    0.223683] gpiochip_find_base: found new base at 338
[    0.223777] gpiochip_add: registered GPIOs 338 to 381 on device: INT33FC:02
[    7.823125] acpi 80860F16:00: GPIO: looking up 80860F16:00 cd-gpios
[    7.823138] acpi 80860F16:00: GPIO: looking up 80860F16:00 cd-gpio
[    7.823415] sdhci-acpi 80860F16:00: failed to setup card detect gpio
user@Minnowboard:~$ ls /sys/class/gpio
export  gpiochip338  gpiochip382  gpiochip410  unexport
root@Minnowboard:~# mount -t debugfs none /sys/kernel/debug
root@Minnowboard:~# cat gpio
GPIOs 338-381, platform/INT33FC:02, INT33FC:02:
gpio-0   (Unrequested         ) in     hi pad-29  offset:0x1d0 mux:0                  up   20k
...
gpio-43  (Unrequested         ) in out lo pad-40  offset:0x280 mux:0                          
...
GPIOs 382-409, platform/INT33FC:01, INT33FC:01:
gpio-0   (Unrequested         ) in     lo pad-19  offset:0x130 mux:2                          
...
gpio-27  (Unrequested         )        lo pad-7   offset:0x070 mux:0                  down 20k
GPIOs 410-511, platform/INT33FC:00, INT33FC:00:
gpio-0   (Unrequested         ) in     lo pad-85  offset:0x550 mux:1                           
...                        
gpio-101 (Unrequested         ) in out lo pad-100 offset:0x640 mux:0                      
```

To know the GPIO values let's look at the Minnowboard Elinux Wikipage

[Minnowboard Elinux Wikipage](http://elinux.org/Minnowboard:MinnowMax#Low_Speed_Expansion_.28Top.29)

or we use the following script

```
user@Minnowboard:~$ wget https://raw.githubusercontent.com/MinnowBoard/minnow-max-extras/master/lse/what_gpio_num.sh
user@Minnowboard:~$ chmod +x what_gpio_num.sh
root@Minnowboard:~# ./what_gpio_num.sh
```

### GPIO, Userspace Tests

A very simple test is to enable a GPIO as output and use a multimeter to check the voltage, Minnowboard MAX Pin 1 (Ground | Gnd) and Pin 21 (GPIO / Wakeup | GPIO\_S5\_0) are connected to the negative y positive terminales of our multimeter.

The next commands will give us the configuration and output of 0 and 3.3 Volts respectively:

```
root@Minnowboard:~# echo 338 > /sys/class/gpio/export
root@Minnowboard:~# echo out > /sys/class/gpio/gpio338/direction
root@Minnowboard:~# echo 0 > /sys/class/gpio/gpio338/value
root@Minnowboard:~# echo 1 > /sys/class/gpio/gpio338/value
root@Minnowboard:~# echo 0 > /sys/class/gpio/gpio338/value 
root@Minnowboard:~# echo 1 > /sys/class/gpio/gpio338/value
```

### GPIO, Online Resources

* [Linux Kernel Documentation GPIO](https://www.kernel.org/doc/Documentation/gpio/sysfs.txt)
* [Martin's Atelier: Kernel Munging Cookbook](http://www.mjoldfield.com/atelier/2014/12/mbmx-gpio.html)
* [ELinux General Purpose Input Output](http://elinux.org/GPIO)

## End of File


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://theiotlearninginitiative.gitbook.io/minnowboardmax/linux/subsystems/general-purpose-input-output.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
