CN / EN
CN / EN

提问

获得支持

您的项目私密技术问题如需获得一对一支持,请点击下方联系我们。

GR551X SDK开发中如何配置Long range工作模式 GR551x

已解决

Ping

汇顶员工
2021-11-10 15:21

Long Range是BLE 5.0 新增加的特性,能够增加蓝牙的通信距离,将最大的发送功率,从4.0/4.1/4.2中的10mW增大到5.0的100mW,如下图所示:

注意:Long Range的广播与普通BLE广播不兼容,所以广播、扫描双方必须都设置为Long Range。

1. GR551X 支持Long range模式,硬件相关规格如下:

2. SDK中设置方法如下: 调用ble_gap_phy_update接口切换PHY,选择BLE_GAP_PHY_LE_CODED参数即可,接口调用和参数说明可以参考throughput工程和<GR55xx_BLE_Throughput示例手册_V1.9.pdf>文档介绍。

/**@defgroup BLE_GAP_PHYS GAP PHYs (bitmask) * @{ */#define BLE_GAP_PHY_ANY       0x00     /**< No preferred PHY. */#define BLE_GAP_PHY_LE_1MBPS  (1 << 0) /**< LE 1M PHY preferred for an active link. */#define BLE_GAP_PHY_LE_2MBPS  (1 << 1) /**< LE 2M PHY preferred for an active link. */#define BLE_GAP_PHY_LE_CODED  (1 << 2) /**< LE Coded PHY preferred for an active link. *//**@} */
/** **************************************************************************************** * @brief Set the PHY preferences for the connection identified by the connection index. * @note Once this operation has been completed, the callback function @ref gap_cb_fun_t::app_gap_phy_update_cb will be called. * * @param[in] conn_idx:   The index of connection. * @param[in] tx_phys:    The transmitter PHYs that the Host prefers the Controller to use (see @ref BLE_GAP_PHYS). * @param[in] rx_phys:    A bit field that indicates the receiver PHYs that the Host prefers the Controller to use (see @ref BLE_GAP_PHYS). * @param[in] phy_opt:    A bit field that allows the Host to specify options for PHYs (see @ref BLE_GAP_PHY_OPTIONS). * * @retval ::SDK_SUCCESS: Operation is Success. * @retval ::SDK_ERR_INVALID_CONN_IDX: Invalid connection index supplied. * @retval ::SDK_ERR_NO_RESOURCES: Not enough resources. **************************************************************************************** */uint16_t ble_gap_phy_update(uint8_t conn_idx, uint8_t tx_phys , uint8_t rx_phys, uint8_t phy_opt);

(1) tx_phys和rx_phys都要设置为Coded PHY;

(2) phy_opt设置为1是500kbps,设置为2是125kbps,设置为0表示不指定;


3. 关于设置1M PHY & Long range广播共存的方法如下:

基于projects\ble\ble_basic_example\ble_app_gap_extended_adv例程

(1). 重构extended_adv_start函数,增加广播通道和PHY设置参数;

static void extended_adv_start(uint8_t adv_idx, \                                         gap_le_phy_value_t prim_pyh, \                                         gap_le_phy_value_t second_pyh, \                                         const uint8_t *adv_data){    sdk_err_t error_code;    ble_gap_pair_enable(false);    s_gap_adv_param.type = GAP_ADV_TYPE_EXTENDED;    s_gap_adv_param.disc_mode = GAP_DISC_MODE_GEN_DISCOVERABLE;    /* The advertisement shall not be both connectable and scannable, and High duty cycle directed advertising cannot be used */    s_gap_adv_param.prop       = GAP_ADV_PROP_CONNECTABLE_BIT;    s_gap_adv_param.max_tx_pwr = 0;    s_gap_adv_param.filter_pol = GAP_ADV_ALLOW_SCAN_ANY_CON_ANY;    memset(&s_gap_adv_param.peer_addr, 0, sizeof(gap_bdaddr_t));    s_gap_adv_param.prim_cfg.adv_intv_min   = APP_ADV_MIN_INTERVAL;    s_gap_adv_param.prim_cfg.adv_intv_max   = APP_ADV_MAX_INTERVAL;    s_gap_adv_param.prim_cfg.chnl_map       = GAP_ADV_CHANNEL_37_38_39;    s_gap_adv_param.prim_cfg.phy            = prim_pyh;    s_gap_adv_param.second_cfg.max_skip     = 0;    s_gap_adv_param.second_cfg.phy          = second_pyh;    s_gap_adv_param.second_cfg.adv_sid      = 0x00;    s_gap_adv_param.period_cfg.adv_intv_min = 0;    s_gap_adv_param.period_cfg.adv_intv_max = 0;    error_code = ble_gap_ext_adv_param_set(adv_idx, BLE_GAP_OWN_ADDR_STATIC, &s_gap_adv_param);    APP_ERROR_CHECK(error_code);    error_code = ble_gap_adv_data_set(adv_idx, BLE_GAP_ADV_DATA_TYPE_DATA, adv_data, (adv_data[0]+1));    APP_ERROR_CHECK(error_code);    s_gap_adv_time_param.duration = 0;    s_gap_adv_time_param.max_adv_evt = 0;    error_code = ble_gap_adv_start(adv_idx, &s_gap_adv_time_param);    APP_ERROR_CHECK(error_code);}

(2) 开启1M PHY & Long range广播

static const uint8_t s_adv_data_set_coded_pyh[] ={    0x0e,    BLE_GAP_AD_TYPE_COMPLETE_NAME,    'L', 'o', 'n', 'g', 'R', 'a', 'n', 'g', 'e', '_', 'A', 'D', 'V',};static const uint8_t s_adv_data_set_1M_pyh[] ={    0x0d,    BLE_GAP_AD_TYPE_COMPLETE_NAME,    'E', 'x', 't', 'e', 'n', 'd', 'e', 'd', '_', 'A', 'D', 'V',};
/* * GLOBAL FUNCTION DEFINITIONS ***************************************************************************************** */void disconnect_task(void){    sdk_err_t    error_code;    error_code = ble_gap_adv_start(0, &s_gap_adv_time_param);    APP_ERROR_CHECK(error_code);    error_code = ble_gap_adv_start(1, &s_gap_adv_time_param);    APP_ERROR_CHECK(error_code);}
void ble_init_cmp_callback(void){    sdk_err_t    error_code;    gap_bdaddr_t bd_addr;    sdk_version_t version;    sys_sdk_verison_get(&version);    APP_LOG_INFO("Goodix GR551x SDK V%d.%d.d (commit %x)",                 version.major, version.minor, version.build, version.commit_id);    error_code = ble_gap_addr_get(&bd_addr);    APP_ERROR_CHECK(error_code);    APP_LOG_INFO("Local Board X:X:X:X:X:X.",                 bd_addr.gap_addr.addr[5],                 bd_addr.gap_addr.addr[4],                 bd_addr.gap_addr.addr[3],                 bd_addr.gap_addr.addr[2],                 bd_addr.gap_addr.addr[1],                 bd_addr.gap_addr.addr[0]);    //Long Range  
    extended_adv_start(0, GAP_PHY_CODED_VALUE, GAP_PHY_CODED_VALUE, s_adv_data_set_coded_pyh);    //1M PHY    extended_adv_start(1, GAP_PHY_1MBPS_VALUE, GAP_PHY_1MBPS_VALUE, s_adv_data_set_1M_pyh);} 


0收藏

0赞成

最佳答案

131***607

2021-12-15 17:50

5515有沟通群吗?有些问题请教一下

2条评论

0赞成

0收藏

您的评论

登录后可回答问题,请 注册

我们时刻倾听您的声音
联系销售

扫描关注公众号

打开微信,使用“扫一扫”即可关注