can: mcp251xfd: make TDC controllable from userspace
Subsystems (2)
PATCH 1/1 can: mcp251xfd: make TDC controllable from userspace
TDC is currently hardcoded enabled so lower CAN FD data bitrates result in a bus-off condition. This patch allows userspace to control TDC as needed.
Demonstration of the feature in action:
$ ip link set can0 down
$ ip link set can0 type can sample-point 0.875 bitrate 125000 dsample-point 0.875 dbitrate 500000 fd on berr-reporting on restart-ms 100
$ ip link set can0 up
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
can <BERR-REPORTING,FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 100
bitrate 125000 sample-point 0.875
tq 50 prop-seg 69 phase-seg1 70 phase-seg2 20 sjw 10 brp 2
mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp_inc 1
dbitrate 500000 dsample-point 0.875
dtq 125 dprop-seg 6 dphase-seg1 7 dphase-seg2 2 dsjw 1 dbrp 5
mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp_inc 1
tdco 0..63
clock 40000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus spi parentdev spi0.0
$ ip link set can0 down
$ ip link set can0 type can sample-point 0.875 bitrate 1000000 dsample-point 0.875 dbitrate 4000000 fd on berr-reporting on restart-ms 100
$ ip link set can0 up
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
can <BERR-REPORTING,FD,TDC-AUTO> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 100
bitrate 1000000 sample-point 0.875
tq 25 prop-seg 17 phase-seg1 17 phase-seg2 5 sjw 2 brp 1
mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp_inc 1
dbitrate 4000000 dsample-point 0.800
dtq 25 dprop-seg 3 dphase-seg1 4 dphase-seg2 2 dsjw 1 dbrp 1
tdco 8
mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp_inc 1
tdco 0..63
clock 40000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus spi parentdev spi0.0There has been some confusion about the MCP2518FD using a relative or absolute TDCO due to the datasheet specifying a range of [-64,63]. I have a custom board with a 40 MHz clock and an estimated loop delay of 100 to 216 ns. During testing at a data bit rate of 4 Mbit/s I found that using can_get_relative_tdco() resulted in bus-off errors. The final TDCO value was 1 which corresponds to a 10% SSP in an absolute configuration. This behavior is expected if the TDCO value is really absolute and not relative. Using priv->can.tdc.tdco instead results in a final TDCO of 8, setting the SSP at exactly 80%. This configuration works.
--- .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +18 -7
@@ -75,6 +75,15 @@ static const struct can_bittiming_const mcp251xfd_data_bittiming_const = { .brp_inc = 1, }; +static const struct can_tdc_const mcp251xfd_tdc_const = { + .tdcv_min =0 , + .tdcv_max =63 , + .tdco_min =0 , + .tdco_max =63 , + .tdcf_min =0 , + .tdcf_max =0 , +}; +static const char *__mcp251xfd_get_model_str (enum mcp251xfd_model model) {switch (model) {
@@ -511,7 +520,6 @@ static int mcp251xfd_set_bittiming(const struct mcp251xfd_priv *priv)const struct can_bittiming *bt = &priv->can.bittiming;const struct can_bittiming *dbt = &priv->can.data_bittiming;u32 val =0 ; -s8 tdco;int err;/* CAN Control Register
@@ -575,11 +583,13 @@ static int mcp251xfd_set_bittiming(const struct mcp251xfd_priv *priv)return err;/* Transmitter Delay Compensation */ - tdco =clamp_t (int, dbt->brp * (dbt->prop_seg + dbt->phase_seg1), --64 ,63 ); - val =FIELD_PREP (MCP251XFD_REG_TDC_TDCMOD_MASK , -MCP251XFD_REG_TDC_TDCMOD_AUTO ) | -FIELD_PREP (MCP251XFD_REG_TDC_TDCO_MASK , tdco); +if (can_tdc_is_enabled (&priv->can)) + val =FIELD_PREP (MCP251XFD_REG_TDC_TDCMOD_MASK , +MCP251XFD_REG_TDC_TDCMOD_AUTO ); +else + val =FIELD_PREP (MCP251XFD_REG_TDC_TDCMOD_MASK , +MCP251XFD_REG_TDC_TDCMOD_DISABLED ); + val |=FIELD_PREP (MCP251XFD_REG_TDC_TDCO_MASK , priv->can.tdc.tdco);return regmap_write (priv->map_reg,MCP251XFD_REG_TDC , val); }
@@ -2083,10 +2093,11 @@ static int mcp251xfd_probe(struct spi_device *spi) priv->can.do_get_berr_counter = mcp251xfd_get_berr_counter; priv->can.bittiming_const = &mcp251xfd_bittiming_const; priv->can.data_bittiming_const = &mcp251xfd_data_bittiming_const; + priv->can.tdc_const = &mcp251xfd_tdc_const; priv->can.ctrlmode_supported =CAN_CTRLMODE_LOOPBACK |CAN_CTRLMODE_LISTENONLY |CAN_CTRLMODE_BERR_REPORTING |CAN_CTRLMODE_FD |CAN_CTRLMODE_FD_NON_ISO | -CAN_CTRLMODE_CC_LEN8_DLC ; +CAN_CTRLMODE_CC_LEN8_DLC |CAN_CTRLMODE_TDC_AUTO ;set_bit (MCP251XFD_FLAGS_DOWN , priv->flags); priv->ndev = ndev; priv->spi = spi;
Signature · 1 line
2.39.5 (Apple Git-154)
Hi Kelsey,
The patch looks overall good. I have a few nitpicks.
For the patch title, when you format the patch, use the -v option to indicate the version:
https://git-scm.com/docs/git-format-patch#Documentation/git-format-patch.txt--vltngt
Your next iteration will be the version 3, so it will be
git format-patch -v3 ...
Also add in CC the maintainers. Use ./script/get_maintainer.pl to see who the maintainers are.
Quoted 7 lines · Kelsey Maes
TDC is currently hardcoded enabled so lower CAN FD data bitrates result in a bus-off condition. This patch allows userspace to control TDC as needed.
Demonstration of the feature in action:
$ ip link set can0 down $ ip link set can0 type can sample-point 0.875 bitrate 125000 dsample-point 0.875 dbitrate 500000 fd on berr-reporting on restart-ms 100 $ ip link set can0 up
We probably do not need this level of details. Can you remove all the parameters which are not directly relevant to the TDC and let the framework calculate the sample-point? Also remove the "set can0 down" command and combine the "set can0 up" together with the configuration command:
$ ip link set can0 up type can bitrate 125000 dbitrate 500000 fd on $ ip -details link show can0
This way, there is less information to parse and it is more clear to see what information is relevant.
Quoted 4 lines
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
can <BERR-REPORTING,FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 100Quoted 8 lines
bitrate 125000 sample-point 0.875
tq 50 prop-seg 69 phase-seg1 70 phase-seg2 20 sjw 10 brp 2
mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp_inc 1
dbitrate 500000 dsample-point 0.875
dtq 125 dprop-seg 6 dphase-seg1 7 dphase-seg2 2 dsjw 1 dbrp 5
mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp_inc 1
tdco 0..63
clock 40000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus spi parentdev spi0.0Nitpick: when you copy the terminal output (or more generally when you quote any text) a good practice is to prefix the quoted lines with two spaces. Like this:
$ echo "hello" hello
Quoted 17 lines
$ ip link set can0 down
$ ip link set can0 type can sample-point 0.875 bitrate 1000000 dsample-point 0.875 dbitrate 4000000 fd on berr-reporting on restart-ms 100
$ ip link set can0 up
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
can <BERR-REPORTING,FD,TDC-AUTO> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 100
bitrate 1000000 sample-point 0.875
tq 25 prop-seg 17 phase-seg1 17 phase-seg2 5 sjw 2 brp 1
mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp_inc 1
dbitrate 4000000 dsample-point 0.800
dtq 25 dprop-seg 3 dphase-seg1 4 dphase-seg2 2 dsjw 1 dbrp 1
tdco 8
mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp_inc 1
tdco 0..63
clock 40000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus spi parentdev spi0.0Quoted 9 lines
There has been some confusion about the MCP2518FD using a relative or absolute TDCO due to the datasheet specifying a range of [-64,63]. I have a custom board with a 40 MHz clock and an estimated loop delay of 100 to 216 ns. During testing at a data bit rate of 4 Mbit/s I found that using
can_get_relative_tdco()resulted in bus-off errors. The final TDCO value was 1 which corresponds to a 10% SSP in an absolute configuration. This behavior is expected if the TDCO value is really absolute and not relative. Usingpriv->can.tdc.tdcoinstead results in a final TDCO of 8, setting the SSP at exactly 80%. This configuration works.
Your patch actually fixes an issue. Can you add this tag?
MCP25xxFD SPI CAN")
@Marc, what do you think about the backport? The TDC framework was introduced a bit later so it is not possible to apply this patch as-is to the v5.10.x stable branch. However, it should apply smoothly to v5.15.x and anything after.
So my suggestion would be to leave this unfixed in v5.10 (this isn't a major issue either) and just backport it to v5.15 and greater.
Quoted 39 lines
Signed-off-by Kelsey Maes <[email protected]>--- .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-)drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +9
-3@@ -75,6 +75,15 @@ static const struct can_bittiming_const mcp251xfd_data_bittiming_const = { .brp_inc = 1, }; +static const struct can_tdc_const mcp251xfd_tdc_const = { + .tdcv_min =0 , + .tdcv_max =63 , + .tdco_min =0 , + .tdco_max =63 , + .tdcf_min =0 , + .tdcf_max =0 , +}; +static const char *__mcp251xfd_get_model_str (enum mcp251xfd_model model) {switch (model) {@@ -511,7 +520,6 @@ static int mcp251xfd_set_bittiming(const struct mcp251xfd_priv *priv)const struct can_bittiming *bt = &priv->can.bittiming;const struct can_bittiming *dbt = &priv->can.data_bittiming;u32 val =0 ; -s8 tdco;int err;/* CAN Control Register @@ -575,11 +583,13 @@ static int mcp251xfd_set_bittiming(const struct mcp251xfd_priv *priv)return err;/* Transmitter Delay Compensation */ - tdco =clamp_t (int, dbt->brp * (dbt->prop_seg + dbt->phase_seg1), --64 ,63 );
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_set_bittiming(const struct mcp251xfd_priv *priv) · line 592
Quoted 10 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +7
-3- val =FIELD_PREP (MCP251XFD_REG_TDC_TDCMOD_MASK , -MCP251XFD_REG_TDC_TDCMOD_AUTO ) | -FIELD_PREP (MCP251XFD_REG_TDC_TDCO_MASK , tdco); +if (can_tdc_is_enabled (&priv->can)) + val =FIELD_PREP (MCP251XFD_REG_TDC_TDCMOD_MASK , +MCP251XFD_REG_TDC_TDCMOD_AUTO ); +else + val =FIELD_PREP (MCP251XFD_REG_TDC_TDCMOD_MASK , +MCP251XFD_REG_TDC_TDCMOD_DISABLED ); + val |=FIELD_PREP (MCP251XFD_REG_TDC_TDCO_MASK , priv->can.tdc.tdco);
If can_tdc_is_enabled() returns false, tdco is zero. You can move that last line inside the if:
if (can_tdc_is_enabled(&priv->can))
val = FIELD_PREP(MCP251XFD_REG_TDC_TDCMOD_MASK,
MCP251XFD_REG_TDC_TDCMOD_AUTO) |
FIELD_PREP(MCP251XFD_REG_TDC_TDCO_MASK,
priv->can.tdc.tdco);Quoted 5 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +0
-0return regmap_write (priv->map_reg,MCP251XFD_REG_TDC , val); }@@ -2083,10 +2093,11 @@ static int mcp251xfd_probe(struct spi_device *spi) priv->can.do_get_berr_counter = mcp251xfd_get_berr_counter; priv->can.bittiming_const = &mcp251xfd_bittiming_const;
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c static int mcp251xfd_probe(struct spi_device *spi) · line 2103
Quoted 10 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2
-1priv->can.data_bittiming_const = &mcp251xfd_data_bittiming_const; + priv->can.tdc_const = &mcp251xfd_tdc_const; priv->can.ctrlmode_supported =CAN_CTRLMODE_LOOPBACK |CAN_CTRLMODE_LISTENONLY |CAN_CTRLMODE_BERR_REPORTING |CAN_CTRLMODE_FD |CAN_CTRLMODE_FD_NON_ISO | -CAN_CTRLMODE_CC_LEN8_DLC ; +CAN_CTRLMODE_CC_LEN8_DLC |CAN_CTRLMODE_TDC_AUTO ;set_bit (MCP251XFD_FLAGS_DOWN , priv->flags); priv->ndev = ndev; priv->spi = spi;
Yours sincerely,
Vincent Mailhol
Marc Kleine-Budde
maintainerQuoted 15 lines · Vincent Mailhol
Quoted 9 lines
There has been some confusion about the MCP2518FD using a relative or absolute TDCO due to the datasheet specifying a range of [-64,63]. I have a custom board with a 40 MHz clock and an estimated loop delay of 100 to 216 ns. During testing at a data bit rate of 4 Mbit/s I found that using
can_get_relative_tdco()resulted in bus-off errors. The final TDCO value was 1 which corresponds to a 10% SSP in an absolute configuration. This behavior is expected if the TDCO value is really absolute and not relative. Usingpriv->can.tdc.tdcoinstead results in a final TDCO of 8, setting the SSP at exactly 80%. This configuration works.Your patch actually fixes an issue. Can you add this tag?
Fixes 55e5b97f003e ("can: mcp25xxfd: add driver for MicrochipMCP25xxFD SPI CAN")
Quoted 7 lines
@Marc, what do you think about the backport? The TDC framework was introduced a bit later so it is not possible to apply this patch as-is to the v5.10.x stable branch. However, it should apply smoothly to v5.15.x and anything after.
So my suggestion would be to leave this unfixed in v5.10 (this isn't a major issue either) and just backport it to v5.15 and greater.
Sounds like a plan!
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Marc Kleine-Budde
maintainerQuoted 2 lines · Kelsey Maes
TDC is currently hardcoded enabled so lower CAN FD data bitrates result in a bus-off condition. This patch allows userspace to control TDC as needed.
I think the underlying problem is that the original code always enables TDC. Lower data bitrates result in a DBRP > 1, as you stated in your original mail:
Quoted 2 lines
Quoted 2 lines
I have a problem where I get a bus-off condition when using bit rates that use a DBRP > 1.
...and in auto mode TDC is only enabled for DBRP == 1 or 2. Switching to CAN_CTRLMODE_TDC_AUTO brings the positive side effect, that TDC is controllable from user space. So the commit message can be made more precise, what about:
Subject: can: mcp251xfd: fix TDC setting for low data bit rates
THe TDC is currently hardcoded enabled. This means even for lower CAN-FD data bitrates (with a DBRP (data bitrate prescaler) > 2) a TDC is configured. This leads to a bus-off condition.
ISO 11898-1 section 11.3.3 says "Transmitter delay compensation" (TDC) is only applicable if data BRP is 1 or 2.
To fix the problem, switch the driver to use the TDC calculation provided by the CAN driver framework (which respects ISO 11898-1 section 11.3.3). This has the positive side effect, that the user space can control TDC as needed.
Can you also add these tags:
BTW: In you original mail, you've written that you're using a bitrate of 125 kbit/s and a data bitrate of 500 kbit/s. This is a bit unusual. Is that a real world application? Are you allowed to say which one?
I just noticed that there is another potential problem with this combination of bit rates. The used BRP for the arbitration- and data bitrate are not identical:
| Bit timing parameters for mcp251xfd with 40.000000 MHz ref clock (CIA recommendation) using algo 'v6.3' | _----+--------------=> TSeg1: 2 … 256 | / / _---------=> TSeg2: 1 … 128 | | | / _-----=> SJW: 1 … 128 | | | | / _-=> BRP: 1 … 256 (inc: 1) | | | | | / | nominal | | | | | real Bitrt nom real SampP | Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error NBTCFG | 500000 25 34 35 10 5 1 500000 0.0% 87.5% 87.5% 0.0% 0x00440904 | 125000 50 69 70 20 10 2 125000 0.0% 87.5% 87.5% 0.0% 0x018a1309 | | Data Bit timing parameters for mcp251xfd with 40.000000 MHz ref clock (CIA recommendation) using algo 'v6.3' | _----+--------------=> TSeg1: 1 … 32 | / / _---------=> TSeg2: 1 … 16 | | | / _-----=> SJW: 1 … 16 | | | | / _-=> BRP: 1 … 256 (inc: 1) | | | | | / | nominal | | | | | real Bitrt nom real SampP | Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error NBTCFG | 500000 125 6 7 2 1 5 500000 0.0% 87.5% 87.5% 0.0% 0x040c0100
This leads to a phase error while switching from arbitration to the data bitrate. A common BRP of 5 is better:
| Bit timing parameters for mcp251xfd with 40.000000 MHz ref clock (cmd-line) using algo 'v6.3' | nominal real Bitrt nom real SampP | Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error NBTCFG | 125000 125 27 28 8 4 5 125000 0.0% 87.5% 87.5% 0.0% 0x04360703 | | Data Bit timing parameters for mcp251xfd with 40.000000 MHz ref clock (cmd-line) using algo 'v6.3' | nominal real Bitrt nom real SampP | Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error NBTCFG | 500000 125 6 7 2 1 5 500000 0.0% 87.5% 87.5% 0.0% 0x040c0100
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Quoted 31 lines · Marc Kleine-Budde
Quoted 2 lines · Kelsey Maes
TDC is currently hardcoded enabled so lower CAN FD data bitrates result in a bus-off condition. This patch allows userspace to control TDC as needed.
I think the underlying problem is that the original code always enables TDC. Lower data bitrates result in a DBRP > 1, as you stated in your original mail:
Quoted 2 lines
Quoted 2 lines
I have a problem where I get a bus-off condition when using bit rates that use a DBRP > 1.
...and in auto mode TDC is only enabled for DBRP == 1 or 2. Switching to
CAN_CTRLMODE_TDC_AUTObrings the positive side effect, that TDC is controllable from user space. So the commit message can be made more precise, what about:Subject: can: mcp251xfd: fix TDC setting for low data bit rates
THe TDC is currently hardcoded enabled. This means even for lower CAN-FD data bitrates (with a DBRP (data bitrate prescaler) > 2) a TDC is configured. This leads to a bus-off condition.
ISO 11898-1 section 11.3.3 says "Transmitter delay compensation" (TDC) is only applicable if data BRP is 1 or 2.
To fix the problem, switch the driver to use the TDC calculation provided by the CAN driver framework (which respects ISO 11898-1 section 11.3.3). This has the positive side effect, that the user space can control TDC as needed.
Quoted 4 lines
Can you also add these tags:
Sure, I’m fine with that.
Quoted 3 lines
BTW: In you original mail, you've written that you're using a bitrate of 125 kbit/s and a data bitrate of 500 kbit/s. This is a bit unusual. Is that a real world application? Are you allowed to say which one?
We are building an industrial automation system that uses CAN bus in place of RS-485 for controlling potentially distant modules. That particular bitrate is one of 4 possible bitrates the system can operate at: 125 / 500, 250 / 1000, 500 / 2000, 1000 / 4000. We have an automatic bit rate detection mechanism and having a fixed 1:4 ratio simplifies the implementation. The lower bitrates will only be used in situations where a very long bus, poor wiring, and/or noise issues prevent the use of higher bitrates. These are all very common issues we have encountered with our existing RS-485 systems in the field.
Quoted 28 lines
I just noticed that there is another potential problem with this combination of bit rates. The used BRP for the arbitration- and data bitrate are not identical:
| Bit timing parameters for mcp251xfd with 40.000000 MHz ref clock (CIA recommendation) using algo 'v6.3' | _----+--------------=> TSeg1: 2 … 256 | / / _---------=> TSeg2: 1 … 128 | | | / _-----=> SJW: 1 … 128 | | | | / _-=> BRP: 1 … 256 (inc: 1) | | | | | / | nominal | | | | | real Bitrt nom real SampP | Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error NBTCFG | 500000 25 34 35 10 5 1 500000 0.0% 87.5% 87.5% 0.0% 0x00440904 | 125000 50 69 70 20 10 2 125000 0.0% 87.5% 87.5% 0.0% 0x018a1309 | | Data Bit timing parameters for mcp251xfd with 40.000000 MHz ref clock (CIA recommendation) using algo 'v6.3' | _----+--------------=> TSeg1: 1 … 32 | / / _---------=> TSeg2: 1 … 16 | | | / _-----=> SJW: 1 … 16 | | | | / _-=> BRP: 1 … 256 (inc: 1) | | | | | / | nominal | | | | | real Bitrt nom real SampP | Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error NBTCFG | 500000 125 6 7 2 1 5 500000 0.0% 87.5% 87.5% 0.0% 0x040c0100This leads to a phase error while switching from arbitration to the data bitrate. A common BRP of 5 is better:
Quoted 9 lines
| Bit timing parameters for mcp251xfd with 40.000000 MHz ref clock (cmd-line) using algo 'v6.3' | nominal real Bitrt nom real SampP | Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error NBTCFG | 125000 125 27 28 8 4 5 125000 0.0% 87.5% 87.5% 0.0% 0x04360703 | | Data Bit timing parameters for mcp251xfd with 40.000000 MHz ref clock (cmd-line) using algo 'v6.3' | nominal real Bitrt nom real SampP | Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error NBTCFG | 500000 125 6 7 2 1 5 500000 0.0% 87.5% 87.5% 0.0% 0x040c0100
I agree. This problem can be worked around by specifying the timing parameters explicitly, if required. It has not been an issue so far.
--
Kelsey Maes
VP Process Inc.
Marc Kleine-Budde
maintainerQuoted 9 lines · Kelsey Maes
Quoted 2 lines
Sure, I’m fine with that.
Quoted 3 lines
BTW: In you original mail, you've written that you're using a bitrate of 125 kbit/s and a data bitrate of 500 kbit/s. This is a bit unusual. Is that a real world application? Are you allowed to say which one?
Quoted 8 lines
We are building an industrial automation system that uses CAN bus in place of RS-485 for controlling potentially distant modules. That particular bitrate is one of 4 possible bitrates the system can operate at: 125 / 500, 250 / 1000, 500 / 2000, 1000 / 4000. We have an automatic bit rate detection mechanism and having a fixed 1:4 ratio simplifies the implementation. The lower bitrates will only be used in situations where a very long bus, poor wiring, and/or noise issues prevent the use of higher bitrates. These are all very common issues we have encountered with our existing RS-485 systems in the field.
I see, so 125/500 is a real world use-case. I'll add lower data bitrates to the can-utils tools then :)
Quoted 3 lines
Quoted 3 lines
I just noticed that there is another potential problem with this combination of bit rates. The used BRP for the arbitration- and data bitrate are not identical:
[...]
Quoted 2 lines
Quoted 2 lines
This leads to a phase error while switching from arbitration to the data bitrate. A common BRP of 5 is better:
[...]
Quoted 2 lines
I agree. This problem can be worked around by specifying the timing parameters explicitly, if required. It has not been an issue so far.
Ack
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |