modm API documentation

FDCAN2 (CAN with Flexible Data-Rate) More...

#include <modm/platform/can/can_2.hpp>

Inheritance diagram for modm::platform::Fdcan2:
modm::Can modm::PeripheralDriver

Public Typedefs

using ErrorCallback = void (*)()
 
using FilterConfig = MessageRam::FilterConfig
 

Public Types

enum  Mode : uint32_t {
  Normal, Restricted, Monitoring, Sleep,
  TestExternalLoopback, TestInternalLoopback, ListenOnly = Monitoring, LoopBack = TestInternalLoopback
}
 
enum  BusState : uint8_t { BusState::Connected = 0, BusState::ErrorWarning = 1, BusState::ErrorPassive = 2, Off = 3 }
 

Static Public Member Functions

template<class... Signals>
static void connect (Gpio::InputType inputType=Gpio::InputType::Floating)
 
template<class SystemClock , bitrate_t bitrate = kbps(125), percent_t tolerance = pct(1), bitrate_t fastDataBitrate = 0>
static void initialize (uint32_t interruptPriority, Mode startupMode=Mode::Normal, bool overwriteOnOverrun=true)
 
static void setMode (Mode mode)
 
static void setAutomaticRetransmission (bool retransmission)
 
static bool isMessageAvailable ()
 
static bool isReadyToSend ()
 
static bool getMessage (can::Message &message, uint8_t *filter_id=nullptr, uint16_t *timestamp=nullptr)
 
static bool sendMessage (const can::Message &message)
 
static bool setStandardFilter (uint8_t standardIndex, FilterConfig config, modm::can::StandardIdentifier id, modm::can::StandardMask mask)
 
static bool setStandardFilter (uint8_t standardIndex, FilterConfig config, modm::can::StandardIdentifier id0, modm::can::StandardIdentifier id1)
 
static bool setStandardRangeFilter (uint8_t standardIndex, FilterConfig config, modm::can::StandardIdentifier first, modm::can::StandardIdentifier last)
 
static bool setExtendedFilter (uint8_t extendedIndex, FilterConfig config, modm::can::ExtendedIdentifier id, modm::can::ExtendedMask mask)
 
static bool setExtendedFilter (uint8_t extendedIndex, FilterConfig config, modm::can::ExtendedIdentifier id0, modm::can::ExtendedIdentifier id1)
 
static bool setExtendedRangeFilter (uint8_t extendedIndex, FilterConfig config, modm::can::ExtendedIdentifier first, modm::can::ExtendedIdentifier last)
 
static void clearStandardFilters ()
 Disable all standard filters, receive no standard frames.
 
static void clearExtendedFilters ()
 Disable all extended filters, receive no extended frames.
 
static uint8_t getReceiveErrorCounter ()
 
static uint8_t getTransmitErrorCounter ()
 
static BusState getBusState ()
 
static void setErrorInterruptCallback (ErrorCallback callback)
 
static ErrorCallback getErrorInterruptCallback ()
 
static uint16_t getCurrentTimestamp ()
 
static void acknowledgeInterruptFlag ()
 
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 
template<double available, double requested, percent_t tolerance>
static void assertDurationInTolerance ()
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
template<class... Signals>
static void connect ()
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static bool getMessage (can::Message &message)
 Returns true if a message was copied into the message buffer.
 
static void getParameter ()
 returns a parameter
 
template<class SystemClock , bitrate_t bitrate = 125_kbps, percent_t tolerance = 1_pct>
static void initialize (Mode startupMode)
 
static void initialize ()
 initializes the peripheral, must be called before use.
 
static void setParameter ()
 sets a parameter
 

Static Public Attributes

static constexpr size_t RxBufferSize = 32
 
static constexpr size_t TxBufferSize = 32
 
static constexpr uint8_t StandardFilterCount = MessageRam::StandardFilterCount
 
static constexpr uint8_t ExtendedFilterCount = MessageRam::ExtendedFilterCount
 

Detailed Description

FDCAN2 (CAN with Flexible Data-Rate)

The controller area network (CAN) subsystem consists of one CAN module, a shared Message RAM memory and a configuration block. The modules (FDCAN) are compliant with ISO 11898-1: 2015 (CAN protocol specification version 2.0 part A, B) and CAN FD protocol specification version 1.0. A Message RAM implements filters, receive FIFOs, transmit event FIFOs and transmit FIFOs. The RAM is 0.8 Kbyte per FDCAN instance, except for the H7 series, which has 10 Kbytes of total message RAM arbitrarily split between FDCAN instances.

This driver supports SW-managed/in-memory FIFOs which augment the hardware TX and RX FIFOs. Note that the HW TX queue defaults to FIFO order but can be configured to transmit the highest priority (lowest arbitration ID) frames first.

Filter

Up to 28 filters can be defined for 11-bit IDs, up to 8 filters for 29-bit IDs. The filter banks are not shared between the CAN instances.

Configuration

You can set the in-memory (SW-managed) buffer size using the buffer.tx and buffer.rx parameters. If set to 0, filling a HW FIFO will immediately drop frames.

The tx_hw_queue_mode configures the order in which frames are transmitted from the hardware buffers. "FIFO" transmits in the order frames were enqueued. "Priority" transmits the message with the lowest arbitration ID first.

Author
Raphael Lehmann raphael@rleh.de
Christopher Durand christopher.durand@rwth-aachen.de
Kaelin Laundry wasabifan@outlook.com

Member Enumeration Documentation

enum modm::Can::BusState : uint8_t
inheritedstrong
Enum ValuesDocumentation
Connected 

This bit is set by hardware when the warning limit has been reached (Receive Error Counter or Transmit Error Counter ≥ 96).

ErrorWarning 

This bit is set by hardware when the Error Passive limit has been reached (Receive Error Counter or Transmit Error Counter > 127).

ErrorPassive 

This bit is set by hardware when it enters the bus-off state. The bus-off state is entered on TEC overflow, greater than 255

Member Function Documentation

static void modm::PeripheralDriver::acknowledgeInterruptFlag ( )
inheritedstatic

Acknowledge an interrupt flag.

We use acknowledge here, since it describes the intention rather than the actual implementation.

template<uint64_t available, uint64_t requested, percent_t tolerance>
static void modm::PeripheralDriver::assertBaudrateInTolerance ( )
inheritedinlinestatic

Since baudrates are usually generated by prescaling a system clock, only several distinct values can be generated. This method checks if the user requested baudrate is within error tolerance of the system achievable baudrate.

template<class... Signals>
static void modm::Can::connect ( )
inheritedstatic

Configures the Tx and Rx signals and connects them.

Template Parameters
SignalsOne Tx and one Rx signal are required and can be passed out-of-order.
static uint8_t modm::platform::Fdcan2::getReceiveErrorCounter ( )
inlinestatic

Get Receive Error Counter.

In case of an error during reception, this counter is incremented by 1 or by 8 depending on the error condition as defined by the CAN standard. After every successful reception the counter is decremented by 1 or reset to 120 if its value was higher than 128. When the counter value exceeds 127, the CAN controller enters the error passive state.

static uint8_t modm::platform::Fdcan2::getTransmitErrorCounter ( )
inlinestatic

Get Transmit Error Counter.

template<class SystemClock , bitrate_t bitrate = 125_kbps, percent_t tolerance = 1_pct>
static void modm::Can::initialize ( Mode  startupMode)
inheritedstatic

Initializes the hardware and sets the baudrate.

Template Parameters
SystemClockthe currently active system clock
bitratethe desired bitrate in Hz
tolerancethe allowed relative tolerance for the resulting baudrate
template<class SystemClock , bitrate_t bitrate = kbps(125), percent_t tolerance = pct(1), bitrate_t fastDataBitrate = 0>
static void modm::platform::Fdcan2::initialize ( uint32_t  interruptPriority,
Mode  startupMode = Mode::Normal,
bool  overwriteOnOverrun = true 
)
inlinestatic

Enables the clock for the CAN controller and resets all settings

Template Parameters
SystemClockSystem clock struct with an FDCAN2 member containing the clock speed supplied to the peripheral.
Warning
The CAN subsystem prescaler can be configured using the RCC module and must be taken into account in the provided clock speed value.
Template Parameters
bitrateNominal CAN bitrate
toleranceMaximum relative deviation between requested and resulting CAN bitrates. If the tolerance is exceeded a compile-time assertion will be triggered.
fastDataBitrateCAN bitrate for data in FD frames with bit rate switching Set to 0 to disable CANFD support.
Parameters
interruptPriorityInterrupt vector priority (0=highest to 15=lowest)
startupModeMode of operation set after initialization
See also
Fdcan2::Mode
Parameters
overwriteOnOverrunOnce a receive FIFO is full the next incoming message will overwrite the previous one if true otherwise the incoming message will be discarded
Warning
Has to called after connect(), but before any other function from this class!
static void modm::platform::Fdcan2::setErrorInterruptCallback ( ErrorCallback  callback)
inlinestatic

Set the error interrupt callback.

It will be called on the following events:

  • The FDCAN peripheral enters ERROR_PASSIVE or BUS_OFF state
  • The error counter exceeds the warning limit

To disable the interrupt set the callback to nullptr.

bool modm::platform::Fdcan2::setExtendedFilter ( uint8_t  extendedIndex,
FilterConfig  config,
modm::can::ExtendedIdentifier  id,
modm::can::ExtendedMask  mask 
)
static

Set extended filter with id and mask

Parameters
extendedIndexExtended filter index 0..7
Returns
true if filter index is valid
bool modm::platform::Fdcan2::setExtendedFilter ( uint8_t  extendedIndex,
FilterConfig  config,
modm::can::ExtendedIdentifier  id0,
modm::can::ExtendedIdentifier  id1 
)
static

Set standard filter with dual ids Matches on any of both specified ids

Parameters
extendedIndexExtended filter index 0..7
Returns
true if filter index is valid
bool modm::platform::Fdcan2::setExtendedRangeFilter ( uint8_t  extendedIndex,
FilterConfig  config,
modm::can::ExtendedIdentifier  first,
modm::can::ExtendedIdentifier  last 
)
static

Set standard range filter Matches the inclusive range between both specified ids

Parameters
extendedIndexExtended filter index 0..7
Returns
true if filter index is valid
void modm::platform::Fdcan2::setMode ( Mode  mode)
static

Set the operating mode.

Default after initialization is the normal mode.

bool modm::platform::Fdcan2::setStandardFilter ( uint8_t  standardIndex,
FilterConfig  config,
modm::can::StandardIdentifier  id,
modm::can::StandardMask  mask 
)
static

Set standard filter with id and mask

Parameters
standardIndexStandard filter index 0..27
Returns
true if filter index is valid
bool modm::platform::Fdcan2::setStandardFilter ( uint8_t  standardIndex,
FilterConfig  config,
modm::can::StandardIdentifier  id0,
modm::can::StandardIdentifier  id1 
)
static

Set standard filter with dual ids Matches on any of both specified ids

Parameters
standardIndexStandard filter index 0..27
Returns
true if filter index is valid
bool modm::platform::Fdcan2::setStandardRangeFilter ( uint8_t  standardIndex,
FilterConfig  config,
modm::can::StandardIdentifier  first,
modm::can::StandardIdentifier  last 
)
static

Set standard range filter Matches the inclusive range between both specified ids

Parameters
standardIndexStandard filter index 0..27
Returns
true if filter index is valid

The documentation for this class was generated from the following files: