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

ncs 1.6.1 peripheral_uart example - increasing NUS size

Hi,

I'm working with the ncs 1.6.1 peripheral_uart example and am looking to increase the size of the data frame to send 240 bytes per data frame.

I have seen several threads regarding this, but have not seen the complete solution shown anywhere.

Could you post an example of main.c and prj.conf where the NUS data frame is 240 bytes?

Thanks

  • Hi Alvin

    There are no changes necessary in main.c, but you'll need to add the following configs to the prj.conf file:

    CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
    
    CONFIG_BT_BUF_ACL_RX_SIZE=251
    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=247
    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=251
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

    The project must also be configured to set the BT_NUS_UART_BUFFER_SIZE to 240 and UART_0_NRF_TX_BUFFER_SIZE in your project's Kconfig file to 240. After that the peripheral_uart sample will be able to transmit 240 bytes at a time (I just tested it on my end). You should make sure that the central you use to connect to the device supports MTU sizes of up to 240 though.

    Best regards,

    Simon

  • That worked, thank you.

    I could not get UART_0_NRF_TX_BUFFER_SIZE to update when adding it to the Kconfig file, so I just added the following line into the prj.conf file:

    CONFIG_UART_0_NRF_TX_BUFFER_SIZE=240

    In main.c, would it be appropriate use bt_conn_le_data_len_update() to update the MTU to 240?

  • Glad to hear that! 

    Yes, you can add a data length update to for example trig upon connection in order to try setting the MTU size to 240 for your connection. Please note that the central will be "in charge" and the peripheral will have to accept whatever MTU the central decides to use.

    Best regards,

    Simon

  • I'm trying to implement bt_conn_le_data_len_update() and it looks like the MTU is not getting updated.

    Could you let me know if I'm implementing this incorrectly? Also for tx_max_time in dataLenParam, is 50ms a reasonable value?

    Here is the code that I added to connected()

        struct bt_conn_le_data_len_param dataLenParam = {240, 50000};
        
    	int success = bt_conn_le_data_len_update(current_conn, &dataLenParam);
    
        LOG_INF("Len update success: %d", success);
        
        uint16_t currentMTU = bt_gatt_get_mtu(current_conn);
        
        LOG_INF("Current MTU: %d", currentMTU);

    Here are the RTT logs:

    00> [00:00:54.818,237] <inf> peripheral_uart: Len update success: 0
    00> [00:00:54.818,237] <inf> peripheral_uart: Current MTU: 23

  • Hi

    Please check out how data length updates are done in the throughput sample in NCS, located in \NCS_FOLDER\nrf\samples\bluetooth\throughput. 

    Specifically check out the le_data_length_updated() function and info.le.data_len if loop.

    Best regards,

    Simon

Related