PER Firmware
Loading...
Searching...
No Matches
fdcan.h File Reference

G4 FDCAN public API implementation. More...

#include <stdint.h>
#include "stm32g474xx.h"
Include dependency graph for fdcan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CanMsgTypeDef_t
 Classic CAN frame. More...
 

Enumerations

enum  PHAL_FDCAN_BaudRate_t : uint32_t { FDCAN_BAUD_250K = 250000U , FDCAN_BAUD_500K = 500000U , FDCAN_BAUD_1M = 1000000U }
 Supported baud rates for PER G4 FDCAN HAL. More...
 

Functions

void PHAL_FDCAN_init (FDCAN_GlobalTypeDef *fdcan, PHAL_FDCAN_BaudRate_t bit_rate)
 Initialize an FDCAN peripheral for classic (non-FD) CAN operation.
 
bool PHAL_FDCAN_setFilters (FDCAN_GlobalTypeDef *fdcan, const uint32_t *sid_list, uint32_t num_sid, const uint32_t *xid_list, uint32_t num_xid)
 Configure exact-match acceptance filters for RX FIFO0.
 
bool PHAL_FDCAN_send (CanMsgTypeDef_t *msg)
 Queue a frame for transmission.
 
bool PHAL_FDCAN_txFifoFree (const FDCAN_GlobalTypeDef *fdcan)
 Check whether the TX FIFO has at least one free slot.
 
void PHAL_FDCAN_rxCallback (CanMsgTypeDef_t *msg)
 Weak callback fired once per received frame.
 
void PHAL_FDCAN_txCallback (FDCAN_GlobalTypeDef *fdcan)
 Weak callback fired when a queued frame finishes transmitting.
 

Variables

static constexpr uint32_t PHAL_FDCAN_MAX_NUM_SID_FILTER = 28
 
static constexpr uint32_t PHAL_FDCAN_MAX_NUM_XID_FILTER = 8
 

Detailed Description

G4 FDCAN public API implementation.

Author
Millan Kumar (kumar.nosp@m.798@.nosp@m.purdu.nosp@m.e.ed.nosp@m.u)

Enumeration Type Documentation

◆ PHAL_FDCAN_BaudRate_t

enum PHAL_FDCAN_BaudRate_t : uint32_t

Supported baud rates for PER G4 FDCAN HAL.

Enumerator
FDCAN_BAUD_250K 
FDCAN_BAUD_500K 
FDCAN_BAUD_1M 

Function Documentation

◆ PHAL_FDCAN_init()

void PHAL_FDCAN_init ( FDCAN_GlobalTypeDef * fdcan,
PHAL_FDCAN_BaudRate_t bit_rate )

Initialize an FDCAN peripheral for classic (non-FD) CAN operation.

  • Setups up FDCAN clock (from PCLK1)
  • ~87.5% sample point
  • Classic CAN mode (FD/BRS off), auto-retransmission enabled, TX pause on
  • TX FIFO mode
  • RX FIFO0 new message (line 0) and TX complete interrupts (line 1)
  • Sets filter to accept everything into RX FIFO0
    • Use PHAL_FDCAN_setFilters later
Parameters
fdcanPeripheral instance (FDCAN1/2/3)
bit_ratedesired bit rate in bits per second
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PHAL_FDCAN_rxCallback()

void PHAL_FDCAN_rxCallback ( CanMsgTypeDef_t * msg)
extern

Weak callback fired once per received frame.

Called from FDCANx_IT0_IRQHandler (interrupt context) for every frame popped from RX FIFO0.

Default implementation does nothing.

Parameters
msgthe received frame (valid only for the duration of the call)
Here is the caller graph for this function:

◆ PHAL_FDCAN_send()

bool PHAL_FDCAN_send ( CanMsgTypeDef_t * msg)

Queue a frame for transmission.

Non-blocking: if the TX FIFO is already full this returns false instead of blocking/waiting.

Parameters
msgframe to send; sent on msg->Bus peripheral
Returns
true if the frame was queued; false if the TX FIFO is full
Here is the call graph for this function:

◆ PHAL_FDCAN_setFilters()

bool PHAL_FDCAN_setFilters ( FDCAN_GlobalTypeDef * fdcan,
const uint32_t * sid_list,
uint32_t num_sid,
const uint32_t * xid_list,
uint32_t num_xid )

Configure exact-match acceptance filters for RX FIFO0.

Every ID in sid_list/xid_list is matched exactly. Any message whose ID is not in either list is rejected.

Note: this replaces any previously existing filter configurations

Parameters
fdcanPeripheral instance (FDCAN1/2/3)
sid_listarray of standard (11-bit) IDs to accept; may be NULL if num_sid == 0
num_sidnumber of entries in sid_list, up to MAX_NUM_SID_FILTER allowed
xid_listarray of extended (29-bit) IDs to accept; may be NULL if num_xid == 0
num_xidnumber of entries in xid_list, up to MAX_NUM_XID_FILTER allowed
Returns
true on success; false if num_sid or num_xid exceeds its max
Here is the call graph for this function:

◆ PHAL_FDCAN_txCallback()

void PHAL_FDCAN_txCallback ( FDCAN_GlobalTypeDef * fdcan)
extern

Weak callback fired when a queued frame finishes transmitting.

Called from FDCANx_IT1_IRQHandler (interrupt context).

Default implementation does nothing.

Parameters
fdcanthe peripheral instance that completed a transmission
Here is the caller graph for this function:

◆ PHAL_FDCAN_txFifoFree()

bool PHAL_FDCAN_txFifoFree ( const FDCAN_GlobalTypeDef * fdcan)

Check whether the TX FIFO has at least one free slot.

Parameters
fdcanperipheral instance
Returns
true if a slot is free
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ PHAL_FDCAN_MAX_NUM_SID_FILTER

uint32_t PHAL_FDCAN_MAX_NUM_SID_FILTER = 28
staticconstexpr

◆ PHAL_FDCAN_MAX_NUM_XID_FILTER

uint32_t PHAL_FDCAN_MAX_NUM_XID_FILTER = 8
staticconstexpr