The STM STM32MP15 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 MP15:
-
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 MP15 Development Kit:
-
CAN1 port lines are multiplexed with USART3 RXD/CTS.
-
CAN2 port lines are multiplexed with DCMI_D6/DCMI_D7.
-
Both CAN ports are connected to CAN transceivers and are 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 MP15 kernel configuration file.
Kernel driver
File | Description |
---|---|
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 STM32MP15 CAN interface device tree binding is documented at Documentation/devicetree/bindings/net/can/bosch,m_can.yaml
Example: CAN1 on the ConnectCore MP15 Development Kit
Definition of the device
soc {
m_can1: can@4400e000 {
compatible = "bosch,m_can";
reg = <0x4400e000 0x400>, <0x44011000 0x1400>;
reg-names = "m_can", "message_ram";
interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "int0", "int1";
clocks = <&scmi_clk CK_SCMI_HSE>, <&rcc FDCAN_K>;
clock-names = "hclk", "cclk";
bosch,mram-cfg = <0x0 0 0 32 0 0 2 2>;
status = "disabled";
};
};
IOMUX configuration
ccmp15_can1_pins_a: can1-0 {
pins1 {
pinmux = <STM32_PINMUX('B', 9, AF9)>; /* CAN1_TX */
slew-rate = <1>;
drive-push-pull;
bias-disable;
};
pins2 {
pinmux = <STM32_PINMUX('B', 8, AF9)>; /* CAN1_RX */
bias-disable;
};
pins3 {
pinmux = <STM32_PINMUX('C', 7, GPIO)>; /* FDCAN1_STB */
bias-pull-down;
drive-push-pull;
slew-rate = <0>;
};
};
ccmp15_can1_sleep_pins_a: can1-sleep-0 {
pins {
pinmux = <STM32_PINMUX('B', 9, ANALOG)>, /* CAN1_TX */
<STM32_PINMUX('B', 8, ANALOG)>; /* CAN1_RX */
<STM32_PINMUX('C', 7, ANALOG)>; /* FDCAN1_STB */
};
};
Bus enabling
The default device tree configuration for ConnectCore MP15 Development Kit has:
-
CAN1 disabled
-
CAN2 disabled
Enable CAN1 using the CAN overlay _ov_board_can1_ccmp15-dvk.dts
which creates 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 MP15 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.