NCS UARTE1 receiver (UART_RX_RDY) returns wrong (short) buffer length

Hi Team,

I think I've found an issue when using the nrFX UARTE1 Zephyr driver.  I'm building an application based on the Bluetooth peripheral UART sample.

I use 20 byte buffers.  In the attached log you can see that I've sent 44 bytes and received 44 bytes. Then I send the 44 bytes again and only receive 43, but in this case the last buffer contains the 4 bytes sent but the length is passed with the value of 3. This occurs about 20% of the time.  Because the last '\r' character is not found the UART disable-enable doesn't occur and a new buffer is not allocated.  Then I get bus fault trying to free an already freed buffer. (see the last section of the log).  What might be the problem here?

 case UART_RX_RDY:
        buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
        buf->len += evt->data.rx.len;
        buf_release = false;

        
        LOG_INF("Data to Rx FIFO, %u bytes", buf->len);
        if (buf->len == UART_BUF_SIZE) 
        {
            k_fifo_put(&fifo_uart_rx_data, buf);
            // UART will get a new Rx buffer from call to UART_RX_BUF_REQUEST in this case
        } 
        else if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
              (evt->data.rx.buf[buf->len - 1] == '\r'))
        {
            // End of packet found
            k_fifo_put(&fifo_uart_rx_data, buf);
            evt->data.rx.len = 0;
            current_buf = evt->data.rx.buf;
            buf_release = true;
            uart_rx_disable(uart);
        }
        else
            LOG_INF("UART buf not full");
        
        break;    

Also, why do we have to find an end of packet char and disable the uart rx? Shouldn't the driver reset the buffer pointers to the start of the buffer after the Rx timeout?  Currently the next bytes received are added to the end of the last few bytes received before another timeout or full buffer.

Why do you need the += in the  buf->len += evt->data.rx.len; line?

I'm using NCS 1.6.1

Thanks in advance.

Simon

   

Parents Reply Children
No Data
Related