#include <zephyr.h>
#include <sys/printk.h>
#include <drivers/uart.h>

#define UART_DEV_NAME DT_LABEL(DT_NODELABEL(uart0))
#define UART_BUF_SIZE 1024

static uint8_t uart_buf [UART_BUF_SIZE];

static void uart_cb(const struct device * uart, void * user_data)
{
	
	uart_irq_update(uart);
    int data_length = 0;

	if (uart_irq_rx_ready(uart)) {
		data_length = uart_fifo_read(uart, uart_buf,
					     UART_BUF_SIZE);
		uart_buf[data_length] = 0;
    }
    printk("%s", uart_buf);
}

void main(void)
{
        
	const struct device *uart = device_get_binding(UART_DEV_NAME);

	uart_irq_callback_set(uart, uart_cb);
	uart_irq_rx_enable(uart);
	printk("UART sample start\n");
	while (1) {
		k_cpu_idle();
	}
}