Question

I just enabled receive interrupts for UART3, but I get a hard fault as soon as I send it data. Here's how I'm initializing it:

LPC_UART_TypeDef *uart;

LPC_SC->PCONP |= 1 << 25;
LPC_PINCON->PINSEL1 |= 0b1111 << 18;

uart = LPC_UART3;
uart->FCR = 0b111; // Reset FIFOs
uart->LCR = 0b10000011;
uart->DLL = 12;
uart->DLM = 0;
uart->FDR = 0xe5;
uart->LCR = 0b00000011;
uart->IER = 1; // Enable RBR interrupt

NVIC_EnableIRQ(UART3_IRQn);

According to GDB, my ISR isn't even getting hit. I've confirmed that it's in my vector table at the right place, with the correct address plus bit 0 set (for Thumb-2 mode, as it is for all my other handlers). In fact, when I replace the ISR with an empty function, I still get the fault. Here's the output from my fault handler:

Hard fault FORCED 
   r0 = 0000000a
   r1 = 0000000b
   r2 = 000002ed
   r3 = 00000000
  r12 = 00000000
   lr = fffffffd
   pc = 00000000
  psr = 60000218
 BFAR = e000ed38
 CFSR = 00020000
 DFSR = 00000000
 AFSR = 00000000
SHCSR = 00070000

Neither LR nor PC seem very helpful. This is the first IRQ I've added. All the other vector table entries are SysTick and below.

How can I find out what's causing the fault?

Here's my vector table:

.word zeptos_msp_top
.word zeptos_reset_isr
.word 0 /* NMI */
.word zeptos_hardfault_isr_shim
.word zeptos_memmanage_isr
.word zeptos_busfault_isr
.word zeptos_usagefault_isr
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word 0 /* Reserved */
.word zeptos_svc_isr
.word 0 /* DebugMon */
.word 0 /* Reserved */
.word zeptos_pendsv_isr
.word zeptos_systick_isr
.word 0 /* WDT */
.word 0 /* Timer 0 */
.word 0 /* Timer 1 */
.word 0 /* Timer 2 */
.word 0 /* Timer 3 */
.word 0 /* Timer 4 */
.word 0 /* UART 0 */
.word 0 /* UART 1 */
.word 0 /* UART 2 */
.word zeptos_uart3_isr
Était-ce utile?

La solution

The 0x00 for the PC register looks suspicous like a 0x00000000 in the vector table. Check whether your interrupt vector table is correct, the handler for UART3on lpc176x is at position 24.

The table entry ((uint32_t*)0x00000)[24] must point to your handler plus thumb bit.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top