Multiple GPT Timers on IMXMN8

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

Multiple GPT Timers on IMXMN8

471 Views
borges89
Contributor I

void GPT1_IRQHandler(void){

GPT_ClearStatusFlags(GPT1, kGPT_OutputCompare1Flag);
gpt1IsrFlag=true;

#if defined __CORTEX_M && (__CORTEX_M == 4U || __CORTEX_M == 7U)
__DSB();
#endif
}


void GPT2_IRQHandler(void){

GPT_ClearStatusFlags(GPT2, kGPT_OutputCompare1Flag);
gpt2IsrFlag=true;
//Gridif_fixed_pll();

#if defined __CORTEX_M && (__CORTEX_M == 4U || __CORTEX_M == 7U)
__DSB();
#endif
}
//Gridif_variable_pll();
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F, Cortex-M7, Cortex-M7F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
//#if defined __CORTEX_M && (__CORTEX_M == 4U || __CORTEX_M == 7U)
// __DSB();
//#endif
//}
void timers_init(void)
{
uint32_t gptFreq;
gpt_config_t gptConfig;

/* Board pin, clock, debug console init */
/* M7 has its local cache and enabled by default,
* need to set smart subsystems (0x28000000 ~ 0x3FFFFFFF)
* non-cacheable before accessing this address region */


CLOCK_SetRootMux(kCLOCK_RootGpt2, kCLOCK_GptRootmuxSystemPll2Div10); /* Set GPT2 source to SYSTEM PLL2 DIV10 100MHZ */
CLOCK_SetRootDivider(kCLOCK_RootGpt2, 1U, 2U);

GPT_GetDefaultConfig(&gptConfig);

/* Initialize GPT modules */
GPT_Init(GPT2, &gptConfig);

 

/* Set root clock to 400MHZ / 2 = 50MHZ */

 

CLOCK_SetRootMux(kCLOCK_RootGpt1, kCLOCK_GptRootmuxSysPll1Div2); /* Set GPT1 source to SYSTEM PLL1 DIV2 400MHZ */
CLOCK_SetRootDivider(kCLOCK_RootGpt1, 1U, 4U);

/* Initialize GPT modules */
GPT_Init(GPT1, &gptConfig);

 

/* Divide GPT clock source frequency by 3 inside GPT module */
GPT_SetClockDivider(GPT1, 3);
GPT_SetClockDivider(GPT2, 1);


/* Get GPT clock frequency */
gptFreq = GPT1_CLK_FREQ;

/* GPT frequency is divided by 3 inside module */
gptFreq /= 3;

/* Set both GPT modules to 1 second duration */
GPT_SetOutputCompareValue(GPT1, kGPT_OutputCompare_Channel1, gptFreq/25000);
GPT_SetOutputCompareValue(GPT2, kGPT_OutputCompare_Channel1, 1628); // 512*60 Hz

/* Enable GPT Output Compare1 interrupt */
GPT_EnableInterrupts(GPT1, kGPT_OutputCompare1InterruptEnable);
GPT_EnableInterrupts(GPT2, kGPT_OutputCompare1InterruptEnable);

/* Enable at the Interrupt */
EnableIRQ(GPT1_IRQn);
EnableIRQ(GPT2_IRQn);
NVIC_SetPriority(GPT1_IRQn, 0x8);
NVIC_SetPriority(GPT2_IRQn, 0x0);
GPT_StartTimer(GPT2);
GPT_StartTimer(GPT1);


/* Set both GPT modules to 1 second duration */
// GPT_SetOutputCompareValue(GPT2, kGPT_OutputCompare_Channel1, 1);

/* Enable GPT Output Compare1 interrupt */
// GPT_EnableInterrupts(GPT2, kGPT_OutputCompare1InterruptEnable);

/* Enable at the Interrupt */
// EnableIRQ(GPT2_IRQn);
// GPT_StartTimer(GPT2);


}

 

 

 

I am trying to run two GPT timer interrupts. While each one of them work but when I try to start them together, debugger in Eclipse reboots. Can you please help me fix this? Is there any demo available where multiple ISRs are configured on different GPT timers. 

0 Kudos
0 Replies