Hi
I have tried to get access to the GPIO ports on the iMX7ULP-EVK, but it s causing me some troubles. It should be possible to either set a value or read a value from a port in the embedded Linux system by creating a node e.g.:
echo 611 > /sys/class/gpio/export
Where 611 corresponds to PTF3? I'm a bit uncertain about this number, but it is coming from
cat /sys/kernel/debug/pinctrl/40ac0000.pinctrl/gpio-ranges
which corresponds to the four groups of ports (PTC, PTD, PTE and PTF) and for the last one, PTF it says:
40b1000.gpio GPIOS [608-627] PINS [96 - 115]
PTF3 is the fourth counting from zero, that means is should be 611 - is this right?
At least I can create a node the command at the top, and if I try to make a node outside the ranges from the list, I get an error. When I have made a node, I get access to the features like "active-low", "direction" etc.. However I cannot change the direction from in to out for port 611 but I can for port 610. Could this be related to the Device Tree Source?
If I read out the value of the port 611 it is zero and remains zero even if apply 3.3V to the PTF3 pin on the evaluation board (accessible on the connector for the Arduino - and yes, I have taken R155 into consideration, since the resistor needs to be mounted to enable the pin-header. I just applied the 3.3v on the pads for the resistor). Could the missing ability to read from the status of the pad be related to missing configuration of the Device Tree Source?
Questions about GPIO in Device Tree Source
I have managed to compile the Device Tree Source from the files embedded in the yocto project, and if I change the model name (IMX7ULP-EVK) to something else, I can see that is has changed in the .dtb file (by decompiling the file afterwards). The file is working afterwards since the processor can boot and use the MIPI interface. I then tried to add some code for the for the GPIO:
In imx7ulp-evk.dts inside "&iomuxc1"
&pinctrl {
pinctrl_gpio_leds: gpio_leds_grp {
fsl,pins = <
IMX7ULP_PAD_PTF14__PTF14 0x22 /* Configure PTF14 as GPIO */
IMX7ULP_PAD_PTF15__PTF15 0x22 /* Configure PTF15 as GPIO */
>;
};
};
In the imx7ulp-evkb.dts I place the following code:
gpio_leds {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_gpio_leds>;
led1 {
label = "LED1";
gpios = <&gpio_ptf 14 GPIO_ACTIVE_HIGH>; /* PTF14 */
default-state = "off";
};
led2 {
label = "LED2";
gpios = <&gpio_ptf 15 GPIO_ACTIVE_HIGH>; /* PTF15 */
default-state = "off";
};
};
I still have an error to fix before I manage to compile the additional code above, but it could be nice of there were an example how to get the GPIO ports to work from start to finish (I haven't been to find the information) just to confirm that I am on the right track?
I how does this go together with the pin mux that is configured for the m4 processor?
Hope some can bring some clarity to have to get the GPIOs working for an embedded linxux.
Solved! Go to Solution.
Hi Aldo
Thanks for your response.
I'm not sure what you mean with "peripherals being used on the M4 should be disabled on the Cortex-A" since my intention keep as many functions as possible working on the evk, and only change the functions needed to make some GPIOs free and available.
I managed to compile a new .dtb file that enables the gpio pins. The definition of the leds remained the same as in the original post, but the pin-mux had to be changed slightly:
&pinctrl {
pinctrl_gpio_leds: gpio_leds_grp {
fsl,pins = <
IMX7ULP_PAD_PTF14__PTF14 0x14 /* Configure PTF14 as GPIO */
IMX7ULP_PAD_PTF15__PTF15 0x14 /* Configure PTF15 as GPIO */
>;
};
};
If the GPIOs have been configured correctly, that will visible in the linux kernel
cat /sys/kernel/debug/gpio
providing a output similar to this:
Now the output of the pin can be changed by:
echo 1 > /sys/class/leds/LED1/brightness /* turn on led */
echo 0 > /sys/class/leds/LED1/brightness /* turn off led */
This also answered the question in relation to the number of the GPIO ports, which were respectively 622 and 623. Also when a GPIO port has been defined as a an LED in the Device Tree Source, then it is not possible to access the GPIO as a node, but instead /sys/class/leds/LED1/ has to be used to access the properties.
Hello,
What error are you getting when trying to compile?
PTA & PTB are used on the M4, and do remember that peripherals being used on the M4 should be disabled on the Cortex-A or it will crash when booting into Linux.
Also, make sure to not use them on user space that can cuase the same as above, it is better to have everything configured on device tree to avoid this kind of issues.
Best regards/Saludos,
Aldo.
Hi Aldo
Thanks for your response.
I'm not sure what you mean with "peripherals being used on the M4 should be disabled on the Cortex-A" since my intention keep as many functions as possible working on the evk, and only change the functions needed to make some GPIOs free and available.
I managed to compile a new .dtb file that enables the gpio pins. The definition of the leds remained the same as in the original post, but the pin-mux had to be changed slightly:
&pinctrl {
pinctrl_gpio_leds: gpio_leds_grp {
fsl,pins = <
IMX7ULP_PAD_PTF14__PTF14 0x14 /* Configure PTF14 as GPIO */
IMX7ULP_PAD_PTF15__PTF15 0x14 /* Configure PTF15 as GPIO */
>;
};
};
If the GPIOs have been configured correctly, that will visible in the linux kernel
cat /sys/kernel/debug/gpio
providing a output similar to this:
Now the output of the pin can be changed by:
echo 1 > /sys/class/leds/LED1/brightness /* turn on led */
echo 0 > /sys/class/leds/LED1/brightness /* turn off led */
This also answered the question in relation to the number of the GPIO ports, which were respectively 622 and 623. Also when a GPIO port has been defined as a an LED in the Device Tree Source, then it is not possible to access the GPIO as a node, but instead /sys/class/leds/LED1/ has to be used to access the properties.