This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART IRQ Callback Set Causes Crash

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>;
};
  • Hello,

    Please try the project attached below and see if it results in the same crash. I have not worked with the UART interrupt APIs before, but from the API documentation it seems like you can only call the send functions inside the UART callback itself. Maybe it is the call to uart_fifo_fill() from main() that causes your program to crash?

    Test code:

    7317.simple_uart.zip

    This project is one I made only to see if I could replicate the crash your mentioned. If you want a project to use as a reference, then it is probably better that you use the Low Power UART SDK sample.

    Best regards,

    Vidar

Related