you might read further in that thread about adding asm volatile ("dsb") ; to ISR.
Turned out, that double calling of isr was not an issue for me (in my code isrCount1 and isrCount2 are always the same, apart from rare race condition). maybe because TFLG was polled?
So, I played further
Code:
uint32_t isrCount1=0;
uint32_t isrCount2=0;
void pitIsr() // 12 interrupts
{
for (int i = 0; i < 4; i++)
{
if (IMXRT_PIT_CHANNELS[i].TFLG == 1) // if channel TFLG is set, clear it
{
IMXRT_PIT_CHANNELS[i].TFLG = 1;
isrCount1++;
}
}
isrCount2++;
}
void pitIsr1() //48 interrupts
{
IMXRT_PIT_CHANNELS[0].TFLG = 1;
isrCount1++;
isrCount2++;
}
void pitIsr2() // 24 interruts
{
IMXRT_PIT_CHANNELS[0].TFLG = IMXRT_PIT_CHANNELS[0].TFLG;
isrCount1++;
isrCount2++;
}
void pitIsr3() //12 interrupts
{
IMXRT_PIT_CHANNELS[0].TFLG = IMXRT_PIT_CHANNELS[0].TFLG;
isrCount1++;
isrCount2++;
asm volatile ("dsb");
}
void pitIsr4() // 12 interrupts
{
IMXRT_PIT_CHANNELS[0].TFLG = 1;
isrCount1++;
isrCount2++;
asm volatile ("dsb");
}
void beginPIT(uint32_t cycles)
{
CCM_CCGR1 |= CCM_CCGR1_PIT(CCM_CCGR_ON);
PIT_MCR = 0;
IMXRT_PIT_CHANNELS[0].TCTRL=0;
IMXRT_PIT_CHANNELS[0].LDVAL = cycles;
IMXRT_PIT_CHANNELS[0].TFLG = 1;
IMXRT_PIT_CHANNELS[0].TCTRL = PIT_TCTRL_TEN | PIT_TCTRL_TIE;
attachInterruptVector(IRQ_PIT, pitIsr2);
NVIC_ENABLE_IRQ(IRQ_PIT);
}
void setup()
{
while(!Serial);
Serial.println("Test_PIT");
pinMode(LED_BUILTIN,OUTPUT);
beginPIT(1000*1000L);
}
void loop()
{ static uint32_t loopCount=0;
digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
delay(500);
Serial.printf("%10u %10u %10u %10u\n",loopCount,IMXRT_PIT_CHANNELS[0].CVAL, isrCount1, isrCount2);
loopCount++;
isrCount1=isrCount2=0;
}
that is:
pitIsr was called 12 times
pitIsr1 was called 48 times
pitIsr2 was called 24 times
pitIsr3 was called 12 times
pitIsr4 was called 12 times
single polling alone is not enough, either polling all or calling "dsb"