Skip to content

Commit 0c4abcd

Browse files
william-tang914nashif
authored andcommitted
drivers: can: mcux: flexcan: support Enhanced CAN Bit Timing registers
Some FlexCAN devices have enhanced bit timing registers (EPRS ENCBT EDCBT) with extended timing configuration ranges and different behavior compared to standard bit timing registers. This change adds proper support for these enhanced registers, utilize full bit timing capabilities. Key differences for enhanced bit timing registers: - Extended timing ranges with larger maximum values for sjw, phase_seg1, phase_seg2, and prescaler fields - No propagation segment configuration support, so prop_seg must be 0 - prop_seg value is used directly without the typical 'minus 1' adjustment The implementation adds conditional compilation based on the `FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG` feature flag. For Enhanced registers, use extended timing limits and prop_seg directly. Test this commit on mimxrt1180_evk/mimxrt1189/cm33 drivers.can.timing test case, and enable `TEST_ALL_BITRATES` Kconfig symbol. Signed-off-by: William Tang <william.tang@nxp.com>
1 parent c55d2ea commit 0c4abcd

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

drivers/can/can_mcux_flexcan.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,13 @@ static int mcux_flexcan_start(const struct device *dev)
309309
timing.rJumpwidth = data->timing.sjw - 1U;
310310
timing.phaseSeg1 = data->timing.phase_seg1 - 1U;
311311
timing.phaseSeg2 = data->timing.phase_seg2 - 1U;
312+
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG) && \
313+
FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG)
314+
/* No propagation segment configuration, so prop_seg must be 0 */
315+
timing.propSeg = data->timing.prop_seg;
316+
#else
312317
timing.propSeg = data->timing.prop_seg - 1U;
318+
#endif
313319
FLEXCAN_SetTimingConfig(base, &timing);
314320

315321
#ifdef CONFIG_CAN_MCUX_FLEXCAN_FD
@@ -1256,7 +1262,13 @@ static int mcux_flexcan_init(const struct device *dev)
12561262
flexcan_config.enableListenOnlyMode = true;
12571263

12581264
flexcan_config.timingConfig.rJumpwidth = data->timing.sjw - 1U;
1265+
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG) && \
1266+
FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG)
1267+
/* No propagation segment configuration, so prop_seg must be 0 */
1268+
flexcan_config.timingConfig.propSeg = data->timing.prop_seg;
1269+
#else
12591270
flexcan_config.timingConfig.propSeg = data->timing.prop_seg - 1U;
1271+
#endif
12601272
flexcan_config.timingConfig.phaseSeg1 = data->timing.phase_seg1 - 1U;
12611273
flexcan_config.timingConfig.phaseSeg2 = data->timing.phase_seg2 - 1U;
12621274

@@ -1358,13 +1370,46 @@ static DEVICE_API(can, mcux_flexcan_fd_driver_api) = {
13581370
* FlexCAN FD timing limits are specified in the "CAN Bit Timing
13591371
* Register (CBT)" and "CAN FD Bit Timing Register" field description
13601372
* tables in the SoC reference manual.
1373+
* Some devices have enhanced bit timing registers (EPRS ENCBT EDCBT)
1374+
* with different limits and do not have propagation segment configuration.
13611375
*
13621376
* Note that the values here are the "physical" timing limits, whereas
13631377
* the register field limits are physical values minus 1 (which is
13641378
* handled by the flexcan_timing_config_t field assignments elsewhere
13651379
* in this driver). The exception to this are the prop_seg values for
13661380
* the data phase, which correspond to the allowed register values.
13671381
*/
1382+
#if (defined(FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG) && \
1383+
FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG)
1384+
.timing_min = {
1385+
.sjw = 0x01,
1386+
.prop_seg = 0,
1387+
.phase_seg1 = 0x02,
1388+
.phase_seg2 = 0x02,
1389+
.prescaler = 0x01
1390+
},
1391+
.timing_max = {
1392+
.sjw = 0x80,
1393+
.prop_seg = 0,
1394+
.phase_seg1 = 0x100,
1395+
.phase_seg2 = 0x80,
1396+
.prescaler = 0x400
1397+
},
1398+
.timing_data_min = {
1399+
.sjw = 0x01,
1400+
.prop_seg = 0,
1401+
.phase_seg1 = 0x02,
1402+
.phase_seg2 = 0x02,
1403+
.prescaler = 0x01
1404+
},
1405+
.timing_data_max = {
1406+
.sjw = 0x10,
1407+
.prop_seg = 0,
1408+
.phase_seg1 = 0x20,
1409+
.phase_seg2 = 0x10,
1410+
.prescaler = 0x400
1411+
},
1412+
#else
13681413
.timing_min = {
13691414
.sjw = 0x01,
13701415
.prop_seg = 0x01,
@@ -1393,6 +1438,7 @@ static DEVICE_API(can, mcux_flexcan_fd_driver_api) = {
13931438
.phase_seg2 = 0x08,
13941439
.prescaler = 0x400
13951440
},
1441+
#endif /* FSL_FEATURE_FLEXCAN_HAS_ENHANCED_BIT_TIMING_REG */
13961442
};
13971443
#endif /* CONFIG_CAN_MCUX_FLEXCAN_FD */
13981444

0 commit comments

Comments
 (0)