Classes | Macros | Enumerations | Functions
canard_stm32.h File Reference
#include <canard.h>
#include <string.h>
Include dependency graph for canard_stm32.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CanardSTM32AcceptanceFilterConfiguration
 
struct  CanardSTM32CANTimings
 
struct  CanardSTM32Stats
 

Macros

#define CANARD_STM32_DEBUG_INNER_PRIORITY_INVERSION   1
 
#define CANARD_STM32_ERROR_MSR_INAK_NOT_CLEARED   1002
 
#define CANARD_STM32_ERROR_MSR_INAK_NOT_SET   1001
 
#define CANARD_STM32_ERROR_UNSUPPORTED_BIT_RATE   1000
 
#define CANARD_STM32_ERROR_UNSUPPORTED_FRAME_FORMAT   1003
 
#define CANARD_STM32_NUM_ACCEPTANCE_FILTERS   14U
 
#define CANARD_STM32_USE_CAN2   0
 

Enumerations

enum  CanardSTM32IfaceMode { CanardSTM32IfaceModeNormal, CanardSTM32IfaceModeSilent, CanardSTM32IfaceModeAutomaticTxAbortOnError }
 

Functions

static int16_t canardSTM32ComputeCANTimings (const uint32_t peripheral_clock_rate, const uint32_t target_bitrate, CanardSTM32CANTimings *const out_timings)
 
int16_t canardSTM32ConfigureAcceptanceFilters (const CanardSTM32AcceptanceFilterConfiguration *const filter_configs, const uint8_t num_filter_configs)
 
CanardSTM32Stats canardSTM32GetStats (void)
 
int16_t canardSTM32Init (const CanardSTM32CANTimings *const timings, const CanardSTM32IfaceMode iface_mode)
 
int16_t canardSTM32Receive (CanardCANFrame *const out_frame)
 
int16_t canardSTM32Transmit (const CanardCANFrame *const frame)
 

Macro Definition Documentation

◆ CANARD_STM32_DEBUG_INNER_PRIORITY_INVERSION

#define CANARD_STM32_DEBUG_INNER_PRIORITY_INVERSION   1

Trigger an assertion failure if inner priority inversion is detected at run time. This setting has no effect in release builds, where NDEBUG is defined.

Definition at line 34 of file canard_stm32.h.

◆ CANARD_STM32_ERROR_MSR_INAK_NOT_CLEARED

#define CANARD_STM32_ERROR_MSR_INAK_NOT_CLEARED   1002

Definition at line 43 of file canard_stm32.h.

◆ CANARD_STM32_ERROR_MSR_INAK_NOT_SET

#define CANARD_STM32_ERROR_MSR_INAK_NOT_SET   1001

Definition at line 42 of file canard_stm32.h.

◆ CANARD_STM32_ERROR_UNSUPPORTED_BIT_RATE

#define CANARD_STM32_ERROR_UNSUPPORTED_BIT_RATE   1000

Driver error codes. These values are returned negated from API functions that return int.

Definition at line 41 of file canard_stm32.h.

◆ CANARD_STM32_ERROR_UNSUPPORTED_FRAME_FORMAT

#define CANARD_STM32_ERROR_UNSUPPORTED_FRAME_FORMAT   1003

Definition at line 44 of file canard_stm32.h.

◆ CANARD_STM32_NUM_ACCEPTANCE_FILTERS

#define CANARD_STM32_NUM_ACCEPTANCE_FILTERS   14U

This is defined by the bxCAN hardware. Devices with only one CAN interface have 14 filters (e.g. F103). Devices with two CAN interfaces have 28 filters, which are shared between two interfaces (e.g. F105, F446). The filters are distributed between CAN1 and CAN2 by means of the CAN2 start filter bank selection, which is a number from 1 to 27 inclusive. Seeing as the start bank cannot be set to 0, CAN2 has one filter less to use.

Definition at line 54 of file canard_stm32.h.

◆ CANARD_STM32_USE_CAN2

#define CANARD_STM32_USE_CAN2   0

Set this build config macro to 1 to use CAN2 instead of CAN1, if available. Setting this parameter when CAN2 is not available may not be detected at compile time!

Definition at line 26 of file canard_stm32.h.

Enumeration Type Documentation

◆ CanardSTM32IfaceMode

The interface can be initialized in either of these modes.

The Silent mode is useful for automatic CAN bit rate detection, where the interface is initialized at an arbitrarily guessed CAN bit rate (typically either 1 Mbps, 500 Kbps, 250 Kbps, or 125 Kbps, these are the standard values defined by the UAVCAN specification), and the bus is then listened for 1 second in order to determine whether the bit rate was guessed correctly. It is paramount to use the silent mode in this case so as to not interfere with ongoing communications on the bus if the guess was incorrect.

The automatic TX abort on error mode should be used during dynamic node ID allocation. The reason for that is well explained in the UAVCAN specification, please read it.

The normal mode should be used for all other use cases, particularly for the normal operation of the node, hence the name.

Enumerator
CanardSTM32IfaceModeNormal 

Normal mode.

CanardSTM32IfaceModeSilent 

Do not affect the bus, only listen.

CanardSTM32IfaceModeAutomaticTxAbortOnError 

Abort pending TX if a bus error has occurred.

Definition at line 71 of file canard_stm32.h.

Function Documentation

◆ canardSTM32ComputeCANTimings()

static int16_t canardSTM32ComputeCANTimings ( const uint32_t  peripheral_clock_rate,
const uint32_t  target_bitrate,
CanardSTM32CANTimings *const  out_timings 
)
inlinestatic

Given the rate of the clock supplied to the bxCAN macrocell (typically PCLK1) and the desired bit rate, this function iteratively solves for the best possible timing settings. The CAN bus timing parameters, such as the sample point location, the number of time quantas per bit, etc., are optimized according to the recommendations provided in the specifications of UAVCAN, DeviceNet, and CANOpen.

Unless noted otherwise, all units are SI units; particularly, frequency is specified in hertz.

The implementation is adapted from libuavcan.

This function is defined in the header in order to encourage the linker to discard it if it is not used.

Return values
0Success
negativeSolution could not be found for the provided inputs.

Definition at line 190 of file canard_stm32.h.

◆ canardSTM32ConfigureAcceptanceFilters()

int16_t canardSTM32ConfigureAcceptanceFilters ( const CanardSTM32AcceptanceFilterConfiguration *const  filter_configs,
const uint8_t  num_filter_configs 
)

Sets up acceptance filters according to the provided list of ID and masks. Note that when the interface is reinitialized, hardware acceptance filters are reset. Also note that during filter reconfiguration, some RX frames may be lost.

Setting zero filters will result in rejection of all frames. In order to accept all frames, set one filter with ID = Mask = 0, which is also the default configuration.

Return values
0Success
negativeError

Definition at line 449 of file canard_stm32.c.

◆ canardSTM32GetStats()

CanardSTM32Stats canardSTM32GetStats ( void  )

Returns the running interface statistics.

Definition at line 565 of file canard_stm32.c.

◆ canardSTM32Init()

int16_t canardSTM32Init ( const CanardSTM32CANTimings *const  timings,
const CanardSTM32IfaceMode  iface_mode 
)

Initializes the CAN controller at the specified bit rate. The mode can be either normal, silent, or auto-abort on error; in silent mode the controller will be only listening, not affecting the state of the bus; in the auto abort mode the controller will cancel the pending transmissions if a bus error is encountered. The auto abort mode is needed for dynamic node ID allocation procedure; please refer to the UAVCAN specification for more information about this topic.

This function can be invoked any number of times; every invocation re-initializes everything from scratch.

WARNING: The clock of the CAN module must be enabled before this function is invoked! If CAN2 is used, CAN1 must be also enabled!

WARNING: The driver is not thread-safe! It does not use IRQ or critical sections though, so it is safe to invoke its API functions from the IRQ context from the application.

Return values
0Success
negativeError

Definition at line 168 of file canard_stm32.c.

◆ canardSTM32Receive()

int16_t canardSTM32Receive ( CanardCANFrame *const  out_frame)

Reads one frame from the hardware RX FIFO, unless all FIFO are empty. This function does never block.

Return values
1Read successfully
0The buffer is empty
negativeError

Definition at line 387 of file canard_stm32.c.

◆ canardSTM32Transmit()

int16_t canardSTM32Transmit ( const CanardCANFrame *const  frame)

Pushes one frame into the TX buffer, if there is space. Note that proper care is taken to ensure that no inner priority inversion is taking place. This function does never block.

Return values
1Transmitted successfully
0No space in the buffer
negativeError

Definition at line 281 of file canard_stm32.c.



uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03