embassy-rs / nrf-softdevice

Apache License 2.0
256 stars 76 forks source link

Use PHY Coded as Primary PHY for advertisement #199

Closed jlpettersson closed 9 months ago

jlpettersson commented 9 months ago

I use softdevice 140 on nrf52840. I want to use Coded PHY as Primary PHY during Advertisement.

I configured it and used it like this:

        let config = peripheral::Config{
            primary_phy: Phy::Coded,
            secondary_phy: Phy::Coded,
...

let conn = unwrap!(peripheral::advertise_connectable(sd, adv, &config).await);

but I get this error when flushing to the device:

WARN  sd_ble_gap_adv_set_configure err InvalidParam
└─ <mod path> @ <file>:0
WARN  sd_ble_gap_adv_stop: BleInvalidAdvHandle
└─ <mod path> @ <file>:0
ERROR panicked at 'unwrap failed: peripheral :: advertise_connectable(sd, adv, & config).await'
error: `Raw(InvalidParam)`

According to the documentation Coded PHY should be supported as Primary PHY for advertisement.

I tried to dig into the code at https://github.com/embassy-rs/nrf-softdevice/blob/master/nrf-softdevice-s140/src/bindings.rs#L6073 but it just seem to be some wrapped assembly? I don't understand how this error is thrown or how it can be fixed.

Is there some knowledge around this?

Dirbaio commented 9 months ago

coded must use extended advertising. this works for me:



let config = peripheral::Config {
    primary_phy: Phy::Coded,
    secondary_phy: Phy::Coded,
    tx_power: TxPower::Plus8dBm,
    interval: 1600, // 1s
    timeout: None,
    max_events: Some(1),
    filter_policy: peripheral::FilterPolicy::Any,
};
let data = peripheral::ConnectableAdvertisement::ExtendedNonscannableUndirected {
    adv_data: &adv_data,
    set_id: 0,
};

match peripheral::advertise_connectable(sd, data, config).await { ... }