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

NCS how to increase NUS max frame size

nRF5340 with NCS 1.4.0.

I'm using the NUS (code derived from central_uart & peripheral_uart sample) and i'm trying to send longer frame.

I have tried to add the following lines in my proj.conf but I was unsuccessful:

CONFIG_BT_DATA_LEN_UPDATE=y
CONFIG_BT_L2CAP_RX_MTU=247
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_CTLR_TX_BUFFER_SIZE=251
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

What should i do to allow frame of 251 bytes ?

Edited subject: NCS how to enable DLE -> NCS how to increase NUS max frame size

Parents
  • Hi Nicolas, 

    The data length update should be executed automatically. 
    Could you please check in your autoconf.h do you have:
    #define CONFIG_BT_AUTO_DATA_LEN_UPDATE 1
    #define CONFIG_BT_DATA_LEN_UPDATE 1

    I would suggest to try testing with our throughput example

    You can try capture a sniffer trace to make it easier to investigate. 

    If you want to do it manually you would need to define CONFIG_BT_USER_DATA_LEN_UPDATE and call bt_conn_le_data_len_update() to execute. 

  • My NUS code is now working with longer frame. Here is the modification I have done to make this works:

    Using hci_rpmsg with the added conf:

    CONFIG_BT_CTLR_TX_BUFFER_SIZE=251
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
    CONFIG_BT_MAX_CONN=8

    Added to central and peripheral conf:

    CONFIG_BT_L2CAP_TX_MTU=247
    CONFIG_BT_L2CAP_RX_MTU=247

    Added a call to bt_gatt_exchange_mtu() in the central code:

    static void exchange_func(struct bt_conn *conn, uint8_t att_err,
            struct bt_gatt_exchange_params *params)
    {
        struct bt_conn_info info = {0};
        int err;
    
        LOG_INF("MTU exchange %s", att_err == 0 ? "successful" : "failed");
    
        err = bt_conn_get_info(conn, &info);
        if (err) {
            LOG_ERR("Failed to get connection info %d", err);
        }
    }
    
    static void discovery_complete(struct bt_gatt_dm *dm, void *context)
    {
        struct bt_nus_client *nus = context;
        LOG_INF("Service discovery completed");
    
        bt_gatt_dm_data_print(dm);
    
        bt_nus_handles_assign(dm, nus);
        bt_nus_subscribe_receive(nus);
    
        bt_gatt_dm_data_release(dm);
    
        exchange_params.func = exchange_func;
    
        int err = bt_gatt_exchange_mtu(default_conn, &exchange_params);
        if (err) {
            LOG_ERR("MTU exchange failed (err %d)", err);
        } else {
            LOG_INF("MTU exchange pending");
        }
    }

  • In my autoconf.h the following are defined:
    #define CONFIG_BT_AUTO_DATA_LEN_UPDATE 1
    #define CONFIG_BT_DATA_LEN_UPDATE 1

    But the max data len was only updated by calling bt_gatt_exchange_mtu(). Is this normal ?

  • Please make sure you don't have CONFIG_BT_USER_DATA_LEN_UPDATE=y defined anywhere. 

Reply Children
Related