Our Latest News

Dual-Core High-Rate CAN-FD Review – Flynn Embedded

Dual-Core High-Rate CAN-FD Review – Flynn Embedded

In order to let more engineers understand the multi-core heterogeneous processors, Flynn Embedded has launched a special topic of “Play Multi-core Heterogeneous” to help you solve the problems encountered in the development process of multi-core heterogeneous processors. The topic of “Playing with Multi-core Heterogeneous” is continuously updated, welcome your continuous attention.

Introduction

With the advantages of real-time, anti-interference and security, CAN2.0 has been widely used in industrial and automotive industries, but its maximum rate is only 1 Mbit/s, and only 8 bytes of valid data can be transmitted at most per frame, and only about 50% of the bandwidth in the message is used for valid data transmission. However, with the development of industry, the number of various sensors and controllers increases and the amount of data on the bus also surges, which makes the shortcomings of CAN2.0 bus in terms of transmission rate and bandwidth exposed more obviously, and thus CAN-FD is born.

CAN-FD has a significant increase in transmission rate and bandwidth, with baud rates up to 8 Mbit/s and up to 64 bytes of valid data per frame, increasing transmission efficiency to approximately 80%.

CAN-FD has a significant increase in transmission rate and bandwidth, with baud rates up to 8 Mbit/s and up to 64 bytes of valid data per frame, increasing transmission efficiency to approximately 80%.

There are two CAN-FDs on the Flynn Embedded OKMX8MP-C development board. Today, based on this development board, I will take the M-core and A-core of the processor to control one CAN-FD to communicate with each other as an example, and tell how the M-core and A-core control the CAN-FD high-speed communication from the application point of view.

The NXP i.MX8M Plus processor on Fibridge’s embedded OKMX8MP-C development board is equipped with strong performance, integrating four Arm Cortex-A53 multitasking cores up to 1.8GHz (1.6GHz for industrial grade) and one Cortex-M7 real-time core, which can handle both high-speed data throughput and processing, as well as complex human-machine interface processing, it can handle them all with ease.

I. M-core CAN-FD

CAN-FD initialization

The CAN-FD initialization mainly includes the initialization of the bus clock, the pins and the corresponding registers. The details are as follows.

(1) CAN bus clock.

The CAN bus is now multiplied to 800MHz and then 10 divided to 80MHz.

CLOCK_SetRootMux(kCLOCK_RootFlexCan1, kCLOCK_FlexCanRootmuxSysPll1); // Set the CAN1 bus clock to 800MHz CLOCK_SetRootDivider(kCLOCK_RootFlexCan1, 2U, 5U); // The divider factor is 2*5=10, setting the CAN1 bus clock to 80MHz

(2) Pin configuration.

CAN-FD supports variable rate, i.e. the baud rate of control area and data area can not be the same, the maximum baud rate of control area is 1Mbit/s; the maximum baud rate of data area is 8Mbit/s. The subsequent program assigns the values of seg1, seg2, etc. set in the time slot according to the bus clock and the set baud rate.

pConfig->bitRate = 1000000U; // CAN-FD control area baud rate is 1Mbit/s pConfig->bitRateFD = 8000000U; // CAN-FD data area baud rate is 8Mbit/s

(4) CAN-FD enable.

In addition to enabling CAN-FD, the variable baud rate also needs to be enabled, otherwise the maximum rate of the data area is the same as the rate of the control area, up to 1 Mbit/s.

base->MCR |= CAN_MCR_FDEN_MASK; // CAN-FD enable fdctrl |= CAN_FDCTRL_FDRATE_MASK; // Variable baud rate enable

(5) Close the self-return loop

If the self-loopback is enabled, the CAN1 data will be looped back within the chip and will not go to the external pins, which can exclude the interference of the external terminals when debugging the program, but for the real application, the self-loopback needs to be turned off and the data will be sent and received from the external pins.

pConfig->enableLoopBack = false; // No loopback, use external pins

(6) Frame format.

This time we use 11-bit standard data frames, the little ones also try extended frames later on. You need to set your own ID for easy identification by other devices on the bus.

mbConfig.format = kFLEXCAN_FrameFormatStandard; // 11-bit standard frame, not extended mbConfig.type = kFLEXCAN_FrameTypeData; // data frame, not remote frame mbConfig.id = FLEXCAN_ID_STD (rxIdentifier); // Frame ID to distinguish between different devices in the bus

(7) Receiving filter.

The user can set receive filter rules so that only data with a specific frame ID is received, reducing the amount of data processed by the application.

rxIdentifier = 0; FLEXCAN_SetRxMbGlobalMask(EXAMPLE_CAN, FLEXCAN_RX_MB_STD_MASK(rxIdentifier, 0, 0));//receive all ID data

2.CAN-FD transceiver flow

In this test, M-core is the master, CAN1 sends a frame containing 64 bytes of data, CAN2 receives it, sends the 64 bytes again and CAN1 receives it. Compare the 64 bytes of data sent and received to see if they are the same. Repeat 100 times.

(1) CAN-FD transmits data.

EXAMPLE_CAN is represented as CAN1, flexcanHandle is the CAN instance containing the send receive callback function, and txXfer is the 64 bytes of data to be sent.

FLEXCAN_TransferFDSendNonBlocking(EXAMPLE_CAN, &flexcanHandle, &txXfer); // CAN-FD send data

(2) CAN-FD received data.

EXAMPLE_CAN is denoted as CAN1, flexcanHandle is the CAN instance containing the send receive callback function, and rxXfer is the 64 bytes of data received.

FLEXCAN_TransferFDReceiveNonBlocking(EXAMPLE_CAN, &flexcanHandle, &rxXfer); // CAN-FD receive function

(3) Comparison of received and sent data.

for (j = 0U; j <= DLC; j++) // compare sent and received data, inconsistent print { if(txXfer.framefd->dataWord[j] ! = rxXfer.framefd->dataWord[j]) { LOG_INFO(“Data mismatch !!!! j=%d \r\n”,j); } }

II. A-core CAN-FD

CAN2 is reserved in the A-core device tree, the kernel parses the device tree and generates can0 under /dev. After setting the baud rate and enabling the can0 node, the application opens the interface with the open function, the write function sends data and the read function receives data. We have used the CAN interface example as a cross-platform comprehensive demo program, which can be called directly by the partners with parameters.

  1. Assigning Nodes

(1) M-core exclusive CAN1, A-core exclusive CAN2, modify the device tree, and in the device tree OK8MP-C.dts, delete the CAN1 device node and keep the CAN2 device node. Compile the new device tree.

(2) Copy the generated OK8MP-C.dtb and Image to the /run/media/mmcblk2p1/ directory of the development board, enter the sync command to synchronize and restart the board.

(3) Enter the command uname -r through the A-core serial port to display the kernel version, and change the name of the folder in the /lib/modbule directory to the kernel version so that the module can be automatically loaded to generate the can0 node and restart the development board.

Process name can_demo

Usage: . /can_demo device name [parameter options]… …

Demo Demo

The test interface is can0 (corresponding to the development board CAN2), the baud rate of the control area is 1Mbit/s, the maximum data area is 8Mbit/s, 11-bit standard frame, no filter frame ID, no active data sending, no loopback. Therefore the command is.

. /can_demo can0-b 1000 -fd 8000.

III. Program Validation

Hardware connection

Use Dupont wire to short CAN1 and CAN2 can-H and short can-L at the same time, be careful not to reverse the connection.

M-core program

Modify the uboot environment variable to set the M-core to boot, and also put the M-core program forlinx_m7_tcm_firmware.bin.

into the /run/media/mmcblk2p1/ directory. For more details, please refer to the previous article [Playing with Multicore Heterogeneity] M-core program startup, writing and emulation – Flynn Embedded.

A-core procedure

(1) Copy can_demo from the computer to the default directory of the core board using serial Xmodem, network FTP, SCP, U disk, TF card, etc. and enter the following command to modify the permissions.

chmod 777 can_demo

(2) Enter 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.

. /can_demo can0 -b 1000 -fd 8000

Practical testing

(1) After re-powering the OKMX8MP-C development board, the M-core program will start, and after completing the initialization of CAN1, the information will be output in the M-core debug serial port and wait for the key.

(2) Enter the following command in the A-core debug serial port, CAN2 will be in the state of receiving.

. /can_demo can0 -b 1000 -fd 8000

(3) Press key A or a in M-core serial port, M-core CAN1 will send 64 bytes of data, A-core CAN2 will receive the data and send the received data again, M-core CAN1 will compare the received and sent data and output the result. Cycle 100 times.

(4) Through the test can be seen, relying on the powerful performance of i.MX8M Plus, dual-core are sending a large amount of data at a high rate of 8Mbit/s, all without abnormalities.

The above is based on the Feiling embedded OKMX8MP-C development board dual-core control CAN-FD for small partners to use the method, is not feeling very powerful performance?

    GET A FREE QUOTE

    FPGA IC & FULL BOM LIST

    We'd love to

    hear from you

    Highlight multiple sections with this eye-catching call to action style.

      Contact Us

      Exhibition Bay South Squre, Fuhai Bao’an Shenzhen China

      • Sales@ebics.com
      • +86.755.27389663