10 #define CANARD_STM32_H
25 #if !defined(CANARD_STM32_USE_CAN2)
26 # define CANARD_STM32_USE_CAN2 0
33 #if !defined(CANARD_STM32_DEBUG_INNER_PRIORITY_INVERSION)
34 # define CANARD_STM32_DEBUG_INNER_PRIORITY_INVERSION 1
41 #define CANARD_STM32_ERROR_UNSUPPORTED_BIT_RATE 1000
42 #define CANARD_STM32_ERROR_MSR_INAK_NOT_SET 1001
43 #define CANARD_STM32_ERROR_MSR_INAK_NOT_CLEARED 1002
44 #define CANARD_STM32_ERROR_UNSUPPORTED_FRAME_FORMAT 1003
54 #define CANARD_STM32_NUM_ACCEPTANCE_FILTERS 14U
167 const uint8_t num_filter_configs);
194 if (target_bitrate < 1000)
199 CANARD_ASSERT(out_timings !=
NULL);
200 memset(out_timings, 0,
sizeof(*out_timings));
205 static const uint8_t MaxBS1 = 16;
206 static const uint8_t MaxBS2 = 8;
219 const uint8_t max_quanta_per_bit = (
uint8_t)((target_bitrate >= 1000000) ? 10 : 17);
220 CANARD_ASSERT(max_quanta_per_bit <= (MaxBS1 + MaxBS2));
222 static const uint16_t MaxSamplePointLocationPermill = 900;
234 const uint32_t prescaler_bs = peripheral_clock_rate / target_bitrate;
241 while ((prescaler_bs % (1U + bs1_bs2_sum)) != 0)
243 if (bs1_bs2_sum <= 2)
250 const uint32_t prescaler = prescaler_bs / (1U + bs1_bs2_sum);
251 if ((prescaler < 1U) || (prescaler > 1024U))
277 CANARD_ASSERT(bs1_bs2_sum > bs1);
280 const uint16_t sample_point_permill = (
uint16_t)(1000U * (1U + bs1) / (1U + bs1 + bs2));
282 if (sample_point_permill > MaxSamplePointLocationPermill)
284 bs1 = (
uint8_t)((7 * bs1_bs2_sum - 1) / 8);
285 bs2 = (
uint8_t)(bs1_bs2_sum - bs1);
289 const bool valid = (bs1 >= 1) && (bs1 <= MaxBS1) && (bs2 >= 1) && (bs2 <= MaxBS2);
299 if ((target_bitrate != (peripheral_clock_rate / (prescaler * (1U + bs1 + bs2)))) ||