UTILS FDCAN How to Use ¶
- group UTILS_FDCAN_How_To_Use
-
How to use the UTILS FDCAN Timing module ¶
This module provides utility functions for FDCAN timing calculations covering two main use cases:
A. Computation of Bit Timings from Bus Parameters ¶
Compute the FDCAN bit timing parameters (prescaler, time segments, etc.) from desired bus parameters such as bitrate, sample point, and clock frequency.
Steps:
Fill a
stm32_utils_fdcan_input_bus_param_tstructure with the desired bus parameters:FDCAN kernel clock (kHz)
Desired bitrate (kbit/s)
Desired sample point (per mille)
Maximum allowed bitrate tolerance (per mille)
Call
STM32_UTILS_FDCAN_ComputeBitTiming()with:Pointer to input bus parameters
Bit timing type (nominal or data)
Pointer to a
stm32_utils_fdcan_bit_timing_tstructure to receive the computed timingsPointer to a
stm32_utils_fdcan_output_config_tstructure to receive the real bus parameters
Apply the computed timings to the FDCAN peripheral configuration:
Fill a
hal_fdcan_nominal_bit_timing_torhal_fdcan_data_bit_timing_tstructure with the computed values.Call
HAL_FDCAN_SetConfig()or dedicated functionsHAL_FDCAN_SetNominalBitTiming()andHAL_FDCAN_SetDataBitTiming()to apply the timing settings.
B. Computation of Bus Parameters from Bit Timings ¶
Compute the resulting bus parameters (bitrate, sample point) from known bit timing parameters (prescaler, time segments, etc.).
Steps:
Fill a
stm32_utils_fdcan_bit_timing_tstructure with the bit timing values:Prescaler
Time segment 1
Time segment 2
Synchronization jump width
Remark: Use the functions
HAL_FDCAN_GetNominalBitTiming()orHAL_FDCAN_GetDataBitTiming()to retrieve the current bit timing settings.
Call
STM32_UTILS_FDCAN_ComputeBitrate()with:Pointer to the bit timing structure
FDCAN kernel clock (kHz)
Pointer to a
stm32_utils_fdcan_output_config_tstructure to receive the computed bus parameters
Use the computed bus parameters as needed in the application.