S32K3 CAN TIMESTAMP NOT OK when use external timer(STM0)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

S32K3 CAN TIMESTAMP NOT OK when use external timer(STM0)

跳至解决方案
1,329 次查看
Zhougw
Contributor III
RTD: SW32K3_RTD_R21-11_3.0.0_P07_D2306
MCU: #S32K396
Question:TimeStamp of CAN didn't change when use STM0 as external timer.
 
when I use default config, Timer register of CAN will increase, and timestamp of mailbox would change after Can transmition.
when I enable global time in CAN config, use STM0 for external timer reference, Timer register of CAN is always 0, timestamp of mailbox is always 0. HR_TIME_STAMP did not change. Can_43_FLEXCAN_TimestampTimerOverflowCallback can be called, Can_Ipw_u32CurrentCompareVal can change. Count of STM0 can change. 
What's wrong, why timerstamp didn't change? Count of STM0 can change, Can transimition is OK(CanIf_TxConfirmation can be called).
 
 
code in main function:
Gpt_Init(NULL_PTR);
Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_0, 400000U);  // PIT
Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_1, 4000000U);     // STM
Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_0, 400000U);  // PIT
Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_1);  // STM
Can_43_FLEXCAN_Init(&Can_43_FLEXCAN_Config);
Can_43_FLEXCAN_SetControllerMode(CanController_Veh, CAN_CS_STARTED);  
Platform_SetIrq(FlexCAN3_0_IRQn, TRUE);
Platform_SetIrq(FlexCAN3_1_IRQn, TRUE);
Platform_SetIrq(STM0_IRQn, TRUE);
for(;;)
{
if(IP_PIT_0->TIMER[0].TFLG == 1)
{
IP_PIT_0->TIMER[0].TFLG = 1;
CanTx_10ms();
}
}
Zhougw_0-1779675042721.pngZhougw_1-1779675065490.png

 

 

0 项奖励
回复
1 解答
1,198 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@Zhougw

Attached are the project I tested and a video of my test results.

The hardware used for the test is based on the S32K396EVB.

I have modified the clock to 20MHz, so you can directly test the project I provided or debug the ELF file.

I checked your EB configuration, and I think this might be a problem with the clock configuration in your "Mcu" module.

You can refer to this configuration and try again.

Senlent_1-1779846985514.png

 

 

在原帖中查看解决方案

0 项奖励
回复
9 回复数
1,232 次查看
Zhougw
Contributor III

@Senlent 

I used the same configuration in a S32K312 board,everything is OK。 variable in code reading HR_TIME_STAMP  can update, HR_TIME_STAMP register in trace32  can also update. HR_TIME_STAMP[5](the base project used mailbox5) flow STM0_CNT.

RTD is the same version. 

Zhougw_0-1779784887653.png

 

0 项奖励
回复
1,199 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@Zhougw

Attached are the project I tested and a video of my test results.

The hardware used for the test is based on the S32K396EVB.

I have modified the clock to 20MHz, so you can directly test the project I provided or debug the ELF file.

I checked your EB configuration, and I think this might be a problem with the clock configuration in your "Mcu" module.

You can refer to this configuration and try again.

Senlent_1-1779846985514.png

 

 

0 项奖励
回复
1,192 次查看
Zhougw
Contributor III
I have tested your elf,HR_TIME_STAMP fallows STM0_CNT.
I changed PLL configuration in my project, it is still the same, I will check other configuration.
 

下载.png

0 项奖励
回复
1,315 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@Zhougw

Please refer to this discussion; a test demonstration example is provided in the attachment.

https://community.nxp.com/t5/S32K/Flexcan-use-case-of-timestamp/td-p/1992642

0 项奖励
回复
1,300 次查看
Zhougw
Contributor III
All my project is based on EBtresos, Is there any demo of EBtresos? or could you tell me what register should i check

I checked registers about timestamp of CAN, didn't find any abnormal register
DCMRWF1.CAN_TIMESTAMP_EN=1(enable),
DCMRWF1.CAN_TIMESTAMP_SEL=1(STM0)
CAN.TIMER_src=1 :external time tick
CAN.MBTSBASE=1/2: high-resolution timer
CAN.TSTAMPCAP=2: start of CAN frame
STM0.CNT:increasing

and CAN is transmitting msg, CanIf_TxConfirmation is called ok.

what am i missing? Timestamp in MB or HR_TIME_STAMP is not updated by hardware?
0 项奖励
回复
1,293 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@Zhougw

Using this function in EB is not very complicated.

This is the configuration process I saw.

Please check if you have configured it according to the requirements.

Senlent_0-1779701867599.png

 

0 项奖励
回复
1,267 次查看
Zhougw
Contributor III
the image I post shows I configred the callback function. Can_Ipw_u32CurrentCompareVal is updated in this function, I saw it can change in trace32.
from my understanding, it only influnce the higher bit of the timestamp, the lower bit should be HR_TIME_STAMP, i think the problem is why HR_TIME_STAMP did not update.
I tried to read HR_TIME_STAMP in main function, it is always 0. before I add this code, HR_TIME_STAMP is not zero, it just didn't change after can transmition, I watched HR_TIME_STAMP register in trace32.
so, count of STM0 can update, CAN_CTRL2 configured right(TIMER_src=1,.MBTSBASE=1 or 2,TSTAMPCAP=2), can transmit ok, why HR_TIME_STAMP didn't update, I check reference mannual and doc of RTD, didn't see anything else need to do.
0 项奖励
回复
1,259 次查看
Senlent
NXP TechSupport
NXP TechSupport

Hi@Zhougw

Provide the ELF file and configuration project, and I'll test it for you.

0 项奖励
回复
1,240 次查看
Zhougw
Contributor III

RTD: SW32K3_RTD_R21-11_3.0.0_P07_D2306.exe
external crystal: 20M

today, I use other project successed once(Can TimeStamp Required Accuracy : 1 -> 1000,add code to read HR_TIME_STAMP after Can_43_FLEXCAN_Write),then I change code back to find difference, HR_TIME_STAMP didn't update. even i change the code back, HR_TIME_STAMP didn't update. no matter how i change the code, never succeeded again.

To make test easier, I enabled can loopback mode, so port_init is not needed.
EB can only configure FLEXCAN_MSGBUFFTIMESTAMP_TIMER, I need to use FLEXCAN_MSGBUFFTIMESTAMP_LOWER.
In function FlexCAN_ConfigTimestamp,I replaced base->CTRL2 |= Temp; to base->CTRL2 |= 0x8180; this is the same as changing Flexcan_aCtrlConfigPB in FlexCAN_Ip_PBcfg.c.

0 项奖励
回复