S32G399A STM issue

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
3,949件の閲覧回数
asj
Contributor II

Hi everyone,

I'm facing an issue with the STM1 timer. I've configured two counters: Counter_1 running at 1ms for STM0 (CH0) and Counter_2 running at 1us for STM1 (CH0). The STM0 counter works fine, but STM1 is not updating as expected. Instead of updating every 1us, it updates every 15-25s. 

Configuration Details:

Clock for both STM0 and STM1: 133.33333 MHz
Prescaler (PSC) for both: 1
Compare values: 0x208D5 for 1ms (STM0) and 0x85 for 1us (STM1)
Interrupt priority: 4 for STM0, 5 for STM1

0 件の賞賛
返信
1 解決策
3,640件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,asj

Thank you for your reply.

According to the timer's PSC and clock frequency, it is theoretically possible to achieve 1us, if you doubt the reason for performance, you can try to set STM1 larger time, such as 100us or 2ms.

BR

Joey

元の投稿で解決策を見る

0 件の賞賛
返信
10 返答(返信)
3,936件の閲覧回数
asj
Contributor II

These are my ISRs where I set the CMP value by adding a "timeout value" (0x85 for 1us), and clear the interrupt flag, these are done inside "Handler":

ISR(IsrSTM0)
{
    Handler((uint8) STM_CFG_STM0_INSTANCE, (uint8) STM_CFG_STMN_CH0);
    Os_IncrementCounter_Counter_1();       
}

ISR(IsrSTM1)
{
    Handler((uint8) STM_CFG_STM1_INSTANCE, (uint8) STM_CFG_STMN_CH0);
    Os_IncrementCounter_Counter_2();
}



0 件の賞賛
返信
3,926件の閲覧回数
Joey_z
NXP Employee
NXP Employee

Hi,asj

Thank you for contacting us.

Could you share more information about your code? For example, how do you configure your STM?

In addition, is it normal only to use the STM1?


BR

Joey

0 件の賞賛
返信
3,921件の閲覧回数
asj
Contributor II
This is my STM configuration:

static const Stm_Prv_InstanceConfig_tst Stm_Cfg_PbInstanceConfInirba_Stm_Config_acst[STM_CFG_PB_NUMBER_OF_STM_INSTANCES] =
{
/* STM peripheral instance*/ /* Freeze mode */ /* Prescaler value(range 1 to 256) */

/* Instance configuration for instance STM0*/
{
STM_CFG_STM0_INSTANCE, // STM peripheral instance
TRUE, // Freeze mode
1, // Prescale value(range 1 to 256)
},
/* Instance configuration for instance STM1*/
{
STM_CFG_STM1_INSTANCE, // STM peripheral instance
TRUE, // Freeze mode
1, // Prescale value(range 1 to 256)
},

};

static const Stm_GptChannelConfig_tst Stm_Cfg_GptPbChannelConfigInirba_Stm_Config_acst[STM_CFG_GPT_NUMBER_OF_LOGIC_STM_CHANNELS] =
{
/* Instance of the STM STM hardware channel */
/* peripheral, STM_REG_STMN_CHm */
/* m = 0, 1, 2, 3
{
STM_CFG_STM0_INSTANCE,
STM_CFG_STMN_CH0,
},
{
STM_CFG_STM1_INSTANCE,
STM_CFG_STMN_CH0,
},

};



This is how I'm setting the compare value:
Stm_StartTimer
((uint8)  RBA_STM_CFG_STM0_INSTANCE,
                          (uint8)  RBA_STM_CFG_STMN_CH0,
                          (uint32) 0x208D5);                   // 1ms
    //Rework OS timer clock value
   
    // Init OS system timer - STM1 and CH0
Stm_StartTimer((uint8)  RBA_STM_CFG_STM1_INSTANCE,
                         (uint8)  RBA_STM_CFG_STMN_CH0,
                          (uint32) 0x85);                   // 1us

Stm_StartTimer function does the following:
/* Read the current counter value */
     Stm_Prv_CounterStartValue_au32[HwTimerInstance_u8][HwTimerChannel_u8]STM_PRV_REG_CNT((HwTimerInstance_u8));

     /* Load the compare value,which is the sum of current counter value and timeout value */
     STM_PRV_REG_CMP((HwTimerInstance_u8), (HwTimerChannel_u8)) = (uint32)(TimeOutValue_u32+Stm_Prv_CounterStartValue_au32[HwTimerInstance_u8][HwTimerChannel_u8]);

     /* Store the timeout value */
     Stm_Prv_TimeoutValue_au32[HwTimerInstance_u8][HwTimerChannel_u8]=TimeOutValue_u32;

     /* Enable the channel */
     STM_PRV_REG_STMCCR_CEN_TIMER_CH_ENABLED((HwTimerInstance_u8), (HwTimerChannel_u8));

The logic for updation of CMP value:
/* store current compare value */
    Stm_cmp_value_u32=STM_PRV_REG_CMP((HwTimerInstance_u8), (HwTimerChannel_u8));

    /* Set the compare value */
    STM_PRV_REG_CMP((HwTimerInstance_u8), (HwTimerChannel_u8))=(uint32)(Stm_cmp_value_u32 + Stm_Prv_TimeoutValue_au32[HwTimerInstance_u8][HwTimerChannel_u8]);
}

And as for the second question, I'm trying to use both STM0 and STM1 for different time intervals, to implement counters for my usecase.
0 件の賞賛
返信
3,912件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,asj

Thank you for your information.

I will try to look at the code for you and find the problem. In addition, The second problem is that I suggest that you do not apply STM0 and only use STM1 to check whether STM1 itself is configured incorrectly. If STM1 works well alone, you should focus on finding configuration problems between the two STMS when they are used.

BR

Joey

0 件の賞賛
返信
3,908件の閲覧回数
asj
Contributor II

Okay, I can do that, but the thing is if I'm using them both for 1ms, they work. So that's why I had the doubt. Anyways, I'll do it and let you know

Do let me know if you find anything from the code

0 件の賞賛
返信
3,848件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,asj

Are you using STM0 and STM1 in debug mode, and if so, check to see if the value of CNT reaches the comparison value to enter the interrupt.
Also, try setting Freeze mode to FALSE.

BR

Joey

0 件の賞賛
返信
3,835件の閲覧回数
asj
Contributor II

Hi Joey,

Yes, I am. The CNT value for STM0 (1ms) continuously updates every 1ms, upon reaching CMP value (IRQ assertion is happening properly). But for STM1 (1us), the CMP value only updates after CNT value falls over from FFFFFFFF to 00000000 and then matches the CMP value (IRQ assertion is improper). So, it takes 10-15s for my counter to update its value.

Thanks,

asj

0 件の賞賛
返信
3,777件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,asj

Sorry for replying so late.

Did you try setting Freeze mode to FALSE?

Additionally, after the channel interrupt has been handled, clear the channel interrupt flag (CIF).

Joey_z_0-1742782471178.png

BR

Joey

 

 

 

0 件の賞賛
返信
3,691件の閲覧回数
asj
Contributor II

Hi Joey,

Sorry for the late reply.

Yes, I'm doing that. My doubt now, is whether a time period of 1us is feasible. This means 1000000 interrupts per second. So, it might lead to a runtime problem. Could you shed some light on this?

BR

asj

0 件の賞賛
返信
3,641件の閲覧回数
Joey_z
NXP Employee
NXP Employee

hi,asj

Thank you for your reply.

According to the timer's PSC and clock frequency, it is theoretically possible to achieve 1us, if you doubt the reason for performance, you can try to set STM1 larger time, such as 100us or 2ms.

BR

Joey

0 件の賞賛
返信
%3CLINGO-SUB%20id%3D%22lingo-sub-2063622%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ES32G399A%20STM%E3%81%AE%E5%95%8F%E9%A1%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2063622%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%E3%80%81%E7%9A%86%E3%81%95%E3%82%93%3C%2FP%3E%3CP%3ESTM1%20%E3%82%BF%E3%82%A4%E3%83%9E%E3%83%BC%E3%81%A7%E5%95%8F%E9%A1%8C%E3%81%8C%E7%99%BA%E7%94%9F%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82STM0%20(CH0)%20%E3%81%AE%201ms%20%E3%81%A7%E5%8B%95%E4%BD%9C%E3%81%99%E3%82%8B%20Counter_1%20%E3%81%A8%20STM1%20(CH0)%20%E3%81%AE%201us%20%E3%81%A7%E5%8B%95%E4%BD%9C%E3%81%99%E3%82%8B%20Counter_2%20%E3%81%AE%202%20%E3%81%A4%E3%81%AE%E3%82%AB%E3%82%A6%E3%83%B3%E3%82%BF%E3%83%BC%E3%82%92%E6%A7%8B%E6%88%90%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82STM0%20%E3%82%AB%E3%82%A6%E3%83%B3%E3%82%BF%E3%81%AF%E6%AD%A3%E5%B8%B8%E3%81%AB%E5%8B%95%E4%BD%9C%E3%81%97%E3%81%BE%E3%81%99%E3%81%8C%E3%80%81STM1%20%E3%81%8C%E6%9C%9F%E5%BE%85%E3%81%A9%E3%81%8A%E3%82%8A%E3%81%AB%E6%9B%B4%E6%96%B0%E3%81%95%E3%82%8C%E3%81%BE%E3%81%9B%E3%82%93%E3%80%821us%E3%81%94%E3%81%A8%E3%81%AB%E6%9B%B4%E6%96%B0%E3%81%99%E3%82%8B%E3%81%AE%E3%81%A7%E3%81%AF%E3%81%AA%E3%81%8F%E3%80%8115%E3%80%9C25%E7%A7%92%E3%81%94%E3%81%A8%E3%81%AB%E6%9B%B4%E6%96%B0%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%E6%A7%8B%E6%88%90%E3%81%AE%E8%A9%B3%E7%B4%B0%3A%3C%2FP%3E%3CP%3ESTM0%20%E3%81%A8%20STM1%20%E3%81%AE%E4%B8%A1%E6%96%B9%E3%81%AE%E3%82%AF%E3%83%AD%E3%83%83%E3%82%AF%3A%20133.33333%20MHz%3CBR%20%2F%3E%E4%B8%A1%E6%96%B9%E3%81%AE%E3%83%97%E3%83%AA%E3%82%B9%E3%82%B1%E3%83%BC%E3%83%A9%E3%83%BC(PSC)%3A1%3CBR%20%2F%3E%E5%80%A4%E3%81%AE%E6%AF%94%E8%BC%83%3A1ms%E3%81%AE0x208D5(STM0)%E3%81%A81us%E3%81%AE0x85(STM1)%3CBR%20%2F%3E%E5%89%B2%E3%82%8A%E8%BE%BC%E3%81%BF%E5%84%AA%E5%85%88%E5%BA%A6%3ASTM0%E3%81%AE%E5%A0%B4%E5%90%88%E3%81%AF4%E3%80%81STM1%E3%81%AE%E5%A0%B4%E5%90%88%E3%81%AF5%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2063754%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3AS32G399A%20STM%E3%81%AE%E5%95%8F%E9%A1%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2063754%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E3%81%95%E3%81%A6%E3%80%81%E7%A7%81%E3%81%AF%E3%81%9D%E3%82%8C%E3%82%92%E8%A1%8C%E3%81%86%E3%81%93%E3%81%A8%E3%81%8C%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%99%E3%81%8C%E3%80%81%E5%95%8F%E9%A1%8C%E3%81%AF%E3%80%81%E4%B8%A1%E6%96%B9%E3%82%921ms%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%81%84%E3%82%8B%E5%A0%B4%E5%90%88%E3%80%81%E3%81%9D%E3%82%8C%E3%82%89%E3%81%AF%E6%A9%9F%E8%83%BD%E3%81%99%E3%82%8B%E3%81%A8%E3%81%84%E3%81%86%E3%81%93%E3%81%A8%E3%81%A7%E3%81%99%E3%80%82%E3%81%A0%E3%81%8B%E3%82%89%E3%80%81%E7%A7%81%E3%81%AF%E7%96%91%E5%95%8F%E3%82%92%E6%8C%81%E3%81%A3%E3%81%A6%E3%81%84%E3%81%BE%E3%81%97%E3%81%9F%E3%80%82%E3%81%A8%E3%81%AB%E3%81%8B%E3%81%8F%E3%80%81%E3%82%84%E3%81%A3%E3%81%A6%E3%81%BF%E3%81%A6%E3%80%81%E3%81%8A%E7%9F%A5%E3%82%89%E3%81%9B%E3%81%97%E3%81%BE%E3%81%99%3CBR%20%2F%3E%3CBR%20%2F%3E%E3%82%B3%E3%83%BC%E3%83%89%E3%81%8B%E3%82%89%E4%BD%95%E3%81%8B%E8%A6%8B%E3%81%A4%E3%81%91%E3%81%9F%E5%A0%B4%E5%90%88%E3%81%AF%E3%81%8A%E7%9F%A5%E3%82%89%E3%81%9B%E3%81%8F%E3%81%A0%E3%81%95%E3%81%84%3C%2FP%3E%3C%2FLINGO-BODY%3E