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

nrf_serial drv_err

Hello, I'm using a modified version of the serial example of the SDK 13.0.0 with a PCA10056. The modification are that i use nrf_serial_read in non-blocking mode (timeout = 0) and i use NRF_UART_HWFC_DISABLED. When i send data to the serial, i receive back the data but after a few bytes, i don't receive the echo anymore. After adding a serial_evt_handler, i detect a NRF_SERIAL_EVENT_DRV_ERR when the serial get stuck.

Is there something i can do to avoid the serial getting stuck ? If no, is there a way to recover from a NRF_SERIAL_EVENT_DRV_ERR ?

Here is the code:

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#include "nrf.h"
#include "nrf_drv_clock.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_drv_power.h"
#include "nrf_serial.h"
#include "app_timer.h"


#include "app_error.h"
#include "app_util.h"
#include "boards.h"

/** @file
 * @defgroup nrf_serial_example main.c
 * @{
 * @ingroup nrf_serial_example
 * @brief Example of @ref nrf_serial usage. Simple loopback.
 *
 */

#define OP_QUEUES_SIZE          3
#define APP_TIMER_PRESCALER     NRF_SERIAL_APP_TIMER_PRESCALER

static void sleep_handler(void)
{
    __WFE();
    __SEV();
    __WFE();
}

NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uart0_drv_config,
                      RX_PIN_NUMBER, TX_PIN_NUMBER,
                      RTS_PIN_NUMBER, CTS_PIN_NUMBER,
                      NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
                      NRF_UART_BAUDRATE_115200,
                      UART_DEFAULT_CONFIG_IRQ_PRIORITY);

#define SERIAL_FIFO_TX_SIZE 32
#define SERIAL_FIFO_RX_SIZE 32

NRF_SERIAL_QUEUES_DEF(serial_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);


#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1

NRF_SERIAL_BUFFERS_DEF(serial_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);

NRF_SERIAL_CONFIG_DEF(serial_config, NRF_SERIAL_MODE_IRQ,
                      &serial_queues, &serial_buffs, NULL, sleep_handler);


NRF_SERIAL_UART_DEF(serial_uart, 0);

int main(void)
{
    ret_code_t ret;

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    ret = nrf_drv_power_init(NULL);
    APP_ERROR_CHECK(ret);

    nrf_drv_clock_lfclk_request(NULL);
    ret = app_timer_init();
    APP_ERROR_CHECK(ret);

    bsp_board_leds_init();
    bsp_board_buttons_init();

    ret = nrf_serial_init(&serial_uart, &m_uart0_drv_config, &serial_config);
    APP_ERROR_CHECK(ret);

    static char tx_message[] = "Hello nrf_serial!\n\r";

    ret = nrf_serial_write(&serial_uart,
                           tx_message,
                           strlen(tx_message),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
    APP_ERROR_CHECK(ret);

    while (true)
    {
        char c;
        ret = nrf_serial_read(&serial_uart, &c, sizeof(c), NULL, 0);
        if (ret != NRF_SUCCESS)
        {
            continue;
        }
        (void)nrf_serial_write(&serial_uart, &c, sizeof(c), NULL, 0);
        (void)nrf_serial_flush(&serial_uart, 0);

    }
}

/** @} */

And here is the test result from PC side (Need to transmit multiple bytes without delay for the bug to happen):

16.05.2017 11:47:11.554 [RX] - 48 65 6C 6C 6F 20 6E 72 66 5F 73 65 72 69 61 6C 21 0A 0D 
16.05.2017 11:47:15.806 [TX] - 01 02 
16.05.2017 11:47:15.908 [RX] - 01 02 
16.05.2017 11:47:16.373 [TX] - 01 02 
16.05.2017 11:47:16.475 [RX] - 01 02 
16.05.2017 11:47:16.934 [TX] - 01 02 
16.05.2017 11:47:17.036 [RX] - 01 02 
16.05.2017 11:47:17.446 [TX] - 01 02 
16.05.2017 11:47:17.941 [TX] - 01 02 
16.05.2017 11:47:18.493 [TX] - 01 02 
16.05.2017 11:47:22.054 [TX] - 01 02 
16.05.2017 11:47:22.982 [TX] - 01 02 
Parents Reply Children
No Data
Related