Controllong GPIO on torizon

Hello,

Question 1

I want to use GPIO5 and GPIO6 of apalis imx8 for led control.

	/* Apalis GPIO5 */
	pinctrl_gpio5: gpio5grp {
		fsl,pins = <
			IMX8QM_FLEXCAN2_RX_LSIO_GPIO4_IO01		0x06000021
		>;
	};

	/* Apalis GPIO6 */
	pinctrl_gpio6: gpio6grp {
		fsl,pins = <
			IMX8QM_FLEXCAN2_TX_LSIO_GPIO4_IO02		0x00000021
		>;
	};

In 0x00000021 14th and 15th bits are 00.
as per pad control register it means pull down of 100kohm.

default pins are active high.
So the voltage on pin should be 0v by default but in my case i am getting 3v on both gpio5 and gpio6.

question 2
for apalis imx8
GPIO5 - gpiochip4-1 and
GPIO6 - gpiochip4-2

root@b664282aeebd:~# gpioinfo
gpiochip4 - 32 lines:
	line   0:    "MXM3_18"       unused   input  active-high 
	line   1: "MXM3_11/GPIO5" unused input active-high 
	line   2: "MXM3_13/GPIO6" unused input active-high 
	line   3:   "MXM3_274"       unused   input  active-high 
	line   4:    "MXM3_84" "regulator-usb-host-vbus" output active-high [used]
	line   5:   "MXM3_262"       unused   input  active-high 
	line   6:    "MXM3_96"       unused   input  active-high 
	line   7:      unnamed       unused   input  active-high 
	line   8:      unnamed       unused   input  active-high 
	line   9:      unnamed       unused   input  active-high 
	line  10:      unnamed       unused   input  active-high 
	line  11:      unnamed     "enable"  output  active-high [used]
	line  12:   "MXM3_190"       unused   input  active-high 
	line  13:      unnamed       unused   input  active-high 
	line  14:      unnamed       unused   input  active-high 
	line  15:      unnamed       unused   input  active-high 
	line  16:   "MXM3_269"       unused   input  active-high 
	line  17:   "MXM3_251"       unused   input  active-high 
	line  18:   "MXM3_253"       unused   input  active-high 
	line  19:   "MXM3_295"       unused   input  active-high 
	line  20:   "MXM3_299"       unused   input  active-high 
	line  21:   "MXM3_301"       unused   input  active-high 
	line  22:   "MXM3_297"       unused   input  active-high 
	line  23:   "MXM3_293"       unused   input  active-high 
	line  24:   "MXM3_291"       unused   input  active-high 
	line  25:   "MXM3_289"       unused   input  active-high 
	line  26:   "MXM3_287"       unused   input  active-high 
	line  27:      unnamed       unused   input  active-high 
	line  28:      unnamed       unused   input  active-high 
	line  29:      unnamed       unused   input  active-high 
	line  30:      unnamed       unused   input  active-high 
	line  31:      unnamed       unused   input  active-high 

so pin number to export the
gpio5 (4-1)*32 + 1 = 97
gpio6 (4-1)*32 + 2 = 98

I can not export these pins to use on imx8 core.

apalis-imx8-06852506:~# echo 97 > /sys/class/gpio/export
sh: echo: write error: Invalid argument
apalis-imx8-06852506:~# echo 98 > /sys/class/gpio/export
sh: echo: write error: Invalid argument
apalis-imx8-06852506:~# 

question 3
How to give docker container access to the network-manager of host, so that I can check network connectivity of my apalis board from inside the container.

Greetings @bhagwat_99,

Question 1:
It looks like you’re using the wrong bit field values. Those are for the i.MX6 SoC. Each NXP SoC has their own values for bit field definitions. Unfortunatley we don’t have a table for the i.MX8 SoC. So you’ll need to reference the NXP i.MX8 reference manual to get the correct definitions for this SoC.

Question 2:
First of all you’re using the wrong formula to calculate the kernel numbers for those GPIO. The correct formula as well as a table can be found here: GPIO Alphanumeric to GPIO Numeric Assignment | Toradex Developer Center

Secondly, manipulating GPIOs with sysfs the way you are is a deprecated method. For a more modern method please see the article here: How to Use GPIO on TorizonCore | Toradex Developer Center

Question 3:
There is a docker run argument you can pass to give your container the same network as the host --network=host. However if you want to run Network Manager in a container and have it interact with the host this may get a little strange. I imagine at the least you’ll need to also bindmount dbus into the container so it can interact with the host dbus. You may need to run the container with elevated permissions as well.

Another option would be to just ssh from the container to the host via localhost. Then run the Network Manager already present on the host and report back the details you need via SSH.

Best Regards,
Jeremias

As Jeremias said iMX8 has different control pad bits.

Bits 6-5 PULL

00b - prohibited
01b - pull-up
10b - pull-down
11b - pull disabled

And it’s highly recommended to use an external pul up or down resistors for critical circuits.

1 Like

Hello @jeremias.tx ,
first of all thank you so. This information helped me a lot. One thing I learned here is never trust anyone except official documentation :grinning:

Hello @alex.tx ,
Thank you so much for help. This data saved me. Where did you find it. Could you share the link.

This is from i.MX 8QuadMax Reference manual.

Table you posted in your original question is from official Reference Manual ether. Just for iMX6 and it’s mentioned above that table.

1 Like

Thank you @alex.tx

Glad we were able to assist you!

Greeting @jeremias.tx @alex.tx ,

Tools I am using
Computer on Module - Apalis iMX8
Carrier Board - Ixora Carrier Board
Computer on Module OS - Torizon
Development PC OS - Linux

I want to use GPIO5(GPIO4IO1) and GPIO6(GPIO4IO2) for led control which also have used for flexcan2.
In imx8-apalis-v1.1.dtsi file included for device tree customization, I found node

        /* Apalis GPIO5 */
		pinctrl_gpio5: gpio5grp {
			fsl,pins = <
				IMX8QM_FLEXCAN2_RX_LSIO_GPIO4_IO01		0x06000021
			>;
		};

		/* Apalis GPIO6 */
		pinctrl_gpio6: gpio6grp {
			fsl,pins = <
				IMX8QM_FLEXCAN2_TX_LSIO_GPIO4_IO02		0x00000021
			>;
		};

        /* Apalis CAN2 */
		pinctrl_flexcan2: flexcan1grp {
			fsl,pins = <
				IMX8QM_FLEXCAN1_TX_DMA_FLEXCAN1_TX		0x21
				IMX8QM_FLEXCAN1_RX_DMA_FLEXCAN1_RX		0x21
			>;
		};

as per the reference manual to use these pins as gpio, in pad control resistor
bit 29-27 need to set 011
mux_mode

000b - DMA_FLEXCAN2_RX
011b - LSIO_GPIO4_IO01

and I want pins to be pulled down so
bit 6-5 need to be 10
Pull Down Pull Up
00b - prohibited
01b - pull-up
10b - pull-down
11b - pull disabled

so the final combination is 0x1e000041 is ok. So I did the changes in imx8-apalis-v1.1.dtsi


		/* Apalis GPIO5 */
		pinctrl_gpio5: gpio5grp {
			fsl,pins = <
				IMX8QM_FLEXCAN2_RX_LSIO_GPIO4_IO01		0x1e000041
			>;
		};

		/* Apalis GPIO6 */
		pinctrl_gpio6: gpio6grp {
			fsl,pins = <
				IMX8QM_FLEXCAN2_TX_LSIO_GPIO4_IO02		0x1e000041
			>;
		};

also in the same file i added the node

custom_status_led {

		pinctrl-names = "default";
		pinctrl-0 = <&pinctrl_gpio5>, <&pinctrl_gpio6>;

        
		network_led{
			label = "network_led";
			gpios = <&lsio_gpio4 1 GPIO_ACTIVE_HIGH>;
		};
		
		status_led {
			label = "status_led";
			gpios = <&lsio_gpio4 2 GPIO_ACTIVE_HIGH>;
		};
	};

But the final values are as follows

apalis-imx8-06852506:~$ sudo su
Password: 
apalis-imx8-06852506:/var/rootdirs/home/torizon# cd /sys/kernel/debug/pinctrl/scu\:pinctrl/
apalis-imx8-06852506:/sys/kernel/debug/pinctrl/scu:pinctrl# cat pinconf-pins | grep -i flexcan
pin 146 (IMX8QM_FLEXCAN0_RX): 0x40
pin 147 (IMX8QM_FLEXCAN0_TX): 0x18000040
pin 148 (IMX8QM_FLEXCAN1_RX): 0x40
pin 149 (IMX8QM_FLEXCAN1_TX): 0x18000040
pin 150 (IMX8QM_FLEXCAN2_RX): 0x1e000021
pin 151 (IMX8QM_FLEXCAN2_TX): 0x1e000021

In 0x1e000021 00 and 06 have replaced with 1e but 21 is same. should have changed to 41 to pull it down.

root@bb0e38d81cdd:/# gpioget 4 1
1
root@bb0e38d81cdd:/# gpioget 4 2
1

What changes should i make in device tree pull down these pins
Do I need to make changes to imx8-apalis-ixora-v1.2.dtsi

/* Apalis CAN2 */
&flexcan2 {
        xceiver-supply = <&reg_can2_supply>;
        status = "okay";
    };
}; 

change status to disable?

as per the reference manual to use these pins as gpio, in pad control resistor
bit 29-27 need to set 011
mux_mode

First of all you don’t need to set the mux yourself in the bit. The pin macro itself IMX8QM_FLEXCAN2_RX_LSIO_GPIO4_IO01 is already defined such that the pins is configured for GPIO use. See here: pads-imx8qm.h « pinctrl « dt-bindings « include - linux-toradex.git - Linux kernel for Apalis, Colibri and Verdin modules

Secondly, the new node you added custom_status_led I don’t think it does anything. All this does is define a block, but there’s no driver associated with this. Perhaps it might be easier to use the Linux driver for controlling LEDs with GPIOs as shown in this example: GPIO (Linux) | Toradex Developer Center

change status to disable?

You shouldn’t need to. The node flexcan2 uses different pins than the ones you’re using for GPIOs here.

Best Regards,
Jeremias

Greetings @jeremias.tx
Thank you for your help.
How can i just pull down gpio5(gpio4io1) and gpio6(gpio4io2) which is by default pulled up.

I would refer to the kernel documentation regarding the device tree gpio-leds bindings. As well as the general GPIO device tree bindings:

Best Regards,
Jeremias