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

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 configre 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_FDCalculateImprovedTimingValues(&sFlexcanConfig.sTimingConfig,
    * &sFlexcanConfig.psFDConfig->sTimingConfig, sFlexcanConfig.u32BaudRateBps,
    * sFlexcanConfig.psFDConfig->u32BaudRateBps, sFlexcanConfig.u32ClkFreqHz);
    * sFlexcanConfig.psFDConfig = &sFDConfig;
    * // Module initialization
    * FLEXCAN_Init(CAN, &sFlexcanConfig);
    * // Set up send transfer configuration
    * flexcan_frame_t g_sFrame;
    * // Create FlexCAN handle structure and set call back function.
    * FLEXCAN_TransferCreateHandle(CAN, &g_sFlexcanHandle, flexcan_callback, NULL);
    * // Clean Tx Message Buffer.
    * 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_sTxXfer.u8MsgBufIdx = (uint8_t)TX_MESSAGE_BUFFER_NUM;
    * g_sTxXfer.psFrameFD = &g_sFrame;
    * // Send node interrupt transfer
    * 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_FDCalculateImprovedTimingValues(&sFlexcanConfig.sTimingConfig,
    * &sFlexcanConfig.psFDConfig->sTimingConfig, sFlexcanConfig.u32BaudRateBps,
    * sFlexcanConfig.psFDConfig->u32BaudRateBps, sFlexcanConfig.u32ClkFreqHz);
    * sFlexcanConfig.psFDConfig = &sFDConfig;
    * // Module initialization
    * FLEXCAN_Init(CAN, &sFlexcanConfig);
    * // Set up send transfer configuration
    * flexcan_frame_t g_sFrame;
    * // Create FlexCAN handle structure and set call back function.
    * FLEXCAN_TransferCreateHandle(CAN, &g_sFlexcanHandle, flexcan_callback, NULL);
    * // Set Rx Masking mechanism.
    * FLEXCAN_SetRxMbGlobalMask(CAN, FLEXCAN_RX_MB_STD_MASK(g_u32RxIdentifier, 0, 0));
    * // Setup Rx Message Buffer.
    * sRxMbConfig.eFormat = kFLEXCAN_FrameFormatStandard;
    * sRxMbConfig.eType = kFLEXCAN_FrameTypeData;
    * sRxMbConfig.u32Id = FLEXCAN_ID_STD(g_u32RxIdentifier);
    * // Clean Rx Message Buffer.
    * FLEXCAN_SetFDRxMbConfig(CAN, RX_MESSAGE_BUFFER_NUM, &sRxMbConfig, true);
    * g_sTxXfer.u8MsgBufIdx = (uint8_t)RX_MESSAGE_BUFFER_NUM;
    * g_sTxXfer.psFrameFD = &g_sFrame;
    * // Receive node interrupt transfer
    * FLEXCAN_TransferFDSendNonBlocking(&g_sFlexcanHandle, &g_sTxXfer);
    *