How to specify S=2 (500kbps) and S=8 (125kbps) in ESP32S3 BLE5.0 coded PHY?

NoveltySeek
Posts: 4
Joined: Fri Jun 23, 2023 10:04 am

How to specify S=2 (500kbps) and S=8 (125kbps) in ESP32S3 BLE5.0 coded PHY?

Postby NoveltySeek » Fri Jun 23, 2023 10:46 am

I am able to advertise using the coded PHY, but I'm unsure about how to specify S=2 (500kbps) and S=8 (125kbps) coding options.

I found the following configuration values in esp_gap_ble_api.h:

Code: Select all

#define ESP_BLE_GAP_PHY_OPTIONS_NO_PREF                  0 /*!< The Host has no preferred coding when transmitting on the LE Coded PHY */
#define ESP_BLE_GAP_PHY_OPTIONS_PREF_S2_CODING           1 /*!< The Host prefers that S=2 coding be used when transmitting on the LE Coded PHY */
#define ESP_BLE_GAP_PHY_OPTIONS_PREF_S8_CODING           2 /*!< The Host prefers that S=8 coding be used when transmitting on the LE Coded PHY */
typedef uint16_t esp_ble_gap_prefer_phy_options_t;
I also found a function that seems capable of setting this:

Code: Select all

esp_err_t esp_ble_gap_set_prefered_phy(esp_bd_addr_t bd_addr,
                                       esp_ble_gap_all_phys_t all_phys_mask,
                                       esp_ble_gap_phy_mask_t tx_phy_mask,
                                       esp_ble_gap_phy_mask_t rx_phy_mask,
                                       esp_ble_gap_prefer_phy_options_t phy_options);
I tried setting ESP_BLE_GAP_PHY_OPTIONS_PREF_S8_CODING and calling the function, and it appears to have succeeded with a return value of 0. However, I received the following error:
BT_BTM: BTM_BleSetPreferPhy, invalid parameters

Please let me know what might be causing this issue.
Thank you in advance.

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: How to specify S=2 (500kbps) and S=8 (125kbps) in ESP32S3 BLE5.0 coded PHY?

Postby lbernstone » Sun Jun 25, 2023 3:10 am

You'll have to dig around to see exactly how to set it, but NimBLE has them available. I recommend you use it rather than the included library in any case.
https://github.com/h2zero/NimBLE-Arduin ... 1304-L1306

NoveltySeek
Posts: 4
Joined: Fri Jun 23, 2023 10:04 am

Re: How to specify S=2 (500kbps) and S=8 (125kbps) in ESP32S3 BLE5.0 coded PHY?

Postby NoveltySeek » Mon Jun 26, 2023 2:57 am

Hello lbernstone,

Thank you for providing valuable information. I appreciate it.
I will give it a try using NimBLE. I will keep you updated if there are any developments.

NoveltySeek
Posts: 4
Joined: Fri Jun 23, 2023 10:04 am

Re: How to specify S=2 (500kbps) and S=8 (125kbps) in ESP32S3 BLE5.0 coded PHY?

Postby NoveltySeek » Mon Jun 26, 2023 10:41 pm

I tried the advertising feature using the following sample code from NimBLE, but my application crashes, causing ATOMS3 to go into a reboot loop.
https://github.com/h2zero/NimBLE-Arduin ... rtiser.ino

For now, I have decided to pause development with NimBLE and review the Bluetooth specifications to understand the issue better.
https://www.bluetooth.com/specification ... ation-5-4/

I am attempting to evaluate the difference in range by using coded phy for both the primary and secondary phy during advertising, switching between S=2 and S=8.

First, during the start of advertising, the host (ESP-IDF) sends a command called HCI_LE_Set_Extended_Advertising_Parameters to the controller (ESP32S3). This command includes the settings for S=2 or S=8. I discovered that this option was added in v2 of HCI_LE_Set_Extended_Advertising_Parameters and is not supported in v1.

Please refer to section 7.8.53 of the document linked below for more details:
https://www.bluetooth.org/DocMan/handle ... _id=556599

Upon checking esp_gap_ble_api.h in ESP-IDF, I found that the esp_ble_gap_ext_adv_params_t structure complies with v1. (NimBLE's ble_hci_le_set_ext_adv_params_cp structure in hci_common.h also conforms to v1.)

I will attempt to modify and build ESP-IDF and try invoking it from arduino-esp32. However, it is uncertain whether the controller (ESP32S3) supports it or not.

NoveltySeek
Posts: 4
Joined: Fri Jun 23, 2023 10:04 am

Re: How to specify S=2 (500kbps) and S=8 (125kbps) in ESP32S3 BLE5.0 coded PHY?

Postby NoveltySeek » Mon Jul 03, 2023 12:06 pm

I modified the ESP-IDF to send the HCI_LE_Set_Extended_Advertising_Parameters [v2] (OCF: 0x007F) command to the esp32-s3, but I received an UNKNOWN HCI COMMAND (0x01) in the HCI_Command_Complete event. It appears that the esp32-s3 does not support advertising with S=2.

Additionally, on the receiving side of the HCI_LE_Extended_Advertising_Report (Event Code: 0x3E), both the Primary_PHY and Secondary_PHY received S=8 (0x03). According to the specification, S=2 (0x04) is "Reserved for future use," and it is not defined with a #define in the ESP-IDF. (I haven't been able to confirm the value when actually receiving an advertisement with S=2 because there are no devices capable of transmitting advertisements with S=2.)

In conclusion, the esp32-s3 does not support advertising with S=2, and advertising with Coded PHY results in S=8.

Who is online

Users browsing this forum: No registered users and 56 guests