We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hey all. We are having a weird issue on an LPC2148 part. Code here:
Main source file:
#include <LPC214X.h> #include "event.h" #include "timer.h" #include "PJstate.h" #include "led.h" #include "buffer.h" #include "pc.h" EVENTGROUP pjEvent = 0; EVENTGROUP ioEvent = 0; void UARTS_Init(void) { // int irqID; // Fpclk = 15.000.000 MHz // DLM,DLH = Fpclk / (9600*16) = 98 = 0x62 PINSEL0 |= 0x00050000; // Select UART1 RXD/TXD & UART0 RXD/TXD // UART1 - PC side U1FCR = 7; // Enable and clear FIFO's U1LCR = 0x83; // 8N1, enable Divisor latch bit U1DLL = 0x62; U1DLM = 0; // baud rate fixed to 9600 @ PCLK = 15 Mhz U1LCR = 3; // Disable Divisor latch bit U1IER = 0x00; // Disable(d) RBR Interrupt } void Timer0_Init(void) { T0CTCR = 0x00; // Timer Mode T0TCR = 0x01; // Enable Counter T0MCR = 0x03; // Interrupt and Reset when TC = T0MR0 //T0MR0 = 0x00003A98; // 1ms = 15k T0MR0 = 0x00003a98; } __irq void IRQ_Timer(void) { T0IR = 0x01; // Clear Timer Interrupt VICVectAddr = (unsigned long)0; } void Interrupt_Init(void) { VICVectCntl0 = 0x00000024; VICVectAddr0 = (unsigned long)&IRQ_Timer; VICIntSelect = 0x00000000; VICIntEnable = 0x00000010; } void DebounceSwitch3(void) { } void ServIO(void) { setEvent(DEBOUNCE, &ioEvent); if (chkEvent(DEBOUNCE, &ioEvent)) { //DebounceSwitch3(); } } int main (void) { int running = 0; Timer0_Init(); UARTS_Init(); Interrupt_Init(); U1THR = 'X'; while (1) { PJFsmMain(); ServIO(); } } // main
Other source file (hdr with prototype not included):
void PJFsmMain(void) { PJPowerOn(); } void PJPowerOn(void) { }
The program when compiled endlessly spits 'X' out on the serial port. It is continuously crashing/resetting.
Modifying pretty much any line within the code makes it so it does not crash. Simply removing the DebounceSwitch3() function that is not called will make the code not crash. Remove the calls to PJFsmMain() that simply calls another empty function and everything seems fine. Really looks to me like something is getting corrupted somewhere but from a code perspective, I do not see where.
Our startup.s was modified to leave the processor in supervisor mode. irq stack = 0x80bytes, supervisor stack = 0x400bytes.
I think the problem must be related to interrupt/stack corruption issues however i am at a bit of a loss as to what to look for next/how to prove it.
Thanks for any suggestions, Ryan
Unfortunately if you're referring to the '&', this is not the issue.
Somewhat bizarre actually. Both
VICVectAddr0 = (unsigned long)IRQ_Timer; and VICVectAddr0 = (unsigned long)&IRQ_Timer;
Compile to the same thing believe it or not!
SUB R0,PC,#0x00000034 STR R0,[R1,#-0x0F00]
I had noticed that before but as I know the code is getting to the timer handler had assumed it was correct despite it looking otherwise. Seems like a compiler bug to me.
Somewhat bizarre actually.
Actually, not at all. That's how functions have to behave, as per the definition of the language.
Seems like a compiler bug to me.
On the contrary. Any other behaviour would constitute a bug.
Guess I've never asked myself how &function_name should behave. I would have thought that an error should have been generated but know otherwise now. Learn something new every day. I've always simply used the function name.
None the less, main issue still remains. =) Any suggestions?
Some compilers warns about a superfluous &. Some compilers don't.
Revenge of the uninitialized default handler. Remember to initialize VICDefVectAddr. Time to read about handling spurious interrupts.
Thanks to the people who read/responded!