How to control gpio in NHXP imx8mplus evk

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to control gpio in NHXP imx8mplus evk

3,251 Views
vrutik7781
Contributor I

Hi all.

i'm trying to control GPIO pins, for that i installed libgpiod package.

when i try gpioset with that command given as below:-

gpioset gpiochip5 9=1     
error = "gpioset: invalid line value"


same error come when i try gpioget.

vrutik7781_0-1710738016825.jpeg

in my board pin 13,14,16,18 are present for expansion in J21 connector.

vrutik7781_1-1710738129723.jpeg

 

when i run gpioinfo that time i getting this information ,

from this i try to run gpioset & gpioget (gpioset gpiochip5 9=1 ) i'm getting error = "gpioset: invalid line value".

 

can anyone suggest me how to approach. 

vrutik7781_0-1710740952531.jpeg

 

0 Kudos
Reply
20 Replies

3,223 Views
vrutik7781
Contributor I

vrutik7781_0-1710756244339.jpeg

below one is the file path, in this it is already enable

home/deevia/imx-yocto-bsp/sources/meta-freescale-3rdparty/recipes-kernel/linux/linux-kontron/defconfig

@weidong_sun 

0 Kudos
Reply

3,227 Views
vrutik7781
Contributor I

vrutik7781_0-1710754662562.jpeg

 

but in our case inside sys/class -> gpio folder is not present 

vrutik7781_1-1710754832290.jpeg

while searching on internet i found this article on one of the website.

So that's why i installed libgpiod package but through that also when i try i'm getting error i attached that snippet.

can you help to resolve this @weidong_sun 

 

0 Kudos
Reply

3,212 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Dear @vrutik7781 ,

 

1. /sys/clase/gpio/ (SYSFS)

I checked kernel configuration just now. my kernel version is 6.1.55, /sys/clase/gpio/ (SYSFS) for gpio should be deprecated.

weidong_sun_0-1710758632484.png

So your kernel should be the same as mine.

Sorry for my mistake!

2. command tools of libgpiod

Currently I saw only the following tools are provided for command line operation.

- gpiodetect

- gpioinfo

- gpioset

- gpioget

- gpiomon

I didn't find a tool to set gpio direction. You want to set EXP_P1_1 to output 1, but from your listed gpio information, all expansion gpios are INPUT.  I think if you want it to OUTPU 1, at first the gpio should be set to OUTPU, then set it 1.

If above tools are not sufficient for your operation, maybe you will have to write code to get the purpose. 

 

Thanks!

Regards,

weidong

 

 

0 Kudos
Reply

3,209 Views
vrutik7781
Contributor I

dear @weidong_sun 

i tried to add below code in my recipe in my layer .while running bitbake my_recipe_name ,it throws compile time errors i'm getting error like function definition are not present..

int main() {
struct gpiod_chip *chip;
struct gpiod_line *line;
int req, value;

chip = gpiod_chip_open("/dev/gpiochip0");
if (!chip)
return -1;

line = gpiod_chip_get_line(chip, 3);
if (!line) {
gpiod_chip_close(chip);
return -1;
}

req = gpiod_line_request_input(line, "gpio_state");
if (req) {
gpiod_chip_close(chip);
return -1;
}

value = gpiod_line_get_value(line);

printf("GPIO value is: %d\n", value);

gpiod_chip_close(chip);
}

0 Kudos
Reply

3,191 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Dear @vrutik7781 ,

 

No necessary to add your app to Yocto Layer, you know it is not convenient to build it in Yocto. You can follow these steps to do it.
1. Exporting toolchain from Yocto
2. Installing the toolchain to /opt/
3. Writing code and Makefile for your code
4. Configuring cross compilation environment using the following commands
# source /opt/fsl-imx-wayland/6.1-mickledore/environment-setup-armv8a-poky-linux
# make your_app

Here is my the directory of toolchain, for your reference.

weidong_sun_0-1710808960042.png


[Note]
On the issue of building app, please re-create a new post on community or a new case in our SFDC system.

 

Thanks!

Regards,

weidong

 

0 Kudos
Reply

3,184 Views
vrutik7781
Contributor I
dear @weidong_sun

can you please suggest me is their any document or reference is available to do the following steps:
1. Exporting toolchain from Yocto
2. Installing the toolchain to /opt/
3. Writing code and Makefile for your code
4. Configuring cross compilation environment using the following commands
# source /opt/fsl-imx-wayland/6.1-mickledore/environment-setup-armv8a-poky-linux
# make your_app.


I'm totally new in Yocto community if through any reference or document i go then it's helpful for me.

And also i want to know which toolchain i need to export ?

Please help me to solve this issue.

Thanks!
Regards,
Vrutik.
0 Kudos
Reply

3,158 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Dear @vrutik7781 ,

 

See the link , please!

All iMX linux materials are here:

https://www.nxp.com/design/design-center/software/embedded-software/i-mx-software/embedded-linux-for...

weidong_sun_0-1710896099228.png

Download all documents, please!

Then you open IMX_LINUX_USERS_GUIDE.pdf, on page 33, chapter 4.5.12 How to build U-Boot and Kernel in standalone environment, you can find the command:

weidong_sun_1-1710896400160.png

In order to get more libs, you can use imx-image-multimedia, like this:

# DISTRO=fsl-imx-fb MACHINE=imx6ull14x14evk bitbake imx-image-multimedia -c populate_sdk

For image types, you can find them in IMX_YOCTO_PROJECT_USERS_GUIDE.pdf, all yocto operations are also in the document.

 

Try it, please!

Regards,

weidong

0 Kudos
Reply

3,139 Views
vrutik7781
Contributor I

dear @weidong_sun

 

sorry for disturbing you , while trying this method I'm getting following errors.

vrutik7781_0-1710926147641.pngvrutik7781_1-1710926166630.png

 

I try this thing,

"If the building process is interrupted, modify conf/local.conf to comment out the line:
PACKAGE_CLASSES = "package_deb", and then execute the populate_sdk command again."

but again I'm facing same issue what should i need to do?

 

Thanks.

Regards.

Vrutik  

0 Kudos
Reply

3,114 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Dear @vrutik7781 ,

 

I tested L6.1.55_2.1.0 yocto bsp. My cross compilation platform is ubuntu 20.04 host.

Before building it, some necessary software packages must be installed using apt-get install , See IMX_YOCTO_PROJECT_USERS_GUIDE.pdf, please!

Below is all steps on building toolchain for imx8 serials, even if we build it based on i.mx8mp, the toolchain can also be used for other i.mx CPU based on arm64.

# cd ~/imx-yocto-bsp

# DISTRO=fsl-imx-wayland MACHINE=imx8mp-lpddr4-evk source imx-setup-release.sh -b build-wayland

The following command is to get all packages for toolchain. at the time, it is under build-wayland .

# bitbake imx-image-multimedia -c populate_sdk --runall=fetch -k

weidong_sun_4-1710987094926.pngweidong_sun_5-1710988123573.png

 

So far all packages needed by toolchain have been downloaded successfully.

Then begin to build toolchain

#  bitbake imx-image-multimedia -c populate_sdk

weidong_sun_6-1710988257368.png

 

 

After compilation is done, you can find a xxx.sh file in tmp/work/deploy.

you can copy it to /opt/ , then 

# sudo chmod a+x xxx.sh

# ./xxx.sh

The toolchain will start installation.

 

Regards,

weidong

 

0 Kudos
Reply

3,102 Views
vrutik7781
Contributor I

dear @weidong_sun

 

My cross compilation platform is also ubunto 20.04 host.

by referring IMX_YOCTO_PROJECT_USERS_GUIDE.pdf i created my image by following the steps and installing the required packages.

i try the command to get all packages for toolchain and it downloaded successfully.

bitbake imx-image-full -c populate_sdk --runall=fetch -k

vrutik7781_0-1710998549730.png

 

after that i try to build toolchain, but again I'm facing same issue..

 

bitbake imx-image-full -c populate_sdk

vrutik7781_1-1710998673452.pngvrutik7781_2-1710998684764.png

vrutik7781_3-1710998695637.png

i try the Note: given in IMX_LINUX_USERS_GUIDE.pdf, on page 33, chapter 4.5.12. modify conf/local.conf to comment out the line.

vrutik7781_4-1710999162876.png

after also I'm facing same issue.

 

Can you please give me guidance what should i need to resolve this issue.

 

Thanks.

vrutik

 

0 Kudos
Reply

3,098 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hello @vrutik7781 ,

 

You didn't follow my steps.

imx-image-multimedia, not imx-image-full.

 

Regards,

weidong

0 Kudos
Reply

3,094 Views
vrutik7781
Contributor I

Dear @weidong_sun

 

my image is imx-image-full that's why instead of imx-image-multimedia  i am using imx-image-full.

vrutik7781_0-1711003302243.png

while building image only, i build imx-image-full, is it the right way ?

 

 

 

 

 

0 Kudos
Reply

3,081 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hello @vrutik7781 ,

 

imx-image-full includes qt lib, if you don't want to build qt app, no need to build the image, it is very big.

 

Regards,

weidong

0 Kudos
Reply

3,064 Views
vrutik7781
Contributor I
Dear @weidong_sun

i want imx-image-full , through this method it possible or not?
0 Kudos
Reply

2,992 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Dear @vrutik7781 ,

 

It seems that there are some issues on the package "nativesdk-qtbase", maybe it's incomplete. 

Try these steps:

1. Cleaning all previous downloading

## bitbake nativesdk-qtbase -c cleanall   ( or  bitbake nativesdk-qtbase -c cleansstate)

2. Fetching it separately

# bitbake nativesdk-qtbase -c fetch

3. Compiling it separately

# bitbake nativesdk-qtbase -c compile

 

I tested above steps on my ubuntu host, no problem.

weidong_sun_0-1711073022427.png

 

For other packages, if you encounter similar issue, above steps can also be used.

 

Thanks!

Regards,

weidong

0 Kudos
Reply

2,891 Views
vrutik7781
Contributor I

Dear @weidong_sun

Thanks for your support. I'm able to export toolchain and install in /opt/ successfully.

vrutik7781_0-1711115314947.png

vrutik7781_1-1711115340107.png

After that I've gone for the third step, Makefile for my code and for that I referred : main.c - https://variwiki.com/index.php?title=MX8M_GPIO and did changes as per my requirements, but I am getting an errors: undefined references, even though I've installed libgpiod.

vrutik7781_2-1711116089604.png

I request you to please assist me here to resolve this.

Regards,

Vrutik

0 Kudos
Reply

2,757 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Dear @vrutik7781 ,

 

Obviously, cross compiler didn't find libgpiod lib, so link errors occurred.

check if cross compiler includes the lib, please!

weidong_sun_1-1711329937507.png

 

if not, add the line to ./conf/local.conf

==========================

IMAGE_INSTALL:append = " libgpiod libgpiod-dev libgpiod-tools"

==========================

weidong_sun_0-1711325764173.png

 

If above suggestions can't still solve the question, please re-create a new post or case for building your app!  iMX support team will continue to support you.

 

Thanks!

Regards,

weidong

 

 

 

0 Kudos
Reply

2,746 Views
vrutik7781
Contributor I

Dear @weidong_sun

 

I check and it is present in my case.

vrutik7781_0-1711357277351.png

but while creating Makefile it gives error.

 

Ok I'll create new post regarding building my app.

 

Thanks & regards

Vrutik.

0 Kudos
Reply

3,225 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Dear @vrutik7781 ,

 

Try to select CONFIG_GPIO_SYSFS in kernel configuration.

 

Regards,

weidong

0 Kudos
Reply

3,234 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Dear @vrutik7781 ,

 

Let us see iMX8MP-11X11-evk schematic, please!

weidong_sun_0-1710747691359.png

1. Connections between PCA6416 & J21

PCA6416.P1_1--->J21.pin13  ( EXP_P1_1)

PCA6416.P1_2--->J21.pin15  ( EXP_P1_2)

PCA6416.P1_3--->J21.pin16  ( EXP_P1_3)

PCA6416.P1_4--->J21.pin13  ( EXP_P1_4)

2. Numbering of PCA6416 on linux platform

Let us assume the base number of PCA6416 is BASE on linux platform, 

Then each GPIO number of PCA6416 on linux will be:

--P0 port

P0_0 : BASE + 0 

P0_1: BASE + 1

...

P0_7: BASE + 7

--P1 port

P1_0 : BASE + 8

P1_1 : BASE + 9

...

P1_7 : BASE +15

So we only need to know the BASE of PCA6416 on linux system.

3. Checking BSAE of PCA6416

Try the following steps, please!

# cd /sys/class/gpio

# ls -l

gpiochipBASE -->.../.../devices/platform/30a40000.i2c/i2c-1/1-0020/gpio/gpiochipBASE

[Note]

BASE should be a concrete number you will see.

Let us assume the BASE is 500, then the PCA6416's starting gpio number is 500, what you found above is :

gpiochip500 -->.../.../devices/platform/30a40000.i2c/i2c-1/1-0020/gpio/gpiochip500

 

THEN:

EXP_P1_1 : gpio number is 500 + 9 = 509

EXP_P1_2 : gpio number is 500 + 10 = 510

EXP_P1_3 : gpio number is 500 + 11 = 511

EXP_P1_4 : gpio number is 500 + 12 = 512

 

4. Operating expansion gpios

Taking EXP_P1_0 as an example:

# cd /sys/class/gpio/gpiochip500

# echo out > direction    (set it to be OUTPUT,  "in" is used to set it INPUT ) 

# echo 1 > value   (set it to output High,  0 output Low)

 

Above steps are on how to operate expansion GPIO on linux platform, for you reference.

Try it, please!

 

Thanks!

Regards,

weidong

 

 

 

 

0 Kudos
Reply