I have setup the UART along the same lines as the sample project in the DevZone Academy. I have extended the example provided to suit the project needs.
What I am getting is a hard fault when data in received by the board.
The logic is
1. Configure the UART with a callback function.
2. Transmit test data every 1 second.
3. In the call back handle the UART_TX_DONE
4. In the UART_TX_DONE, enable the Rx with 100ms timeout.
5. In the UART_RX_DONE print the length of data received.
If I send any length of data to the board, it prints the length and hard faults.
The output from the board is as follows
00> UART event 2 00> UART Rx Length 3 00> [00:00:09.650,024] <err> os: ***** HARD FAULT ***** 00> [00:00:09.650,024] <err> os: Debug event 00> [00:00:09.650,054] <err> os: r0/a1: 0x00000000 r1/a2: 0x00000003 r2/a3: 0x00000002 00> [00:00:09.650,054] <err> os: r3/a4: 0x00000002 r12/ip: 0x00000004 r14/lr: 0x0001bc55 00> [00:00:09.650,085] <err> os: xpsr: 0x81000021 00> [00:00:09.650,085] <err> os: Faulting instruction address (r15/pc): 0x0001bc54 00> [00:00:09.650,115] <err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0 00> [00:00:09.650,146] <err> os: Fault during interrupt handling 00> 00> [00:00:09.650,177] <err> os: Current thread: 0x20004e18 (idle) 00> [00:00:09.913,208] <err> os: Halting system
UART event 2 is from the callback which is UART_RX_DONE
The call back function
static void uartRxCallback(const struct device *dev, struct uart_event *evt, void *user_data) { printk("UART event %d\n", evt->type); switch(evt->type) { case UART_RX_RDY: printk("UART Rx Length %d\n", evt->data.rx.len); break; case UART_RX_DISABLED: //uart_rx_enable(uartD, uartRxBuffer, UART_RX_BUFFER_SIZE, 100); break; case UART_RX_BUF_RELEASED: break; case UART_TX_DONE: //uartHandle->txLength = evt->data.tx.len; uart_rx_enable(uartD, uartRxBuffer, UART_RX_BUFFER_SIZE, 100); break; case UART_TX_ABORTED: printk("UART Tx Aborted\n"); break; case UART_RX_STOPPED: printk("UART Rx Stopped\n"); break; default: break; } }
Happy to provide more code if required.
The printk is piped to RTT.
Thanks