From 3d057a7b53564e77e144af49aacf764b51b849f6 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Sun, 28 Jun 2026 16:21:26 -0300 Subject: [PATCH] arch/arm: Fix LPC2378 to work again Olimex LPC-2378-STK was the first board I ran NuttX in 2010. Then in 2023 I found this board on eBay and decided to buy it to try NuttX on it again, but for my disappointment it was not working: https://acassis.wordpress.com/2023/04/01/testing-nuttx-again-on-olimex-lpc2378-stk-board/ Then I opened an Issue: https://github.com/apache/nuttx/issues/19201 and Xiang Xiao and ldube helped me to get it working again. Signed-off-by: Alan C. Assis --- arch/arm/include/lpc2378/irq.h | 2 -- arch/arm/src/lpc2378/lpc2378.h | 2 -- arch/arm/src/lpc2378/lpc23xx_decodeirq.c | 35 +++++++++++++++--------- arch/arm/src/lpc2378/lpc23xx_irq.c | 6 ---- arch/arm/src/lpc2378/lpc23xx_timerisr.c | 10 ------- 5 files changed, 22 insertions(+), 33 deletions(-) diff --git a/arch/arm/include/lpc2378/irq.h b/arch/arm/include/lpc2378/irq.h index 423159a533d09..bf60801f5d25d 100644 --- a/arch/arm/include/lpc2378/irq.h +++ b/arch/arm/include/lpc2378/irq.h @@ -119,10 +119,8 @@ extern "C" #define EXTERN extern #endif -#ifndef CONFIG_VECTORED_INTERRUPTS void up_attach_vector(int irq, int priority, vic_vector_t handler); void up_detach_vector(int vector); -#endif #undef EXTERN #ifdef __cplusplus diff --git a/arch/arm/src/lpc2378/lpc2378.h b/arch/arm/src/lpc2378/lpc2378.h index d9023e84fef15..f1495f6601f60 100644 --- a/arch/arm/src/lpc2378/lpc2378.h +++ b/arch/arm/src/lpc2378/lpc2378.h @@ -50,8 +50,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* #define CONFIG_VECTORED_INTERRUPTS */ - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/arch/arm/src/lpc2378/lpc23xx_decodeirq.c b/arch/arm/src/lpc2378/lpc23xx_decodeirq.c index c8c56e250ba41..47f2bbb496f79 100644 --- a/arch/arm/src/lpc2378/lpc23xx_decodeirq.c +++ b/arch/arm/src/lpc2378/lpc23xx_decodeirq.c @@ -84,11 +84,7 @@ * ****************************************************************************/ -#ifndef CONFIG_VECTORED_INTERRUPTS -uint32_t *arm_decodeirq(uint32_t *regs) -#else static uint32_t *lpc23xx_decodeirq(uint32_t *regs) -#endif { struct tcb_s *tcb = this_task(); @@ -144,22 +140,35 @@ static uint32_t *lpc23xx_decodeirq(uint32_t *regs) #endif } -#ifdef CONFIG_VECTORED_INTERRUPTS uint32_t *arm_decodeirq(uint32_t *regs) { - vic_vector_t vector = (vic_vector_t) vic_getreg(VIC_ADDRESS_OFFSET); +#ifdef CONFIG_SUPPRESS_INTERRUPTS + err("ERROR: Unexpected IRQ\n"); + PANIC(); +#else + + /* Check which IRQ fires */ - /* Acknowledge the interrupt */ + uint32_t irqbits = vic_getreg(VIC_IRQSTATUS_OFFSET) & 0xffffffff; + unsigned int irq; - arm_ack_irq(irq); + for (irq = 0; irq < NR_IRQS; irq++) + { + if (irqbits & (uint32_t) (1 << irq)) + { + break; + } + } - /* Valid Interrupt */ + /* Verify that the resulting IRQ number is valid */ - if (vector != NULL) + if (irq < NR_IRQS) { - (vector)(regs); + /* Deliver the IRQ */ + + regs = arm_doirq(irq, regs); } +#endif - return NULL; /* Return not used in this architecture */ + return regs; } -#endif diff --git a/arch/arm/src/lpc2378/lpc23xx_irq.c b/arch/arm/src/lpc2378/lpc23xx_irq.c index 9b05374a4b4a0..1febde9c636e8 100644 --- a/arch/arm/src/lpc2378/lpc23xx_irq.c +++ b/arch/arm/src/lpc2378/lpc23xx_irq.c @@ -193,9 +193,7 @@ void arm_ack_irq(int irq) /* Clear interrupt */ vic_putreg((1 << irq), VIC_SOFTINTCLEAR_OFFSET); -#ifdef CONFIG_VECTORED_INTERRUPTS vic_putreg(0, VIC_ADDRESS_OFFSET); /* dummy write to clear VICADDRESS */ -#endif } /**************************************************************************** @@ -230,7 +228,6 @@ int up_prioritize_irq(int irq, int priority) * ****************************************************************************/ -#ifndef CONFIG_VECTORED_INTERRUPTS void up_attach_vector(int irq, int vector, vic_vector_t handler) { /* Verify that the IRQ number and vector number are within range */ @@ -255,7 +252,6 @@ void up_attach_vector(int irq, int vector, vic_vector_t handler) leave_critical_section(flags); } } -#endif /**************************************************************************** * Name: up_detach_vector @@ -265,7 +261,6 @@ void up_attach_vector(int irq, int vector, vic_vector_t handler) * ****************************************************************************/ -#ifdef CONFIG_VECTORED_INTERRUPTS void up_detach_vector(int vector) { /* Verify that the vector number is within range */ @@ -278,4 +273,3 @@ void up_detach_vector(int vector) vic_putreg(0, (VIC_VECTADDR0_OFFSET + offset)); } } -#endif diff --git a/arch/arm/src/lpc2378/lpc23xx_timerisr.c b/arch/arm/src/lpc2378/lpc23xx_timerisr.c index 46f04cfd9e618..23d3d0b65734c 100644 --- a/arch/arm/src/lpc2378/lpc23xx_timerisr.c +++ b/arch/arm/src/lpc2378/lpc23xx_timerisr.c @@ -91,11 +91,7 @@ * ****************************************************************************/ -#ifdef CONFIG_VECTORED_INTERRUPTS -static int lpc23xx_timerisr(uint32_t * regs) -#else static int lpc23xx_timerisr(int irq, uint32_t * regs, void *arg) -#endif { static uint32_t tick; @@ -109,11 +105,9 @@ static int lpc23xx_timerisr(int irq, uint32_t * regs, void *arg) /* Reset the VIC as well */ -#ifdef CONFIG_VECTORED_INTERRUPTS /* write any value to VICAddress to acknowledge the interrupt */ vic_putreg(0, VIC_ADDRESS_OFFSET); -#endif if (tick++ > 100) { @@ -186,11 +180,7 @@ void up_timer_initialize(void) /* Attach the timer interrupt vector */ -#ifdef CONFIG_VECTORED_INTERRUPTS - up_attach_vector(IRQ_SYSTIMER, ???, (vic_vector_t) lpc23xx_timerisr); -#else irq_attach(IRQ_SYSTIMER, (xcpt_t)lpc23xx_timerisr, NULL); -#endif /* And enable the system timer interrupt */