LPTMR interrupt stuck in Default ISR - KL46, KDS, SDK 2

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

LPTMR interrupt stuck in Default ISR - KL46, KDS, SDK 2

Jump to solution
2,069 Views
carlosmendoza
Contributor III

Hi,

I'm hoping to trigger sampling from the ADC module using the low power timer's modulo counter interrupt. This is the interrupt that's generated when the value in the counter register CNR is equal to the value in the compare register CMR. However, running the code causes the microcontroller to loop indefinitely in the "DefaultISR". My best guess is that the microcontroller generates the interrupt and attempts to service it but then the microcontroller doesn't know which ISR to call so it gets stuck looping through the default ISR.

I'm using an FRDM-KL46 board, KDS and the SDK 2.0. I have successfully triggered the ADC module on this MCU with both the LPTMR and the Timer PWM module using CodeWarrior 10.6 and Processor Expert. But, I'm hoping to learn how to do this using KDS and the SDK 2.0.

Troubleshooting reveals the following hints:

1) Pausing execution and stepping through the code shows that the microcontroller configured the LPTMR registers correctly and that in fact the LPTMR's interrupt is generated. I can tell because the LPTMR's control and status register CSR has its timer compare flag bit TCF set to 1 when the code "hangs" and yet TCF was set to zero before hanging. I can also see that the CNR register reached the desired value. I know that the configuration is correct because I'm comparing my code against the LPTMR example that comes with the SDK 2.0 and that code works without problems.

Moreover, my code gets stuck looping in the "DefaultISR" code in "startup_MKL46Z4.S" line 190. Here the code loads the address of the "DefaultISR" into register r0 and then it jumps to this address. Thus, the code loops indefinitely jumping again into the DefaultISR instead of jumping to the LPTMR's ISR or whatever intermediate steps before eventually jumping to my LPTMR's ISR.

2) When I compile I get the following warning and additional information:

'LPTMR0_IRQHandler' defined but not used [-Wunused-function]
in expansion of macro 'LPTMR_LED_HANDLER'

I don't get this warning when I compile the LPTMR example included with the SDK 2.0. So this leads me to think that my LPTMR's ISR is not being "installed" in the vector table.

I understand that in the SDK 2.0, instead of installing ISRs we just name them using a standardized convention defined at the interrupt vector table in "startup_MKL46Z4.S". Then if we want to name the ISRs something else for convenience's sake then we just use a define statement. I'm using the definition LPTMR_LED_HANDLER as an alias for LPTMR0_IRQHandler just like it's done in the working LPTMR example provided with the SDK 2.0.

3) Last hint: in my code I have included some CMSIS header files because that's what I saw done in the ADC example provided in the SDK 2.0. I'm still not sure why this is done. However, one of these header files, "MKL46Z4.h" contains the statement LPTimer_IRQHandler which is defined as LPTMR0_IRQHandler. That code section has the comment "SDK_Compatibility_Symbols". Therefore, twice in the code I have statements that are aliases for "LPTMR0_IRQHandler". This made me think that perhaps the presence of the CMSIS headers is generating a conflict with the interrupt vector table. If I comment out the  LPTimer_IRQHandler define statement in the CMSIS file then I no longer get the compiler warning about my LPTMR's ISR being defined but not used. The code still gets stuck looping in the DefaultISR but at least this gives me an additional hint of what the problem might be.

That's all I have for now. I wouldn't be surprised if there's a very easy fix for this problem or a simple detail I'm overlooking.

Any troubleshooting ideas would help a lot. Many thanks in advance!

Carlos

lptmr

frdm-kl46z

#kds 3.2.0

#sdk 2

cmsis

defaultisr

Labels (1)
1 Solution
1,222 Views
carlosmendoza
Contributor III

I figured it out! I accidentally declared my ISR as "static". So, of course, it was inaccessible to any code outside of my LPTMR C module.

Moral of the story: ISRs must be public. Otherwise they don't get linked to the vector table and your MCU gets stuck in the Default ISR trying to service an interrupt without a corresponding routine.

I'll leave the question here because I'm sure I'm not the only person bound to make this mistake. If anything, I learned how the vector table works in SDK 2.0 :smileywink:

View solution in original post

3 Replies
1,223 Views
carlosmendoza
Contributor III

I figured it out! I accidentally declared my ISR as "static". So, of course, it was inaccessible to any code outside of my LPTMR C module.

Moral of the story: ISRs must be public. Otherwise they don't get linked to the vector table and your MCU gets stuck in the Default ISR trying to service an interrupt without a corresponding routine.

I'll leave the question here because I'm sure I'm not the only person bound to make this mistake. If anything, I learned how the vector table works in SDK 2.0 :smileywink:

1,222 Views
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Carlos,

Thanks for sharing how you fixed the error.

Best Regards!
Carlos Mendoza
Technical Support Engineer

0 Kudos
1,222 Views
carlosmendoza
Contributor III

I saw the following advice to my problem in the Kinetis SDK FAQ but I'm not sure how to apply it for the SDK 2.0.

I’m trying to use a driver and keep falling into the default ISR in startup_<mcu>.s

Make sure to include an interrupt handler for the peripheral you’re using inside your project. By default, all the peripheral IRQ handlers go into a default handler that does an infinite branch. The easiest way to fix this issue is to add the C:\Freescale\KSDK_1.2.0\platform\drivers\src\<drivername>\fsl_<drivername>_irq.c file inside your project.

The SDK 2.0 folders don't contains any fsl_<drivername>_irq.c files or any *irq*.c files. I do see them in the KSDK_1.3.0 but the LPTMR example from SDK 2.0 doesn't use them either.

Again, this tells me that my ISR doesn't get registered or linked to the interrupt vector table even though I'm pretty much copying the working code from the LPTMR example in the SKD 2.0 folders.

0 Kudos