How could I get CAN bus bittiming consts?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How could I get CAN bus bittiming consts?

Jump to solution
1,054 Views
sarh2o
Contributor II

Hi NXP experts,

I'm trying to implement CAN bittiming for NXP FlexCAN on VxWorks.

First of all, I'd like to know whether NXP has implemented bittiming calculation in C language.

If so, could you please share it with me? Then I don't need to write it from the scratch but just port it to VxWorks as long as the license is friendly enough (not GPL-like license). I know Linux has an implementation, but I can not port this one.

If not, I have some questions about how to get CAN bittiming consts.

To my understanding, there are 3 inputs for a bittiming calculator:

1. CAN Clock Frequency

2. CAN baud rate

3. bittiming constants

The first 2 are easy to get. But for the 3rd input bittiming constants, I don't know where I can find.

I think these constants should be hardware-dependent.

I have checked Linux's FlexCAN driver (drivers/net/can/flexcan.c). I saw that there were 6 groups of constants

static const struct can_bittiming_const flexcan_bittiming_const = {
.name = DRV_NAME,
.tseg1_min = 4,
.tseg1_max = 16,
.tseg2_min = 2,
.tseg2_max = 8,
.sjw_max = 4,
.brp_min = 1,
.brp_max = 256,
.brp_inc = 1,
};

static const struct can_bittiming_const flexcan_fd_bittiming_const = {
.name = DRV_NAME,
.tseg1_min = 2,
.tseg1_max = 96,
.tseg2_min = 2,
.tseg2_max = 32,
.sjw_max = 16,
.brp_min = 1,
.brp_max = 1024,
.brp_inc = 1,
};

static const struct can_bittiming_const flexcan_fd_data_bittiming_const = {
.name = DRV_NAME,
.tseg1_min = 2,
.tseg1_max = 39,
.tseg2_min = 2,
.tseg2_max = 8,
.sjw_max = 4,
.brp_min = 1,
.brp_max = 1024,
.brp_inc = 1,
};

static const struct can_bittiming_const s32_flexcan_bittiming_const = {
.name = DRV_NAME,
.tseg1_min = 4,
.tseg1_max = 16,
.tseg2_min = 4,
.tseg2_max = 8,
.sjw_max = 4,
.brp_min = 1,
.brp_max = 256,
.brp_inc = 1,
};

static const struct can_bittiming_const s32_flexcan_fd_bittiming_const = {
.name = DRV_NAME,
.tseg1_min = 4,
.tseg1_max = 96,
.tseg2_min = 4,
.tseg2_max = 32,
.sjw_max = 32,
.brp_min = 1,
.brp_max = 1024,
.brp_inc = 1,
};

static const struct can_bittiming_const s32_flexcan_fd_data_bittiming_const = {
.name = DRV_NAME,
.tseg1_min = 2,
.tseg1_max = 39,
.tseg2_min = 2,
.tseg2_max = 8,
.sjw_max = 8,
.brp_min = 1,
.brp_max = 1024,
.brp_inc = 1,
};

I think the 3 prefixed with "s32_" are specific for S32G boards and other 3 are for other boards.

Could you please let me know where these values come from?

From datasheet? I have S32G doc "S32G2RM". The version is Rev 4 October, 2021.

There is indeed a chapter "Protocol timing" which describes the value range of each constant like: SYNC_SEG, Time Segment1, Time Segment2 and so on.

But after comparing the ranges in the doc with those in "flexcan.c", I found some differences.

So I'd like to consult you.

Could you please help?

 

Thanks in advance!

0 Kudos
1 Solution
989 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello Sarh2o,

As you told, the bittiming constants with prefix “s32_” are used for S32G. As far as I checked the S32G RM, found below mismatching between register spec and flexcan.c (yellow colored cells are mismatching). I reported this to Linux CAN driver team and the Linux team clarified this is the defect of flexcan.c although this does not cause any apparent functionality problems. The team raised the ticket ALB-8894 on JIRA for this defect.
 As for the sample code which calculates segments value and PRESDIV values for FlexCAN, I have never seen such codes at least for S32G and C55 generation products.

Bio_TICFSL_0-1653314409200.png

 

Best Regards,

View solution in original post

Tags (1)
0 Kudos
2 Replies
990 Views
Bio_TICFSL
NXP TechSupport
NXP TechSupport

Hello Sarh2o,

As you told, the bittiming constants with prefix “s32_” are used for S32G. As far as I checked the S32G RM, found below mismatching between register spec and flexcan.c (yellow colored cells are mismatching). I reported this to Linux CAN driver team and the Linux team clarified this is the defect of flexcan.c although this does not cause any apparent functionality problems. The team raised the ticket ALB-8894 on JIRA for this defect.
 As for the sample code which calculates segments value and PRESDIV values for FlexCAN, I have never seen such codes at least for S32G and C55 generation products.

Bio_TICFSL_0-1653314409200.png

 

Best Regards,

Tags (1)
0 Kudos
979 Views
sarh2o
Contributor II

Hi @Bio_TICFSL ,

Great thanks for your reply!

Now it is clear to me. I will use the constants defined in the reference manual.

0 Kudos