Increase nrf5340 NUS sending data speed

Hello Nordic team,

I'm a beginner on Nordic connect sdk, here have a question about how to increase nrf5340 sending data speed by NUS?

Below is what I testing model now.

Peripheral BLE : nrf5340 (peripheral_uart)

Central BLE: nrf52840 dongle (central_uart)

I want to use nrf5340 send data continuous to nrf52840 dongle. So, I rewrite "ble_write_thread" as below(Flag "enable_send" is opened when connected to nrf52840 dongle).

void ble_write_thread(void)
{
	/* Don't go any further until BLE is initialized */
	k_sem_take(&ble_init_ok, K_FOREVER);
	for (;;) {
		#if CUSTOMIZE_PROTOCOL

		if(enable_send)
		{
			time_stamp = k_uptime_get_32();
			LOG_INF("Time %d", time_stamp);
			test_buf[0] = (uint8_t)((time_stamp >>24) & 0x000000FF);
			test_buf[1] = (uint8_t)((time_stamp >>16) & 0x000000FF);
			test_buf[2] = (uint8_t)((time_stamp >>8) & 0x000000FF);
			test_buf[3] = (uint8_t)((time_stamp) & 0x000000FF);
			bt_nus_send(NULL, test_buf, 40);
		}
		#else	
		/* Wait indefinitely for data to be sent over bluetooth */

		struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,
						     K_FOREVER);
		LOG_HEXDUMP_INF(buf->data,buf->len,"ble write thread");
		if (bt_nus_send(NULL, buf->data, buf->len)) {
			LOG_WRN("Failed to send data over BLE connection");
		}

		k_free(buf);
		#endif
	}
}

Then, I was tested nrf5340 can send 40 bytes and 50ms send one time. I want to decrease 50ms to maybe 20ms or less.

But, I cannot find which config or setting let me to decrease this thread trigger speed.

Can Nordic team give me some suggestion and I am happy to provide more info as required.

Allen

Parents
  • Hi!

    What is your connection interval defined as?

    Maybe you could try to decrease the connection interval? So that you can send data more often.

    Br,
    Joakim

  • Hi Joakim,

    Thanks for your reply.

    I guess you mean central_uart (nrf52840 dongle) connection interval?

    On central_uart sample code do not have define connection interval (maybe I do not know where to change)?

    So, I add below code to change connection interval.(min 7.5ms, max 30ms)

    static const struct bt_le_conn_param conn_params = BT_LE_CONN_PARAM_INIT(
    	7.5, 30, 10, 400);
    
    static int scan_init(void)
    {
    	int err;
    	struct bt_scan_init_param scan_init = {
    		.scan_param = NULL,
    		.conn_param = &conn_params,
    		.connect_if_match = 1,
    
    	};
    
    	bt_scan_init(&scan_init);
    	bt_scan_cb_register(&scan_cb);
    
    	err = bt_scan_filter_add(BT_SCAN_FILTER_TYPE_UUID, BT_UUID_NUS_SERVICE);
    	if (err) {
    		LOG_ERR("Scanning filters cannot be set (err %d)", err);
    		return err;
    	}
    
    	err = bt_scan_filter_enable(BT_SCAN_UUID_FILTER, false);
    	if (err) {
    		LOG_ERR("Filters cannot be turned on (err %d)", err);
    		return err;
    	}
    
    	LOG_INF("Scan module initialized");
    	return err;
    }

    Then, the transfer speed still 50ms.

    Allen

    Thanks

  • Thanks. 

    You could also try to increase the transmit buffer. That could help improve the throughput. 

    I would suggest that you take a look at our throughput example in the SDK. This could give you some good advice on how to increase the throughput for your application. 

    Br, 
    Joakim

  • Hello Joakim,

    I have referenced BLE throughput sample and below Q&A

     https://devzone.nordicsemi.com/f/nordic-q-a/84487/ble-uart-nus-altering-mtu-and-faster-interval 

     https://devzone.nordicsemi.com/f/nordic-q-a/86786/nrf5340-max-throughput 

    Now, I can set MTU size = 247bytes, PHY data rate = 2M/S and connection interval = 400ms.

    Then, I change send data array length to 244 bytes and print the receive data on nRF 52840 dongle UART log.

    The testing result is 52840 dongle will get one packet data(244bytes) per 250ms.

    Is this result correct? or there are some other improvement method?

    Below is my prj.conf setting

    nrf5340:

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # Enable the UART driver
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_UARTE0=y
    CONFIG_SERIAL=y
    
    CONFIG_GPIO=y
    
    # Make sure printk is printing to the UART console
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_UART_Service"
    CONFIG_BT_DEVICE_APPEARANCE=833
    CONFIG_BT_MAX_CONN=1
    CONFIG_BT_MAX_PAIRED=1
    
    # Enable the NUS service
    CONFIG_BT_NUS=y
    
    # Enable bonding
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    
    # Enable DK LED and Buttons library
    CONFIG_DK_LIBRARY=y
    
    # This example requires more workqueue stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=n
    CONFIG_LOG_BACKEND_UART=y
    
    CONFIG_ASSERT=y
    
    CONFIG_BT_NUS_UART_BUFFER_SIZE=247
    #CONFIG_BT_NUS_UART_RX_WAIT_TIME=20
    
    CONFIG_BT_BUF_ACL_RX_SIZE=502
    #CONFIG_BT_GATT_CLIENT=y
    CONFIG_BT_ATT_PREPARE_COUNT=2
    CONFIG_BT_CONN_TX_MAX=10
    CONFIG_BT_L2CAP_TX_BUF_COUNT=10
    CONFIG_BT_L2CAP_TX_MTU=498
    CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
    CONFIG_BT_CTLR_PHY_2M=y
    CONFIG_BT_CTLR_RX_BUFFERS=2
    CONFIG_BT_BUF_ACL_TX_COUNT=10
    CONFIG_BT_BUF_ACL_TX_SIZE=502
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
    CONFIG_BT_USER_DATA_LEN_UPDATE=y 

    nrf52840 dongle:

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # Enable the UART driver
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_UARTE0=y
    CONFIG_SERIAL=y
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    
    # Enable the BLE stack with GATT Client configuration
    CONFIG_BT=y
    CONFIG_BT_CENTRAL=y
    CONFIG_BT_SMP=y
    CONFIG_BT_GATT_CLIENT=y
    
    # Enable the BLE modules from NCS
    CONFIG_BT_NUS_CLIENT=y
    CONFIG_BT_SCAN=y
    CONFIG_BT_SCAN_FILTER_ENABLE=y
    CONFIG_BT_SCAN_UUID_CNT=1
    CONFIG_BT_GATT_DM=y
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # This example requires more workqueue stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Enable bonding
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n
    
    CONFIG_ASSERT=y
    
    CONFIG_BT_BUF_ACL_RX_SIZE=502
    CONFIG_BT_ATT_PREPARE_COUNT=2
    CONFIG_BT_CONN_TX_MAX=10
    CONFIG_BT_L2CAP_TX_BUF_COUNT=10
    CONFIG_BT_L2CAP_TX_MTU=498
    CONFIG_BT_BUF_ACL_TX_SIZE=502
    CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
    CONFIG_BT_CTLR_PHY_2M=y
    
    CONFIG_BT_USER_DATA_LEN_UPDATE=y
    CONFIG_BT_USER_PHY_UPDATE=y
    CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n

    In the other hand, I find document is about throughput maximum on nRF52.

    Is this test result is as same as nRF5340?

    https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsds_s140%2FSDS%2Fs1xx%2Fble_data_throughput%2Fble_data_throughput.html

    Waiting for you suggestions.

    Many Thanks

    Allen

  • Thanks. 

    Configuration looks good. 

    Did you test the example that Vidar linked to? As you can see from the ticket you linked, they were able to achieve around 1000kbps.

    Br, 
    Joakim

Reply Children
Related