STM Timer+IfxCpu_disableInterrupts() problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User20311
Level 1
Level 1
10 sign-ins 10 replies posted 5 replies posted
chip:tc275
ide:ads

steps:

1.Making a 1ms timer:



static void prvSetupTimerInterrupt( void )
{
IfxStm_Timer_Config timerConfig;
IfxStm_Timer_initConfig(&timerConfig, STMs[CPU_ID]);
timerConfig.base.frequency = 1000; //1ms
timerConfig.base.isrPriority = 2;
IfxStm_Timer_init(&Timers[CPU_ID], &timerConfig);
IfxStm_Timer_run(&Timers[CPU_ID]);
}

IFX_INTERRUPT(stm0_isr, 0, 2)
{
counter1ms++;
}


2.

delay(int ms)
{
var old=counter1ms;
while(counter1ms-old>=ms);
}
core0_main()
{
.....//init code
prvSetupTimerInterrupt();

boolean interruptState = IfxCpu_disableInterrupts();

int32_t i=1000000;
while(i--);//Simulate time-consuming operations, such as flash operations

IfxCpu_restoreInterrupts(interruptState);

delay(10);

}


Problem:
When the simulation time-consuming operation( such as while i--, or flash operations ) takes a little time and the delay (10) function is executed, the STM timer will no longer enter the interrupt, until after a period of time, the STM will re-enter the interrupt (may be STM overflow?)

How to solve this problem?
0 Likes
7 Replies
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
The STM doesn't generate periodic interrupts (except for overflow). In your STM IRQ handler, you need to set the STM up for the next period. Try this:

IFX_INTERRUPT(stm0_isr, 0, 2)
{
counter1ms++;
IfxStm_Timer_acknowledgeTimerIrq( &timerConfig );
}

Have a look at StmDemo.c for a full implementation.
0 Likes
User20311
Level 1
Level 1
10 sign-ins 10 replies posted 5 replies posted
Yes, I forgot to write on this post. I already have this statement in my code
4852.attach
But the problem still exists
0 Likes
JexJiang
Level 3
Level 3
25 replies posted 5 questions asked First solution authored

Hi,Do you solve it?I ran into the same problem

0 Likes

Hi @JexJiang .  What does your ISR look like?  The iLLD API has changed a bit, and this is the new implementation per the iLLD documentation:

IFX_INTERRUPT(stm0Sr0ISR, 0, IFX_INTPRIO_STM0_SR0)
{
IfxStm_increaseCompare(stmSfr, stmConfig.comparator, stmConfig.ticks);
}
 
 
0 Likes

企业微信截图_16415205016892.png

yes, This is my ISR.but when i used 

boolean interruptState = IfxCpu_disableInterrupts();

//to do some things
IfxCpu_restoreInterrupts(interruptState);
It can't enter ISR.

 

0 Likes
µC_Wrangler
Employee
Employee
50 solutions authored 100 sign-ins 25 likes received

Hmm, that's odd - once the interrupt is pending, the ISR should be invoked after interrupts are restored, regardless of how long interrupts were disabled.

Can you try adding a line before the IfxCpu_restoreInterrupts line to capture the interrupt pending flag into a global variable?  Something like this:

stm0_pending = SRC_STM0SR0.B.SRR;

0 Likes

Hi:

 Thanks for your reply.I created a new project and tested it. The reason is not that the STM interrupt is not generated, but that it entered the state of IfxCpu_Trap_contextManagementError. I started a new question:https://community.infineon.com/t5/AURIX/TC397-STM-Interrupt-and-Pflash-operation-conflict/m-p/330626...

0 Likes