cancel
Showing results for 
Search instead for 
Did you mean: 

mpu-mcu spi communication

nesnes
Associate III

Hi, @Erwan SZYMANSKI @KDJEM.1 @Andrew Neil @KDJEM.1 @SofLit 

I am trying to establish SPI communication between my Nucleo-G431RB and STM32MP157F-DK2 boards. I am finding the documentation quite confusing. I attempted to use STM32CubeIDE, but it resulted in various issues, possibly due to using Ubuntu.

Could you help me set this up without using STM32CubeIDE or the HAL library? I have a distribution package for the STM32MP157F-DK2 and have patched the DTS file to enable SPI according to the STM32 wiki. Now, I need to add a custom application to my own created layer in the distribution package and write the driver. However, I am having trouble finding resources to accomplish this.

 

 

9 REPLIES 9
nesnes
Associate III

Here are my patches. I built the image and flashed it to the mp1 board.

diff --git a/stm32mp15-pinctrl.dtsi.orig b/stm32mp15-pinctrl.dtsi
index 20b4f0d..bff8e08 100644
--- a/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi
+++ b/arch/arm/boot/dts/stm32mp15-pinctrl.dtsi
@@ -2028,14 +2028,15 @@
 	spi5_pins_a: spi5-0 {
 		pins1 {
 			pinmux = <STM32_PINMUX('F', 7, AF5)>, /* SPI5_SCK */
-				 <STM32_PINMUX('F', 9, AF5)>; /* SPI5_MOSI */
+					<STM32_PINMUX('F', 9, AF5)>; /* SPI5_MOSI */
 			bias-disable;
 			drive-push-pull;
 			slew-rate = <1>;
 		};
 
 		pins2 {
-			pinmux = <STM32_PINMUX('F', 8, AF5)>; /* SPI5_MISO */
+			pinmux = <STM32_PINMUX('F', 8, AF5)>, /* SPI5_MISO */
+					<STM32_PINMUX('F', 6, AF5)>; /* SPI5_NSS */
 			bias-disable;
 		};
 	};
@@ -2043,11 +2044,13 @@
 	spi5_sleep_pins_a: spi5-sleep-0 {
 		pins {
 			pinmux = <STM32_PINMUX('F', 7, ANALOG)>, /* SPI5_SCK */
-				 <STM32_PINMUX('F', 8, ANALOG)>, /* SPI5_MISO */
-				 <STM32_PINMUX('F', 9, ANALOG)>; /* SPI5_MOSI */
+					<STM32_PINMUX('F', 8, ANALOG)>, /* SPI5_MISO */
+					<STM32_PINMUX('F', 9, ANALOG)>, /* SPI5_MOSI */
+					<STM32_PINMUX('F', 6, ANALOG)>; /* SPI5_NSS */
 		};
 	};
 
+
 	stusb1600_pins_a: stusb1600-0 {
 		pins {
 			pinmux = <STM32_PINMUX('I', 11, GPIO)>;

 

diff --git a/stm32mp157f-dk2.dts.orig b/stm32mp157f-dk2.dts.spi
index 2462656..6ba6038 100644
--- a/arch/arm/boot/dts/stm32mp157f-dk2.dts
+++ b/arch/arm/boot/dts/stm32mp157f-dk2.dts
@@ -167,3 +167,19 @@
 		vddio-supply = <&v3v3>;
 	};
 };
+
+&spi5 {
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&spi5_pins_a>;
+	pinctrl-1 = <&spi5_sleep_pins_a>;
+	status = "okay";
+
+	#address-cells = <0>;
+	cs-gpios = <0>;
+	spi-slave;
+
+	slave {
+		compatible = "lwn,bk4";
+		spi-max-frequency = <10000000>;
+	};
+ };

 

@Erwan SZYMANSKI  , I am waiting for your response and help.




Hello @nesnes ,
From my side, I am not expert on MCU part so I will not be able to help on Nucleo side.

However, for Linux side, does the STM32MP15 is the SPI master or SPI slave ? The DTS, more particularly the NSS pin, is not declared the same way depending on its role. Look at the paragraph mentioned here : https://wiki.stmicroelectronics.cn/stm32mpu/wiki/SPI_device_tree_configuration#Example_of_SPI_master-2Fslave_communication_on_STM32MP157F-DK2_board

Concerning the way to add your own application into Yocto and your own driver, this paragraph in the wiki points on both aspects : https://wiki.stmicroelectronics.cn/stm32mpu/wiki/STM32MPU_Distribution_Package#Integrating_developments_made_with_the_Developer_Package

Kind regards,
Erwan.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Help on STM32MP15  part would be great. I did the configurations as slave according to the wiki page. But I got stuck at the wring the driver code part because all the recourses I found uses the Cubeıde but I want to do my task with adding application to my image for the spi.

@nesnes ,
I think I did not catch exactly the point, do you have trouble to make your SPI application on Linux side, or to integrate it in your Yocto final image ? 

Kind regards,
Erwan.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

@Erwan SZYMANSKIBoth actually. First I am trying to write the application for spi without cubeide . Just like I did with I2C  but couldn't find resources(available codes) for that and since ım new ı don't now how to write the application myself. Secondly I want to add this application to my image with my own layer on distribution package. Adding the application on my local.conf and etc. configuration. I would be really thankful if u can help.

@Erwan SZYMANSKIHi waiting for your response , have a nice day.

Hello @nesnes ,
Sorry, we try to do our best to answer during this summer period, but we do not have a lot of bandwidth to do. My appologies.

Concerning your use case :

1) SPI slave Linux application

It depends if it does require a specific home made driver or not. If a generic SPI driver is enough for you, and you can use spidev.c driver, let's move to your application part. You need to understand how you interact between SPI user application and your application.
For that, you need to inform yourself about the generic method to interact between User Space and Kernel Space. Then, you can get inspired by an application such as spidev-test present in kernel sources under <kernel>/tools/spi/ folder. You will find the spidev-test.c file.

2) Concerning the deployment of your application into Yocto, I already pointed this link : https://wiki.stmicroelectronics.cn/stm32mpu/wiki/How_to_add_a_customer_application

It shows you an example with a fake hello world application, which is integrated into a Yocto image.

Kind regards,
Erwan.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hi thank you for your responce I will look at the things you write . Have a nice summer 🙂