Skip to content

Commit bd0545c

Browse files
committed
Update BLE SoftDevice from SDK14 to SDK15
- Adjust memory for SoftDevice - Enable PRIO=5 for interrupt priority check - Change NRF_SD_BLE_API_VERSION to 6 - Add handle and buffer for advertising and scanning - Remove guard for phy update - Change scatter files and mbed_lib.json for PR #8607
1 parent e3e6eac commit bd0545c

File tree

13 files changed

+182
-79
lines changed

13 files changed

+182
-79
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,15 +332,13 @@ void btle_handler(const ble_evt_t *p_ble_evt)
332332

333333

334334
#if (NRF_SD_BLE_API_VERSION >= 5)
335-
#ifndef S140
336335
// Handle PHY upgrade request
337336
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
338337
gap.on_phy_update_request(
339338
p_ble_evt->evt.gap_evt.conn_handle,
340339
p_ble_evt->evt.gap_evt.params.phy_update_request
341340
);
342341
break;
343-
#endif
344342
case BLE_GAP_EVT_PHY_UPDATE:
345343
gap.on_phy_update(
346344
p_ble_evt->evt.gap_evt.conn_handle,

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp

Lines changed: 162 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ nRF5xGap::nRF5xGap() : Gap(),
144144
_connections_role()
145145
{
146146
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
147+
#if (NRF_SD_BLE_API_VERSION >= 6)
148+
m_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
149+
#endif
147150
}
148151
/**************************************************************************/
149152
/*!
@@ -209,13 +212,37 @@ ble_error_t nRF5xGap::setAdvertisingData(const GapAdvertisingData &advData, cons
209212
// }
210213
//}
211214

215+
#if (NRF_SD_BLE_API_VERSION >= 6)
216+
/* sd_ble_gap_adv_data_set has been decprecated */
217+
if (m_advHandle != BLE_GAP_ADV_SET_HANDLE_NOT_SET) {
218+
/* This is for updating advdata*/
219+
ble_gap_adv_data_t adv_data = {0};
220+
adv_data.adv_data.p_data = const_cast<uint8_t*>(advData.getPayload());
221+
adv_data.adv_data.len = advData.getPayloadLen();
222+
adv_data.scan_rsp_data.p_data = const_cast<uint8_t*>(scanResponse.getPayload());
223+
adv_data.scan_rsp_data.len = scanResponse.getPayloadLen();
224+
225+
ASSERT_TRUE(ERROR_NONE ==
226+
sd_ble_gap_adv_stop(m_advHandle),
227+
BLE_ERROR_PARAM_OUT_OF_RANGE);
228+
229+
ASSERT_TRUE(ERROR_NONE ==
230+
sd_ble_gap_adv_set_configure(&m_advHandle, &adv_data, NULL),
231+
BLE_ERROR_PARAM_OUT_OF_RANGE);
232+
233+
ASSERT_TRUE(ERROR_NONE ==
234+
sd_ble_gap_adv_start(m_advHandle, NRF_CONNECTION_TAG),
235+
BLE_ERROR_PARAM_OUT_OF_RANGE);
236+
}
237+
#else
212238
/* Send advertising data! */
213239
ASSERT_TRUE(ERROR_NONE ==
214240
sd_ble_gap_adv_data_set(advData.getPayload(),
215241
advData.getPayloadLen(),
216242
scanResponse.getPayload(),
217243
scanResponse.getPayloadLen()),
218244
BLE_ERROR_PARAM_OUT_OF_RANGE);
245+
#endif
219246

220247
/* Make sure the GAP Service appearance value is aligned with the
221248
*appearance from GapAdvertisingData */
@@ -346,14 +373,56 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)
346373

347374
/* Start Advertising */
348375

376+
#if (NRF_SD_BLE_API_VERSION >= 6)
349377

378+
/* FIXME: Must be chanaged if extended paramters added into GapAdvertisingParams */
379+
switch (params.getAdvertisingType()) {
380+
case GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED:
381+
adv_para.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
382+
break;
383+
384+
case GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED:
385+
adv_para.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED;
386+
break;
387+
388+
case GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED:
389+
adv_para.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
390+
break;
391+
392+
case GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED:
393+
adv_para.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
394+
break;
395+
396+
default:
397+
return BLE_ERROR_PARAM_OUT_OF_RANGE;
398+
break;
399+
}
400+
401+
adv_para.interval = params.getIntervalInADVUnits(); // advertising interval (in units of 0.625 ms)
402+
adv_para.duration = params.getTimeout() * 100; // units have been changed from seconds to 10ms units.
403+
memset(adv_para.channel_mask, 0, sizeof(adv_para.channel_mask));
404+
adv_para.filter_policy = advertisingPolicyMode; // BLE_GAP_ADV_FP_ANY
405+
adv_para.primary_phy = BLE_GAP_PHY_1MBPS; /* Use _preferred_tx_phys if validated */
406+
adv_para.p_peer_addr = NULL;
407+
408+
m_adv_data.adv_data.p_data = const_cast<uint8_t*>(_advPayload.getPayload());
409+
m_adv_data.adv_data.len = _advPayload.getPayloadLen();
410+
m_adv_data.scan_rsp_data.p_data = const_cast<uint8_t*>(_scanResponse.getPayload());
411+
m_adv_data.scan_rsp_data.len = _scanResponse.getPayloadLen();
412+
#else
350413
adv_para.type = params.getAdvertisingType();
351414
adv_para.p_peer_addr = NULL; // Undirected advertisement
352415
adv_para.fp = advertisingPolicyMode;
353416
adv_para.interval = params.getIntervalInADVUnits(); // advertising interval (in units of 0.625 ms)
354417
adv_para.timeout = params.getTimeout();
418+
#endif
355419

356-
#if (NRF_SD_BLE_API_VERSION >= 5)
420+
421+
#if (NRF_SD_BLE_API_VERSION >= 6)
422+
if ((err = sd_ble_gap_adv_set_configure(&m_advHandle, &m_adv_data, &adv_para) == ERROR_NONE)) {
423+
err = sd_ble_gap_adv_start(m_advHandle, NRF_CONNECTION_TAG);
424+
}
425+
#elif (NRF_SD_BLE_API_VERSION == 5)
357426
err = sd_ble_gap_adv_start(&adv_para, NRF_CONNECTION_TAG);
358427
#else
359428
err = sd_ble_gap_adv_start(&adv_para);
@@ -400,15 +469,29 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
400469
#else
401470
/* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
402471

472+
#if (NRF_SD_BLE_API_VERSION >= 6)
473+
scanParams.filter_policy = scanningPolicyMode;
474+
#else
403475
scanParams.use_whitelist = scanningPolicyMode;
404476
scanParams.adv_dir_report = 0;
477+
#endif
405478
#endif
406479

480+
#if (NRF_SD_BLE_API_VERSION >= 6)
481+
scanParams.extended = 0;
482+
memset(scanParams.channel_mask, 0, sizeof(scanParams.channel_mask));
483+
scanParams.scan_phys = BLE_GAP_PHY_1MBPS; /* Use _preferred_rx_phys if validated */
484+
485+
scanParams.interval = scanningParams.getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
486+
scanParams.window = scanningParams.getWindow(); /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
487+
scanParams.timeout = scanningParams.getTimeout()*100; /**< Scan timeout between 0x0001 and 0xFFFF in 10 ms units, 0x0000 disables timeout. */
488+
#else
407489
scanParams.active = scanningParams.getActiveScanning(); /**< If 1, perform active scanning (scan requests). */
408490

409491
scanParams.interval = scanningParams.getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
410492
scanParams.window = scanningParams.getWindow(); /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
411493
scanParams.timeout = scanningParams.getTimeout(); /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
494+
#endif
412495

413496
if (_privacy_enabled) {
414497
bool enable_resolution =
@@ -423,9 +506,20 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
423506
}
424507
}
425508

509+
#if (NRF_SD_BLE_API_VERSION >= 6)
510+
m_scan_buffer.p_data = m_raw_scan_buffer;
511+
m_scan_buffer.len = sizeof(m_raw_scan_buffer);
512+
m_resume_scanning = true;
513+
//if (sd_ble_gap_scan_start(&scanParams, &m_scan_buffer) != NRF_SUCCESS) {
514+
uint32_t res = sd_ble_gap_scan_start(&scanParams, &m_scan_buffer);
515+
if (res != NRF_SUCCESS) {
516+
return BLE_ERROR_PARAM_OUT_OF_RANGE;
517+
}
518+
#else
426519
if (sd_ble_gap_scan_start(&scanParams) != NRF_SUCCESS) {
427520
return BLE_ERROR_PARAM_OUT_OF_RANGE;
428521
}
522+
#endif
429523

430524
return BLE_ERROR_NONE;
431525
}
@@ -458,7 +552,11 @@ ble_error_t nRF5xGap::stopScan(void) {
458552
ble_error_t nRF5xGap::stopAdvertising(void)
459553
{
460554
/* Stop Advertising */
555+
#if (NRF_SD_BLE_API_VERSION >= 6)
556+
ASSERT_TRUE(ERROR_NONE == sd_ble_gap_adv_stop(m_advHandle), BLE_ERROR_PARAM_OUT_OF_RANGE);
557+
#else
461558
ASSERT_TRUE(ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
559+
#endif
462560

463561
state.advertising = 0;
464562

@@ -604,8 +702,11 @@ ble_error_t nRF5xGap::connect(
604702
}
605703
#else
606704
/* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */
607-
705+
#if (NRF_SD_BLE_API_VERSION >= 6)
706+
scanParams.filter_policy |= (whitelistAddressesSize) ? 1 : 0;
707+
#else
608708
scanParams.use_whitelist = (whitelistAddressesSize) ? 1 : 0;
709+
#endif
609710

610711
if (_privacy_enabled) {
611712
bool enable_resolution =
@@ -634,6 +735,10 @@ ble_error_t nRF5xGap::connect(
634735
scanParams.timeout = _scanningParams.getTimeout(); /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
635736
}
636737

738+
#if NRF_SD_BLE_API_VERSION >= 6
739+
m_resume_scanning = false;
740+
#endif
741+
637742
#if NRF_SD_BLE_API_VERSION >= 5
638743
uint32_t rc = sd_ble_gap_connect(addr_ptr, &scanParams, &connParams, NRF_CONNECTION_TAG);
639744
#else
@@ -679,6 +784,9 @@ ble_error_t nRF5xGap::setPreferredPhys(
679784
uint8_t preferred_rx_phys = rxPhys? rxPhys->value() : 0;
680785

681786
#ifdef S140
787+
#if (NRF_SD_BLE_API_VERSION) >= 6
788+
/* Set _preferred_tx_phys and _preferred_rx_phys here, used when start advertising or scanning */
789+
#else
682790
ble_opt_t opt = { 0 };
683791
opt.gap_opt.preferred_phys.tx_phys = preferred_tx_phys;
684792
opt.gap_opt.preferred_phys.rx_phys = preferred_rx_phys;
@@ -699,7 +807,7 @@ ble_error_t nRF5xGap::setPreferredPhys(
699807
default:
700808
return BLE_ERROR_UNSPECIFIED;
701809
}
702-
810+
#endif
703811
#endif
704812

705813
_preferred_tx_phys = preferred_tx_phys;
@@ -714,7 +822,7 @@ ble_error_t nRF5xGap::setPhy(
714822
const ble::phy_set_t* rxPhys,
715823
CodedSymbolPerBit_t codedSymbol
716824
) {
717-
#ifdef S140
825+
#if defined(S140) && ((NRF_SD_BLE_API_VERSION) < 6)
718826
return BLE_ERROR_NOT_IMPLEMENTED;
719827
#else
720828
// TODO handle coded symbol once supported by the softdevice.
@@ -824,6 +932,9 @@ ble_error_t nRF5xGap::reset(void)
824932

825933
/* Clear derived class members */
826934
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
935+
#if (NRF_SD_BLE_API_VERSION >= 6)
936+
m_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
937+
#endif
827938

828939
/* Set the whitelist policy filter modes to IGNORE_WHITELIST */
829940
advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST;
@@ -992,7 +1103,25 @@ ble_error_t nRF5xGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
9921103
ble_error_t nRF5xGap::setTxPower(int8_t txPower)
9931104
{
9941105
unsigned rc;
1106+
#if (NRF_SD_BLE_API_VERSION >= 6)
1107+
/* FIXME: This has to change API for specified paramter */
1108+
uint16_t handle = 0;
1109+
rc = NRF_SUCCESS;
1110+
if ((handle = getConnectionHandle()) != BLE_CONN_HANDLE_INVALID) {
1111+
rc = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, handle, txPower);
1112+
}
1113+
if ((rc == NRF_SUCCESS) && (m_advHandle != BLE_GAP_ADV_SET_HANDLE_NOT_SET)) {
1114+
handle = (uint16_t)m_advHandle;
1115+
rc = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, handle, txPower);
1116+
}
1117+
if (rc == NRF_SUCCESS) {
1118+
rc = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT, 0 /* This is ingored for ROLE_SCAN_INIT*/, txPower);
1119+
}
1120+
1121+
if (rc != NRF_SUCCESS) {
1122+
#else
9951123
if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) {
1124+
#endif
9961125
switch (rc) {
9971126
case NRF_ERROR_BUSY:
9981127
return BLE_STACK_BUSY;
@@ -1543,6 +1672,34 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
15431672
);
15441673
const uint8_t* peer_address = evt.peer_addr.addr;
15451674

1675+
#if (NRF_SD_BLE_API_VERSION >= 6)
1676+
GapAdvertisingParams::AdvertisingType_t type;
1677+
if (evt.type.connectable && !evt.type.directed) {
1678+
type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED;
1679+
} else if (evt.type.connectable && evt.type.directed) {
1680+
type = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED;
1681+
} else if (evt.type.scannable && !evt.type.directed) {
1682+
type = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED;
1683+
} else if (!evt.type.connectable && !evt.type.directed) {
1684+
type = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED;
1685+
} else {
1686+
// wrong condition
1687+
}
1688+
processAdvertisementReport(
1689+
peer_address,
1690+
evt.rssi,
1691+
(evt.type.scan_response? 1 : 0),
1692+
type,
1693+
evt.data.len,
1694+
evt.data.p_data,
1695+
peer_addr_type
1696+
);
1697+
1698+
/* If no action for connecting, must call sd_ble_gap_scan_start() aging for resuming scanning */
1699+
if (m_resume_scanning) {
1700+
sd_ble_gap_scan_start(NULL, &m_scan_buffer);
1701+
}
1702+
#else
15461703
processAdvertisementReport(
15471704
peer_address,
15481705
evt.rssi,
@@ -1552,6 +1709,7 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
15521709
evt.data,
15531710
peer_addr_type
15541711
);
1712+
#endif
15551713
}
15561714

15571715
ble_error_t nRF5xGap::get_role(ble::connection_handle_t connection, Role_t& role) {
@@ -1635,7 +1793,6 @@ void nRF5xGap::on_phy_update(
16351793
);
16361794
}
16371795

1638-
#ifndef S140
16391796
void nRF5xGap::on_phy_update_request(
16401797
Handle_t connection,
16411798
const ble_gap_evt_phy_update_request_t& evt
@@ -1655,7 +1812,6 @@ void nRF5xGap::on_phy_update_request(
16551812

16561813
sd_ble_gap_phy_update(connection, &phys);
16571814
}
1658-
#endif
16591815

16601816

16611817

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,18 @@ class nRF5xGap : public ::Gap, public ble::pal::ConnectionEventMonitor {
301301
void release_all_connections_role();
302302

303303
void on_phy_update(Handle_t connection, const ble_gap_evt_phy_update_t& evt);
304-
// FIXME: remove guard when S140 updated
305-
#ifndef S140
306304
void on_phy_update_request(Handle_t connection, const ble_gap_evt_phy_update_request_t& evt);
305+
306+
#if (NRF_SD_BLE_API_VERSION) >= 6
307+
uint8_t m_advHandle;
308+
/*
309+
Note: The advertising data must be kept alive in memory until advertising is terminated. Not doing so will lead to undefined behavior.
310+
Note: Updating advertising data while advertising can only be done by providing new advertising data buffers.
311+
*/
312+
ble_gap_adv_data_t m_adv_data;
313+
uint8_t m_raw_scan_buffer[BLE_GAP_SCAN_BUFFER_MIN];
314+
ble_data_t m_scan_buffer;
315+
bool m_resume_scanning; /* When the application receives a ble_gap_adv_report_t, it must now resume scanning by calling sd_ble_gap_scan_start() */
307316
#endif
308317

309318
uint16_t m_connectionHandle;

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_ARM_STD/nRF52832.sct

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@
99
#define MBED_APP_SIZE 0x80000
1010
#endif
1111

12-
/* If softdevice is present, set aside space for it */
13-
#if !defined(MBED_RAM_START)
14-
#if defined(SOFTDEVICE_PRESENT)
15-
#define MBED_RAM_START 0x20001D70
16-
#define MBED_RAM_SIZE 0xE290
17-
#else
18-
#define MBED_RAM_START 0x20000000
19-
#define MBED_RAM_SIZE 0x10000
20-
#endif
21-
#endif
22-
2312
#define MBED_RAM0_START MBED_RAM_START
2413
#define MBED_RAM0_SIZE 0xE0
2514
#define MBED_RAM1_START (MBED_RAM_START + MBED_RAM0_SIZE)

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52832/device/TOOLCHAIN_GCC_ARM/NRF52832.ld

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@
2525
#define MBED_APP_SIZE 0x80000
2626
#endif
2727

28-
/* If softdevice is present, set aside space for it */
29-
#if !defined(MBED_RAM_START)
30-
#if defined(SOFTDEVICE_PRESENT)
31-
#define MBED_RAM_START 0x20001D70
32-
#define MBED_RAM_SIZE 0xE290
33-
#else
34-
#define MBED_RAM_START 0x20000000
35-
#define MBED_RAM_SIZE 0x10000
36-
#endif
37-
#endif
38-
3928
#define MBED_RAM0_START MBED_RAM_START
4029
#define MBED_RAM0_SIZE 0xE0
4130
#define MBED_RAM1_START (MBED_RAM_START + MBED_RAM0_SIZE)

0 commit comments

Comments
 (0)