How do I setup a flextimer overflow interrupt function?

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

How do I setup a flextimer overflow interrupt function?

Jump to solution
1,379 Views
DanKSI
Contributor III

Hi,

I have a question regarding setting up an interrupt function to be called when a FlexTimer overflow occurs.  I want to use the FlexTimer 0 to call the Flex0_ISR function everytime the timer overflows, but the interrupt function is not being called.  From what I can tell, the timer is running, as I see CNT register increasing, and I believe the interrupt should be firing at the FlexTimer level (SC->TOF and SC->TOIE are both set to 1).  I am sure I am overlooking something or enabling the incorrect interrupt.

Thanks.

This is code I am using:

//Interrupt function prototype

static void    Flex0_ISR (pointer);

void cmsis_task(uint_32 node_num)

{

  _mqx_uint mqxIntReturn;

  //Setup the interrupt

  _int_install_isr(NVIC_FlexTimer0, Flex0_ISR, NULL);

  mqxIntReturn =  _bsp_int_init(NVIC_FlexTimer0, 7, 0, TRUE);

  //Enable the clock to the FlexTimer 0

  CCM_CCGR1 |= CCM_CCGR1_CG8(0x3); //FTM0 clock is on during all modes, except stop mode (0x03)

  CCM_CSCMR2 = (CCM_CSCMR2 & CCM_CSCMR2_FTM0_EXT_CLK_SEL_MASK) | CCM_CSCMR2_FTM0_EXT_CLK_SEL(2);

  CCM_CSCDR1 |= CCM_CSCDR1_FTM0_CLK_EN_MASK;

  //Setup FlexTimer 0

  FTM0_MOD = 83;

  FTM0_CNT = 0x0; //Reset counter to zero

  FTM0_CNTIN = 0; //Set the Counter Initial Value to 0

  //Set FTM 0 Clock Source to System Clock, and Prescaler to / 1

  FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0) | FTM_SC_TOIE_MASK;

  //Ensure the M4 can access the FlexTimer 0 interrupt

  MSCM_BASE_PTR->IRSPRC42 = 0x03;

}

int doFlexOnce = 0;

//Interrupt function

static void Flex0_ISR(pointer parameter)

{

  if(doFlexOnce == 0)

  {

  doFlexOnce++;

  }

}

Labels (2)
Tags (2)
0 Kudos
1 Solution
903 Views
DanKSI
Contributor III

Hi.

I was able to get the ISR function call working by changing the interrupt priority from 7 to 3 in the _bsp_int_init function call.  I added some code to clear the TOF bit in the FTM_SC register when inside the ISR function and it now functions as expected.

Thanks.

View solution in original post

0 Kudos
4 Replies
904 Views
DanKSI
Contributor III

Hi.

I was able to get the ISR function call working by changing the interrupt priority from 7 to 3 in the _bsp_int_init function call.  I added some code to clear the TOF bit in the FTM_SC register when inside the ISR function and it now functions as expected.

Thanks.

0 Kudos
903 Views
timesyssupport
Senior Contributor II

Hello Dan,

Could you clarify please, is this under Linux, or MQX? If MQX, I apologize, but we are only able to support Linux Vybrid issues.

Thank you,

Timesys Support

0 Kudos
903 Views
DanKSI
Contributor III

I am finally getting back to this.  I am trying to set this up using MQX on the M4.

I need to have some specific timings to control some external hardware and if MQX gets in the way too much, I may need to switch to a bare metal approach.

Thanks for any help with this.

0 Kudos
903 Views
karina_valencia
NXP Apps Support
NXP Apps Support

timesyssupport​ can you help here?

0 Kudos