Hi,
I am looking to write an ISR in C (bare metal) for one Kinetis L.
However I didn't get any procedure to setup any particular ISR.
Can somebody guide me where should I look for these details?
.....Still better if I can get an example code.
Solved! Go to Solution.
ok...thank you one and all.
I've tested this and this works.
Well I think basic idea is that correspoinding to a IRQ function in Kinetis_sysinit.c, you have to create a function by the same name (Example UART0_IRQHandler() for UART0). The newly defined function would be the ISR for the interrut(UART0 in this case).
Let me know if I've missed anything.
Put this in main.c:
/*
* SET_NMI_INTERRUPT() - This will cause an NMI interrupt.
* It is a one shot, and does not need to be reset.
*/
#define SET_NMI_INTERRUPT() SCB_ICSR |= SCB_ICSR_NMIPENDSET_MASK
volatile int nmi_counter=0;
void NMI_Handler() // override the weak definition
{
++nmi_counter; // Put a break point here.
}
int main(int argc,char **argv)
{
while(1)
SET_NMI_INTERRUPT();
}
|
ok...thank you one and all.
I've tested this and this works.
Well I think basic idea is that correspoinding to a IRQ function in Kinetis_sysinit.c, you have to create a function by the same name (Example UART0_IRQHandler() for UART0). The newly defined function would be the ISR for the interrut(UART0 in this case).
Let me know if I've missed anything.
Look in kinetis_sysinit.c.
For example, if I define " void SysTick_Handler(){}" else where, that will go in the vector table due to the weak keyword.
In ARM, a plain"C" function can be an interrupt handler, as the hardware knows that when a function returns it was from an interrupt, and how to handle it.
Thanks for your response Marco....though I should have mentioned that I am using CodeWarrior10.3.......
But I think this should help.......Let me check.
Looking forward to more explanations/responses ......like more generic ones.
Hi Vivek,
I can tell you how I got working ISR for Kinetis, but I guess it depends on the toolchain you're using.
With IAR Embedded Workbench, I just declare the ISR like a normal routine:
void lptmr_isr(void)
{
lp_seconds++;
LPTMR0_CSR |= LPTMR_CSR_TCF_MASK; // write 1 to TCF to clear the LPT timer compare flag
}
In the example I use LPTMR for 1 second interrupt; I have a file named vectors.c taken from the sample code. It declares an array and forces it to be allocated in the intvec segment:
#pragma location = ".intvec"
const vector_entry __vector_table[] = //@ ".intvec" =
{
VECTOR_000, /* Initial SP */
VECTOR_001, /* Initial PC */
VECTOR_002,
VECTOR_003,
...
The entries VECTOR_*** are defined in vectors.h
#define VECTOR_000 | (pointer*)__BOOT_STACK_ADDRESS | |
#define VECTOR_001 | __startup | |
#define VECTOR_002 | default_isr |
you just have to substitue the right entry with your ISR. I'm working this way on KL15, KL25, K70 families.
Regards
Marco