The STM STM32MP13 CPU has two FDCAN controllers which operate at up to 1Mbps. The STM CAN is a communications controller implementing the CAN protocol according to the CAN 2.0B protocol specification. It supports standard and extended message frames. A 10 Kbyte message RAM implements filters, receive FIFOs, receive buffers, transmit event FIFOs, transmit buffers (and triggers for TTCAN). The driver is a network device driver of the PF_CAN protocol family.

On the ConnectCore MP13:

  • CAN1 port lines are available at castellated and LGA pads, multiplexed with other functionalities.

  • CAN2 port lines are available at castellated and LGA pads, multiplexed with other functionalities.

On the ConnectCore MP13 Development Kit:

  • CAN2 port lines are multiplexed with other functionalities of the chip.

  • CAN2 port is connected to CAN transceiver and is accessible through connectors.

  • You can add a termination resistor to the bus by closing a jumper near the CAN connectors.

Kernel configuration

You can manage the CAN support through the kernel configuration options:

  • CAN Bus support (CONFIG_CAN)

  • Bosch M_CAN support (CONFIG_CAN_M_CAN)

These options are enabled as built-in on the default ConnectCore MP13 kernel configuration file.

Kernel driver

File Description

drivers/net/can/m_can/m_can_platform.c

Bosch M_CAN driver

The CAN support is based on the SocketCAN stack. For more information and source code about this project, see http://elinux.org/CAN_Bus and https://github.com/linux-can/.

Device tree bindings and customization

The STM32MP13 CAN interface device tree binding is documented at Documentation/devicetree/bindings/net/can/bosch,m_can.yaml

Example: CAN2 on the ConnectCore MP13 Development Kit

Definition of the device

STM32MP13 device tree
soc {
	m_can2: can@4400f000 {
		compatible = "bosch,m_can";
		reg = <0x4400f000 0x400>, <0x44011000 0x2800>;
		reg-names = "m_can", "message_ram";
		interrupts = <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>,
			     <GIC_SPI 23 IRQ_TYPE_LEVEL_HIGH>;
		interrupt-names = "int0", "int1";
		clocks = <&scmi_clk CK_SCMI_HSE>, <&rcc FDCAN_K>;
		clock-names = "hclk", "cclk";
		bosch,mram-cfg = <0x1400 0 0 32 0 0 2 2>;
		status = "disabled";
	};
};

IOMUX configuration

ConnectCore MP13 Development Kit device tree
ccmp13_can2_pins_a: ccmp13-can2-0 {
	pins1 {
		pinmux = <STM32_PINMUX('B', 13, AF9)>; /* CAN2_TX */
		slew-rate = <1>;
		drive-push-pull;
		bias-disable;
	};
	pins2 {
		pinmux = <STM32_PINMUX('B', 5, AF9)>; /* CAN2_RX */
		bias-disable;
	};
	pins3 {
		pinmux = <STM32_PINMUX('C', 7, GPIO)>; /* FDCAN2_STB */
		bias-pull-down;
		drive-push-pull;
		slew-rate = <0>;
	};
};

ccmp13_can2_sleep_pins_a: ccmp13-can2-sleep-0 {
	pins {
		pinmux = <STM32_PINMUX('B', 13, ANALOG)>, /* CAN2_TX */
			 <STM32_PINMUX('B', 5, ANALOG)>, /* CAN2_RX */
			 <STM32_PINMUX('C', 7, ANALOG)>; /* FDCAN2_STB */
	};
};

Bus enabling

The default device tree configuration for ConnectCore MP13 Development Kit has:

  • CAN2 enabled

Enable CAN2 will create can0 device node.

CAN user space usage examples

CAN device interface

The CAN driver is a network device driver from the PF_CAN protocol family. It exposes device data through the sysfs at /sys/class/net/canX/, where X is the port index, starting at zero.

Linux creates port indexes sequentially as enabled CAN ports are found in the device tree.

The CAN network device driver interface provides a generic interface to set up, configure, and monitor CAN network devices. For example, you can configure the CAN device via the netlink interface using the program ip from the iproute2 utility suite.

Configuring the interface

Before you can start the CAN network device, you must configure the bitrate at which it will communicate. In the following example, X is the index of the CAN node you want to configure:

# ip link set canX up type can bitrate 125000
A termination resistor is typically required for baudrates higher than 125000 baud. You can add a termination resistor by closing a jumper near the CAN connector on the board.

Starting and stopping the CAN network device

Similar to other network interfaces, you can start or stop a CAN network device with the ifconfig command. In the following example, X is the index of the CAN node you want to bring up or down.

To start:

# ifconfig canX up

To stop:

# ifconfig canX down

For more information, see the Linux kernel documentation: Documentation/networking/can.rst.

Sample application

Example applications called apix-can-send-example and apix-can-recv-example are included in the dey-examples-digiapix recipe (part of dey-examples package) of the meta-digi layer. These applications show how to send and receive packets through the CAN ports using Digi APIx library on the ConnectCore MP13 platform.

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

First bring the interface down in case it’s already configured and up:

# ifconfig canX down

To send an 8-bit CAN message to node can0 with ID 0x12 at a baudrate of 500 Kbit/s:

# apix-can-send-example -i can0 -I 0x12 -b 500000

To receive a similar message:

# apix-can-recv-example -i can0 -b 500000

See CAN API for more information about the CAN APIx.