Skip to main content

CAN & CAN FD

LibXR supports both standard CAN and CAN FD. You need to enable the respective peripherals and interrupts in STM32CubeMX, and allocate at least one filter for both standard and extended frames.

Default Filters and FIFO Configuration

LibXR configures one default filter for each CAN/CAN FD controller, separately for standard and extended frames, allowing all data frames to pass through.

The FIFO configuration for different numbers of CAN/CAN FD controllers is as follows:

Classic CANCAN1CAN1+CAN2CAN1+CAN2+CAN3
FIFO0CAN1CAN1CAN1+CAN2
FIFO1N/ACAN2CAN3
CAN FDCANFD1CANFD1+CANFD2CANFD1+CANFD2+CANFD3
FIFO0CANFD1CANFD1CANFD1
FIFO1N/ACANFD2CANFD2+CANFD3

Example

The second parameter represents the transmission queue size, which buffers outgoing messages.

STM32CAN can1(&hcan1, 5);
STM32CANFD fdcan1(&hfdcan1, 5);

Configuration File

After code generation, the following CAN-related configuration will be added to User/libxr_config.yaml:

CAN:
CAN1:
queue_size: 5

FDCAN:
FDCAN1:
queue_size: 5
  • queue_size: The size of the transmit queue for the CAN/FDCAN interface.

To apply changes, modify this file directly and run:
xr_cubemx_cfg -d .
or
xr_gen_code_stm32 -i ./.config.yaml -o ./User/app_main.cpp