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