STM32 FDCAN Example: conflicting settings for bitrate switching?

Hello,
I've been trying to setup and test CAN-FD communication (with bitrate switching) between two STM32 microcontrollers with a built-in CAN-FD peripheral, and started by following this example from Mathworks.
The example sets the CAN-FD timing parameters in STM32CubeMX for a nominal rate of 1 Mbps and a data rate of 2.5 Mbps. On the other hand, it is asking to set the "Frame Format" parameter in STM32CubeMX to "FD mode without BitRate Switching".
Setting the Frame Format to "...without BitRate Switching" would cause the FDCAN_CCCR.BRSE bit to be 0, and based on STM32 documentation (e.g. STM32H7 reference manual): "With FDCAN_CCCR.FDOE = 1 and FDCAN_CCCR.BRSE = 0, only bit FDF of a Tx buffer element is evaluated. With FDCAN_CCCR.FDOE = 1 and FDCAN_CCCR.BRSE = 1, transmission of CAN FD frames with bitrate switching is enabled."
So it seems like the Frame Format setting will override the different bit rates, and the generated application will communicate at a fixed rate of 1 Mbps. Is this an error in the instructions given for the example, or am I missing something?

3 Comments

AI says that you are completely correct, and you have spotted a genuine contradiction in that MathWorks example documentation.
Contact support for confirmation:
Hi Ali,
This is a valid point and would be best addressed by MathWorks Technical Support. I recommend contacting Technical Support directly: https://www.mathworks.com/support/contact_us.html
Thanks.
@Mohammed Shaheen & @Torsten Thanks for your comments. I'll reach out to the support team.

Sign in to comment.

 Accepted Answer

Thank you, your analysis is correct.
Setting "FD mode without BitRate Switching" in STM32CubeMX sets FDCAN_CCCR.BRSE = 0 at initialization, permanently disabling BitRate Switching at the hardware level. The Data baud rate (2.5 Mbps) configured in CubeMX is silently ignored and the entire frame transmits at the nominal rate (1 Mbps). Even the "Enable bit rate switching" checkbox on the FDCAN Write block has no effect when CCCR.BRSE = 0, both must be set together.
To correctly enable CAN-FD with BitRate Switching:
  1. STM32CubeMX: Set FrameFormat to "FD mode with Bit Rate Switching".
  2. FDCAN Write block: Enable "Enable bit rate switching".
This is an error in the example documentation and has been logged for correction in a future release. In the meantime, refer to the "Interrupt Based with HTS221 Sensor Data" section of the same example, which correctly demonstrates this configuration.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!