The STM STM32MP25 CPU has 3 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 MP25:

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

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

  • CAN3 port lines are available at LGA pads, multiplexed with other functionalities.

On the ConnectCore MP25 Development Kit:

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

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

  • Both CAN ports are connected to CAN transceivers and are accessible through 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 MP25 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 STM32MP25 CAN interface device tree binding is documented at Documentation/devicetree/bindings/net/can/bosch,m_can.yaml

Example: CAN2 on the ConnectCore MP25 Development Kit

Definition of the device

STM32MP25 device tree
soc@0 {
        m_can2: can@402e0000 {
                compatible = "bosch,m_can";
                reg = <0x402e0000 0x400>, <0x40310000 0x2800>;
                reg-names = "m_can", "message_ram";
                interrupts = <GIC_SPI 92 IRQ_TYPE_LEVEL_HIGH>,
                             <GIC_SPI 95 IRQ_TYPE_LEVEL_HIGH>;
                interrupt-names = "int0", "int1";
                clocks = <&rcc CK_BUS_FDCAN>, <&rcc CK_KER_FDCAN>;
                clock-names = "hclk", "cclk";
                bosch,mram-cfg = <0x1400 0 0 32 0 0 2 2>;
                feature-domains = <&rifsc STM32MP25_RIFSC_FDCAN_ID>;
                power-domains = <&CLUSTER_PD>;
                status = "disabled";
        };
};

IOMUX configuration

ConnectCore MP25 Development Kit device tree
ccmp25_m_can2_pins: ccmp25-m-can2-0 {
        pins1 {
                pinmux = <STM32_PINMUX('I', 9, AF4)>; /* FDCAN2_TX */
                slew-rate = <1>;
                drive-push-pull;
                bias-disable;
        };
        pins2 {
                pinmux = <STM32_PINMUX('I', 10, AF4)>; /* FDCAN2_RX */
                bias-disable;
        };
};

Bus enabling

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

  • CAN1 enabled

  • CAN2 enabled

CAN user space use 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 entries are found in the device tree.

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

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 MP25 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.