01 Multiplexing GPIO
1.1 Adoption of the Iomux Method1.SD2_DATA01 is used as GPIO.
First look in OKMX93-linux-kernel/arch/arm64/boot/dts/freescale/imx93-pinfunc.h
The specific parameters here are not described anymore. Please check the corresponding registers in the imx93RM_RevD_alpha_customer.pdf manual.
2. The new multiplexed gpio pins in iomux in the device tree are as follows:
Device tree: OKMX93-linux-sdk/OKMX93-linux-kernel/arch/arm64/boot/dts/freescale/OK-MX93-C.dts
3. Add pinctrl_gpio1 pin-multiplexing configuration
Also search for the MX93_PAD_SD2_DATA1 pin name in the device tree to see if it is multiplexed into other functions elsewhere.
We can see that this pin is multiplexed into the USDHC2 function. Please search for pinctrl_usdhc2 to block the USDHC2 function.
4.Compile the device tree. Replace the device tree and re-burn it.
5.View all gpio settings
6.We can see from the device tree pin configuration that the corresponding GPIO is gpio@43820080 in the device tree, i.e. gpiochip1.
Specific correspondence:
7.We can use the following command to check which GPIOs are currently occupied in the system.
8. Output modes
We can use the following command to set the GPIO to high level. Measuring high with a multi-meter indicates a successful GPIO test.
We can use the following command to set the GPIO to low level. Measuring low with a multi-meter indicates a successful GPIO test.
Look at gpioinfo, we can see that line4 is in the output state.
9. Input modes
We can use the following command to set the GPIO to input mode and read the current GPIO level status.
Look at gpioinfo,we can see that line 4 is in the input state.
10. Interrupt mode
We can use the following commands to set GPIO interrupt monitoring
Pin grounding
Disconnect grounding
Look at gpioinfo, we can see that line4 is in the input state.
1.2 Libgpiod Application Examples
Currently imx93 uses the linux 5.15.52 kernel system. The sysfs GPIO interface (/sys/class/gpio), which previously operated gpio, has been deprecated, and its replacement is the GPIO character device API Libgpiod.
The following is an example of operating the keys (K1) and LEDs (D6) on the EVK.
1. Modify the device tree
Path:OKMX93-linux-sdk/OKMX93-linux-kernel/arch/arm64/boot/dts/freescale/OK-MX93-C.dts
The default led-1 and keys nodes are first blocked to avoid conflicts,in the following form:
Add the gpio_key node below:
Modify pinctrl_gpio_key to add multiplexing of led pins:
The pins used for buttons are: MX93_PAD_CCM_CLKO2__GPIO3_IO27 LED
The pins used for LEDs are: MX93_PAD_CCM_CLKO3__GPIO4_IO28
Save and exit and recompile the device tree.
After compiling, re-burn OK-MX93-C.dtb
1. Compile the test source code
Copy gpiotest.c, gpio-toggle.c, and lib.tar.bz2 from the Libgpiod test source directory to the development environment.
Extract lib.tar.bz2 to this directory, the gpiod.h file and the libgpiod library will be used for compilation.
Example 1: Cyclic control of LED on and off at 1s intervals
Example 1: Cyclic control of LED on and off at 1s intervals
(1) Set environment variables (note the space after the point)
(2) Cross-compilation
(3) Copy the executable file gpio-toggle to the development board.
(4) Execute and see that the LED (D6) lights up for 1s and goes out for 1s.
Input parameters 2 and 28 are: gpiochip2 line28
Example 2: Press the key to control the LED on and off, and the status will be flipped every time you press the key. Cross-compile gpio-test.c
(1) Set environment variables (note the space after the point)
(2) Cross-compilation
(3) Copy the executable file gpio-test to the development board.
(4) Execute, we can see that every time we press a key, the LED status is flipped once.
Input parameter 1. 27 is: gpiochip1 line27
2.28 for: gpiochip2 line28
02 Extended GPIO
The PCAL6524 is a 24-bit general-purpose I/O expander with i2c interface. Specific description can refer to the "NXP1-PCAL6524HE.pdf". Development board is not welded PCAL6524 by default, if we want to realize this program, the hardware needs to be welded on this module.In the following test, the PCAL6524 is connected to the i2c3 and the GPIO_IO1 is used for the interrupt pin (if other pins are used as interrupts, we can adjust it accordingly). Configuration and test methods are as follows:
Path:
OKMX93-linux-sdk/OKMX93-linux-kernel/arch/arm64/boot/dts/freescale/OK-MX93-C.dts
1.Add the pcal6524 node under i2c3:
2.Add pinctrl_pcal6524 under the &iomuxc node:
3. Block the previous pin multiplexing to avoid conflicts:
4. Compile Device Tree Replace the device tree and re-burn it.
5. Gpiodetect command to view GPIO devices
We can see the extra gpiochip4, 24 lines. Refer to the "Multiplexing GPIOs" section for the test methods.
For additional information, visit the OK-MX9352-C Single Board Computer
Originally published at www.forlinx.net.