on our custom carrier board we need to dynamically change the gpios to input/output. As described here this is currently not possible with the gpiod library alone because it does not change the cpu registers. The pinmux file sets the input/output configuration statically.
When we are changing input to output should we only change bit 4 and bit 6 to zero and leave the other bits as is?
In the pinmux sheet the gpio should be set Bidirectional and 3.3V Tolerance Enable should be disabled. In our case GPIO 2, 9, 11, 12.
gpioset has a --bias option. Am I right assuming that this also does not work because this exists in the cpu register?
In our program we now need to access /dev/mem which requires root access. Obviously we do not want to run our program as root. Any suggestions to make this safer?
To sum it up first write the cpu registers and afterwards use the gpiod library.
I already got the gpios working. I know which gpio number I need to use for gpiod and I know the cpu register offset. We are using Jetpack 6.2 (L4T 36.4.3). In Jetpack 5 this was still possible.
In our application we have the same hardware for different applications. The applications have different gpio settings therefore we need to change it dynamically.
The question is how we approach this. We could replace the pinmux for each application before flashing or create a service which does this dynamically.
Creating a separate pinmux for each intended HW application is recommended. Using scripts you could decide which pinmux/board configuration to use before flashing.
The only issue is that when we have an application and decide after launching the product that we want to change the gpio mode. We cannot reflash the board because our update process only replaces the application not the whole operating system.
Do you mean that some application would use the pin as input and some would use the pin as output?
If so, I think configuring Bidirectional in pinmux spreadsheet can meet this requirement.
Yes I want to switch between input and output mode. Does that mean that the tegra-pinctrl driver is only enabled for the default 40-pin header in the device tree? Therefore the gpiod methods should work correctly when the Pin is configured as BIDIRECTIONAL and 3.3V Tolerance Enable is off and the device tree change exists?
Because I want to use Pin 2, 9, 11 and 12 I only need to add the device tree change to Pin 2, 12 because they are not on the default 40-pin header? Did I understand that correctly?
I think I made a mistake in the pinmux or while flashing. I tested it again setting input to output without changing the device tree and now it works. Setting BIDIRECTIONAL and 3.3V Tolerance Enable is off in the pinmux is essential. Since when does this work in jetpack 6? I read in some post that you need to change the cpu registers manually.
No, it should also be able to work for other pins.
Correct, using Bidirectional should be enough for your use case to use the pin either input or output.
Please just note that gpioget will configure the pin as Input, and gpioset will configure the pin as Output.