From 30f0467491bdb704ee7c844c5bd293adf943883b Mon Sep 17 00:00:00 2001 From: fastbike Date: Mon, 29 Apr 2024 20:33:36 +1200 Subject: [PATCH] Fix for https://github.com/arduino/ArduinoCore-renesas/issues/295 to allow flexible bit rate either one of the 4 predefined rates or a custom rate --- libraries/Arduino_CAN/src/R7FA4M1_CAN.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/Arduino_CAN/src/R7FA4M1_CAN.cpp b/libraries/Arduino_CAN/src/R7FA4M1_CAN.cpp index c53f4494..95241ec5 100644 --- a/libraries/Arduino_CAN/src/R7FA4M1_CAN.cpp +++ b/libraries/Arduino_CAN/src/R7FA4M1_CAN.cpp @@ -161,7 +161,7 @@ bool R7FA4M1_CAN::begin(uint32_t const can_bitrate) /* Calculate the CAN bitrate based on the value of this functions parameter. */ - static uint32_t const F_CAN_CLK_Hz = 24*1000*1000UL; + static uint32_t const F_CAN_CLK_Hz = 24*1000*1000UL; static uint32_t const TQ_MIN = 8; static uint32_t const TQ_MAX = 25; static uint32_t const TSEG_1_MIN = 4; @@ -172,7 +172,7 @@ bool R7FA4M1_CAN::begin(uint32_t const can_bitrate) auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] = util::calc_can_bit_timing(can_bitrate, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX); init_ok &= is_valid_baudrate; - + if (is_valid_baudrate) { _can_bit_timing_cfg.baud_rate_prescaler = baud_rate_prescaler; _can_bit_timing_cfg.time_segment_1 = time_segment_1; @@ -187,6 +187,7 @@ bool R7FA4M1_CAN::begin(uint32_t const can_bitrate) return init_ok; } +//////////////////////// void R7FA4M1_CAN::end() { R_CAN_Close(&_can_ctrl);