cancel
Showing results for 
Search instead for 
Did you mean: 

Enable SPI4 on Linux Side of STM32MP157C-DK2

DBuer
Associate II

I would like to access a SPI Device (Ethercat Shield) over the Arduino Headers (SPI4). What do i have to do to get the /dev/spidev... device file in Linux ?

Sorry, but i'm still confused what is enabled, what do i have to enable in DTS files and when i have to rebuild the kernel (that works :) )

Thanks Daniel

1 ACCEPTED SOLUTION

Accepted Solutions
AntonioST
ST Employee

You can use this DT fragment to enable spidev on spi4

&spi4 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&spi4_pins_a>;
	pinctrl-1 = <&spi4_sleep_pins_a>;
	status = "okay";
	cs-gpios = <&gpioe 11 0>;
 
	spidev@0{
		compatible = "spidev";
		reg = <0>;
		spi-max-frequency = <4000000>;
		#address-cells = <1>;
		#size-cells = <0>;
	};
};

View solution in original post

4 REPLIES 4
AntonioST
ST Employee

You can use this DT fragment to enable spidev on spi4

&spi4 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&spi4_pins_a>;
	pinctrl-1 = <&spi4_sleep_pins_a>;
	status = "okay";
	cs-gpios = <&gpioe 11 0>;
 
	spidev@0{
		compatible = "spidev";
		reg = <0>;
		spi-max-frequency = <4000000>;
		#address-cells = <1>;
		#size-cells = <0>;
	};
};

DBuer
Associate II

Thanks a lot

Hi Antonio,

 

I am currently reviewing one of the Linux kernel files (included in the latest Linux 6.1 source provided with OpenSTLinux SDK), called stm32mp1-op~stm32mp-r2-r0/linux-6.1.82/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi.

It seems that the definitions are outdated. There is definitely no "spi4_sleep_pins_a," so the example shown here several times causes the Linux kernel compilation error.

Since I confirmed that my board, through UBOOT, boots files dependent on stm32mp157c-dk2, I added a section with SPI4 at the end of stm32mp157c-dk2.dtb to run an example from the page "How to use SPI from Linux userland with spidev". Unfortunately, during kernel compilation, I get the following error:

 

arch/arm/boot/dts/stm32mp151.dtsi:1397.23-1410.6: ERROR (phandle_references): /soc/etzpc@5c007000/spi@44005000: Reference to non-existent node or label "spi4_sleep_pins_a"

 

 

I am not sure if the statement "On the STM32MP157X-DKX discovery board, MOSI and MISO signals are accessible via the D12 and D11 pins" is still valid with respect to the definitions contained in the DTSI file.

 

Could you provide corrections or guidance on how to run the SPI loopback example using the latest version of OpenSTLinux and the Linux kernel 6.1.88?

 

 

I noticed that there are different definitions of DTS depending on the version of the Linux kernel:

Linux 5.4:

https://raw.githubusercontent.com/STMicroelectronics/linux/refs/heads/v5.4-stm32mp/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi

 

	spi4_pins_a: spi4-0 {
		pins1 {
			pinmux = <STM32_PINMUX('E', 12, AF5)>, /* SPI4_SCK */
				 <STM32_PINMUX('E', 14, AF5)>; /* SPI4_MOSI */
			bias-disable;
			drive-push-pull;
			slew-rate = <1>;
		};

		pins2 {
			pinmux = <STM32_PINMUX('E', 13, AF5)>; /* SPI4_MISO */
			bias-disable;
		};
	};

	spi4_sleep_pins_a: spi4-sleep-0 {
		pins {
			pinmux = <STM32_PINMUX('E', 12, ANALOG)>, /* SPI4_SCK */
				 <STM32_PINMUX('E', 13, ANALOG)>, /* SPI4_MISO */
				 <STM32_PINMUX('E', 14, ANALOG)>; /* SPI4_MOSI */
		};
	};

 

Linux (5.10, 5.15) 6.1:

https://raw.githubusercontent.com/STMicroelectronics/linux/refs/heads/v6.1-stm32mp/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi

	spi4_pins_b: spi4-1 {
		pins1 {
			pinmux = <STM32_PINMUX('E', 12, AF5)>, /* SPI4_SCK */
				 <STM32_PINMUX('E', 14, AF5)>; /* SPI4_MOSI */
			bias-disable;
			drive-push-pull;
			slew-rate = <1>;
		};

		pins2 {
			pinmux = <STM32_PINMUX('E', 13, AF5)>; /* SPI4_MISO */
			bias-disable;
		};
	};

	spi4_sleep_pins_b: spi4-sleep-1 {
		pins {
			pinmux = <STM32_PINMUX('E', 12, ANALOG)>, /* SPI4_SCK */
				 <STM32_PINMUX('E', 13, ANALOG)>, /* SPI4_MISO */
				 <STM32_PINMUX('E', 14, ANALOG)>; /* SPI4_MOSI */
		};
	};

 

spi4_pins_a: spi4-0 -> spi4_pins_b: spi4-1 

(5.4)                         -> (5.10, 5.15, 6.10)