MCUXpresso SDK API Reference Manual  Rev 2.16.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
FlexCAN Peripheral and Driver Overview

Content including 1) peripheral features, work logic and work method; 2) driver design logic and use method; 3) typical use case. More...

Peripheral feature and how this peripheral works

The FlexCAN module is a full implementation of the CAN protocol specification, the CAN with Flexible Data rate (CAN FD) protocol, and the CAN 2.0 version B protocol, which supports both standard and extended message frames and long payloads up to 64 bytes, transferred at faster rates (up to 8 Mbps). The FlexCAN module can be divided into several submodules : The "Protocol Engine" (PE) submodule, The "Controller Host Interface" (CHI) submodule and The "Bus Interface Unit" (BIU) submodule.

Features

How this driver are designed to make this peripheral works

The FlexCAN driver provides APIs with Functional layer and Transactional layer. The Functional Layer is provided with highly optimized implementation and highly flexible usage of the peripheral features. The Transactional layer is provided with high abstraction, limited flexibility/optimization, and not all features are covered.

Functional Layer

Transactional Layer

Transactional layer is state retained thus it use the flexcan_handle_t to specify the peripheral. User need to initialize the handle by calling FLEXCAN_TransferCreateHandle API.

How to use this driver

General Control Macro

Configuration Items Before Calling FlexCAN Driver APIs

Initialize

CAN Timing calculation

Message buffer configure and transaction

Typical Use Case

  1. Send/receive CAN FD frame to/from CAN bus with interrupt mode.
    Send node

    * flexcan_handle_t g_sFlexcanHandle;
    * flexcan_config_t sFlexcanConfig;
    * flexcan_fd_config_t sFDConfig;
    * FLEXCAN_GetDefaultConfig(&sFlexcanConfig, EXAMPLE_CAN_CLK_FREQ);
    * FLEXCAN_GetFDDefaultConfig(&sFlexcanConfig, &sFDConfig);
    * FLEXCAN_Init(CAN, &sFlexcanConfig);
    * flexcan_frame_t g_sFrame;
    * FLEXCAN_TransferCreateHandle(CAN, &g_sFlexcanHandle, flexcan_callback, NULL);
    * FLEXCAN_SetFDTxMbConfig(CAN, TX_MESSAGE_BUFFER_NUM, true);
    * g_sFrame.bitsId = FLEXCAN_ID_STD(g_u32TxIdentifier);
    * g_sFrame.bitType = (uint8_t)kFLEXCAN_FrameTypeData;
    * g_sFrame.bitsLength = 15U;
    * g_sFrame.bitBrs = 1U;
    * g_sFrame.bitEdl = 1U;
    * g_sTxXfer.u8MsgBufIdx = (uint8_t)TX_MESSAGE_BUFFER_NUM;
    * g_sTxXfer.psFrameFD = &g_sFrame;
    * FLEXCAN_TransferFDSendNonBlocking(&g_sFlexcanHandle, &g_sTxXfer);
    *

    Receive node

    * flexcan_handle_t g_sFlexcanHandle;
    * flexcan_config_t sFlexcanConfig;
    * flexcan_fd_config_t sFDConfig;
    * FLEXCAN_GetDefaultConfig(&sFlexcanConfig, EXAMPLE_CAN_CLK_FREQ);
    * FLEXCAN_GetFDDefaultConfig(&sFlexcanConfig, &sFDConfig);
    * FLEXCAN_Init(CAN, &sFlexcanConfig);
    * flexcan_frame_t g_sFrame;
    * FLEXCAN_TransferCreateHandle(CAN, &g_sFlexcanHandle, flexcan_callback, NULL);
    * FLEXCAN_SetRxMbGlobalMask(CAN, FLEXCAN_RX_MB_STD_MASK(g_u32RxIdentifier, 0, 0));
    * sRxMbConfig.eFormat = kFLEXCAN_FrameFormatStandard;
    * sRxMbConfig.eType = kFLEXCAN_FrameTypeData;
    * sRxMbConfig.u32Id = FLEXCAN_ID_STD(g_u32RxIdentifier);
    * FLEXCAN_SetFDRxMbConfig(CAN, RX_MESSAGE_BUFFER_NUM, &sRxMbConfig, true);
    * g_sTxXfer.u8MsgBufIdx = (uint8_t)RX_MESSAGE_BUFFER_NUM;
    * g_sTxXfer.psFrameFD = &g_sFrame;
    * FLEXCAN_TransferFDSendNonBlocking(&g_sFlexcanHandle, &g_sTxXfer);
    *