FDCAN CheatSheet
FDCAN CheatSheet
This chapter will explain FDCAN Basic knowledge and corresponding HAL library API.CAN FD Medium FD
Meaning is flexible data, Flexible data communication , And the baud rate can be different from the baud rate
in the arbitration stage
Catalog
91.1 Important tips for beginners
91.2 FDCAN Basic knowledge of
91.2.1 CAN FD Protocol is introduced
91.2.2 CAN FD characteristic
91.2.3 CAN FD Format
91.2.4 CAN FD comparison CAN2.0 The promotion of
91.3 FDCAN Bus HAL Library usage
91.3.1 FDCAN Bus architecture FDCAN_GlobalTypeDef
91.3.2 FDCAN Bus time trigger structure TTCAN_TypeDef
91.3.3 FDCAN Bus initialization structure FDCAN_InitTypeDef
FDCAN The basics are in the... Of this tutorial 90 Chapter gives a very detailed description . Here we will explain
several knowledge points used in this chapter , For details, please refer to section 90 Chapter .
STM32H7 Of CAN FD accord with ISO 11898-12015 standard .STM32 On the device FDCAN The functions of are
as follows :
(1) accord with CAN agreement 2.0 edition A,B and ISO 11898-1:2015,-4.
(3)CAN The kernel implements protocol control and transmit / receive shift register .
(4)Tx handler Control messages from CAN news RAM To CAN kernel .
(1) Compatible with classic CAN, Can follow ISO 11898-1 Send and receive data .
(10) Distinguish between temporary and permanent failures of nodes and automatically close defective
nodes .
The first arbitration stage (The first arbitration phase) It's a message , It includes :
(2)ID Number and other places , Indicates the purpose of the message ( Provide or request data ), And
speed and format configuration (CAN or CAN-FD).
(1) Data length code (DLC), Indicates how many data bytes the message contains .
(1) Acknowledgement sent by other nodes on the bus (ACK) 's receiver ( If at least one receiver
successfully receives the message )
(2) Frame tail (EOF), stay IFS No messages are transmitted during this period : The goal is to separate the
current frame from the next .
Be careful : about 29bit Identifier frame , When adding 18bit Mark to the second 1 It's an arbitration stage IDE
bit And then with the standard CAN FD It's similar .
CAN-FD It can meet the need of communication network with higher bandwidth . Each frame has at most 64
Bytes of CAN-FD And to maximize the bit rate , Make the data phase faster 8 times , In the second arbitration
stage, it is necessary to return to the normal bit rate . Ensure the integrity of data transmission by :
(1)17 The polynomial of order 1 is the largest 16 The payload of bytes carries CRC.
After the identifier ,CAN 2.0 and CAN-FD It has different functions :
(1)CAN 2.0 send out RTR Bit to accurately determine the frame type : Data frame (RTR Mainly ) Or
remote frame (RTR) It's implicit ).
(2) because CAN-FD Only data frames are supported , So always send the dominant RRS( Retain ).
IDE Bits remain in the same position , And use the same action to distinguish the basic format (11 Bit identifier
). Please note that , In the case of extended formats ,IDE Bits are transmitted either explicitly or implicitly (29
Bit identifier ).
And CAN 2.0 comparison , stay CAN-FD In the frame , Three new bits are added to the control field :
(1) Extended data length (EDL) position : The hidden frame is CAN-FD, Otherwise, it is dominant ( be
called R0) stay CAN 2.0 In the frame .
(2) Bit rate switching (BRS): Indicates whether two bit rates are enabled ( for example , When the data
phase bits are transmitted to the arbitration phase at different bit rates ).
(3) Error status indicator (ESI): Indicates whether the node is in error active mode or error passive mode .
The last part of the control field is the data length code (DLC), It has the same position and the same length
(4 position ), be used for CAN 2.0 and CAN-FD. DLC Function in CAN-FD and CAN 2.0 In the same way , but
CAN-FD There is a small change ( The details in the table below ). CAN-FD Extended frames allow sending in
a single message 64 Data bytes , and CAN 2.0 Payload data can be sent up to 8 Bytes .
Improve network bandwidth by adding data fields of payload data , Because it requires less packet processing .
meanwhile , By providing CRC Add more bits to enhance message integrity :
(1) If the payload data is at most 16 Bytes , be CRC With 17 Bit code .
(2) If the payload data is greater than 20(16) Bytes , be CRC With 21 Bit code .
in addition , To make sure CAN-FD The robustness of the frame , The padding mechanism supports CRC Field .
The following table summarizes CAN-FD and CAN 2.0 The main difference between . The main functions
provided are as follows CAN 2.0 comparison ,CAN FD The improvement of is that the increase of data payload
and speed is caused by CAN-FD Available in BRS,EDL and ESI To make sure that .
91.3 FDCAN Bus HAL Library usage
91.3.1 FDCAN Bus architecture FDCAN_GlobalTypeDef
FD CAN The bus related registers are passed through HAL The structure in the library FDCAN_GlobalTypeDef
Definition , stay stm32h743xx.h This type definition can be found in :
typedef struct
{
__IO uint32_t CREL;
__IO uint32_t ENDN;
__IO uint32_t RESERVED1;
__IO uint32_t DBTP;
__IO uint32_t TEST;
__IO uint32_t RWD;
__IO uint32_t CCCR;
__IO uint32_t NBTP;
__IO uint32_t TSCC;
__IO uint32_t TSCV;
__IO uint32_t TOCC;
__IO uint32_t TOCV;
__IO uint32_t RESERVED2[4];
__IO uint32_t ECR;
__IO uint32_t PSR;
__IO uint32_t TDCR;
__IO uint32_t RESERVED3;
__IO uint32_t IR;
__IO uint32_t IE;
__IO uint32_t ILS;
__IO uint32_t ILE;
__IO uint32_t RESERVED4[8];
__IO uint32_t GFC;
__IO uint32_t SIDFC;
__IO uint32_t XIDFC;
__IO uint32_t RESERVED5;
__IO uint32_t XIDAM;
__IO uint32_t HPMS;
__IO uint32_t NDAT1;
__IO uint32_t NDAT2;
__IO uint32_t RXF0C;
__IO uint32_t RXF0S;
__IO uint32_t RXF0A;
__IO uint32_t RXBC;
__IO uint32_t RXF1C;
__IO uint32_t RXF1S;
__IO uint32_t RXF1A;
__IO uint32_t RXESC;
__IO uint32_t TXBC;
__IO uint32_t TXFQS;
__IO uint32_t TXESC;
__IO uint32_t TXBRP;
__IO uint32_t TXBAR;
__IO uint32_t TXBCR;
__IO uint32_t TXBTO;
__IO uint32_t TXBCF;
__IO uint32_t TXBTIE;
__IO uint32_t TXBCIE;
__IO uint32_t RESERVED6[2];
__IO uint32_t TXEFC;
__IO uint32_t TXEFS;
__IO uint32_t TXEFA;
__IO uint32_t RESERVED7;
} FDCAN_GlobalTypeDef;
The name and order of the members of this structure and CPU The register of is one A corresponding .
__IO Express volatile, This is the standard C A modifier in language , Indicates that the variable is nonvolatile ,
The compiler should not optimize it .core_m7.h The file defines the macro :
FDCAN The registers related to bus time trigger are through HAL The structure in the library TTCAN_TypeDef
Definition , stay stm32h743xx.h This type definition can be found in :
typedef struct
{
__IO uint32_t TTTMC; /*!< TT Trigger Memory Configuration register, Address
offset: 0x100 */
__IO uint32_t TTRMC; /*!< TT Reference Message Configuration register, Address
offset: 0x104 */
__IO uint32_t TTOCF; /*!< TT Operation Configuration register, Address
offset: 0x108 */
__IO uint32_t TTMLM; /*!< TT Matrix Limits register, Address
offset: 0x10C */
__IO uint32_t TURCF; /*!< TUR Configuration register, Address
offset: 0x110 */
__IO uint32_t TTOCN; /*!< TT Operation Control register, Address
offset: 0x114 */
__IO uint32_t TTGTP; /*!< TT Global Time Preset register, Address
offset: 0x118 */
__IO uint32_t TTTMK; /*!< TT Time Mark register, Address
offset: 0x11C */
__IO uint32_t TTIR; /*!< TT Interrupt register, Address
offset: 0x120 */
__IO uint32_t TTIE; /*!< TT Interrupt Enable register, Address
offset: 0x124 */
__IO uint32_t TTILS; /*!< TT Interrupt Line Select register, Address
offset: 0x128 */
__IO uint32_t TTOST; /*!< TT Operation Status register, Address
offset: 0x12C */
__IO uint32_t TURNA; /*!< TT TUR Numerator Actual register, Address
offset: 0x130 */
__IO uint32_t TTLGT; /*!< TT Local and Global Time register, Address
offset: 0x134 */
__IO uint32_t TTCTC; /*!< TT Cycle Time and Count register, Address
offset: 0x138 */
__IO uint32_t TTCPT; /*!< TT Capture Time register, Address
offset: 0x13C */
__IO uint32_t TTCSM; /*!< TT Cycle Sync Mark register, Address
offset: 0x140 */
__IO uint32_t RESERVED1[111]; /*!< Reserved, 0x144
- 0x2FC */
__IO uint32_t TTTS; /*!< TT Trigger Select register, Address
offset: 0x300 */
} TTCAN_TypeDef;
91.3.3 FDCAN Bus initialization structure FDCAN_InitTypeDef
typedef struct
{
uint32_t FrameFormat; /*!< Specifies the FDCAN frame format.
This parameter can be a value of @ref
FDCAN_frame_format */
uint32_t NominalSyncJumpWidth; /*!< Specifies the maximum number of time quanta the
FDCAN
hardware is allowed to lengthen or
shorten a bit to perform
resynchronization.
This parameter must be a number between 1
and 128 */
uint32_t NominalTimeSeg1; /*!< Specifies the number of time quanta in Bit Segment
1.
This parameter must be a number between 2
and 256 */
uint32_t NominalTimeSeg2; /*!< Specifies the number of time quanta in Bit Segment
2.
This parameter must be a number between 2
and 128 */
uint32_t DataSyncJumpWidth; /*!< Specifies the maximum number of time quanta the
FDCAN
hardware is allowed to lengthen or
shorten a data bit to
perform resynchronization.
This parameter must be a number between 1
and 16 */
uint32_t DataTimeSeg1; /*!< Specifies the number of time quanta in Data Bit
Segment 1.
This parameter must be a number between 1
and 32 */
uint32_t DataTimeSeg2; /*!< Specifies the number of time quanta in Data Bit
Segment 2.
This parameter must be a number between 1
and 16 */
} FDCAN_InitTypeDef;
• FrameFormat
• Mode
• AutoRetransmission
• TransmitPause
Enable or disable the transmission pause feature .ENABLE Enable or DISABLE prohibit .
• ProtocolException
• NominalPrescaler
be used for CAN FD Frequency division setting in arbitration stage , The amount of time that the nominal bit is
generated , Parameter range 1-512.
• NominalSyncJumpWidth
Set up FD CAN The maximum amount of time supported in the arbitration phase can be lengthened or
shortened by one bit To achieve resynchronization , Parameter range 1-128.
• NominalTimeSeg1
Set the arbitration phase Bit Segment 1 Time amount of , Range 2 – 256.
• NominalTimeSeg2
Set the arbitration phase Bit Segment 2 Time amount of , Range 2 – 128.
• DataPrescaler
be used for CAN FD Data stage frequency division setting , Range 1-32.
• DataSyncJumpWidth
Set up FD CAN The maximum amount of time supported in the data phase can be lengthened or shortened by
one bit To achieve data resynchronization , Parameter range 1-16.
• DataTimeSeg1
Set the data stage Data Bit Segment 1 Time amount of , Range 1 – 32.
• DataTimeSeg2
Set the data stage Data Bit Segment 2 Time amount of , Range 1 – 16.
• MessageRAMOffset
• StdFiltersNbr
• ExtFiltersNbr
• RxFifo0ElmtsNbr
• RxFifo0ElmtSize
RX FIFO0 The size of the data in each element , The supported parameters are as follows :
• RxFifo1ElmtsNbr
RX FIFO1 Number , Range 0 To 64.
• RxFifo1ElmtSize
RX FIFO1 The size of the data in each element , The supported parameters are as follows :
• RxBuffersNbr
• RxBuffersSize
Set up Rx Buffer The size of each data in the element , Range 0 - 64:
• TxEventsNbr
• TxBuffersNbr
• TxFifoQueueElmtsNbr
• TxFifoQueueMode
• TxElmtSize
Set up Tx Element Data field size in . The supported parameters are as follows :
typedef struct
{
uint32_t StandardFilterSA; /*!< Specifies the Standard Filter List Start Address.
This parameter must be a 32-bit word address */
uint32_t ExtendedFilterSA; /*!< Specifies the Extended Filter List Start Address.
This parameter must be a 32-bit word address */
uint32_t EndAddress; /*!< Specifies the End Address of the allocated RAM.
This parameter must be a 32-bit word address */
} FDCAN_MsgRamAddressTypeDef;
Set the starting address of the standard filter , Must be 32bit Address .
• ExtendedFilterSA
Set the start address of the extension filter , Must be 32bit Address .
• RxFIFO0SA
• RxFIFO1SA
• RxBufferSA
• TxEventFIFOSA
• TTMemorySA
• EndAddress
Set up application RAM The end address of the space , Must be 32bit Address .
typedef struct
{
uint32_t IdType; /*!< Specifies the identifier type.
This parameter can be a value of @ref FDCAN_id_type
*/
uint32_t RxBufferIndex; /*!< Contains the index of the Rx buffer in which the
matching message will be stored.
This parameter must be a number between 0 and 63.
This parameter is ignored if FilterConfig is different
from FDCAN_FILTER_TO_RXBUFFER
*/
} FDCAN_FilterTypeDef;
• IdType
• FilterIndex
Used to filter indexes , If it is the standard ID, Range 0 To 127. If it's an extension ID, Range 0 To 64.
• FilterType
Used to set the filter type . If members FilterConfig Set to FDCAN_FILTER_TO_RXBUFFER, This parameter will not
work .
/*!< only ID Extended mode supports this parameter , Range from FilterID1 To FilterID2, EIDM
mask not applied */
#define FDCAN_FILTER_RANGE_NO_EIDM ((uint32_t)0x00000003U)
• FilterConfig
• FilterID1
Used to set filtering ID1. If ID The type is FDCAN_STANDARD_ID, Range 0 To 0x7FF. If ID The type is
FDCAN_EXTENDED_ID, The scope is 0 To 0x1FFFFFFF.
• FilterID2
Used to set filtering ID2. If FilterConfig Set to FDCAN_FILTER_TO_RXBUFFER, This parameter has no effect . If ID
The type is FDCAN_STANDARD_ID, Range 0 To 0x7FF. If ID The type is FDCAN_EXTENDED_ID, The scope is 0 To
0x1FFFFFFF.
• RxBufferIndex
The matching message is stored in Rx buffer Index in . Parameter range 0 To 63. If FilterConfig Set to
FDCAN_FILTER_TO_RXBUFFER, This parameter has no effect .
• IsCalibrationMsg
typedef struct
{
uint32_t Identifier; /*!< Specifies the identifier.
This parameter must be a number between:
- 0 and 0x7FF, if IdType is FDCAN_STANDARD_ID
- 0 and 0x1FFFFFFF, if IdType is FDCAN_EXTENDED_ID
*/
uint32_t IdType; /*!< Specifies the identifier type for the message that will be
transmitted.
This parameter can be a value of @ref FDCAN_id_type
*/
uint32_t TxFrameType; /*!< Specifies the frame type of the message that will be
transmitted.
This parameter can be a value of @ref
FDCAN_frame_type */
uint32_t DataLength; /*!< Specifies the length of the frame that will be transmitted.
This parameter can be a value of @ref
FDCAN_data_length_code */
uint32_t BitRateSwitch; /*!< Specifies whether the Tx frame will be transmitted with or
without
bit rate switching.
This parameter can be a value of @ref
FDCAN_bit_rate_switching */
uint32_t FDFormat; /*!< Specifies whether the Tx frame will be transmitted in
classic or
FD format.
This parameter can be a value of @ref FDCAN_format
*/
uint32_t MessageMarker; /*!< Specifies the message marker to be copied into Tx Event
FIFO
element for identification of Tx message status.
This parameter must be a number between 0 and 0xFF
*/
} FDCAN_TxHeaderTypeDef;
• Identifier
Used for setting up ID, If IdType It's a standard. FDCAN_STANDARD_ID, Range 0 To 0x7FF, If IdType yes
FDCAN_EXTENDED_ID Expand ID, Range 0 To 0x1FFFFFFF.
• IdType
• TxFrameType
Used to set the frame type , Data frame or remote control frame .
• DataLength
• ErrorStateIndicator
• BitRateSwitch
#define FDCAN_BRS_OFF ((uint32_t)0x00000000U) /*!< FDCAN Frame sending / Receive without variable
baud rate */
#define FDCAN_BRS_ON ((uint32_t)0x00100000U) /*!< FDCAN Frame sending / The baud rate of the
receiving band is variable */
• FDFormat
Used to set whether the transmission frame is in classic format or CANFD Format .
#define FDCAN_CLASSIC_CAN ((uint32_t)0x00000000U) /*!< Frame sending / Receive and use classic
CAN */
#define FDCAN_FD_CAN ((uint32_t)0x00200000U) /*!< Frame sending / Receive use FDCAN Format
*/
• TxEventFifoControl
• MessageMarker
Used to copy settings to TX EVENT FIFO The news of Maker, To identify the message status , Range 0 To 0xFF.
typedef struct
{
uint32_t Identifier; /*!< Specifies the identifier.
This parameter must be a number between:
- 0 and 0x7FF, if IdType is FDCAN_STANDARD_ID
- 0 and 0x1FFFFFFF, if IdType is
FDCAN_EXTENDED_ID */
uint32_t IdType; /*!< Specifies the identifier type of the received message.
This parameter can be a value of @ref
FDCAN_id_type */
uint32_t RxFrameType; /*!< Specifies the the received message frame type.
This parameter can be a value of @ref
FDCAN_frame_type */
uint32_t RxTimestamp; /*!< Specifies the timestamp counter value captured on start
of frame
reception.
This parameter must be a number between 0 and
0xFFFF */
uint32_t IsFilterMatchingFrame; /*!< Specifies whether the accepted frame did not match any Rx
filter.
Acceptance of non-matching frames may be
enabled via
HAL_FDCAN_ConfigGlobalFilter().
This parameter can be 0 or 1
*/
} FDCAN_RxHeaderTypeDef;
• Identifier
Used for setting up ID, If IdType It's a standard. FDCAN_STANDARD_ID, Range 0 To 0x7FF, If IdType yes
FDCAN_EXTENDED_ID Expand ID, Range 0 To 0x1FFFFFFF.
• IdType
• RxFrameType
Used to set the received frame type , Data frame or remote control frame
• DataLength
• ErrorStateIndicator
• BitRateSwitch
• FDFormat
Used to set whether the received frame is in classic format or CANFD Format
• RxTimestamp
• FilterIndex
Used to set the receive filter index . If it is the standard ID, Range 0 To 127, If it's an extension ID, Range 0 To
63.
• IsFilterMatchingFrame
Used to set whether to receive non matching frames , By function HAL_FDCAN_ConfigGlobalFilter() You can
make .
1: To receive .
#if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
typedef struct __FDCAN_HandleTypeDef
#else
typedef struct
#endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
{
FDCAN_GlobalTypeDef *Instance; /*!< Register base address */
#if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
void (* ClockCalibrationCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t
ClkCalibrationITs); /*!< FDCAN Clock Calibration callback */
void (* TxEventFifoCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t TxEventFifoITs);
/*!< FDCAN Tx Event Fifo callback */
void (* RxFifo0Callback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs);
/*!< FDCAN Rx Fifo 0 callback */
void (* RxFifo1Callback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo1ITs);
/*!< FDCAN Rx Fifo 1 callback */
void (* TxFifoEmptyCallback)(struct __FDCAN_HandleTypeDef *hfdcan);
/*!< FDCAN Tx Fifo Empty callback */
void (* TxBufferCompleteCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t
BufferIndexes); /*!< FDCAN Tx Buffer complete callback */
void (* TxBufferAbortCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes);
/*!< FDCAN Tx Buffer abort callback */
void (* RxBufferNewMessageCallback)(struct __FDCAN_HandleTypeDef *hfdcan);
/*!< FDCAN Rx Buffer New Message callback */
void (* HighPriorityMessageCallback)(struct __FDCAN_HandleTypeDef *hfdcan);
/*!< FDCAN High priority message callback */
void (* TimestampWraparoundCallback)(struct __FDCAN_HandleTypeDef *hfdcan);
/*!< FDCAN Timestamp wraparound callback */
void (* TimeoutOccurredCallback)(struct __FDCAN_HandleTypeDef *hfdcan);
/*!< FDCAN Timeout occurred callback */
void (* ErrorCallback)(struct __FDCAN_HandleTypeDef *hfdcan);
/*!< FDCAN Error callback */
void (* ErrorStatusCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs);
/*!< FDCAN Error status callback */
void (* TT_ScheduleSyncCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t
TTSchedSyncITs); /*!< FDCAN T Schedule Synchronization callback */
void (* TT_TimeMarkCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t TTTimeMarkITs);
/*!< FDCAN TT Time Mark callback */
void (* TT_StopWatchCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t SWTime, uint32_t
SWCycleCount); /*!< FDCAN TT Stop Watch callback */
void (* TT_GlobalTimeCallback)(struct __FDCAN_HandleTypeDef *hfdcan, uint32_t TTGlobTimeITs);
/*!< FDCAN TT Global Time callback */
} FDCAN_HandleTypeDef;
#define USE_HAL_FDCAN_REGISTER_CALLBACKS 1
Here we focus on the following parameters , Other parameters are mainly HAL Use and customize callback
functions inside the library .
• FDCAN_GlobalTypeDef *Instance
• TTCAN_TypeDef *ttcan
• FDCAN_InitTypeDef Init
• FDCAN_MsgRamAddressTypeDef msgRam
• uint32_t LatestTxFifoQRequest
HAL_LockTypeDef Lock
There are many functions involved in this file , Here are a few common functions to do a description :
#if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
if (hfdcan->State == HAL_FDCAN_STATE_RESET)
{
/* Unlock */
hfdcan->Lock = HAL_UNLOCKED;
if (hfdcan->MspInitCallback == NULL)
{
hfdcan->MspInitCallback = HAL_FDCAN_MspInit; /* Legacy weak MspInit */
}
/* Get clock */
tickstart = HAL_GetTick();
return HAL_ERROR;
}
}
/* Request initialization */
SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
/* Get clock */
tickstart = HAL_GetTick();
return HAL_ERROR;
}
}
if (hfdcan->Init.Mode == FDCAN_MODE_INTERNAL_LOOPBACK)
{
SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
}
}
else
{
/* Enable detection mode */
SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
}
}
else
{
/* Nothing to do: normal mode */
}
/* If enabled BRS(BitRate Switching Variable baud rate ), Set up data bit timing register
*/
if (hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
{
hfdcan->Instance->DBTP = ((((uint32_t)hfdcan->Init.DataSyncJumpWidth - 1U) <<
FDCAN_DBTP_DSJW_Pos) | \
(((uint32_t)hfdcan->Init.DataTimeSeg1 - 1U) <<
FDCAN_DBTP_DTSEG1_Pos) | \
(((uint32_t)hfdcan->Init.DataTimeSeg2 - 1U) <<
FDCAN_DBTP_DTSEG2_Pos) | \
(((uint32_t)hfdcan->Init.DataPrescaler - 1U) <<
FDCAN_DBTP_DBRP_Pos));
}
/* initialization Tx FIFO/Queue */
hfdcan->LatestTxFifoQRequest = 0U;
Function parameter :
• The first 1 The parameters are FDCAN_HandleTypeDef Type struct pointer variable , Used to configure
parameters to be initialized .
• Return value , return HAL_TIMEOUT Said the timeout ,HAL_ERROR Parameter error ,HAL_OK Means the
delivery is successful. ,HAL_BUSY Means busy , In use .
matters needing attention :
1. function HAL_FDCAN_MspInit For initialization FDCAN The underlying clock 、 Pin and other functions . You
need to implement specific functions in this function . Because this function is weakly defined , Allow users to
re implement this function in other source files of the project . Of course , There is no limit to the
implementation of this function , It can also be like the early standard library , Users can initialize themselves ,
More flexible .
2. If formal parameter hfdcan The structural members of State No initial state , This place is a pit . In particular, the
user made a local variable FDCAN_HandleTypeDef FdCANHandle.
For local variables , This parameter is a random value , If it's a global variable , commonly MDK and IAR All
variables are initialized to 0, And this happens to be HAL_FDCAN_STATE_RESET = 0x00U.
Method 1: The user initializes itself FDCAN And involved in GPIO etc. .
Method 2: Definition FDCAN_HandleTypeDef FdCANHandle Is a global variable .
if(HAL_FDCAN_DeInit(&FdCANHandle) != HAL_OK)
{
Error_Handler();
}
if(HAL_FDCAN_Init(&FdCANHandle) != HAL_OK)
{
Error_Handler();
}
Use examples :
FDCAN_HandleTypeDef hfdcan1;
/*
*************************************************************************************************
********
* Letter Count name : bsp_InitCan1
* Functional specifications : initial CAN1
* shape ginseng : nothing
* return return value : nothing
*************************************************************************************************
********
*/
void bsp_InitCan1(void)
{
/* Bit time characteristic configuration
Bit time parameter | Nominal | Data
---------------------------|--------------|----------------
fdcan_ker_ck | 20 MHz | 20 MHz
Time_quantum (tq) | 50 ns | 50 ns
Synchronization_segment | 1 tq | 1 tq
Propagation_segment | 23 tq | 1 tq
Phase_segment_1 | 8 tq | 4 tq
Phase_segment_2 | 8 tq | 4 tq
Synchronization_Jump_width | 8 tq | 4 tq
Bit_length | 40 tq = 2us | 10 tq = 0.5us
Bit_rate | 0.5 MBit/s | 2 MBit/s
*/
hfdcan1.Instance = FDCAN1; /* To configure FDCAN1 */
hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_BRS; /* Configuration and use FDCAN Variable
baud rate */
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; /* Configure to use normal mode */
hfdcan1.Init.AutoRetransmission = ENABLE; /* Enable automatic retransmission */
hfdcan1.Init.TransmitPause = DISABLE; /* Configure the disable transmission
pause feature */
hfdcan1.Init.ProtocolException = ENABLE; /* Protocol exception handling enable
*/
/*
Configure baud rate in arbitration phase
CAN The clock 20MHz when , The baud rate in the arbitration phase is
CAN FD Freq / (Sync_Seg + Pro_Seg + Phase_Seg1 + Phase_Seg2) = 20MHz /
(1+0x1F + 8) = 0.5Mbps
/* Pay special attention here Seg1, Here is the sum of the two parameters , Corresponding bit
time characteristic diagram Pro_Seg + Phase_Seg1 */
hfdcan1.Init.NominalTimeSeg1 = 0x1F;
/*
Configure baud rate in data phase
CAN The clock 20MHz when , The baud rate in the data phase is
CAN FD Freq / (Sync_Seg + Pro_Seg + Phase_Seg1 + Phase_Seg2) = 20MHz / (1+5+
4) = 2Mbps
/* Pay special attention here Seg1, Here is the sum of the two parameters , Corresponding bit
time characteristic diagram Pro_Seg + Phase_Seg1, Range */
hfdcan1.Init.DataTimeSeg1 = 0x05;
/* Set up Rx FIFO1 The size of each element in the , Support 8,12,16,20,24,32,48 perhaps 64 byte
*/
hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxBuffersNbr = 0; /* Set up Rx Buffer Number , Range
0-64 */
/* Set up Rx Buffer The size of each element in the , Support 8,12,16,20,24,32,48 perhaps 64
byte */
hfdcan1.Init.RxBufferSize = 0;
// Omit unwritten
}
91.4.2 function HAL_FDCAN_DeInit
The function prototype :
HAL_StatusTypeDef HAL_FDCAN_DeInit(FDCAN_HandleTypeDef *hfdcan)
{
/* Detect handle */
if (hfdcan == NULL)
{
return HAL_ERROR;
}
/* stop it FDCAN */
(void)HAL_FDCAN_Stop(hfdcan);
/* No interruptions */
CLEAR_BIT(hfdcan->Instance->ILE, (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1));
#if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
if (hfdcan->MspDeInitCallback == NULL)
{
hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit; /* Legacy weak MspDeInit */
}
/* return HAL_OK */
return HAL_OK;
}
Function description :
Function parameter :
• The first 1 The parameters are FDCAN_HandleTypeDef Type struct pointer variable .
• Return value , return HAL_TIMEOUT Said the timeout ,HAL_ERROR Parameter error ,HAL_OK Means the
delivery is successful. ,HAL_BUSY Means busy , In use .
91.4.3 function HAL_FDCAN_ConfigFilter
The function prototype :
HAL_StatusTypeDef HAL_FDCAN_ConfigFilter(FDCAN_HandleTypeDef *hfdcan, FDCAN_FilterTypeDef
*sFilterConfig)
{
uint32_t FilterElementW1;
uint32_t FilterElementW2;
uint32_t *FilterAddress;
HAL_FDCAN_StateTypeDef state = hfdcan->State;
/* standard ID */
if (sFilterConfig->IdType == FDCAN_STANDARD_ID)
{
/* Detect function parameters */
assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.StdFiltersNbr -
1U)));
assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x7FFU));
if (sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
{
assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x7FFU));
assert_param(IS_FDCAN_STD_FILTER_TYPE(sFilterConfig->FilterType));
}
return HAL_OK;
}
else
{
/* Update error code e */
hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
return HAL_ERROR;
}
}
Function description :
Function parameter :
• The first 1 The parameters are FDCAN_HandleTypeDef Type struct pointer variable .
• The first 2 The parameters are FDCAN_FilterTypeDef Type structure variable , It is mainly used for filtering
parameter configuration .
• Return value , return HAL_TIMEOUT Said the timeout ,HAL_ERROR Parameter error ,HAL_OK Means the
delivery is successful. ,HAL_BUSY Means busy , In use .
Use examples :
FDCAN_HandleTypeDef hfdcan1;
/*
*************************************************************************************************
********
* Letter Count name : bsp_InitCan1
* Functional specifications : initial CAN1
* shape ginseng : nothing
* return return value : nothing
*************************************************************************************************
********
*/
void bsp_InitCan1(void)
{
/*
Configure filters , The filter is mainly used to receive , Here the
sampling mask bit pattern .
FilterID1 = filter
FilterID2 = mask
*/
sFilterConfig1.IdType = FDCAN_STANDARD_ID; /* Set standards ID Or expand
ID */
/* Used to filter indexes , If it is the standard ID, Range 0 To 127. If it's an
extension ID, Range 0 To 64 */
sFilterConfig1.FilterIndex = 0;
sFilterConfig1.FilterType = FDCAN_FILTER_MASK; /* Filter sampling mask bit
mode */
sFilterConfig1.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; /* If the filter matches ,
Save data to Rx FIFO 0 */
sFilterConfig1.FilterID1 = 0x111; /* In shielded bit
mode ,FilterID1 It's the news ID */
sFilterConfig1.FilterID2 = 0x7FF; /* In shielded
bit mode ,FilterID2 Is the message mask bit */
HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig1); /* Configure filters */
}
91.4.4 function HAL_FDCAN_ConfigFifoWatermark
The function prototype :
HAL_StatusTypeDef HAL_FDCAN_ConfigFifoWatermark(FDCAN_HandleTypeDef *hfdcan, uint32_t FIFO,
uint32_t Watermark)
{
/* Test parameters */
assert_param(IS_FDCAN_FIFO_WATERMARK(FIFO));
if (FIFO == FDCAN_CFG_TX_EVENT_FIFO)
{
assert_param(IS_FDCAN_MAX_VALUE(Watermark, 32U));
}
else /* (FIFO == FDCAN_CFG_RX_FIFO0) || (FIFO == FDCAN_CFG_RX_FIFO1) */
{
assert_param(IS_FDCAN_MAX_VALUE(Watermark, 64U));
}
if (hfdcan->State == HAL_FDCAN_STATE_READY)
{
/* Set send event FIFO */
if (FIFO == FDCAN_CFG_TX_EVENT_FIFO)
{
MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFWM, (Watermark <<
FDCAN_TXEFC_EFWM_Pos));
}
/* Set reception FIFO0 */
else if (FIFO == FDCAN_CFG_RX_FIFO0)
{
MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0WM, (Watermark <<
FDCAN_RXF0C_F0WM_Pos));
}
/* Set reception FIFO1 */
else
{
MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1WM, (Watermark <<
FDCAN_RXF1C_F1WM_Pos));
}
/* Return to status */
return HAL_OK;
}
else
{
/* Update error code */
hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
return HAL_ERROR;
}
}
Function description :
Function parameter :
• The first 1 The parameters are FDCAN_HandleTypeDef Type struct pointer variable .
• The first 2 The parameters are FDCAN FIFO Watermark
#define FDCAN_CFG_TX_EVENT_FIFO ((uint32_t)0x00000000U) /*!< Tx event FIFO */
#define FDCAN_CFG_RX_FIFO0 ((uint32_t)0x00000001U) /*!< Rx FIFO0 */
#define FDCAN_CFG_RX_FIFO1 ((uint32_t)0x00000002U) /*!< Rx FIFO1 */
• The first 3 Parameters FIFO Watermark Interrupt location , If it is FDCAN_CFG_TX_EVENT_FIFO, Range 0 To 32,
If it is FDCAN_CFG_RX_FIFO0 or FDCAN_CFG_RX_FIFO1, Range 0 To 64.
• Return value , return HAL_TIMEOUT Said the timeout ,HAL_ERROR Parameter error ,HAL_OK Means the
delivery is successful. ,HAL_BUSY Means busy , In use .
Use examples :
FDCAN_HandleTypeDef hfdcan1;
return HAL_ERROR;
}
}
Function description :
Function parameter :
• The first 1 The parameters are FDCAN_HandleTypeDef Type struct pointer variable .
• The first 2 Two parameters are used to set the interrupt to be enabled , The supported parameters are as
follows :
#define FDCAN_IT_TX_COMPLETE FDCAN_IE_TCE /*!< Transmission Completed
#define FDCAN_IT_TX_ABORT_COMPLETE FDCAN_IE_TCFE /*!< Transmission Cancellation Finished
*/
#define FDCAN_IT_TX_FIFO_EMPTY FDCAN_IE_TFEE /*!< Tx FIFO Empty
• The first 3 The parameters are Tx Buffer Indexes, You can use any combination of the following parameters :
#define FDCAN_TX_BUFFER0 ((uint32_t)0x00000001U) /*!< Add message to Tx Buffer 0 */
#define FDCAN_TX_BUFFER1 ((uint32_t)0x00000002U) /*!< Add message to Tx Buffer 1 */
#define FDCAN_TX_BUFFER2 ((uint32_t)0x00000004U) /*!< Add message to Tx Buffer 2 */
#define FDCAN_TX_BUFFER3 ((uint32_t)0x00000008U) /*!< Add message to Tx Buffer 3 */
#define FDCAN_TX_BUFFER4 ((uint32_t)0x00000010U) /*!< Add message to Tx Buffer 4 */
#define FDCAN_TX_BUFFER5 ((uint32_t)0x00000020U) /*!< Add message to Tx Buffer 5 */
#define FDCAN_TX_BUFFER6 ((uint32_t)0x00000040U) /*!< Add message to Tx Buffer 6 */
#define FDCAN_TX_BUFFER7 ((uint32_t)0x00000080U) /*!< Add message to Tx Buffer 7 */
#define FDCAN_TX_BUFFER8 ((uint32_t)0x00000100U) /*!< Add message to Tx Buffer 8 */
#define FDCAN_TX_BUFFER9 ((uint32_t)0x00000200U) /*!< Add message to Tx Buffer 9 */
#define FDCAN_TX_BUFFER10 ((uint32_t)0x00000400U) /*!< Add message to Tx Buffer 10 */
#define FDCAN_TX_BUFFER11 ((uint32_t)0x00000800U) /*!< Add message to Tx Buffer 11 */
#define FDCAN_TX_BUFFER12 ((uint32_t)0x00001000U) /*!< Add message to Tx Buffer 12 */
#define FDCAN_TX_BUFFER13 ((uint32_t)0x00002000U) /*!< Add message to Tx Buffer 13 */
#define FDCAN_TX_BUFFER14 ((uint32_t)0x00004000U) /*!< Add message to Tx Buffer 14 */
#define FDCAN_TX_BUFFER15 ((uint32_t)0x00008000U) /*!< Add message to Tx Buffer 15 */
#define FDCAN_TX_BUFFER16 ((uint32_t)0x00010000U) /*!< Add message to Tx Buffer 16 */
#define FDCAN_TX_BUFFER17 ((uint32_t)0x00020000U) /*!< Add message to Tx Buffer 17 */
#define FDCAN_TX_BUFFER18 ((uint32_t)0x00040000U) /*!< Add message to Tx Buffer 18 */
#define FDCAN_TX_BUFFER19 ((uint32_t)0x00080000U) /*!< Add message to Tx Buffer 19 */
#define FDCAN_TX_BUFFER20 ((uint32_t)0x00100000U) /*!< Add message to Tx Buffer 20 */
#define FDCAN_TX_BUFFER21 ((uint32_t)0x00200000U) /*!< Add message to Tx Buffer 21 */
#define FDCAN_TX_BUFFER22 ((uint32_t)0x00400000U) /*!< Add message to Tx Buffer 22 */
#define FDCAN_TX_BUFFER23 ((uint32_t)0x00800000U) /*!< Add message to Tx Buffer 23 */
#define FDCAN_TX_BUFFER24 ((uint32_t)0x01000000U) /*!< Add message to Tx Buffer 24 */
#define FDCAN_TX_BUFFER25 ((uint32_t)0x02000000U) /*!< Add message to Tx Buffer 25 */
#define FDCAN_TX_BUFFER26 ((uint32_t)0x04000000U) /*!< Add message to Tx Buffer 26 */
#define FDCAN_TX_BUFFER27 ((uint32_t)0x08000000U) /*!< Add message to Tx Buffer 27 */
#define FDCAN_TX_BUFFER28 ((uint32_t)0x10000000U) /*!< Add message to Tx Buffer 28 */
#define FDCAN_TX_BUFFER29 ((uint32_t)0x20000000U) /*!< Add message to Tx Buffer 29 */
#define FDCAN_TX_BUFFER30 ((uint32_t)0x40000000U) /*!< Add message to Tx Buffer 30 */
#define FDCAN_TX_BUFFER31 ((uint32_t)0x80000000U) /*!< Add message to Tx Buffer 31 */
• Return value , return HAL_TIMEOUT Said the timeout ,HAL_ERROR Parameter error ,HAL_OK Means the
delivery is successful. ,HAL_BUSY Means busy , In use .
Use examples :
FDCAN_HandleTypeDef hfdcan1;
return HAL_OK;
}
else
{
hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
return HAL_ERROR;
}
}
Function description :
Function parameter :
• The first 1 The parameters are FDCAN_HandleTypeDef Type struct pointer variable .
• Return value , return HAL_TIMEOUT Said the timeout ,HAL_ERROR Parameter error ,HAL_OK Means the
delivery is successful. ,HAL_BUSY Means busy , In use .
Use examples :
/**
* @brief Writes block(s) to a specified address in an SD card, in DMA mode.
* @param pData: Pointer to the buffer that will contain the data to transmit
* @param WriteAddr: Address from where data is to be written
* @param NumOfBlocks: Number of SD blocks to write
* @retval SD status
*/
uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks)
{
if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
{
/* testing Tx FIFO/Queue Whether in RAM Space allocated in */
if ((hfdcan->Instance->TXBC & FDCAN_TXBC_TFQS) == 0U)
{
/* Update error code */
hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
return HAL_ERROR;
}
return HAL_ERROR;
}
else
{
/* obtain Tx FIFO PutIndex */
PutIndex = ((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQPI) >> FDCAN_TXFQS_TFQPI_Pos);
return HAL_ERROR;
}
}
Function description :
This function is used to add a message to Tx FIFO/Queue And activate the corresponding transmission request .
Function parameter :
• The first 1 The parameters are FDCAN_HandleTypeDef Type struct pointer variable .
• The first 2 The parameters are FDCAN_TxHeaderTypeDef Type structure variable , For message sending .
• The first 3 One parameter is the data address to send . The program will copy the data to the send buffer .
• Return value , return HAL_TIMEOUT Said the timeout ,HAL_ERROR Parameter error ,HAL_OK Means the
delivery is successful. ,HAL_BUSY Means busy , In use .
Use examples :
/*
*************************************************************************************************
********
* Letter Count name : can1_SendPacket
* Functional specifications : Send a packet of data
* shape ginseng :_DataBuf Data buffer
* _Len Data length , Support 8,12,16,20,24,32,48 perhaps 64 byte
* return return value : nothing
*************************************************************************************************
********
*/
void can1_SendPacket(uint8_t *_DataBuf, uint8_t _Len)
{
FDCAN_TxHeaderTypeDef TxHeader = {0};
if (state == HAL_FDCAN_STATE_BUSY)
{
if (RxLocation == FDCAN_RX_FIFO0) /* Rx element Assigned to Rx FIFO 0 */
{
/* Check Rx FIFO 0 Allocated RAM Space */
if ((hfdcan->Instance->RXF0C & FDCAN_RXF0C_F0S) == 0U)
{
/* Update error code */
hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
return HAL_ERROR;
}
return HAL_ERROR;
}
else
{
/* Check Rx FIFO 0 Full and open overlay mode */
if(((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0F) >> FDCAN_RXF0S_F0F_Pos) == 1U)
{
if(((hfdcan->Instance->RXF0C & FDCAN_RXF0C_F0OM) >> FDCAN_RXF0C_F0OM_Pos) ==
FDCAN_RX_FIFO_OVERWRITE)
{
/* Overlay mode is turned on , Discard the second 1 Data */
GetIndex = 1U;
}
}
return HAL_ERROR;
}
return HAL_ERROR;
}
else
{
/* Check Rx FIFO 1 Full and open overlay mode */
if(((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1F) >> FDCAN_RXF1S_F1F_Pos) == 1U)
{
if(((hfdcan->Instance->RXF1C & FDCAN_RXF1C_F1OM) >> FDCAN_RXF1C_F1OM_Pos) ==
FDCAN_RX_FIFO_OVERWRITE)
{
/* Overlay mode is turned on , Discard the second 1 Data */
GetIndex = 1U;
}
}
return HAL_ERROR;
}
else
{
/* Calculation Rx buffer Address */
RxAddress = (uint32_t *)(hfdcan->msgRam.RxBufferSA + (RxLocation * hfdcan-
>Init.RxBufferSize * 4U));
}
}
/* receive IdType */
pRxHeader->IdType = *RxAddress & FDCAN_ELEMENT_MASK_XTD;
/* receive Identifier */
if (pRxHeader->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
{
pRxHeader->Identifier = ((*RxAddress & FDCAN_ELEMENT_MASK_STDID) >> 18);
}
else /* Extended ID element */
{
pRxHeader->Identifier = (*RxAddress & FDCAN_ELEMENT_MASK_EXTID);
}
/* receive RxFrameType */
pRxHeader->RxFrameType = (*RxAddress & FDCAN_ELEMENT_MASK_RTR);
/* receive ErrorStateIndicator */
pRxHeader->ErrorStateIndicator = (*RxAddress & FDCAN_ELEMENT_MASK_ESI);
/* receive RxTimestamp */
pRxHeader->RxTimestamp = (*RxAddress & FDCAN_ELEMENT_MASK_TS);
/* receive DataLength */
pRxHeader->DataLength = (*RxAddress & FDCAN_ELEMENT_MASK_DLC);
/* receive BitRateSwitch */
pRxHeader->BitRateSwitch = (*RxAddress & FDCAN_ELEMENT_MASK_BRS);
/* receive FDFormat */
pRxHeader->FDFormat = (*RxAddress & FDCAN_ELEMENT_MASK_FDF);
/* receive FilterIndex */
pRxHeader->FilterIndex = ((*RxAddress & FDCAN_ELEMENT_MASK_FIDX) >> 24);
/* receive NonMatchingFrame */
pRxHeader->IsFilterMatchingFrame = ((*RxAddress & FDCAN_ELEMENT_MASK_ANMF) >> 31);
/* receive Rx payload */
pData = (uint8_t *)RxAddress;
for (ByteCounter = 0; ByteCounter < DLCtoBytes[pRxHeader->DataLength >> 16]; ByteCounter++)
{
pRxData[ByteCounter] = pData[ByteCounter];
}
/* Return to status */
return HAL_OK;
}
else
{
/* Update error code */
hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
return HAL_ERROR;
}
}
Function description :
Function parameter :
• The first 1 The parameters are FDCAN_HandleTypeDef Type struct pointer variable .
• The first 2 The first parameter is the read location , The following parameters are supported :
#define FDCAN_RX_FIFO0 ((uint32_t)0x00000040U) /*!< Get received message from Rx FIFO 0 */
#define FDCAN_RX_FIFO1 ((uint32_t)0x00000041U) /*!< Get received message from Rx FIFO 1 */
#define FDCAN_RX_BUFFER0 ((uint32_t)0x00000000U) /*!< Get received message from Rx Buffer 0 */
#define FDCAN_RX_BUFFER1 ((uint32_t)0x00000001U) /*!< Get received message from Rx Buffer 1 */
#define FDCAN_RX_BUFFER2 ((uint32_t)0x00000002U) /*!< Get received message from Rx Buffer 2 */
#define FDCAN_RX_BUFFER3 ((uint32_t)0x00000003U) /*!< Get received message from Rx Buffer 3 */
#define FDCAN_RX_BUFFER4 ((uint32_t)0x00000004U) /*!< Get received message from Rx Buffer 4 */
#define FDCAN_RX_BUFFER5 ((uint32_t)0x00000005U) /*!< Get received message from Rx Buffer 5 */
#define FDCAN_RX_BUFFER6 ((uint32_t)0x00000006U) /*!< Get received message from Rx Buffer 6 */
#define FDCAN_RX_BUFFER7 ((uint32_t)0x00000007U) /*!< Get received message from Rx Buffer 7 */
#define FDCAN_RX_BUFFER8 ((uint32_t)0x00000008U) /*!< Get received message from Rx Buffer 8 */
#define FDCAN_RX_BUFFER9 ((uint32_t)0x00000009U) /*!< Get received message from Rx Buffer 9 */
#define FDCAN_RX_BUFFER10 ((uint32_t)0x0000000AU) /*!< Get received message from Rx Buffer 10 */
#define FDCAN_RX_BUFFER11 ((uint32_t)0x0000000BU) /*!< Get received message from Rx Buffer 11 */
#define FDCAN_RX_BUFFER12 ((uint32_t)0x0000000CU) /*!< Get received message from Rx Buffer 12 */
#define FDCAN_RX_BUFFER13 ((uint32_t)0x0000000DU) /*!< Get received message from Rx Buffer 13 */
#define FDCAN_RX_BUFFER14 ((uint32_t)0x0000000EU) /*!< Get received message from Rx Buffer 14 */
#define FDCAN_RX_BUFFER15 ((uint32_t)0x0000000FU) /*!< Get received message from Rx Buffer 15 */
#define FDCAN_RX_BUFFER16 ((uint32_t)0x00000010U) /*!< Get received message from Rx Buffer 16 */
#define FDCAN_RX_BUFFER17 ((uint32_t)0x00000011U) /*!< Get received message from Rx Buffer 17 */
#define FDCAN_RX_BUFFER18 ((uint32_t)0x00000012U) /*!< Get received message from Rx Buffer 18 */
#define FDCAN_RX_BUFFER19 ((uint32_t)0x00000013U) /*!< Get received message from Rx Buffer 19 */
#define FDCAN_RX_BUFFER20 ((uint32_t)0x00000014U) /*!< Get received message from Rx Buffer 20 */
#define FDCAN_RX_BUFFER21 ((uint32_t)0x00000015U) /*!< Get received message from Rx Buffer 21 */
#define FDCAN_RX_BUFFER22 ((uint32_t)0x00000016U) /*!< Get received message from Rx Buffer 22 */
#define FDCAN_RX_BUFFER23 ((uint32_t)0x00000017U) /*!< Get received message from Rx Buffer 23 */
#define FDCAN_RX_BUFFER24 ((uint32_t)0x00000018U) /*!< Get received message from Rx Buffer 24 */
#define FDCAN_RX_BUFFER25 ((uint32_t)0x00000019U) /*!< Get received message from Rx Buffer 25 */
#define FDCAN_RX_BUFFER26 ((uint32_t)0x0000001AU) /*!< Get received message from Rx Buffer 26 */
#define FDCAN_RX_BUFFER27 ((uint32_t)0x0000001BU) /*!< Get received message from Rx Buffer 27 */
#define FDCAN_RX_BUFFER28 ((uint32_t)0x0000001CU) /*!< Get received message from Rx Buffer 28 */
#define FDCAN_RX_BUFFER29 ((uint32_t)0x0000001DU) /*!< Get received message from Rx Buffer 29 */
#define FDCAN_RX_BUFFER30 ((uint32_t)0x0000001EU) /*!< Get received message from Rx Buffer 30 */
#define FDCAN_RX_BUFFER31 ((uint32_t)0x0000001FU) /*!< Get received message from Rx Buffer 31 */
#define FDCAN_RX_BUFFER32 ((uint32_t)0x00000020U) /*!< Get received message from Rx Buffer 32 */
#define FDCAN_RX_BUFFER33 ((uint32_t)0x00000021U) /*!< Get received message from Rx Buffer 33 */
#define FDCAN_RX_BUFFER34 ((uint32_t)0x00000022U) /*!< Get received message from Rx Buffer 34 */
#define FDCAN_RX_BUFFER35 ((uint32_t)0x00000023U) /*!< Get received message from Rx Buffer 35 */
#define FDCAN_RX_BUFFER36 ((uint32_t)0x00000024U) /*!< Get received message from Rx Buffer 36 */
#define FDCAN_RX_BUFFER37 ((uint32_t)0x00000025U) /*!< Get received message from Rx Buffer 37 */
#define FDCAN_RX_BUFFER38 ((uint32_t)0x00000026U) /*!< Get received message from Rx Buffer 38 */
#define FDCAN_RX_BUFFER39 ((uint32_t)0x00000027U) /*!< Get received message from Rx Buffer 39 */
#define FDCAN_RX_BUFFER40 ((uint32_t)0x00000028U) /*!< Get received message from Rx Buffer 40 */
#define FDCAN_RX_BUFFER41 ((uint32_t)0x00000029U) /*!< Get received message from Rx Buffer 41 */
#define FDCAN_RX_BUFFER42 ((uint32_t)0x0000002AU) /*!< Get received message from Rx Buffer 42 */
#define FDCAN_RX_BUFFER43 ((uint32_t)0x0000002BU) /*!< Get received message from Rx Buffer 43 */
#define FDCAN_RX_BUFFER44 ((uint32_t)0x0000002CU) /*!< Get received message from Rx Buffer 44 */
#define FDCAN_RX_BUFFER45 ((uint32_t)0x0000002DU) /*!< Get received message from Rx Buffer 45 */
#define FDCAN_RX_BUFFER46 ((uint32_t)0x0000002EU) /*!< Get received message from Rx Buffer 46 */
#define FDCAN_RX_BUFFER47 ((uint32_t)0x0000002FU) /*!< Get received message from Rx Buffer 47 */
#define FDCAN_RX_BUFFER48 ((uint32_t)0x00000030U) /*!< Get received message from Rx Buffer 48 */
#define FDCAN_RX_BUFFER49 ((uint32_t)0x00000031U) /*!< Get received message from Rx Buffer 49 */
#define FDCAN_RX_BUFFER50 ((uint32_t)0x00000032U) /*!< Get received message from Rx Buffer 50 */
#define FDCAN_RX_BUFFER51 ((uint32_t)0x00000033U) /*!< Get received message from Rx Buffer 51 */
#define FDCAN_RX_BUFFER52 ((uint32_t)0x00000034U) /*!< Get received message from Rx Buffer 52 */
#define FDCAN_RX_BUFFER53 ((uint32_t)0x00000035U) /*!< Get received message from Rx Buffer 53 */
#define FDCAN_RX_BUFFER54 ((uint32_t)0x00000036U) /*!< Get received message from Rx Buffer 54 */
#define FDCAN_RX_BUFFER55 ((uint32_t)0x00000037U) /*!< Get received message from Rx Buffer 55 */
#define FDCAN_RX_BUFFER56 ((uint32_t)0x00000038U) /*!< Get received message from Rx Buffer 56 */
#define FDCAN_RX_BUFFER57 ((uint32_t)0x00000039U) /*!< Get received message from Rx Buffer 57 */
#define FDCAN_RX_BUFFER58 ((uint32_t)0x0000003AU) /*!< Get received message from Rx Buffer 58 */
#define FDCAN_RX_BUFFER59 ((uint32_t)0x0000003BU) /*!< Get received message from Rx Buffer 59 */
#define FDCAN_RX_BUFFER60 ((uint32_t)0x0000003CU) /*!< Get received message from Rx Buffer 60 */
#define FDCAN_RX_BUFFER61 ((uint32_t)0x0000003DU) /*!< Get received message from Rx Buffer 61 */
#define FDCAN_RX_BUFFER62 ((uint32_t)0x0000003EU) /*!< Get received message from Rx Buffer 62 */
#define FDCAN_RX_BUFFER63 ((uint32_t)0x0000003FU) /*!< Get received message from Rx Buffer 63 */
• The first 3 The parameters are FDCAN_RxHeaderTypeDef Type structure variable , Mainly used for message
receiving .
• The first 4 The first parameter is the data receiving buffer address .
• Return value , return HAL_TIMEOUT Said the timeout ,HAL_ERROR Parameter error ,HAL_OK Means the
delivery is successful. ,HAL_BUSY Means busy , In use .
Use examples :
/*
*************************************************************************************************
********
* Letter Count name : HAL_FDCAN_RxFifo0Callback
* Functional specifications : CAN Interrupt service routine - Callback function
* shape ginseng : hfdcan
* return return value : nothing
*************************************************************************************************
********
*/
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
if (hfdcan == &hfdcan1)
{
if ((RxFifo0ITs & FDCAN_IT_RX_FIFO0_WATERMARK) != RESET)
{
/* from RX FIFO0 Reading data */
HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &g_Can1RxHeader,
g_Can1RxData);
So much for you in this chapter , more FDCAN Knowledge can be found in the... Of this tutorial 90 Chapter .
版权声明
本文为[Simon223]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/11/20211123010332633V.html









