Raw API
CAN Exported Types
-
struct CAN_BitTimingTypeDef
CAN Timing Initialization structure definition. This struct is used to pass bus timing values to the configuration and bitrate calculation functions.
Public Members
-
uint8_t SJW
Spec: 1 to 4. Synchronization jump width.
-
uint8_t PropSeg
Spec: 1 to 8. Propagation segment.
-
uint8_t PhaseSeg1
Spec: 1 to 8. Phase segment 1.
-
uint8_t PhaseSeg2
Spec: 2 to 8. Phase segment 2.
-
uint16_t Prescaler
Spec: 1 to 1024. Prescaler value.
-
uint8_t SJW
-
struct CAN_DevTable
CAN device table entry structure definition.
Public Members
-
CAN_TypeDef *CANx
Pointer to CAN peripheral base address
-
IRQn_Type IrqNum
CAN interrupt number
-
u32 Rx_HandshakeInterface
DMA handshake interface for RX
-
CAN_TypeDef *CANx
-
struct CAN_InitTypeDef
CAN Mode Initialization structure definition.
Public Members
-
u32 CAN_TimStampEn
Specifies the CAN timestamp timer enable or disable. This parameter can be ENABLE or DISABLE.
-
u32 CAN_TimStampDiv
Specifies the CAN timestamp timer divider. This parameter can be a number between 0x01 and 0xff.
-
u32 CAN_AutoReTxEn
Specifies the message auto re-transmission configuration. This parameter can be ENABLE or DISABLE.
-
u32 CAN_TriSampleEn
Specifies the triple sampling configuration. This parameter can be ENABLE or DISABLE.
-
u32 CAN_WorkMode
Specifies the CAN work mode. This parameter can be a value of CAN Work Mode.
-
u32 CAN_ErrCntThreshold
Specifies the error counter warning threshold. This parameter can be a number between 0x000 and 0x1ff
-
u32 CAN_RxFifoEn
Specifies the CAN FIFO mode configure register. This parameter can be ENABLE or DISABLE.
-
CAN_BitTimingTypeDef CAN_Timing
Specifies the CAN bit timing configuration. See CAN_BitTimingTypeDef.
-
u32 CAN_TimStampEn
-
struct CAN_RxMsgTypeDef
CAN Rx message descriptor structure definition.
Public Members
-
u32 ProtocolType
Specifies the protocol type of frame for the message that will be received. This parameter can be a value of CAN Protocol Type
-
u32 StdId
Specifies the standard identifier. This parameter can be a value between 0 to 0x7FF
-
u32 ExtId
Specifies the extended identifier. This parameter can be a value between 0 to 0x1FFFFFFF
-
u32 MsgBufferIdx
Specifies the message buffer index. This parameter can be a value between 0 to 0xf
-
u32 IDE
Specifies the type of identifier for the message that will be received. This parameter can be a value of CAN ID Type
-
u32 RTR
Specifies the type of frame for the message that will be received. This parameter can be a value of CAN Frame Type
-
u32 DLC
Specifies the length of the frame that will be received. This parameter can be a value between 0 to 8
-
uint8_t Data[64]
Payload data accessed as unsigned 8 bit values.
-
uint32_t Data_32[16]
Payload data accessed as unsigned 32 bit values.
Data and Data_32 form an anonymous union and share the same memory.
-
u32 ID_MASK
Specifies the ID MASK
-
u32 RTR_Mask
Specifies the RTR MASK, refer to CAN RTR Mask Type
-
u32 IDE_Mask
Specifies the IDE MASK, refer to CAN IDE Mask Type
-
u32 RxTimStamp
Specifies the rx time stamp
-
u32 RxLost
Specifies the rx lost times
-
u32 ProtocolType
-
struct CAN_TxMsgTypeDef
CAN Tx message descriptor structure definition.
Public Members
-
u32 ProtocolType
Specifies the protocol type of frame for the message that will be transmitted. This parameter can be a value of CAN Protocol Type
-
u32 StdId
Specifies the standard identifier. This parameter can be a value between 0 to 0x7FF.
-
u32 ExtId
Specifies the extended identifier. This parameter can be a value between 0 to 0x1FFFFFFF.
-
u32 MsgBufferIdx
Specifies the message buffer index. This parameter can be a value between 0 to 0xf.
-
u32 IDE
Specifies the type of identifier for the message that will be transmitted. This parameter can be a value of CAN ID Type
-
u32 RTR
Specifies the type of frame for the message that will be transmitted. This parameter can be a value of CAN Frame Type
-
u32 DLC
Specifies the length of the frame that will be transmitted. This parameter can be a value between 0 to 8
-
uint8_t Data[64]
Payload data accessed as unsigned 8 bit values.
-
uint32_t Data_32[16]
Payload data accessed as unsigned 32 bit values.
Data and Data_32 form an anonymous union and share the same memory.
-
u32 ProtocolType
CAN Exported Constants
CAN Bit Timing
/* Minimum CAN bit timing parameter set. */
#define CAN_TIMING_MIN { \
.SJW = 1, \
.PropSeg= 2, \
.PhaseSeg1 = 2, \
.PhaseSeg2 = 2, \
.Prescaler = 1, \
}
/* Maximum CAN bit timing parameter set. */
#define CAN_TIMING_MAX { \
.SJW = 4, \
.PropSeg = 6, \
.PhaseSeg1 = 8, \
.PhaseSeg2 = 8, \
.Prescaler = 32, \
}
/* Synchronization segment length in time quanta. */
#define CAN_SYNC_SEG 1
/* Clamp val between low and high bounds. */
#define CAN_CLAMP (((val) <= (low)) ? (low) : MIN(val, high))
/* Allowed sample point deviation margin in permille. */
#define CAN_SAMPLE_POINT_MARGIN 50
CAN Frame Type
/* Remote (RTR) frame type. */
#define CAN_REMOTE_FRAME ((u32)0x40000000)
/* Data frame type. */
#define CAN_DATA_FRAME ((u32)0x00000000)
/* Check if CAN frame type value is valid. */
#define IS_CAN_FRAME_TYPE (((TYPE) == CAN_REMOTE_FRAME) || \
((TYPE) == CAN_DATA_FRAME))
CAN IDE Mask Type
/* IDE bit is included in filter mask. */
#define CAN_IDE_BIT_MASK ((u32)0x20000000)
/* IDE bit is excluded from filter mask. */
#define CAN_IDE_BIT_NOT_MASK ((u32)0x00000000)
/* Check if CAN IDE bit mask type is valid. */
#define IS_CAN_IDE_BIT_MASK_TYPE (((TYPE) == CAN_IDE_BIT_MASK) || \
((TYPE) == CAN_IDE_BIT_NOT_MASK))
CAN ID Type
/* Standard 11-bit identifier frame. */
#define CAN_STANDARD_FRAME ((u32)0x00000000)
/* Extended 29-bit identifier frame. */
#define CAN_EXTEND_FRAME ((u32)0x20000000)
/* Check if CAN ID type value is valid. */
#define IS_CAN_ID_TYPE (((TYPE) == CAN_STANDARD_FRAME) || \
((TYPE) == CAN_EXTEND_FRAME))
CAN Index Limit
/* Maximum number of CAN controller instances. */
#define MAX_CAN_INDEX (2)
CAN Interrupts
/* TX complete interrupt. */
#define CAN_TX_INT ((u32)0x00000001)
/* RX complete interrupt. */
#define CAN_RX_INT ((u32)0x00000002)
/* Error interrupt. */
#define CAN_ERR_INT ((u32)0x00000004)
/* Wakeup interrupt. */
#define CAN_WKUP_INT ((u32)0x00000008)
/* Bus-off interrupt. */
#define CAN_BUSOFF_INT ((u32)0x00000010)
/* RAM move done interrupt. */
#define CAN_RAM_MOVE_DONE_INT ((u32)0x00000020)
/* Check if CAN interrupt configuration value is valid. */
#define IS_CAN_CONFIG_IT (((IT) == CAN_TX_INT) || \
((IT) == CAN_RX_INT) || \
((IT) == CAN_ERR_INT)|| \
((IT) == CAN_WKUP_INT)|| \
((IT) == CAN_RAM_MOVE_DONE_INT)|| \
((IT) == CAN_BUSOFF_INT))
/* Check if CAN interrupt clear value is valid. */
#define IS_CAN_CLEAR_IT ((((IT) & (u32)0xFFFFFFC0) == 0x00) && ((IT) != 0x00))
CAN Message Buffer and FIFO
/* CAN message buffer entry length in words. */
#define CAN_MESSAGE_BUFFER_LEN (5)
/* Total number of CAN message buffers. */
#define CAN_MESSAGE_BUFFER_SIZE (16)
/* CAN RX FIFO depth in messages. */
#define CAN_MESSAGE_FIFO_SIZE (4)
/* Message buffer index for RX FIFO read. */
#define CAN_RX_FIFO_READ_MSG_IDX (12)
CAN Message Buffer Status
/* TX frame is pending transmission. */
#define CAN_FRAME_PENDING_TX ((u32)0x00000001)
/* TX frame transmission completed. */
#define CAN_FRAME_FINISH_TX ((u32)0x00000002)
/* TX frame overwrite and resend. */
#define CAN_FRAME_OVERWRITE_SEND_TX ((u32)0x00000003)
/* RX frame is pending reception. */
#define CAN_FRAME_PENDING_RX ((u32)0x00000004)
/* RX frame reception completed. */
#define CAN_FRAME_FINISH_RX ((u32)0x0000000C)
/* Check if CAN message status type is valid. */
#define IS_CAN_MSG_STS_TYPE (((TYPE) == CAN_FRAME_PENDING_TX) || \
((TYPE) == CAN_FRAME_FINISH_TX) || \
((TYPE) == CAN_FRAME_OVERWRITE_SEND_TX) || \
((TYPE) == CAN_FRAME_FINISH_RX) || \
((TYPE) == CAN_FRAME_PENDING_RX))
CAN Protocol Type
/* CAN 2.0 classic protocol frame type. */
#define CAN_CAN20_PROTOCOL_FRAME ((u32)0x00000000)
/* Check if CAN protocol type value is valid. */
#define IS_CAN_PROTOCOL_TYPE ((TYPE) == CAN_CAN20_PROTOCOL_FRAME)
CAN RAM Access Data Mask
/* Combined mask of all RAM data access bits. */
#define CAN_BIT_RAM_ACC_DATA_MASK (CAN_BIT_RAM_ACC_DATA15 | CAN_BIT_RAM_ACC_DATA14 | CAN_BIT_RAM_ACC_DATA13 | CAN_BIT_RAM_ACC_DATA12 | \
CAN_BIT_RAM_ACC_DATA11 | CAN_BIT_RAM_ACC_DATA10 | CAN_BIT_RAM_ACC_DATA9 | CAN_BIT_RAM_ACC_DATA8 | \
CAN_BIT_RAM_ACC_DATA7 | CAN_BIT_RAM_ACC_DATA6 | CAN_BIT_RAM_ACC_DATA5 | CAN_BIT_RAM_ACC_DATA4 | \
CAN_BIT_RAM_ACC_DATA3 | CAN_BIT_RAM_ACC_DATA2 | CAN_BIT_RAM_ACC_DATA1 | CAN_BIT_RAM_ACC_DATA0)
CAN RTR Mask Type
/* RTR bit is included in filter mask. */
#define CAN_RTR_BIT_MASK ((u32)0x40000000)
/* RTR bit is excluded from filter mask. */
#define CAN_RTR_BIT_NOT_MASK ((u32)0x00000000)
/* Check if CAN RTR bit mask type is valid. */
#define IS_CAN_RTR_BIT_MASK_TYPE (((TYPE) == CAN_RTR_BIT_MASK) || \
((TYPE) == CAN_RTR_BIT_NOT_MASK))
CAN Type
/* Check if CAN peripheral pointer is valid. */
#define IS_CAN_ALL_PERIPH (((PERIPH) == CAN0) || \
((PERIPH) == CAN1) || \
((PERIPH) == CAN0_S) || \
((PERIPH) == CAN1_S))
CAN Work Mode
/* Normal bus communication mode. */
#define CAN_NORMAL_MODE ((u32)0x00000000)
/* Silent (listen-only) mode, no transmission. */
#define CAN_SILENCE_MODE ((u32)0x00000000)
/* External loopback test mode. */
#define CAN_EXT_LOOPBACK_MODE ((u32)0x00000001)
/* Internal loopback test mode. */
#define CAN_INT_LOOPBACK_MODE ((u32)0x00000002)
/* Check if CAN work mode value is valid. */
#define IS_CAN_WORK_MODE (((MODE) == CAN_NORMAL_MODE) || \
((MODE) == CAN_SILENCE_MODE) || \
((MODE) == CAN_EXT_LOOPBACK_MODE) || \
((MODE) == CAN_INT_LOOPBACK_MODE))
CAN Exported Functions
CAN Global Functions
-
void CAN_BusCmd(CAN_TypeDef *CANx, u32 NewState)
Bus request ENABLE or DISABLE.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
NewState – New state of the bus request. This parameter can be: ENABLE or DISABLE.
-
u32 CAN_BusStatusGet(CAN_TypeDef *CANx)
Get CAN bus status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
Bus status:
1: on
0: off
-
void CAN_Cmd(CAN_TypeDef *CANx, u32 NewState)
CAN ENABLE or DISABLE.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
NewState – New state of the CAN peripheral. This parameter can be: ENABLE or DISABLE.
-
u32 CAN_FifoLvlGet(CAN_TypeDef *CANx)
Get CAN FIFO level.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
Rx FIFO level
-
u32 CAN_FifoStatusGet(CAN_TypeDef *CANx)
Get CAN FIFO status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
FIFO status, this value can be:
CAN_BIT_FIFO_MSG_FULL
CAN_BIT_FIFO_MSG_EMPTY
CAN_BIT_FIFO_MSG_OVERFLOW
-
void CAN_Init(CAN_TypeDef *CANx, CAN_InitTypeDef *CAN_InitStruct)
Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
CAN_InitStruct – Pointer to a CAN_InitTypeDef structure that contains the configuration information for the specified CAN peripheral.
-
void CAN_LpFilterCmd(CAN_TypeDef *CANx, u32 NewState)
Low power filter ENABLE or DISABLE.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
NewState – New state of the low power filter. This parameter can be: ENABLE or DISABLE.
-
void CAN_LpFilterConfig(CAN_TypeDef *CANx, u32 FltNum)
Low power filter configuration.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
FltNum – Filter threshold.
-
void CAN_RXErrCntClear(CAN_TypeDef *CANx)
CAN RX error counter clear.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
-
u32 CAN_RXErrCntGet(CAN_TypeDef *CANx)
Get CAN RX error counter.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
RX error counter
-
u32 CAN_RXErrCntSTS(CAN_TypeDef *CANx)
Get CAN error counter status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
Error counter status:
CAN_TX_ERR_PASSIVE
CAN_TX_ERR_BUSOFF
CAN_TX_ERR_WARNING
-
void CAN_ReadMsg(CAN_TypeDef *CANx, CAN_RxMsgTypeDef *RxMsg)
Read frame from message ram buffer.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
RxMsg – Rx message pointer.
-
void CAN_ReadRxMsgFromFifo(CAN_TypeDef *CANx, CAN_RxMsgTypeDef *RxMsg)
Read Rx message from FIFO.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
RxMsg – Rx message pointer.
-
void CAN_RxAutoReply(CAN_TypeDef *CANx, CAN_RxMsgTypeDef *RxMsg)
Receive auto reply message.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
RxMsg – Rx message pointer.
-
void CAN_SetRxMsgBuf(CAN_TypeDef *CANx, CAN_RxMsgTypeDef *RxMsg)
Set rx message ram buffer.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
RxMsg – Rx message pointer.
-
void CAN_StructInit(CAN_InitTypeDef *CAN_InitStruct)
Fills each CAN_InitStruct member with its default value.
- Parameters:
CAN_InitStruct – Pointer to a CAN_InitTypeDef structure which will be initialized.
-
void CAN_TXErrCntClear(CAN_TypeDef *CANx)
CAN TX error counter clear.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
-
u32 CAN_TXErrCntGet(CAN_TypeDef *CANx)
Get CAN TX error counter.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
TX error counter
-
void CAN_TxAutoReply(CAN_TypeDef *CANx, CAN_TxMsgTypeDef *TxMsg)
Send auto reply message.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
TxMsg – Tx message pointer.
-
void CAN_WriteMsg(CAN_TypeDef *CANx, CAN_TxMsgTypeDef *TxMsg)
Write frame to message ram buffer.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
TxMsg – Tx message pointer.
CAN Interrupt Status Functions
-
int CAN_CalcBitTiming(uint32_t BitRate, CAN_BitTimingTypeDef *Result)
Calculate optimal CAN Bit Timing parameters.
This function iterates through possible prescaler values to find a configuration that minimizes the deviation from the desired sample point. The results (Prescaler, Segments, SJW) are written to the Result structure.
- Parameters:
BitRate – Target bitrate (e.g., 500000 for 500kbps).
Result – [Out] Pointer to structure where timing params will be saved.
- Return values:
RTK_SUCCESS – Valid timing configuration found.
-RTK_ERR_BADARG – Calculated parameters are invalid or out of range.
RTK_FAIL – System clock could not be retrieved.
-
u32 CAN_CheckMsgBufAvailable(CAN_TypeDef *CANx, u32 MsgBufIdx)
Check message buffer available or not.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgBufIdx – Message buffer index.
- Returns:
Status, can be the following values:
1: available
0: not available
-
void CAN_ClearAllINT(CAN_TypeDef *CANx)
Clears all CAN interrupt pending bits.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
-
void CAN_ClearErrStatus(CAN_TypeDef *CANx, u32 ERR_STS)
Clears the CAN error pending bits.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
ERR_STS – Specifies the error status to be cleared.
-
void CAN_ClearINT(CAN_TypeDef *CANx, u32 CAN_IT)
Clears the CAN interrupt pending bits.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
CAN_IT – Specifies the interrupt to be cleared.
-
int CAN_CoreClockGet(uint32_t *Rate)
Get the current CAN core clock frequency.
- Parameters:
Rate – [Out] Pointer to a variable where the frequency (in Hz) will be stored.
- Return values:
RTK_SUCCESS – Clock rate retrieved successfully.
RTK_FAIL – Invalid parameter (NULL pointer).
-
void CAN_CoreClockSet(void)
Initialize the CAN core clock settings.
Note
Sets the source to XTAL and disables PLL dividers for direct clocking.
-
u32 CAN_GetErrStatus(CAN_TypeDef *CANx)
Get the CAN error status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
Error status
-
u32 CAN_GetINTStatus(CAN_TypeDef *CANx)
Get CAN interrupt status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
Interrupt status
-
u32 CAN_GetRxDmaData(CAN_TypeDef *CANx)
CAN get RX DMA data.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
DMA data
-
void CAN_INTConfig(CAN_TypeDef *CANx, u32 CAN_IT, u32 NewState)
Enables or disables the specified CAN interrupts.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
CAN_IT –
Specifies the CAN interrupts sources to be enabled or disabled. This parameter can be any combination of the following values:
CAN_TX_INT
CAN_RX_INT
CAN_ERR_INT
CAN_WKUP_INT
CAN_BUSOFF_INT
NewState – New state of the specified CAN interrupts. This parameter can be: ENABLE or DISABLE.
-
void CAN_MsgBaseAddrConfig(CAN_TypeDef *CANx, u32 MsgIdx, u32 BaseAddr)
Configure CAN message buffer base address.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgIdx – Message buffer index.
BaseAddr – Message buffer base address.
-
void CAN_MsgBaseAddrEndReg(CAN_TypeDef *CANx, u32 EndAddr)
CAN message buffer end address.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
EndAddr – Message buffer end address.
-
void CAN_MsgBufRxDoneStatusClear(CAN_TypeDef *CANx, u32 MsgBufIdx)
Clear CAN rx done message buffer status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgBufIdx – Message buffer index.
-
u32 CAN_MsgBufRxDoneStatusGet(CAN_TypeDef *CANx, u32 MsgBufIdx)
Get message buffer rx done status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgBufIdx – Message buffer index.
- Returns:
Status, can be the following values:
1: rx complete
0: rx pending
-
u32 CAN_MsgBufStatusGet(CAN_TypeDef *CANx, u32 MsgBufIdx)
Get message buffer status code.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgBufIdx – Message buffer index.
- Returns:
Status, can be the following values:
CAN_FRAME_PENDING_TX
CAN_FRAME_FINISH_TX
CAN_FRAME_OVERWRITE_SEND_TX
CAN_FRAME_PENDING_RX
CAN_FRAME_FINISH_RX
-
u32 CAN_MsgBufStatusRegGet(CAN_TypeDef *CANx, u32 MsgBufIdx)
Get message buffer status register value.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgBufIdx – Message buffer index.
- Returns:
Register value
-
void CAN_MsgBufTxDoneStatusClear(CAN_TypeDef *CANx, u32 MsgBufIdx)
Clear CAN tx done message buffer status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgBufIdx – Message buffer index.
-
u32 CAN_MsgBufTxDoneStatusGet(CAN_TypeDef *CANx, u32 MsgBufIdx)
Get message buffer tx done status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgBufIdx – Message buffer index.
- Returns:
Status, can be the following values:
1: tx complete
0: tx pending
-
void CAN_MsgCtrlRegConfig(CAN_TypeDef *CANx, u32 MsgIdx, u32 RxDmaEn, u32 DmaOffset)
CAN control register configure.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
MsgIdx – Message buffer index.
RxDmaEn – RX DMA enable.
DmaOffset – DMA offset.
-
bool CAN_RXGDMA_Init(u8 Index, GDMA_InitTypeDef *GDMA_InitStruct, void *CallbackData, IRQ_FUN CallbackFunc, u8 *pRxBuf, int RxCount)
Init and Enable CAN RX GDMA.
- Parameters:
Index – 0 or 1.
GDMA_InitStruct – Pointer to a GDMA_InitTypeDef structure that contains the configuration information for the GDMA peripheral.
CallbackData – GDMA callback data.
CallbackFunc – GDMA callback function.
pRxBuf – Pointer to RX buffer.
RxCount – Number of bytes to receive.
- Returns:
Initialization result:
TRUE: DMA channel allocated and initialized successfully.
FALSE: No available DMA channel.
-
void CAN_RamBufferMapConfig(CAN_TypeDef *CANx, uint32_t *AddrList)
Configure the RAM mapping addresses for message buffers.
- Parameters:
CANx – Pointer to CAN peripheral instance (e.g., CAN0).
AddrList – Pointer to an array containing buffer addresses. Size must be at least (CAN_MESSAGE_BUFFER_SIZE + 1).
Note
This function assigns physical memory addresses to the CAN message buffers. The array must contain one extra address for the end register.
-
void CAN_RxDmaDestBaseAddrConfig(CAN_TypeDef *CANx, u32 Addr)
CAN DMA destination base address configure.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
Addr – Base address.
-
void CAN_RxDoneStatusClear(CAN_TypeDef *CANx, u32 Status)
Clear CAN rx done status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
Status – Clear status.
-
u32 CAN_RxDoneStatusGet(CAN_TypeDef *CANx)
Get CAN rx done status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
CAN RX done status bitmask, each bit represents one message buffer RX completion status.
-
void CAN_RxMsgBufINTConfig(CAN_TypeDef *CANx, u32 BUF_IT, u32 NewState)
Enables or disables the specified CAN Rx message buffer interrupts.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
BUF_IT – Specifies the CAN interrupts sources to be enabled or disabled.
NewState – New state of the specified CAN interrupts. This parameter can be: ENABLE or DISABLE.
-
void CAN_TxDoneStatusClear(CAN_TypeDef *CANx, u32 Status)
Clear CAN tx done status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
Status – Clear status.
-
u32 CAN_TxDoneStatusGet(CAN_TypeDef *CANx)
Get CAN tx done status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
CAN TX done status bitmask, each bit represents one message buffer TX completion status.
-
void CAN_TxMsgBufErrClear(CAN_TypeDef *CANx, u32 ERR_FLAG)
Clear tx message buffer error status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
ERR_FLAG – The specified error flag.
-
u32 CAN_TxMsgBufErrGet(CAN_TypeDef *CANx)
Get tx message buffer error status.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
- Returns:
Tx message error status
-
void CAN_TxMsgBufINTConfig(CAN_TypeDef *CANx, u32 BUF_IT, u32 NewState)
Enables or disables the specified CAN Tx message buffer interrupts.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
BUF_IT – Specifies the CAN interrupts sources to be enabled or disabled.
NewState – New state of the specified CAN interrupts. This parameter can be: ENABLE or DISABLE.
-
void CAN_TxMsgTriggerCmd(CAN_TypeDef *CANx, u32 State)
CAN TX message trigger ENABLE or DISABLE.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
State – New state of the TX trigger. This parameter can be: ENABLE or DISABLE.
-
void CAN_TxMsgTriggerConfig(CAN_TypeDef *CANx, u32 CloseOffset, u32 Begin)
CAN TX message trigger configure.
- Parameters:
CANx – Where CANx can be CAN0 or CAN1.
CloseOffset – Close offset.
Begin – Trigger begin.