On 02.11.2021 16:03:33, Matthias Weißer wrote: > we recently had a case here where one member of a CAN bus couldn't > receive frames with data content of only zeros: > > $ cansend can0 123#0000000000000000 > > After some investigation we found the root cause to be a slight > difference (about 1%) in actual bitrates of the two members. The one > with showed the RX errors had a sjw value of 1 and a lot of time > quanta (40) due to the 40MHz CAN clock. > > This leads to a build up of phase error (as sjw is not able to > compensate for enough of the bitrate difference) which at some point > leads to a framing error due to missing a stuff bit. Playing around > with the sample point can improve or worsen the behavior. > > We can fix this quite easily by specifying a higher sjw value. We have seen this behavior, too. :( > Question is now: > Wouldn't it make sense to increase sjw in can_calc_bittiming() to > something like 5% of the total time quanta? You mean of the total bit time? The problem is that the SJW is set to 1 time quanta by default. For a given bit rate the time quanta is not a constant value, but depends on the oscillator frequency and configured bit rate prescaler. As you suggested, I agree a better solution would be to set the SJW to a certain percentage of the bit time. But, what is a proper default value of a percentage based SJW? > This may increase the reliability of the CAN network when there are > differences in the bitrates of the single members. Are there any > arguments against such an arbitrary selection of sjw? > > If you agree with such a change I can come up with a proper patch. If > I wrote totally nonsense please tell me :-) I'm interested in a patch. There are some requirements and thoughts: - introduce a define for the default SJW percentage value - use the default SJW percentage value if the user has not provided a SJW - the "struct can_bittiming" cannot be modified In a later patch we can introduce a configuration interface to set SJW percentage value from user space. regards, Marc -- Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |