Hey,
I am having a bit of trouble trying to control GPIO pins and CAN on the i.MX8MM with Yocto. I can control pins using:
echo XX > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpioXX/direction
or
echo "in" > /sys/class/gpio/gpioXX/direction
echo 1 > /sys/class/gpio/gpioXX/value
or
echo 0 > /sys/class/gpio/gpioXX/value
echo XX > /sys/class/gpio/unexport
But I have not been able to find any information on how to actually set an exposed pin (like on the J1003 header). The only information I have seen is to make sure the DTS file is correct, but not how to actually set it, and to use i.MX Pins Tool v6. When I try to select my board in i.MX Pins Tool v6 I get the error
"Disk operation error. Check disk space and write permissions for data folder C:\ProgramData\NXP\mcu_data_v6"
Which does not make sense because I have over 200GB of free space in that disk and no weird write permissions. So I am really not sure where to go for the GPIO.
With the CAN I am able to get it all configured in the kernel, set up the CAN bitrate and start it, but I have no idea how to actually send a message. Any help or links to information would be greatly appreciated.
Thanks!
Dave
已解决! 转到解答。
For GPIO pins:
In the dts file, you can see there is the name of the pin and the iomux/pad setting of the pin.
For example:
MX8MM_IOMUXC_SAI2_RXC_GPIO4_IO22 0x19
"SAI2_RXC" is the real pin/pad of the i.MX8MM. The GPIO4_IO22 is one of the IOMUX functions of this pin. So, this setting means using the pin SAI2_RXC as a gpio pin gpio4_22.
The number “0x19” is the PAD CTL setting such as Pull enable/disable, Pull-up enable/disable, fast/slow slew rate and so on.
For details of MUX register, please read the i.MX8MM reference manual 8.2.5.105 Pad Mux Register (IOMUXC_SW_MUX_CTL_PAD_SAI2_RXC)
For details of PAD register, please read the i.MX8MM reference manual 8.2.5.259 Pad Control Register (IOMUXC_SW_PAD_CTL_PAD_SAI2_RXC)
Basically, all the pins are well defined in pins-imx8mm.h.So, you just pick up the correct pin name in the .h file. Then you can use the pin as gpio pin.
For the CAN, this may useful for you.
Hey,
Jimmychan was very helpful, but I thought I would leave a comment with exactly how I got the gpio working as I wanted.
Some documentation on how to do this can be found in …/build-dir/tmp/work-shared/imx8mmevk/kernel-source/Documentation and in this document https://www.nxp.com/docs/en/user-guide/i.MX_BSP_Porting_Guide_Linux.pdf. Specifically to enable pin 37 on the expansion header we went to the dts file at .../build-dir/tmp/work-shared/imx8mmevk/kernel-source/arch/arm64/boot/dts/freescale/fsl-imx8mm-evk.dts and on line 322 changed:
MX8MM_IOMUXC_SAI5_RXD1_SAI5_RX_DATA1
to
MX8MM_IOMUXC_SAI5_RXD1_GPIO3_IO22
To set pad SAI5_RXD1 to be GPIO3_IO22 which we learned was a possibility from the IMXMM base board schematic page 16
We then went to line 884 and changed the status on the sai5 group from:
status = "disabled”;
to
status = "okay";
to enable the sai5 group
Then we ran BItbake –c menuconfig linux-imx to recompile the dts file and finally ran bitbake core-image-base to create a new image.
When that was all done we were able to set the GPIO over terminal with the commands:
echo 86 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio86/direction
echo 1 > /sys/class/gpio/gpio86/value
(86 because it is GPIO3_IO22, which in Linux means (3 - 1)*32 + 22 which is 86)
Hope that helps anyone else in a similar situation!
For GPIO pins:
In the dts file, you can see there is the name of the pin and the iomux/pad setting of the pin.
For example:
MX8MM_IOMUXC_SAI2_RXC_GPIO4_IO22 0x19
"SAI2_RXC" is the real pin/pad of the i.MX8MM. The GPIO4_IO22 is one of the IOMUX functions of this pin. So, this setting means using the pin SAI2_RXC as a gpio pin gpio4_22.
The number “0x19” is the PAD CTL setting such as Pull enable/disable, Pull-up enable/disable, fast/slow slew rate and so on.
For details of MUX register, please read the i.MX8MM reference manual 8.2.5.105 Pad Mux Register (IOMUXC_SW_MUX_CTL_PAD_SAI2_RXC)
For details of PAD register, please read the i.MX8MM reference manual 8.2.5.259 Pad Control Register (IOMUXC_SW_PAD_CTL_PAD_SAI2_RXC)
Basically, all the pins are well defined in pins-imx8mm.h.So, you just pick up the correct pin name in the .h file. Then you can use the pin as gpio pin.
For the CAN, this may useful for you.
Thank you so much for the help!
I am still a little confused on a few things with the GPIO, firstly is there a document showing the connection between, for example, SAI2_RXC and an exposed pin on the board? I have found some information in the i.MX 8M Mini Hardware User's Guide 2.17, but it doesn't show alternate uses of each pin. Secondly, I am not sure where the .dts file I should edit is. I have found a .dts files that matches the one you linked at:
.../build-dir/tmp/work-shared/imx8mmevk/kernel-source/arch/arm64/boot/dts/freescale/fsl-imx8mm-evk.dts
on my host machine but when I edit it by changing line 142 from
MX8MM_IOMUXC_GPIO1_IO14_CCMSRCGPCMIX_CLKO1 0x59
to
MX8MM_IOMUXC_GPIO1_IO14_CCMSRCGPCMIX_CLKO1 0x58
to try and select 000 ALT0 — Select signal GPIO1_IO14 as described in i.MX 8M Mini Reference Manual 8.2.5.20
then I run bitbake core-image-base, and flash the SD card
from there I try to set the GPIO as described above (with the XX replaced with 14) and check on pin 31 on J1003 but it did not work.
Do you have any ideas of what I am doing wrong? I have seen some references to rebuilding the .dts file, how would I do that?
Thanks again!
Dave
You can check the schematic of the i.MX8MM-EVK board. You can download it from here:
i.MX 8M Mini Evaluation Kit | NXP
For the IOMUX setting (alternate uses) of each pin, please read the i.MX8MM Reference Manual. You can download it from here:
i.MX 8M Mini Applications Processor | Arm Cortex A53/M4 | 1080P display | NXP
If you want to use the GPIO1_IO14 pin as gpio pin, please change it to GPIO1_IO14 in dts file.
MX8MM_IOMUXC_GPIO1_IO14_GPIO1_IO14