Libuarte splitting buffer data

Hello,

I'm using the libuarte module to receive and send data. In the NRF_LIBUARTE_ASYNC_EVT_RX_DATA, when the buffer is full, it sends two events with the data split. I know this is by design, but how can I change the code to not allow this to happen? I need the data coming from the UART in one packet. I've seen another post where checking if (0 == p_libuarte->p_ctrl_blk->sub_rx_count), it will get the first part of the data (store into a buffer), and then in the next event, the second part will come. However, even with this implementation, it's causing problems.

Is there any way to either modify the libraries to either only use one buffer, reset the rx index (and any other variables) after every transmission, or to use implement a buffer of some kind to store both parts of the data? I've tried using a ring buffer, but for some reason, it's just not working.

Post I've seen speaking about a similar issue:
LIBUARTE RX Buffer Full event

Parents
  • Hi,

    Is there any way to either modify the libraries to either only use one buffer, reset the rx index (and any other variables) after every transmission, or to use implement a buffer of some kind to store both parts of the data? I

    I don't think this is possible without redesigning the the module considerably. 

    , it will get the first part of the data (store into a buffer), and then in the next event, the second part will come. However, even with this implementation, it's causing problems.

    How is this not working, is it due to the latency of waiting for the second buffer to be filled?

    regards

    Jared 

  • This is also causing problems for me as the uart messages are being split and extra code has to be written to join them together. This is a right pain in the ars# for us because we need to act on specific message headers which come in asynchonously. It would be way easier if a ring buffer was used by Libuarte and a event was not generated just because it is at the end of its buffer.

  • Yea, it was such a pain when I had to deal with it. My way of dealing with it was to check if the libuarte buffer was full using the sub_rx_count, if so, check if I received my full packet by looking the start and end header. If the libuarte buffer was not full (so the data isn't split), check if I've received a full packet.

    I don't really, remember all the details, but maybe to code snippet below will help (edited to remove sensitive information).

    if (p_libuarte->p_ctrl_blk->sub_rx_count == 0) { // LIBUARTE buffer is full
            // Start filling app buffer.
            memcpy(app_buffer, p_evt->data.rxtx.p_data, app_length);
            // Index to add more data to.
            app_buffer_idx = app_length;
    
            // Check if full packet
            if ( I received a full packet process it) {
                // Full packet so go to processing
                NRF_LOG_INFO("Full packet so head to processing");
                // Reset the last index.
                app_buffer_idx = 0;
            } else { 
                // Not a full packet so wait until a full packet.
                return;
            }
        } else { // Buffer not full but ready to process data
            // Copy data to the work buffer starting from last index.
            memcpy(app_buffer + app_buffer_idx, p_evt->data.rxtx.p_data, app_length);
    
            app_length += app_buffer_idx; // Add on the extra length of partially full buffer.
    
            NRF_LOG_INFO("Printing full buffer:");
            NRF_LOG_HEXDUMP_INFO(app_buffer, app_length);
    
            // Reset the last index.
            app_buffer_idx = 0;
        }

  • Thanks Jerome. Some more digging here  RE: LIBUARTE RX Buffer Full event

    also found the similar solution. Thank god for these forums!

Reply Children
No Data
Related