The STMicroelectronics STM32MP13 CPU has five I2C buses that operate at up to 400 Kbps. The CPU facilitates the functionality of both I2C master and slave according to the I2C Bus Specification rev03.

On the ConnectCore MP13:

  • I2C4 connects internally to the power management IC (PMIC).

    Interface Address (7-bit)

    PMIC

    0x33

  • I2C2, I2C3 are available for peripherals to use (multiplexed with other functionality).

On the ConnectCore MP13 Development Kit:

  • I2C2 is available on a connector, which you can use to connect additional devices.

    The following table lists the devices on board the ConnectCore MP13 Development Kit I2C2 bus:

    Interface Address (7-bit)

    Real-Time Clock RV3028

    0x52

  • The following table lists the devices on board the ConnectCore MP13 Development Kit I2C3 bus:

    Interface Address (7-bit)

    Audio codec

    0x10

Kernel configuration

You can manage the I2C driver support through the kernel configuration:

  • STM I2C interface (CONFIG_I2C_STM32F7)

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

Kernel driver

The driver for the I2C interface is located at:

File Description

drivers/i2c/busses/i2c-stm32f7.c

STM32 I2C controller driver

Device tree bindings and customization

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

The I2C interfaces are defined in the CPU, system-on-module, and carrier board device tree files.

Example: I2C2

Define the bus

STM32MP13 device tree
i2c2: i2c@40013000 {
	compatible = "st,stm32mp13-i2c";
	reg = <0x40013000 0x400>;
	interrupt-names = "event", "error";
	interrupts-extended = <&exti 22 IRQ_TYPE_LEVEL_HIGH>,
			      <&intc GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>;
	clocks = <&rcc I2C2_K>;
	resets = <&rcc I2C2_R>;
	#address-cells = <1>;
	#size-cells = <0>;
	dmas = <&dmamux1 35 0x400 0x80000001>,
	       <&dmamux1 36 0x400 0x80000001>;
	dma-names = "rx", "tx";
	power-domains = <&pd_core_ret>;
	st,syscfg-fmp = <&syscfg 0x4 0x2>;
	wakeup-source;
	i2c-analog-filter;
	status = "disabled";
};

Configure PINCTRL

ConnectCore MP13 device tree
i2c2_pins_a: i2c2-0 {
	pins {
		pinmux = <STM32_PINMUX('H', 4, AF4)>, /* I2C2_SCL */
			 <STM32_PINMUX('H', 5, AF4)>; /* I2C2_SDA */
		bias-disable;
		drive-open-drain;
		slew-rate = <0>;
	};
};

Define attached I2C client devices

ConnectCore MP13 Development Kit device tree
&i2c2 {

	[...]

	goodix_touch@14 {
		compatible = "goodix,gt9271";
		reg = <0x14>;
		interrupt-parent = <&gpiog>;
		interrupts = <1 IRQ_TYPE_EDGE_RISING>;
		irq-gpios = <&gpiog 1 GPIO_ACTIVE_LOW>;
	};

	[...]

Use the I2C bus

The I2C bus driver exposes device data through the sysfs at /sys/class/i2c-dev/.

The correct way to access an I2C device is through a kernel driver. Accessing the I2C bus from the file system can confuse your I2C bus and cause data loss on devices like EEPROMs. The following tools are recommended for debugging purposes only.

I2C device interface

You can access I2C devices on an adapter from user space, through the /dev interface. This support requires that you enable the kernel configuration option I2C device interface (CONFIG_I2C_CHARDEV).

Once you have enabled the option, you can use the /dev/i2c-N device node where N corresponds to the adapter number, starting at zero.

i2c-tools

You can install the i2c-tools package to access the I2C devices from user space. The package contains the following tools:

Tool Description

i2cdetect

Bus scanning

i2cdump

Device register dumping

i2cget

Device register reading

i2cset

Device register setting

All I2C tools operate on a specific I2C bus which is identified by number.

To obtain a formatted list of all I2C adapters on your system, run:

# i2cdetect -l
i2c-1   i2c             STM32F7 I2C(0x4c004000)                 I2C adapter
i2c-0   i2c             STM32F7 I2C(0x40013000)                 I2C adapter

Query the I2C bus using the I2C bus number to find devices connected to that bus:

# i2cdetect 1
i2cdetect: WARNING! This program can confuse your I2C bus
Continue? [y/N] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

The example above shows a device on the bus at addresses 0x10. The ones showing UU denote this address is currently in use by a driver, while devices without a registered driver show the address.

Access the I2C bus using Digi APIx

An example application called apix-i2c-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 I2C API for more information about the I2C APIx.