The STM STM32MP13 CPU has six SPI buses.

On the ConnectCore MP13 system-on-module:

  • All six SPI ports are available (multiplexed with other functionality)

On the ConnectCore MP13 Development Kit:

  • SPI4 port is available at SPI connector

Kernel configuration

You can manage the SPI driver support through the kernel configuration option:

  • STMicroelectronics STM32 SPI controllers interface (CONFIG_SPI_STM32)

This option is enabled as built-in on the default ConnectCore MP13 kernel configuration file.

Kernel driver

The driver for the SPI interface is located at:

File Description

drivers/spi/spi-stm32.c

SPI driver

Device tree bindings and customization

The STM32MP13 SPI interface device tree binding is documented at Documentation/devicetree/bindings/spi/st,stm32-spi.yaml.

The common STM32MP13 CPU device tree defines all the SPI ports. The platform device tree must:

  • Enable the required SPI port by setting the status property to "okay".

  • Choose the GPIOs that will work as chip select lines using property cs-gpios.

  • Configure the pinctrl of the pads that will work as SPI port plus the GPIOs to be used as chip select lines.

  • Add the SPI slave devices as children of the SPI bus node.

Example: SPI4 port (as master) on the ConnectCore MP13 Development Kit

ConnectCore MP13 Development Kit device tree
&spi4 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&ccmp13_spi4_pins_b>;
	pinctrl-1 = <&ccmp13_spi4_sleep_pins_b>;
	cs-gpios = <&gpiod 10 0>;
	status = "okay";

	spidev@0{
		compatible = "rohm,dh2228fv";
		/*
		 * spidev uses a compatible string 'rohm,fs2228fv' to have the
		 * driver create an spi device node. This is just an example,
		 * there is not a real device connected on the SPI bus.
		 */
		reg = <0>;
		spi-max-frequency = <4000000>;
	};
};

SPI user space usage

The SPI bus cannot be accessed directly from user space. Instead, it is accessed via the SPI client drivers. However, a special sample client driver allows raw access to the SPI bus.

SPI device interface

The Linux kernel offers a sample client driver called spidev that gives you read and write data access to the SPI bus through the /dev interface. You can find this driver under the kernel configuration option User mode SPI device driver support (CONFIG_SPI_SPIDEV). On Digi Embedded Yocto this driver is enabled as a loadable module. The default device tree includes the spidev node in the device tree as an SPI device hanging from the SPI bus:

ConnectCore MP13 Development Kit device tree
&spi4 {
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&ccmp13_spi4_pins_b>;
	pinctrl-1 = <&ccmp13_spi4_sleep_pins_b>;
	cs-gpios = <&gpiod 10 0>;
	status = "okay";

	spidev@0{
		compatible = "rohm,dh2228fv";
		reg = <0>;
		spi-max-frequency = <4000000>;
	};
};
Spidev is not a real hardware SPI slave device but a detail of how Linux controls a device.

Linux will create a device node in the form /dev/spidevX.Y device node where:

  • X corresponds to the SPI port index, starting from 0.

  • Y corresponds to the SPI bus chip select, starting from 0.

Sample application

An example application called apix-spi-example is included in the dey-examples-digiapix recipe (part of dey-examples package) of the meta-digi layer. This application is an example of how to write data to an external EEPROM (24FC1026) and read it back using Digi APIx library on the ConnectCore MP13 platform.

Go to GitHub to see the application instructions and source code.

See SPI API for more information about the SPI APIx.