Weird thing is going on here.
I have LPC1788 board and I just started writing a simple application. If I initialize timer like this, code seems to be executed, but of course my timer interrupt is not called.
void initTimer (void) { LPC_TIM_TypeDef *timer = LPC_TIM1; LPC_SC->PCONP |= (0x1<<2); timer->TC = 0x00; //Clear Timer Counter timer->PR = 0x00; //No prescaler timer->MCR = 0x3; //enable interrupt timer->MR0 = 0x02710; //interrupt every 1ms //NVIC_EnableIRQ(TIMER1_IRQn); timer->TCR = 0x02; //reset timer timer->TCR = 0x01; //enable timer counter } void TIMER1_IRQHandler(void) { LPC_TIM1->IR = (1u<<0); // Reset the MR0 Interrupt; Writing a zero has no effect. decrementFlags(); }
As soon as I enable NVIC IRQ, my code crash and points to Default_Handler PROC in startup.s. Deducing R15(PC) with -8 and use U 0xXXX, I end up in SVC_Handler part. My Timer1_IRQ never got called.
There is really nothing going on in the code besides this. As I just started writing program and hit the wall...
Any idea what else could I try, to debug this ?
Thanks.
It is the .cpp file. Apart from the code above which is in main.cpp file, i only have startup_LPC177x_8x.s file in the project.
No need to paste whole .s file ... this is only the part of Default handler and vectors in which timer is defined ... rest is removed from the post (but it exists in the project code).
__Vectors DCD __initial_sp ; Top of Stack DCD Reset_Handler ; Reset Handler DCD TIMER0_IRQHandler ; 17: Timer0 DCD TIMER1_IRQHandler ; 18: Timer1 DCD TIMER2_IRQHandler ; 19: Timer2 DCD TIMER3_IRQHandler ; 20: Timer3 IF :LNOT::DEF:NO_CRP AREA |.ARM.__at_0x02FC|, CODE, READONLY CRP_Key DCD 0xFFFFFFFF ENDIF AREA |.text|, CODE, READONLY Default_Handler PROC EXPORT WDT_IRQHandler [WEAK] EXPORT TIMER0_IRQHandler [WEAK] EXPORT TIMER1_IRQHandler [WEAK] EXPORT TIMER2_IRQHandler [WEAK] EXPORT TIMER3_IRQHandler [WEAK] EXPORT PLL1_IRQHandler [WEAK] WDT_IRQHandler TIMER0_IRQHandler TIMER1_IRQHandler TIMER2_IRQHandler TIMER3_IRQHandler PLL1_IRQHandler B . ENDP ALIGN
But it is the standard startup file that is included when the project is created. Havent modify anything from it.
extern "C" void TIMER0_IRQHandler(void) { if ( (LPC_TIM0->IR & 0x01) == 0x01 ) { LPC_TIM0->IR |= 1 << 0; } }
extern "C" void TIMER0_IRQHandler(void)
Good call.
If compiling for C++, then the compiler will add name mangling of external C++ symbols as a means to type-safe linking.
But C++ name mangling means the external symbol name of the interrupt handler will not match the name that the assembler file expects - the startup code is written to match the symbol names of a C program.
I was wondering when one of you oiks would think of that.
That is it. It works now! Thank you.
You're welcome. Always here to help.
Yeah
"I was wondering when one of you oiks would think of that."
It took quite a time before this thread got this sentence: "It is the .cpp file."
The original post did not show any C++ code and no file name or file extension was named. But the OP did get the suggestion to verify that the name of the handler actually matched the name expected by the startup file.
It can be quite hard to guess all important information the thread starters tends to forget to mention, while assuming it isn't relevant.