What is CAN-FD?
With the advantages of real-time, anti-interference, and safety, CAN2.0 has been widely used in the industrial and automotive industries. However, its maximum rate is only 1 Mbit/s. , and each frame can only transmit 8 bytes of valid data at most. In addition, only about 50% of the bandwidth in the message is for valid data transmission. And with the industry development, the surge in the number of various sensors, controllers, and data amount on the bus makes the shortcomings of CAN2.0 bus in transmission rate and bandwidth expose more, and thus CAN-FD emerges.CAN-FD has a significant increase in transmission rate and bandwidth.-- the baud rate is up to 8 Mbit/s, the valid data per frame is up to 64 bytes, and the transmission efficiency can increase by approximately 80%, which can further improve the bus real-time performance and transmission efficiency, and broaden the data bandwidth of the bus.
On the Forlinx OKMX8MP-C EVK, there are 2-lane CAN-FD, controlled by M-core and A-core respectively, perform mutual communication. In this article, we will take this as an example to explain the high-speed communication of CAN-FD on a multi-core heterogeneous architecture (M-core plus A-core).
NXP i.MX8M Plus, equipped on Forlinx Embedded OKMX8MP-C EVK, achieves high performance and features implementation of 4x Arm Cortex-A53( multi-core), operating at speed up to 1.8GHz (Industrial clock is 1.6GHz) plus 1xCortex-M7(real-time processing), which enables it to handle high-speed data throughput and a complex human-machine interface with ease.
01 M-core CAN-FD
1. CAN-FD initializationIt includes: CAN bus clock, pin and register. Details are as follows:
(1) CAN bus clock:
Set the CAN bus frequency multiplier to 800MHz and frequency division to 80MHz.
(2) Pin configuration:
Select CAN1 transmit pin as 32 and receive pin as 34.
(3) CAN baud rate:
The CAN-FD supports variable rates, i.e. the baud rate of the control area and the data area can be inconsistent, the control area up to 1 Mbit/s and the data area up to 8 Mbit/s. The subsequent program assigns the values of seg1, seg2, etc. set by the time interval according to the bus clock and the set baud rate.
(4) CAN-FD enable:
In addition to enabling CAN-FD, we may also need to enable the variable baud rate, otherwise the maximum rate of the data area is the same as that of the control area, up to 1Mbit/s.
(5) Closing the Alb(Automatic Loop Back):
If the Alb is on, then the CAN1 data will loop back inside the chip and will not go to the external pins, which can eliminate the interference of the external terminals during program debugging, but in actual applications, it is necessary to turn off the Alb, and send and receive data from the external pins.
(6) Frame format:
This time, we use an 11-bit standard data frame and can also try an extended frame later. We need to set our ID for easy identification by other devices on the bus.
(7) Receiving filtering:
Users can set receiving filter rules so that only data with a specific frame ID is received, reducing the amount of data processed by the application.
CAN-FD receiving and sending process
In this test, M-core plays the master role:
- ①CAN1 first sends a frame containing 64 bytes data(received by A-core CAN2);
- ②CAN2 sends back this 64 bytes data(received by M-core CAN1);
- ③Check the receiving and sending 64 bytes data consistency.
(1) CAN-FD sending data:
(2) CAN-FD receiving data:
(3) Receiving and sending data comparison:
02 A-core CAN-FD
CAN2 is reserved in the A-core device tree, and the kernel parses the device tree to generate can0 under /dev. After setting the baud rate and enabling the can0 node, the open function in the application opens the interface, the write function sends data, and the read function receives data. We have used the CAN interface example as a comprehensive cross-platform demo program that can be called directly by the user with parameters.1. Assigning nodes
(1) CAN1 is dedicated to M-core and CAN2 is dedicated to A-core.Delete the CAN1 device node and keep the CAN2 device node in OK8MP-C.dts to modify the device tree then compile a new device tree.
(2) Copy the generated OK8MP-C.dtb and Image to the directory of EVK: /run/media/mmcblk2p1/, enter the sync command to synchronize and restart the EVK;
(3) Enter the command uname -r through the A-core serial port to display the kernel version, and change the folder name under the directory: /lib/modbule to the kernel version, so that the module can be automatically loaded to generate the can0 node, and restart the EVK.
2. Demo
Process name: can_demo
Using method: ./can_demo device name [parameter option]... ...
Test interface is can0 (corresponding to the EVK CAN2);
Baud rate of the control area is 1Mbit/s;
Data area is up to 8Mbit/s;
11-bit standard frame doesn’t filter frame ID, send data actively and perform loopback. So the command is:
03 Program verification
1. Hardware connectionShort circuit CAN1 and can-H of CAN2 with Jumper wire, also short circuit can-L. Be careful not to reverse the connection.
2. M-core program
Set M-core self-start by modifying the uboot environment variable, and place the M-core program(forlinx_m7_tcm_firmware.bin) under the directory: /run/media/mmcblk2p1.For more details, please refer to the previous article "NXP iMX8MP - Start, Programming and Simulation of M-core for Multi-core Heterogeneous Processor".
3. A-core program
(1) Copy can_demo from the computer to the default directory of the SoM using serial port Xmodem, network FTP, SCP, U disk, TF card, etc. Input the following command to modify the permissions;
(2) Input the following command, the A-core application can_demo will open the can0 node after setting the baud rate, wait for the data sent by the M-core, and then send the received data to the M-core via CAN2.
4. Actual test
(1) After re-powering up the OKMX8MP-C EVK, the M-core program starts, completes the CAN1 initialization and debugs the serial output information to wait for pressing the key;
(2) Input the following command in the A-core debugging serial port and CAN2 will be in the receiving state:
(3) First, press key A or a on the M-core serial port, then M-core CAN1 sends 64 bytes of data while A-core CAN2 receives the data and sends the received data again, and finally, M-core CAN1 receives and compares with the sent data and outputs the result, which cycles 100 times.
(4) The test shows that: owing to the i.MX8M Plus’ impressive performance, the cores can send massive data at a high rate up to 8Mbit/s without anomalies
For additional information, visit the IMX8MP Single Board Computer
Originally published at www.forlinx.net.