2022-01-31 03:00 AM
Hi,
I'm using stm32mp157a-dk1 and I want to drive a pin with the A7.
I add and set (as digital output) the pin PF2 (named "Test") to "Cortex-A7 non secure" in the "Pin Reserved" on the IOC file in the window "Pinout & Configuration" of STM32CubeIDE.
Then I generate the code, but the dts file does not change and I cannot find a pin named "Test" in the Device Tree of the A7.
How can I add the pin on the dts file, so the A7 can drive it?
Moreover, where should I put the dts file to build the linux image with yocto?
(For yocto I follow the Distribution Package Tutorial for STM32)
Thanks in advance,
Andrea
Solved! Go to Solution.
2022-02-14 01:53 AM
Hi @OlivierK ,
Thank you so much for your reply, useful to understand better the DT, but I found the solution to my problem (probably I didn't make myself clear
about my purpose).
In the following, the patch that I get to enable pin d 11 (led blue) and pin h 7 (led orange) for the linux userspace:
diff --git a/stm32mp15xx-dkx.dtsi.orig b/stm32mp15xx-dkx.dtsi
index ee50622..584ed71 100644
--- a/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
+++ b/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
@@ -76,13 +76,22 @@
};
led {
- compatible = "gpio-leds";
+ compatible = "gpio-export";
led-blue {
label = "heartbeat";
gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "heartbeat";
default-state = "off";
+ status = "okay";
};
+
+ led-orange {
+ label = "myled_orange";
+ pinctrl-names = "default";
+ pinctrl-0 = <&my_leds_orange_pins>;
+ status = "okay";
+ };
+
};
sound {
@@ -548,6 +557,17 @@
};
};
+&pinctrl
+{
+ my_leds_orange_pins: my-leds-orange-0
+ {
+ pins
+ {
+ pinmux = <STM32_PINMUX('H', 7, RSVD)>;
+ };
+ };
+};
+
&pwr_regulators {
vdd-supply = <&vdd>;
vdd_3v3_usbfs-supply = <&vdd_usb>;
After the compilation of the new Linux image, I use "gpioinfo" and I get:
gpiochip3 - 16 lines:
...
line 11: unnamed unused output active-high
...
gpiochip7 - 16 lines:
...
line 7: unnamed unused output active-high
Then using the command:
gpioset gpiochip3 11=1
gpioset gpiochip7 7=1
Blue and orange leds switch on.
Best Regards,
Andrea
2022-01-31 05:34 AM
Hi @ASega.1 ,
pure GPIO definition for Linux are not directly supported within CubeMx.
You should manually edit the Device Tree.
See https://wiki.st.com/stm32mpu/wiki/GPIO_device_tree_configuration
and also
https://wiki.st.com/stm32mpu/wiki/How_to_control_a_GPIO_in_kernel_space
https://wiki.st.com/stm32mpu/wiki/How_to_control_a_GPIO_in_userspace
Regards,
In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'
2022-02-03 04:21 AM
Hi @PatrickF ,
Thanks for the reply. I tried in these days following the link you shared, but nothing.
I was able to enable a gpio as a led but not to drive it.
In the following the steps:
--- a/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
+++ b/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
@@ -84,6 +84,15 @@
default-state = "off";
};
};
+
+ led2 {
+ compatible = "gpio-leds";
+ us_boot {
+ label = "boot_us";
+ gpios = <&gpiog 8 GPIO_ACTIVE_HIGH>;
+ };
+ };
sound {
compatible = "audio-graph-card";
line 8: unnamed unused input active-high (before adding the patch)
line 8: unnamed "boot_uS" output active-high [used] (added the patch)
From here I'm not able to drive my pin.
I tried many times and this is the case more similar to what I would.
Now I'm trying with another patch:
--- a/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
+++ b/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
@@ -84,6 +84,15 @@
default-state = "off";
};
};
+
+ gpio_p {
+ compatible = "gpio-export";
+ us_boot {
+ gpio-export,name = "boot_uS";
+ gpio-export,output = <0>;
+ gpios = <&gpiog 8 GPIO_ACTIVE_HIGH>;
+ };
+ };
sound {
compatible = "audio-graph-card";
But is correct the way to add a pin to DTS or I have to change something?
From your wiki I understood something but not where make my changes to add a pin.
Thanks in advance.
Best Regards,
Andrea
2022-02-09 10:38 AM
Hi ASega.1 (Community Member)
It is not allowed to mix user and kernel space. You can drive a GPIO in user space if this pin is not been driven by the kernel. I chose PA14 since PF2 is used on my board.
root@stm32mp1:~# gpioinfo gpiochip0 | grep 14
line 14: unnamed unused output active-high
From there you can control the gpio by s/w from userspace, even driving to 1 or 0 a gpio declared initially as input, gpiolib will configure it as output.
The kernel driver will lock the use of GPIO for gpiolib, that explains the situation you had below.
line 8: unnamed unused input active-high (before adding the patch)
line 8: unnamed "boot_uS" output active-high [used] (added the patch)
From here I'm not able to drive my pin.
To disable this mutually exclusive access, you can disable the .strict property in the DT but this is not recommended :
(To disable strict mode:
workspace/sources/linux-stm32mp/drivers/pinctrl/stm32/pinctrl-stm32.c
static const struct pinmux_ops stm32_pmx_ops = {
.get_functions_count = stm32_pmx_get_funcs_cnt,
.get_function_name = stm32_pmx_get_func_name,
.get_function_groups = stm32_pmx_get_func_groups,
.set_mux = stm32_pmx_set_mux,
.gpio_set_direction = stm32_pmx_gpio_set_direction,
/* PATCH GPIOLib */
.strict = false,
/* .strict = true,*/
};.
Best Regards,
Olivier
2022-02-14 01:53 AM
Hi @OlivierK ,
Thank you so much for your reply, useful to understand better the DT, but I found the solution to my problem (probably I didn't make myself clear
about my purpose).
In the following, the patch that I get to enable pin d 11 (led blue) and pin h 7 (led orange) for the linux userspace:
diff --git a/stm32mp15xx-dkx.dtsi.orig b/stm32mp15xx-dkx.dtsi
index ee50622..584ed71 100644
--- a/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
+++ b/arch/arm/boot/dts/stm32mp15xx-dkx.dtsi
@@ -76,13 +76,22 @@
};
led {
- compatible = "gpio-leds";
+ compatible = "gpio-export";
led-blue {
label = "heartbeat";
gpios = <&gpiod 11 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "heartbeat";
default-state = "off";
+ status = "okay";
};
+
+ led-orange {
+ label = "myled_orange";
+ pinctrl-names = "default";
+ pinctrl-0 = <&my_leds_orange_pins>;
+ status = "okay";
+ };
+
};
sound {
@@ -548,6 +557,17 @@
};
};
+&pinctrl
+{
+ my_leds_orange_pins: my-leds-orange-0
+ {
+ pins
+ {
+ pinmux = <STM32_PINMUX('H', 7, RSVD)>;
+ };
+ };
+};
+
&pwr_regulators {
vdd-supply = <&vdd>;
vdd_3v3_usbfs-supply = <&vdd_usb>;
After the compilation of the new Linux image, I use "gpioinfo" and I get:
gpiochip3 - 16 lines:
...
line 11: unnamed unused output active-high
...
gpiochip7 - 16 lines:
...
line 7: unnamed unused output active-high
Then using the command:
gpioset gpiochip3 11=1
gpioset gpiochip7 7=1
Blue and orange leds switch on.
Best Regards,
Andrea