This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UARTE driver with eASY DMA Giving wrong Rx length in runtime.

Hi Team,

We are using the UARTE(UARTE1) module with DMA for our application with nRF52840 board, for that we are using the "libuarte" example project. For testing purpose we are sending the data from Teraterm continuously and same data we transmitting to the same terminal.

We have observed that some times we getting wrong Rx length while we sending the data from Tera term terminal, out of 10 times we are missing two times. Here with i am sharding my code changes what we did for testing.

Global DATA:

NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 1, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);

NRF_QUEUE_DEF(buffer_t, m_buf_queue, 10, NRF_QUEUE_MODE_NO_OVERFLOW);

=============================================================================================================

main fun:

==============================================================================================================

err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);

APP_ERROR_CHECK(err_code);

nrf_libuarte_async_enable(&libuarte);

while (true)
{
    if(rx_done_flag)
   {
        rx_done_flag = 0;
       nrf_libuarte_async_rx_read();

        err_code = nrf_libuarte_async_tx(&libuarte, Rx_Read_buf.p_data, Rx_Read_buf.length);

      if((NRF_SUCCESS != err_code) && (NRF_ERROR_BUSY != err_code))
      {
            APP_ERROR_CHECK(err_code);
      }
  }
}

============================================================================================================

uart_event_handler:

=========================================================================================================

{
nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
          ret_code_t ret;

switch (p_evt->type)
 {
case NRF_LIBUARTE_ASYNC_EVT_ERROR:
            error_flag++;
           break;

case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
             rx_done_flag++;

        buffer_t buf = {
                       .p_data = p_evt->data.rxtx.p_data,
                        .length = p_evt->data.rxtx.length,
                      };

ret = nrf_queue_push(&m_buf_queue, &buf);
if(NRF_SUCCESS == ret)
nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
}
              break;


case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
                  tx_done_flag++;
                 break;
default:
break;
}

=================================================================================================

Rx_Read:

======================================================================================================

void nrf_libuarte_async_rx_read(void)
{
ret_code_t ret;

if (!nrf_queue_is_empty(&m_buf_queue))
{
ret = nrf_queue_pop(&m_buf_queue, &Rx_Read_buf);
APP_ERROR_CHECK(ret);
}
}

With the above code we are able to read the some of the packets,in between we are getting wrong length vallue.

Regards,

Srinivas.V

Parents
  • Hello, Srinivas.V

    We have observed that some times we getting wrong Rx length while we sending the data from Tera term terminal, out of 10 times we are missing two times. Here with i am sharding my code changes what we did for testing.
    With the above code we are able to read the some of the packets,in between we are getting wrong length vallue.

    Are there any errors being generated by the application, if so - which errors is this?
    Could you elaborate more on the issue you are observing, perhaps with some examples of what you are sending in on Tera term, and what you are seeing in the application?
    Exactly which function is seeing the wrong RX length, and how are you alerted to this?

    Could you make sure that DEBUG is defined in your preprocessor defines, like shown in the included image?
      
    This will allow you to have both the error and generating function printed to the logger, if an error is passed to an APP_ERROR_CHECK.

    For future reference, please use the "Insert->Code" option when sharing code here on DevZone - it drastically increases readability of the shared code.

    Best regards,
    Karl

  • Hi Karl,

    Thanks for your reply. 

    We observed this behaviour while debugging,We have added the rx data queue structure to Live watch window,from there we have observed this data.

    We are continuously sending the fixed data but some times the length is not updating and corresponding data also not getting. 

    We are not getting any errors, i kept one break point at error case in event handler.

    We are seeing the wrong RX length in the  function "nrf_libuarte_async_rx_read"  from the varibles "Rx_Read_buf.p_data", and  "Rx_Read_buf.length".

    Added the code part .

    void nrf_libuarte_async_rx_read(void)
    {
      ret_code_t ret;
    
      if (!nrf_queue_is_empty(&m_buf_queue))
      {
        ret = nrf_queue_pop(&m_buf_queue, &Rx_Read_buf);
        APP_ERROR_CHECK(ret);
      }
    }
    
    int main(void)
    {
        bsp_board_init(BSP_INIT_LEDS);
        
        ret_code_t ret = nrf_drv_clock_init();
        APP_ERROR_CHECK(ret);
      
        nrf_drv_clock_lfclk_request(NULL);
    
        ret_code_t err_code = NRF_LOG_INIT(app_timer_cnt_get);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        nrf_libuarte_async_config_t nrf_libuarte_async_config = {
                .tx_pin     = TX_PIN_NUMBER,
                .rx_pin     = RX_PIN_NUMBER,
                .baudrate   = NRF_UARTE_BAUDRATE_115200,
                .parity     = NRF_UARTE_PARITY_EXCLUDED,
                .hwfc       = NRF_UARTE_HWFC_DISABLED,
                .timeout_us = 200,
                .int_prio   = APP_IRQ_PRIORITY_LOW
        };
    
        err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);
    
        APP_ERROR_CHECK(err_code);
    
        nrf_libuarte_async_enable(&libuarte);
        
        GenerateMACENCKeys();                     //Generates Encryption Keys, this should be obfuscated for implementation
      
        Identification();                         //Handshake the broker and Host
     
      
        while (true)
        {
           if(rx_done_flag) This is updated in event handler after receiving the data
           {
              rx_done_flag = 0;
              nrf_libuarte_async_rx_read();
             
              err_code = nrf_libuarte_async_tx(&libuarte, Rx_Read_buf.p_data, Rx_Read_buf.length);
              
              if((NRF_SUCCESS != err_code) && (NRF_ERROR_BUSY != err_code))
              {
                  APP_ERROR_CHECK(err_code);
              }
              
            }
        }
    }

    Regards,

    Srinivas.V

  • Hello Srinivas.V,

    Srinivas V said:
    Thanks for your reply. 

    No problem at all, I am happy to help!

    Srinivas V said:
    We have added the rx data queue structure to Live watch window,from there we have observed this data.

    So, you are seeing that the function sometimes is called with a larger than expected RX_len value?
    Did you define the DEBUG preprocessor define, as shown in the image of my previous post?

    Could you show me the declaration of your global Rx_Read_buf variable. Is this declared as a const?
    I suspect that you are changing the RX length somewhere, since you are seeing it shift in the live watch.
    If you set this buf to const, you should get a compiler error for every line that tries to change its contents.

    Best regards,
    Karl

Reply
  • Hello Srinivas.V,

    Srinivas V said:
    Thanks for your reply. 

    No problem at all, I am happy to help!

    Srinivas V said:
    We have added the rx data queue structure to Live watch window,from there we have observed this data.

    So, you are seeing that the function sometimes is called with a larger than expected RX_len value?
    Did you define the DEBUG preprocessor define, as shown in the image of my previous post?

    Could you show me the declaration of your global Rx_Read_buf variable. Is this declared as a const?
    I suspect that you are changing the RX length somewhere, since you are seeing it shift in the live watch.
    If you set this buf to const, you should get a compiler error for every line that tries to change its contents.

    Best regards,
    Karl

Children
No Data
Related