GPIO access/permission in Docker container

I’m currently using an existing code base (that has been working well on our Toradex iMx8X device) and have decided to begin actuating an additional GPIO.

The original GPIO Pins I’m using are still working correctly, yet when I attempt to OpenPin() on one of the new GPIO Pins, I get an error:

Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: —> System.IO.IOException: Device or resource busy
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.IO.FileStream.FlushWriteBuffer()
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.IO.FileStream.Dispose(Boolean disposing)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.IO.Stream.Close()
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.IO.StreamWriter.CloseStreamFromDispose(Boolean disposing)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.IO.StreamWriter.Dispose(Boolean disposing)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.IO.TextWriter.Dispose()
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.IO.File.WriteAllText(String path, String contents)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.Device.Gpio.Drivers.SysFsDriver.OpenPin(Int32 pinNumber)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.Device.Gpio.GpioController.OpenPinCore(Int32 pinNumber)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.Device.Gpio.GpioController.OpenPin(Int32 pinNumber)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at System.Device.Gpio.GpioController.OpenPin(Int32 pinNumber, PinMode mode)
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at HardwareController.Motor…ctor() in /source/hardware/Motor.cs:line 119
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at HardwareController.Components…cctor() in /source/Components.cs:line 7
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: — End of inner exception stack trace —
Jan 01 00:00:34 colibri-imx8x-06995390 a0769e06741c[733]: at HardwareController.Program.Main(String args) in /source/Program.cs:line 33

…so What causes this fault?
System.IO.IOException: Device or resource busy

I’ve got udev rules in place for gpio 0-9
My docker-compse.yml maps the gpio chips to the container (which is privileged!)

Also, in point of fact, Pins for GPIO3 and GPIO5 are working as they always have. Only when I try to do OpenPin() on a pin in GPIO4 (the new pin!)
Do I see this error.

How can I verify that correct access & permissions have been granted?

Thx
Paul++

Greetings @Paul,

Could you specify what exact pin(s) you are having issues with? Preferably if you could provide the exact SODIMM numbers so I can be sure. Also could you share what version of our software you are running on the module.

Though based on the error you are getting: System.IO.IOException: Device or resource busy

It sounds like the pins you are trying to access are currently being used by some other sub-system or process.

Best Regards,
Jeremias

Jeremais,

Yes… of immediate concern are GPIO(4,0)=gpio128 and GPIO(4,2)=gpio130
I have other GPIO pins that, with my new hardware revision, are going from unused to “used as GPIO” … where can I find a list of GPIO pins that are actually available? I know it depends on what other functions are activated for my iMx8X … yet, I need to determine if the new Pins are, in fact, allocated otherwise…if so, I need to talk with hardware folks to make new assignments. I’d like to be able to make the new assignments with confidence.

Thanks,
Paul++

Those GPIOs correspond to SODIMM pins 81 and 94. If I check the device tree I can see these pins are being used as part of the WiFi chip interface as seen here: imx8x-colibri.dtsi « freescale « dts « boot « arm64 « arch - linux-toradex.git - Linux kernel for Apalis, Colibri and Verdin modules

Also looking at the datasheet for this module these pins are highlighted with the following note:

This signal is not available on modules with Wi-Fi.

It would appear then these pins are not usable for other functions than their default.

Best Regards,
Jeremias

Jeremias,

Thanks for helping to uncover this. In our case, we are not using the WiFi module, so the inclusion of that device in our device tree is quite useless.
Furthermore, since it is interfering with our using those pins as GPIO, it is
also undesirable. What is the easiest path to update our device tree …
to remove the WiFi device and free up those pins for our GPIO purposes?

Thanks,
Paul++

I’m not sure if you understood me, but as I stated previously. The datasheet clearly states that these pins (81 & 94) are not available for use on WiFi variants of the Colibri i.MX8X. This is a hardware limitation and can’t be re-configured otherwise. Your options are to either use other pins for what you’re trying to do, or use a variant of the Colibri i.MX8X without WiFi, in which case these pins would be available for alternate use.

Best Regards,
Jeremias

Jeremias,

Thanks for the extra clarity. I understand the reconfiguring these pins for any other use is not possible with this WiFi module.

I will look into following one of the other paths that you have suggested.

Paul++