how to update phy from 1M to 2M

There are two DKs, one works as a slave while the other works as a master. When these two peripherals are connected via Bluetooth, they exchange each other's parameters via the exchange function and I want to make their phy both 2M.

Some functions are as follow.

static void exchange_func(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
{
	if (!err) {
		m_nus_max_send_len = bt_nus_get_mtu(conn);
		LOG_INF("ATT MTU size updated to %d bytes", m_nus_max_send_len + 3);
		LOG_INF("MTU exchange done");
#if CONFIG_BT_USER_DATA_LEN_UPDATE
		err = bt_conn_le_data_len_update(conn, BT_LE_DATA_LEN_PARAM_MAX);
		if (err) {
			LOG_ERR("Failed to update data length (error %u)", err);
		}
#endif
	} else {
		LOG_WRN("MTU exchange failed (err %" PRIu8 ")", err);
	}
}

static void data_len_updated(struct bt_conn *conn, struct bt_conn_le_data_len_info *info)
{
	int err;

	LOG_INF("Data length updated. RX length: %d, TX length: %d", info->rx_max_len,
		info->tx_max_len);

	err = bt_conn_le_phy_update(conn, BT_CONN_LE_PHY_PARAM_2M);
	if (err) {
		LOG_ERR("bt_conn_le_phy_update() returned %d", err);
	}
}

static void phy_updated(struct bt_conn *conn, struct bt_conn_le_phy_info *param)
{
	LOG_INF("PHY updated. RX PHY: %d, TX PHY: %d", param->rx_phy, param->tx_phy);
}

BT_CONN_CB_DEFINE(conn_callbacks) = {
	.connected = connected,
	.disconnected = disconnected,
	.security_changed = security_changed,
#if CONFIG_BT_USER_DATA_LEN_UPDATE
	.le_data_len_updated = data_len_updated,
#endif
	.le_phy_updated = phy_updated,
};

When these two boards are connected, the transmission rate between them is 500~600kbps. However, when the slave is directly connected to the mobile phone, the transmission rate is 500kbps(1Mbps) when the phy is 1M(2M).Therefore, I don't think I have successfully changed the phy of the master to 2M, though I did get a 2M phy from the read phy function in my mobile app--"nRF Connect".

And I can't seem to modify the phy directly in the prj.conf. This is my prj.conf of the DK that works as a master.

# 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_DEVICE_NAME="Nordic_Central"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_MAX_CONN=2
CONFIG_BT_MAX_PAIRED=2
CONFIG_BT_SMP=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_GATT_CLIENT=y

# Enable the BLE modules from NCS
CONFIG_BT_NUS=y
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

# Share address between scanner and advertisor
CONFIG_BT_SCAN_WITH_IDENTITY=y
# CONFIG_BT_EXT_ADV=y

# Enable DK LED and Buttons library
CONFIG_DK_LIBRARY=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_USER_DATA_LEN_UPDATE=y
CONFIG_BT_USER_PHY_UPDATE=y


CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_ATT_PREPARE_COUNT=2
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_BUF_ACL_TX_COUNT=10
CONFIG_BT_BUF_ACL_TX_SIZE=251

  • Hello,

    You may find this useful:
    Building a Bluetooth application on nRF Connect SDK - Part 3 Optimizing the connection 

    To have better control of the PHy update you can disable the auto-initiate PHY uppdate procedure by setting this option to =n:
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index.html#CONFIG_BT_AUTO_PHY_UPDATE

    And finally, to understand and observe the difference, I recommend to have an nRF sniffer running in parallell, then you can actually see the transmission on-air to observe what/where etc:
    https://www.nordicsemi.com/Products/Development-tools/nrf-sniffer-for-bluetooth-le 
    (link to doc: https://infocenter.nordicsemi.com/topic/ug_sniffer_ble/UG/sniffer_ble/intro.html)

    Kenneth

  • you can disable the auto-initiate PHY uppdate procedure by setting this option to =n:

    When I tried to add "CONFIG_BT_AUTO_PHY_UPDATE = n" into prj.conf, it encountered an error.

    error: Aborting due to Kconfig warnings
    
    CMake Error at F:/v1.9.1/zephyr/cmake/kconfig.cmake:272 (message):
      command failed with return code: 1
    Call Stack (most recent call first):
      F:/v1.9.1/zephyr/cmake/app/boilerplate.cmake:544 (include)
      F:/v1.9.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      F:/v1.9.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
      CMakeLists.txt:13 (find_package)

    Kconfig:

    execute_process(
      COMMAND ${CMAKE_COMMAND} -E env
      ${COMMON_KCONFIG_ENV_SETTINGS}
      SHIELD_AS_LIST=${SHIELD_AS_LIST_ESCAPED_COMMAND}
      ${PYTHON_EXECUTABLE}
      ${ZEPHYR_BASE}/scripts/kconfig/kconfig.py
      --zephyr-base=${ZEPHYR_BASE}
      ${input_configs_are_handwritten}
      ${KCONFIG_ROOT}
      ${DOTCONFIG}
      ${AUTOCONF_H}
      ${PARSED_KCONFIG_SOURCES_TXT}
      ${input_configs}
      WORKING_DIRECTORY ${APPLICATION_SOURCE_DIR}
      # The working directory is set to the app dir such that the user
      # can use relative paths in CONF_FILE, e.g. CONF_FILE=nrf5.conf
      RESULT_VARIABLE ret
      )
    if(NOT "${ret}" STREQUAL "0")
      message(FATAL_ERROR "command failed with return code: ${ret}")
    endif()

    This is where the error occurs.

    if(NOT "${ret}" STREQUAL "0")
      message(FATAL_ERROR "command failed with return code: ${ret}")
    endif()
    

    When I tried to add "CONFIG_BT_AUTO_PHY_UPDATE = n" into nrf5340dk_nrf5340_cpunet.conf (\child_image\hci_rpmsg\boards\nrf5340dk_nrf5340_cpunet.conf), it encountered an error.

    F:/EEG/1018.central_uart/child_image/hci_rpmsg/boards/nrf5340dk_nrf5340_cpunet.conf:26: warning: attempt to assign the value ' n' to the undefined symbol BT_AUTO_PHY_UPDATE 
    
    error: Aborting due to Kconfig warnings
    
    CMake Error at F:/v1.9.1/zephyr/cmake/kconfig.cmake:272 (message):
      command failed with return code: 1
    Call Stack (most recent call first):
      F:/v1.9.1/zephyr/cmake/app/boilerplate.cmake:544 (include)
      F:/v1.9.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      F:/v1.9.1/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
      CMakeLists.txt:5 (find_package)

    Kconfig:(where errors occurs)

      if(NOT ${ret} EQUAL "0")
        message(FATAL_ERROR "CMake generation for ${ACI_NAME} failed, aborting. Command: ${ret}")
      endif()

  • It is strange that it fails to build, if the only change you did was to add CONFIG_BT_AUTO_PHY_UPDATE=n to both prj.conf and \child_image\hci_rpmsg\boards\nrf5340dk_nrf5340_cpunet.conf

    Maybe try with a pristine build?

    Kenneth

  • Actually, I just use a pristine build rather than build. I also don't understand why it works in the sample but not in my program.

Related