Hi, I’m the Toradex AI Assistant.
I might make mistakes. Our support team will step in if needed. If I answered your question, please tick the “Solution” checkbox. For follow-up questions to me, please use @ToradexAI in your post.
Hello Vishal,
Your code looks correct, but the issue is likely that the GPIO pin needs to be properly configured for GPIO functionality through the device tree. On i.MX 8M Plus based modules, pins need to be explicitly muxed to GPIO function before they can be used as GPIOs (1).
Pin Configuration Requirements
For i.MX 8M Plus based modules, you need to configure the pin multiplexing in the device tree (1). The pin control configuration requires defining a device tree node inside the pin controller node with the fsl,pins property (1).
Device Tree Configuration Steps
- Create a custom device tree overlay to configure GPIO2_25 for GPIO functionality (2):
/dts-v1/;
/plugin/;
#include "imx8mp-pinfunc.h"
/ {
compatible = "toradex,verdin-imx8mp";
fragment@0 {
target = <&iomuxc>;
__overlay__ {
pinctrl_gpio2_25: gpio2_25grp {
fsl,pins = <
/* Replace with correct pin definition for GPIO2_25 */
MX8MP_IOMUXC_[PIN_NAME]__GPIO2_IO25 0x1c4
>;
};
};
};
fragment@1 {
target = <&gpio2>;
__overlay__ {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_gpio2_25>;
};
};
};
- Identify the correct pin definition by checking the i.MX 8M Plus Applications Processor Reference Manual and the pin function definitions in
imx8mp-pinfunc.h(1).
Pin Control Settings
The recommended pad configuration value 0x1c4 provides weak pull-up configuration (1). For GPIO applications, you can also use 0x184 for weak pull-down if needed (1).
Alternative Approach
If you only need to set the pin direction and don’t want to use gpio-hog in the device tree, you can configure just the pinmux in the overlay and then control the direction from your application (3). This approach requires:
- Configure only the pinmux in the device tree overlay
- Use your existing C code to control the GPIO direction and value
Verification Steps
After applying the device tree overlay:
- Check if the GPIO is properly exported:
ls /sys/class/gpio/ - Verify the pin configuration with a multimeter or oscilloscope
- Ensure no other peripherals are using the same pin
The key issue is that without proper device tree configuration, the pin remains in its default function and cannot be controlled as a GPIO (1).
Best regards, Toradex AI Assistant.