CONFIGURE UART ERROR IN NRF54L15

Hi everyone,
When I try configure UART (parity, data_bit, stop_bit, flow_ctrl), I have noticed error when I run in terminal: 
"

*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***

*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***

Failed to configure UART30, err -134

Failed to configure UART20, err -134
"

in file myuart.c: 

static struct uart_config uart_cfg = {
    .baudrate = 115200,
    .parity = UART_CFG_PARITY_NONE,
    .data_bits = UART_CFG_DATA_BITS_8,
    .stop_bits = UART_CFG_STOP_BITS_1,
    .flow_ctrl = UART_CFG_FLOW_CTRL_NONE,
};

void myuart_init(void)
{
    int ret;

    if (!device_is_ready(uart0_dev)) {
        printk("UART30 device not ready\n");
    }
    if (!device_is_ready(uart1_dev)) {
        printk("UART20 device not ready\n");
    }

    /* Configure UART20, UART30 */
    ret = uart_configure(uart0_dev, &uart_cfg);
    if (ret) {
        printk("Failed to configure UART30, err %d\n", ret);
    }
    ret = uart_configure(uart1_dev, &uart_cfg);
    if (ret) {
        printk("Failed to configure UART20, err %d\n", ret);
    }
};

Beside that, I configure UART in file devicetree:

&uart20 {
    compatible = "nordic,nrf-uarte";
    status = "okay";
    current-speed = <115200>;
    pinctrl-0 = <&uart20_default>;
    pinctrl-names = "default";
};

&uart30 {
    compatible = "nordic,nrf-uarte";
    status = "okay";
    current-speed = <115200>;
    pinctrl-0 = <&uart30_default>;
    pinctrl-names = "default";
};

You can explain for me with my error, please?

Thank for that,

  • Hello,

    How does the device pointer to UART20 looks like?

    It should look like this when error message shows uart20 in the message.

    const struct device *uart= DEVICE_DT_GET(DT_NODELABEL(uart20));

    You may check if device name is consistent every part of code.

  • Hi,
    I update my owner source code:

    #include "myuart.h"
    #include <zephyr/sys/printk.h>

    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS      1000

    /* Define the size of the receive buffer */
    // #define UART0_RX_BUF_SIZE  64
    // #define UART1_RX_BUF_SIZE  64
    #define RX_BUF_SIZE     64
    #define UART_BUF_SIZE   56

    #define BUFFER_SIZE 56 //Bộ đệm tổng cho 4 data EEG (môĩ data = 14 byte)
    #define DATA_LENGTH 28  
    #define DATA_COUNT 4

    /* Define the receiving timeout period */
    #define RECEIVE_TIMEOUT    100

    //configure GPIO UART for NRF54L15
    static const struct device *uart0_dev = DEVICE_DT_GET(DT_NODELABEL(uart30));
    static const struct device *uart1_dev = DEVICE_DT_GET(DT_NODELABEL(uart20));

    //configure GPIO UART for NRF52833
    // static const struct device *uart0_dev = DEVICE_DT_GET(DT_NODELABEL(uart0));
    // static const struct device *uart1_dev = DEVICE_DT_GET(DT_NODELABEL(uart1));

    /* Cấu hình UART (baudrate, parity, v.v.) */
    // static struct uart_config uart_cfg = {
    //     .baudrate = 115200,
    //     .parity = UART_CFG_PARITY_NONE,
    //     .data_bits = UART_CFG_DATA_BITS_8,
    //     .stop_bits = UART_CFG_STOP_BITS_1,
    //     .flow_ctrl = UART_CFG_FLOW_CTRL_NONE,
    // };

    /* Buffer nhận dùng cho uart_rx_enable() */
    static uint8_t rx_buf[RX_BUF_SIZE];

    /* Buffer RX cho UART */
    // struct uart_transfer {
    //     uint8_t buffer[BUFFER_SIZE];  // Lưu dữ liệu
    //     size_t  new_index;                 //Vị trí hiện tại trong buffer
    //     uint8_t msg_count;                // Số data input đã nhận (mỗi data kết thúc bằng 0x0A)
    // };

    struct uart_data_t {
        void *fifo_reserved;
        uint8_t data[UART_BUF_SIZE];
        uint16_t len;                       /* Số byte đã nhận được trong data[] */
    };

    /* Instance lưu trữ dữ liệu nhận */
    static struct uart_data_t uart_data_instance = {
        .len = 0,
        .data = {0},
    };

    /* Biến đếm số data input đã nhận (mỗi data kết thúc bằng \n, 0A) */
    static uint8_t data_count = 0;

    // fuction xử lý event UART
    static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
        struct uart_data_t *buf = (struct uart_data_t *)user_data;
        // struct uart_data_t *buf;
        // uint8_t count = 0;
        switch (evt ->type)
        {
            case UART_RX_RDY:
                /* evt->data.rx.buf: buffer nhận được (rx_buf)
                * evt->data.rx.offset: vị trí bắt đầu của dữ liệu mới
                * evt->data.rx.len: số byte dữ liệu nhận được
                */
                // size_t len = evt->data.rx.len;
                // size_t offset = evt->data.rx.offset;
                // uint8_t *data = (uint8_t *)evt->data.rx.buf;

                // buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data[0]);
                uint16_t offset = evt->data.rx.offset;
                uint16_t len = evt->data.rx.len;
                uint8_t *rx_data = (uint8_t *)evt->data.rx.buf + offset;
                // buf->len += evt->data.rx.len;

                /* Copy dữ liệu từ rx_buf sang buf->data, bắt đầu từ vị trí buf->len */
                // if ( (buf->len + len) <= UART_BUF_SIZE ) {
                //     memcpy(&buf->data[buf->len],
                //         ((uint8_t *)evt->data.rx.buf) + offset,
                //         len);
                //     buf->len += len;
                // } else {
                //     /* Nếu dữ liệu nhận được vượt quá kích thước buffer, bạn có thể xử lý lỗi ở đây */
                //     printk("Buffer overflow!\n");
                //     buf->len = 0;
                //     data_count = 0;
                //     break;
                // }

                // Kiểm tra tràn buffer
                if ((buf->len + len) > UART_BUF_SIZE) {
                    printk("Buffer overflow! Resetting\n");
                    buf->len = 0;
                    data_count = 0;
                    break;
                }

                // Copy dữ liệu vào buffer
                memcpy(&buf->data[buf->len], rx_data, len);
                buf->len += len;

                /* Kiểm tra ký tự cuối vừa nhận có phải là ký tự \n, 0A */
                // uint8_t last_byte = ((uint8_t *)evt->data.rx.buf)[buf->len - 1];

                // if ((last_byte == '\n') ||(last_byte == '\r') || (last_byte == '0x0A'))
                // {
                //     data_count++;
                //     printk("%d", data_count);
                // }

                // Kiểm tra từng byte để tìm ký tự kết thúc 0x0A
                for (int i = 0; i < len; i++) {
                    if (rx_data[i] == 0x0A || rx_data[i] == '\n' || rx_data[i] == '\r' )  {
                        data_count++;
                        printk("Data count: %d\n", data_count);
                    }
                }

                /* Nếu đã nhận đủ 4 data input (toàn bộ buffer được đầy) */
                if(data_count == DATA_COUNT)
                {
                    /* Gửi từng byte dữ liệu qua UART30 */
                    for (size_t j = 0; j < UART_BUF_SIZE; j++)
                    {
                        // printk("%c", buf->data[i]);
                        uart_poll_out(uart0_dev, buf->data[j]);
                    }
                    // printk("\n");
                    // uart_poll_out(uart0_dev, '\n');
                    // In ra màn hình (định dạng hex như ví dụ)
                    printk("0x");
                    for (size_t j = 0; j < buf->len; j++) {
                        printk("%02X", buf->data[j]);
                    }
                    printk("\n");

                    /* Reset buffer và bộ đếm */
                    memset(buf->data, 0, UART_BUF_SIZE);
                    buf->len = 0;
                    data_count = 0;
                }

                break;
           
            case UART_RX_DISABLED:
                // Khởi động lại RX sau khi bị disable
                uart_rx_enable(uart1_dev, rx_buf, sizeof(rx_buf), RECEIVE_TIMEOUT);
                break;
               
            default:
                break;
        }

    }


    void myuart_init(void)
    {
        int ret;

        if (!device_is_ready(uart0_dev)) {
            printk("UART30 device not ready\n");
        }
        if (!device_is_ready(uart1_dev)) {
            printk("UART20 device not ready\n");
        }

        /* Cấu hình UART0, UART1 */
        // ret = uart_configure(uart0_dev, &uart_cfg);
        // if (ret) {
        //     printk("Failed to configure UART30, err %d\n", ret);
        // }
        // ret = uart_configure(uart1_dev, &uart_cfg);
        // if (ret) {
        //     printk("Failed to configure UART20, err %d\n", ret);
        // }

        /* Gán callback cho UART0 */
        ret = uart_callback_set(uart1_dev, uart_cb, &uart_data_instance);
        if (ret) {
            printk("Failed to set UART20 callback, err %d\n", ret);
            return;
        }

        /* Bật chế độ nhận bất đồng bộ cho UART20 */
        ret = uart_rx_enable(uart1_dev, rx_buf, sizeof(rx_buf), RECEIVE_TIMEOUT);
        if (ret) {
            printk("Lỗi bật RX trên UART20: %d\n", ret);
            return;
        }

        printk("uart_init Done!\n");

    }


    I declared a static variable for UART20 and UART30 in this code,
    static const struct device *uart0_dev = DEVICE_DT_GET(DT_NODELABEL(uart30));
    static const struct device *uart1_dev = DEVICE_DT_GET(DT_NODELABEL(uart20));


  • Hi,
    I defined UART20 and UART30 in this code. 
    But the struct uart_config doesn't support for this.
    Please help me, how to solution for this?

  • Hello,

    The error messages "Failed to configure UART30, err -134" and "Failed to configure UART20, err -134" means that there is an issue with UART configuration.  

    How have you defined the pins for these nodes?

    I can see you have commented out the configuration part from the code.

    It should be there and after that call the UART API function uart_configure() function and pass it the variable of type uart_config.

    	int err = uart_configure(uart, &uart_cfg);
    
    	if (err == -ENOSYS) {
    		return -ENOSYS;
    	}

    If configuration is supported by the device, you will get negative errno code. (UART Driver - Nordic Developer Academy)

    Can you try these and see if there is any change?

Related