Setting internal pull-up resistor for GPIO

Hi I am working on setting up an internal pull-up resistor on the apalis imx8 v1.1 with ixora carrier board v1.2. I am running windows as my host os. I am running this os on the device: operating system: Linux apalis-imx8-07107340 5.4.193-5.7.0+git.f78299297185 #1-TorizonCore SMP PREEMPT Mon Jul 11 14:42:03 UTC 2022 aarch64 aarch64 aarch

I am developing in python using the gpiod library. I am able to set flags for open drain/source active high/low but attempting to set the flags for internal pull-up resistors results in an error.

Here is how I set-up the gpio pin:

Here is the error I get attempting to set the pull-up resistor flag:

How do I configure the internal pull-up resistor for gpio pins?

Thanks, Mike

Greetings @MikeHA,

I believe I know what’s going on here. So I tried emulating the code snippet you shared on my setup. I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/gpiod/libgpiodcxx/__init__.py", line 572, in request
    rv = libgpiod.gpiod_line_request(_m_line, conf, default_val)
  File "/usr/local/lib/python3.9/dist-packages/gpiod/libgpiod/__init__.py", line 499, in gpiod_line_request
    return gpiod_line_request_bulk(bulk, config, [default_val])
  File "/usr/local/lib/python3.9/dist-packages/gpiod/libgpiod/__init__.py", line 542, in gpiod_line_request_bulk
    return _line_request_values(bulk, config, default_vals)
  File "/usr/local/lib/python3.9/dist-packages/gpiod/libgpiod/__init__.py", line 403, in _line_request_values
    status = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, req)
OSError: [Errno 22] Invalid argument

It looks like it’s failing on an ioctl call to change the GPIO attributes based on your flags. I tried removing the gpiod.line_request.FLAG_ACTIVE_LOW flag and still got the same error. I then tried removing the gpiod.line_request.FLAG_BIAS_PULL_UP flag and the request succeeded without error. Therefore it seems there’s an issue with setting the FLAG_BIAS_PULL_UP attribute.

I then tried doing the same but using the libgpiod command line tool:

gpioset --bias=pull-up 0 8=0
gpioset: error setting the GPIO line values: Invalid argument

Basically the same error. I would imagine setting the internal pull-up is dependent on the underlying hardware and software stack that controls the GPIOs. Since the ioctl call is failing I would assume it’s not possible, at least with libgpiod.

That said, on i.MX SoCs it is possible to set pin attributes (including pull-up/pull-down) from the device tree. For example see here: Device Tree Customization | Toradex Developer Center

However, the exact configuration to do this for i.MX8 isn’t documented by us and needs to be found out via the reference manual for the SoC from NXP themselves. Perhaps this way you can set an internal pull-up (if available for this pin), and do that for your use-case.

Best Regards,
Jeremias

Hey Jeremias,

Customizing the device tree was the conclusion that I came too as well. Thanks for checking!

Best, Mike

Glad I could help clear things up!