This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART high speed issue - ZEPHYR rtos

Hi everyone!

I ported some project from NRFsdk 17.0.2 (all works fine)  to Zephyr rtos and faced with issue - when set high speed uart (460800 - 921600) then some bytes (in the end of packet ) have lost when ESP8266 send data to nrf52840

When speed 115200 it works fine, but I need a high speed and NRFsdk project works fine so Zephyr should works fine too.

Implementation of uart I took from PERIPHERAL_UART example

nrf52840 side log

//all bytes received

[00:11:56.632,812] buf->len 24
[00:11:56.717,346] index 24
[00:11:56.717,346] 
                                 ab cd ef 17 03 02 02 a8  c0 0a 01 ff ff 00 ff a8 |........ ........
                                 c0 01 01 a8 c0 01 01 c9                          |........         
[00:11:56.717,346] CRC c9 _ c9
[00:11:56.717,346] Scenario answer - 2 2

//one byte have lost

[00:11:58.534,484] buf->len 23
[00:11:58.617,431] index 23
[00:11:58.617,431] 
                                 ab cd ef 17 03 02 02 a8  c0 0a 01 ff ff 00 ff a8 |........ ........
                                 c0 01 01 a8 c0 01 01                             |.......          
[00:11:58.617,462] CRC c9 _ 00

////////////////////////////////////

// 3 bytes have lost (should be 126)

[00:02:38.410,217] DCIBMM: buf->len 123
[00:02:38.489,532] DCIBMM: index 123
[00:02:38.489,562] DCIBMM: 
                                 ab cd ef 7d 03 01 01 a8  c0 cd 01 ff ff 00 ff a8 |...}.... ........
                                 c0 01 01 a8 c0 01 01 65  72 6c 63 75 6f 65 73 31 |.......e rlcuoes1
                                 72 00 00 00 00 00 00 65  72 6c 63 75 6f 65 73 31 |r......e rlcuoes1
                                 72 00 32 00 00 00 00 77  71 72 65 79 74 6f 6e 6e |r.2....w qreytonn
                                 6f 00 00 00 00 00 00 6f  43 6e 6e 63 65 69 74 75 |o......o Cnnceitu
                                 46 6b 63 00 00 00 00 77  71 72 65 79 74 6f 6e 6e |Fkc....w qreytonn
                                 6f 00 00 00 00 00 00 50  00 17 00 01 00 a8 c0 1f |o......P ........
                                 01 ff ff 00 ff a8 c0 01  01 a8 c0                |........ ...     
[00:02:38.489,593] DCIBMM: CRC 73 _ 00

// 2 bytes have lost (should be 126)

[00:02:40.409,820] buf->len 124
[00:02:40.489,654] index 124
[00:02:40.489,685]
                                 ab cd ef 7d 03 01 01 a8  c0 cd 01 ff ff 00 ff a8 |...}.... ........
                                 c0 01 01 a8 c0 01 01 65  72 6c 63 75 6f 65 73 31 |.......e rlcuoes1
                                 72 00 00 00 00 00 00 65  72 6c 63 75 6f 65 73 31 |r......e rlcuoes1
                                 72 00 32 00 00 00 00 77  71 72 65 79 74 6f 6e 6e |r.2....w qreytonn
                                 6f 00 00 00 00 00 00 6f  43 6e 6e 63 65 69 74 75 |o......o Cnnceitu
                                 46 6b 63 00 00 00 00 77  71 72 65 79 74 6f 6e 6e |Fkc....w qreytonn
                                 6f 00 00 00 00 00 00 50  00 17 00 01 00 a8 c0 1f |o......P ........
                                 01 ff ff 00 ff a8 c0 01  01 a8 c0 01             |........ ....    
[00:02:40.489,715] CRC 74 _ 00

# prj conf
CONFIG_UART_ASYNC_API=y
CONFIG_NRFX_UART0=y
CONFIG_SERIAL=y
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n
CONFIG_NFCT_PINS_AS_GPIOS=y

CONFIG_NEWLIB_LIBC=y
CONFIG_CPLUSPLUS=y
CONFIG_LIB_CPLUSPLUS=y

#EXT WDT
CONFIG_GPIO=n
CONFIG_NRFX_GPIOTE=y

# Enable the BLE stack with GATT Client configuration
CONFIG_BT=y
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_SETTINGS=y

CONFIG_SETTINGS_NONE=y
CONFIG_BT_GATT_CACHING=n
CONFIG_BT_GATT_CLIENT=y

# Config logger
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n

CONFIG_ASSERT=n

CONFIG_BT_USER_PHY_UPDATE=y
CONFIG_BT_CTLR_TX_PWR_PLUS_8=y

CONFIG_BT_CREATE_CONN_TIMEOUT=3
CONFIG_BT_ATT_PREPARE_COUNT=18
CONFIG_BT_MAX_CONN=18

CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=247
CONFIG_BT_CTLR_ADVANCED_FEATURES=y
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=n
CONFIG_BT_CTLR_CONN_RSSI=y
CONFIG_BT_LL_SW_SPLIT=y
CONFIG_BT_CTLR=y
CONFIG_BT_HCI=y

#PERIPHERAL
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="RECLOUSER"

CONFIG_BT_GATT_NOTIFY_MULTIPLE=y

CONFIG_WATCHDOG=y
CONFIG_NRFX_WDT=y
CONFIG_NRFX_WDT0=y

CONFIG_BT_GAP_PERIPHERAL_PREF_PARAMS=n

CONFIG_BT_L2CAP_TX_MTU=259
CONFIG_BT_BUF_ACL_RX_SIZE=259
CONFIG_MAIN_STACK_SIZE=8192

#CLOCK_CONTROL
CONFIG_CLOCK_CONTROL=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=n
CONFIG_NRFX_TIMER=y
CONFIG_NRFX_TIMER4=y
CONFIG_NRFX_SAADC=y
CONFIG_BOARD_ENABLE_DCDC=n
CONFIG_NRFX_PPI=y

### Enable SMP server ###
# FOR NCS auto make image
CONFIG_MCUMGR_SMP_BT=y
CONFIG_MCUMGR_SMP_BT_AUTHEN=n
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y
CONFIG_MCUMGR=y
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
#CONFIG_BOOTLOADER_MCUBOOT=y
#CONFIG_MCUBOOT_IMAGE_VERSION="0.0.6"

RX uart handle

#define UART_BUF_SIZE                   260
#define UART_WAIT_FOR_BUF_DELAY         K_MSEC(100)
#define UART_RX_TIMEOUT                 5
#define UART_WAIT_FOR_RX                5
	
	
	case UART_RX_RDY:

		buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
		buf->len = evt->data.rx.len;

		current_buf = evt->data.rx.buf;
		buf_release = true;
		uart_rx_disable(uart);

                memcpy(data_array, evt->data.rx.buf, buf->len);
                uart_rx_index = buf->len;
                
                uart_rx_enable(uart, buf->data, sizeof(buf->data), UART_WAIT_FOR_RX);
                k_free(buf);

		break;
		
		

uart init

static int uart_init(void)
{
	int err;
	struct uart_data_t *rx;

	uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
	if (!uart) {
		LOG_ERR("UART binding failed");
		return -ENXIO;
	}

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

        uart_configure(uart, &uart_cfg);

	rx = k_malloc(sizeof(*rx));
	if (rx) {
		rx->len = 0;
	} else {
		return -ENOMEM;
	}

	err = uart_callback_set(uart, uart_cb, NULL);
	if (err) {
		return err;
	}

	 return uart_rx_enable(uart, rx->data, sizeof(rx->data), UART_RX_TIMEOUT);
}

  • Thanks. It works!!! But how can I keep system from FAULT when I send a big packet to nrf52840,

    When I send a very big packet of bytes it causes a fault

    ASSERTION FAIL [err == 0] @ WEST_TOPDIR/nrf/samples/peripheral/lpuart/src/main.c:70
            Failed to provide new buffer
    [00:01:22.163,604] <inf> app: Received data 27 bytes
    [00:01:22.171,356] <inf> app: UART_RX_BUF_RELEASED
    [00:01:22.171,417] <inf> app: Received data 64 bytes
    [00:01:22.189,208] <inf> app: UART_RX_BUF_RELEASED
    [00:01:22.189,270] <inf> app: Received data 64 bytes
    [00:01:22.207,092] <inf> app: UART_RX_BUF_REQUEST
    [00:01:22.207,183] <inf> app: UART_RX_BUF_RELEASED
    [00:01:22.207,214] <inf> app: UART_RX_BUF_RELEASED
    [00:01:22.207,275] <inf> app: UART_RX_BUF_REQUEST
    [00:01:22.217,773] <err> os: r0/a1:  0x00000004  r1/a2:  0x00000046  r2/a3:  0x00000001
    [00:01:22.217,803] <err> os: r3/a4:  0x0000001e r12/ip:  0x00000000 r14/lr:  0x000007af
    [00:01:22.217,864] <err> os:  xpsr:  0x41000038
    [00:01:22.217,895] <err> os: Faulting instruction address (r15/pc): 0x0000fa2c
    [00:01:22.217,895] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
    [00:01:22.217,926] <err> os: Fault during interrupt handling
    
    [00:01:22.217,926] <err> os: Current thread: 0x20000490 (unknown)
    [00:01:22.321,929] <err> os: Halting system
    

    I tried to increase buffer size but no result

    #define BUF_SIZE 500
    static K_MEM_SLAB_DEFINE(uart_slab, BUF_SIZE, 3, 4);

  • ok!!! done!!! all works fine!!!! Thank you very much.

Related