Hi,
I have a nRF52833 DK which I'm evaluating for a new product which uses a UART connected GPS receiver.
I found some simple UART code which compiles OK, but crashes when uart_irq_callback_set is called.
I think I have everything set up OK, so I'm not sure where the problem is.
What am I missing?
Thanks
Andy
proj.conf:
CONFIG_SERIAL=y CONFIG_UART_ASYNC_API=n CONFIG_UART_INTERRUPT_DRIVEN=y
main.c
#include <zephyr.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/uart.h>
#include "SEGGER_RTT.h"
static uint8_t uart_buf[1024];
const struct device *uart;
#define UART1_BUS DT_NODELABEL(uart1)
static const struct uart_config uart1_bus_cfg = {
.baudrate = 9600,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE,
};
void uart_cb(const struct device *x, void *user_data)
{
uart_irq_update(x);
int data_length = 0;
if (uart_irq_rx_ready(x)) {
data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
uart_buf[data_length] = 0;
}
uart_fifo_fill(x, uart_buf, data_length);
}
void main(void)
{
SEGGER_RTT_WriteString(0, "UART Test\r\n");
uart = device_get_binding(DT_LABEL(UART1_BUS));
uart_configure(uart, &uart1_bus_cfg);
if (uart != NULL)
{
SEGGER_RTT_WriteString(0,"UART1 Open\n");
}
else
{
SEGGER_RTT_WriteString(0,"UART1 not available\n");
}
uart_irq_callback_set(uart, uart_cb);
uart_irq_rx_enable(uart);
uart_fifo_fill(uart, "UART loopback start!\r\n", 22);
SEGGER_RTT_WriteString(0, "UART loopback start!\r\n");
while (1) {
k_cpu_idle();
}
}
dts:
&uart1 {
compatible = "nordic,nrf-uarte";
status = "okay";
current-speed = <9600>;
rx-pin = <34>; //<8>;
tx-pin = <33>; //<21>;
};