Skip to content

NRF52 SDK15 update #9019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5a921a4
Baseline legacy build using 14.2 drivers.
TacoGrandeTX Jun 26, 2018
0ec3da7
Mods for baseline 15.0 support
TacoGrandeTX Jun 26, 2018
94b6791
Bringing in Softdevice but excluding BLE feature and improvements in …
TacoGrandeTX Jul 9, 2018
cab0d1e
First porting effort covered by JIRA IOTDEV-1572:
TacoGrandeTX Jul 26, 2018
19e5be1
Ported analogin and pwm_out for IOTDEV-1573.
TacoGrandeTX Aug 8, 2018
cb9a842
Updates to PWM for IOTDEV-1573
TacoGrandeTX Aug 23, 2018
6220290
serial_api: Fixes to compile with SDK15.0
Aug 19, 2018
cd0867a
serial_api: add changes to port from Softdevice 14.2 to 15.0
Aug 16, 2018
604f8c5
Nordic sdk_config: Configure UART instances
Aug 24, 2018
15071c2
serial_api: Fix the interrupt registration for Nordic Serial Device
Aug 24, 2018
9bbf202
Updates for IOTDEV-1575 and nRF52_DK builds
TacoGrandeTX Sep 21, 2018
2c4b9ea
Updates for IOTDEV-1576 (only TRNG API)
TacoGrandeTX Oct 5, 2018
195de4a
NRF52: spi_api: port from Softdevice 14.2 to 15.0
Aug 14, 2018
96e05ab
NRF52: i2c_api: port from Softdevice 14.2 to 15.0
Aug 13, 2018
a331d7e
NRF: enable PRS (Peripheral Resource Sharing) for NRF52832 and NRF52840
Sep 28, 2018
29f9b2e
NRF52832: enable UART
Sep 27, 2018
88d393c
nRF52832 needs NRFX_RNG_ENABLED to use the legacy driver
TacoGrandeTX Oct 8, 2018
6c2f7a6
nRF52_DK: Use mbed_lib.json to set app_offset (MBED_APP_START)
TacoGrandeTX Oct 16, 2018
30132bb
NRF52: Fix vector table
Sep 26, 2018
e99053e
Updates after rebase with Mbed master (circa OS v5.10.1)
TacoGrandeTX Oct 16, 2018
3881db0
Fix build for nRF51 (fewer common files with nRF52)
TacoGrandeTX Oct 22, 2018
ebf58c1
Remove dead #define PORT_SHIFT
TacoGrandeTX Oct 22, 2018
fa09de9
Add missing SoftDevice build support (MBR, NONE, OTA)
Oct 29, 2018
a3ab4eb
Revert "NRF52: Fix vector table"
TacoGrandeTX Nov 14, 2018
b2a8f2f
Cleanup for feature release
TacoGrandeTX Nov 15, 2018
b2ce612
Enabling NRFX_PPI_ENABLED for serial_api updates
TacoGrandeTX Dec 6, 2018
074d5f0
Changes required for rebase:
TacoGrandeTX Dec 6, 2018
8d97ab6
Set the PWM clock prescaler back to default (1MHz clock)
TacoGrandeTX Dec 6, 2018
56134b4
NRF52: serial: fix build warnings
Dec 7, 2018
f484ebb
NRF52: Cleanup unused code
Dec 7, 2018
5e9cb64
Fix timer1 irq configuration
desmond-blue Dec 13, 2018
0396048
Update BLE SoftDevice from SDK14 to SDK15
desmond-blue Dec 9, 2018
fa4c1b8
Fix SoftDevice configuration on NRF52_DK
desmond-blue Dec 14, 2018
0fe61d3
Remove duplicate file
TacoGrandeTX Dec 18, 2018
9098477
Remove RTC from nRF52840_DK and DELTA_DFCM_NNN50 (was testing)
TacoGrandeTX Dec 18, 2018
73e490e
Update file header at TARGET_NRF52 level
TacoGrandeTX Dec 19, 2018
a177fe7
Add BLE feature to mbed_lib.json of SoftDevice
desmond-blue Dec 19, 2018
ef632c8
NRF52: reloc_vector_table: check the RTS pin settings in code
Jan 12, 2019
a883bf7
Fix nrf section iter macro check
desmond-blue Jan 24, 2019
360b099
Merge pull request #7 from desmond-blue/fix-nrf-section-iter
TacoGrandeTX Jan 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,13 @@ void btle_handler(const ble_evt_t *p_ble_evt)


#if (NRF_SD_BLE_API_VERSION >= 5)
#ifndef S140
// Handle PHY upgrade request
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
gap.on_phy_update_request(
p_ble_evt->evt.gap_evt.conn_handle,
p_ble_evt->evt.gap_evt.params.phy_update_request
);
break;
#endif
case BLE_GAP_EVT_PHY_UPDATE:
gap.on_phy_update(
p_ble_evt->evt.gap_evt.conn_handle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ nRF5xGap::nRF5xGap() : Gap(),
_connections_role()
{
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
#if (NRF_SD_BLE_API_VERSION >= 6)
m_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
#endif
}
/**************************************************************************/
/*!
Expand Down Expand Up @@ -226,13 +229,37 @@ ble_error_t nRF5xGap::setAdvertisingData(const GapAdvertisingData &advData, cons
// }
//}

#if (NRF_SD_BLE_API_VERSION >= 6)
/* sd_ble_gap_adv_data_set has been decprecated */
if (m_advHandle != BLE_GAP_ADV_SET_HANDLE_NOT_SET) {
/* This is for updating advdata*/
ble_gap_adv_data_t adv_data = {0};
adv_data.adv_data.p_data = const_cast<uint8_t*>(advData.getPayload());
adv_data.adv_data.len = advData.getPayloadLen();
adv_data.scan_rsp_data.p_data = const_cast<uint8_t*>(scanResponse.getPayload());
adv_data.scan_rsp_data.len = scanResponse.getPayloadLen();

ASSERT_TRUE(ERROR_NONE ==
sd_ble_gap_adv_stop(m_advHandle),
BLE_ERROR_PARAM_OUT_OF_RANGE);

ASSERT_TRUE(ERROR_NONE ==
sd_ble_gap_adv_set_configure(&m_advHandle, &adv_data, NULL),
BLE_ERROR_PARAM_OUT_OF_RANGE);

ASSERT_TRUE(ERROR_NONE ==
sd_ble_gap_adv_start(m_advHandle, NRF_CONNECTION_TAG),
BLE_ERROR_PARAM_OUT_OF_RANGE);
}
#else
/* Send advertising data! */
ASSERT_TRUE(ERROR_NONE ==
sd_ble_gap_adv_data_set(advData.getPayload(),
advData.getPayloadLen(),
scanResponse.getPayload(),
scanResponse.getPayloadLen()),
BLE_ERROR_PARAM_OUT_OF_RANGE);
#endif

/* Make sure the GAP Service appearance value is aligned with the
*appearance from GapAdvertisingData */
Expand Down Expand Up @@ -363,14 +390,56 @@ ble_error_t nRF5xGap::startAdvertising(const GapAdvertisingParams &params)

/* Start Advertising */

#if (NRF_SD_BLE_API_VERSION >= 6)

/* FIXME: Must be chanaged if extended paramters added into GapAdvertisingParams */
switch (params.getAdvertisingType()) {
case GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED:
adv_para.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
break;

case GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED:
adv_para.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED;
break;

case GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED:
adv_para.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
break;

case GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED:
adv_para.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED;
break;

default:
return BLE_ERROR_PARAM_OUT_OF_RANGE;
break;
}

adv_para.interval = params.getIntervalInADVUnits(); // advertising interval (in units of 0.625 ms)
adv_para.duration = params.getTimeout() * 100; // units have been changed from seconds to 10ms units.
memset(adv_para.channel_mask, 0, sizeof(adv_para.channel_mask));
adv_para.filter_policy = advertisingPolicyMode; // BLE_GAP_ADV_FP_ANY
adv_para.primary_phy = BLE_GAP_PHY_1MBPS; /* Use _preferred_tx_phys if validated */
adv_para.p_peer_addr = NULL;

m_adv_data.adv_data.p_data = const_cast<uint8_t*>(_advPayload.getPayload());
m_adv_data.adv_data.len = _advPayload.getPayloadLen();
m_adv_data.scan_rsp_data.p_data = const_cast<uint8_t*>(_scanResponse.getPayload());
m_adv_data.scan_rsp_data.len = _scanResponse.getPayloadLen();
#else
adv_para.type = params.getAdvertisingType();
adv_para.p_peer_addr = NULL; // Undirected advertisement
adv_para.fp = advertisingPolicyMode;
adv_para.interval = params.getIntervalInADVUnits(); // advertising interval (in units of 0.625 ms)
adv_para.timeout = params.getTimeout();
#endif

#if (NRF_SD_BLE_API_VERSION >= 5)

#if (NRF_SD_BLE_API_VERSION >= 6)
if ((err = sd_ble_gap_adv_set_configure(&m_advHandle, &m_adv_data, &adv_para) == ERROR_NONE)) {
err = sd_ble_gap_adv_start(m_advHandle, NRF_CONNECTION_TAG);
}
#elif (NRF_SD_BLE_API_VERSION == 5)
err = sd_ble_gap_adv_start(&adv_para, NRF_CONNECTION_TAG);
#else
err = sd_ble_gap_adv_start(&adv_para);
Expand Down Expand Up @@ -417,15 +486,29 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
#else
/* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */

#if (NRF_SD_BLE_API_VERSION >= 6)
scanParams.filter_policy = scanningPolicyMode;
#else
scanParams.use_whitelist = scanningPolicyMode;
scanParams.adv_dir_report = 0;
#endif
#endif

#if (NRF_SD_BLE_API_VERSION >= 6)
scanParams.extended = 0;
memset(scanParams.channel_mask, 0, sizeof(scanParams.channel_mask));
scanParams.scan_phys = BLE_GAP_PHY_1MBPS; /* Use _preferred_rx_phys if validated */

scanParams.interval = scanningParams.getInterval(); /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
scanParams.window = scanningParams.getWindow(); /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
scanParams.timeout = scanningParams.getTimeout()*100; /**< Scan timeout between 0x0001 and 0xFFFF in 10 ms units, 0x0000 disables timeout. */
#else
scanParams.active = scanningParams.getActiveScanning(); /**< If 1, perform active scanning (scan requests). */

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

if (_privacy_enabled) {
bool enable_resolution =
Expand All @@ -440,9 +523,20 @@ ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
}
}

#if (NRF_SD_BLE_API_VERSION >= 6)
m_scan_buffer.p_data = m_raw_scan_buffer;
m_scan_buffer.len = sizeof(m_raw_scan_buffer);
m_resume_scanning = true;
//if (sd_ble_gap_scan_start(&scanParams, &m_scan_buffer) != NRF_SUCCESS) {
uint32_t res = sd_ble_gap_scan_start(&scanParams, &m_scan_buffer);
if (res != NRF_SUCCESS) {
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
#else
if (sd_ble_gap_scan_start(&scanParams) != NRF_SUCCESS) {
return BLE_ERROR_PARAM_OUT_OF_RANGE;
}
#endif

return BLE_ERROR_NONE;
}
Expand Down Expand Up @@ -475,7 +569,11 @@ ble_error_t nRF5xGap::stopScan(void) {
ble_error_t nRF5xGap::stopAdvertising(void)
{
/* Stop Advertising */
#if (NRF_SD_BLE_API_VERSION >= 6)
ASSERT_TRUE(ERROR_NONE == sd_ble_gap_adv_stop(m_advHandle), BLE_ERROR_PARAM_OUT_OF_RANGE);
#else
ASSERT_TRUE(ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
#endif

state.advertising = 0;

Expand Down Expand Up @@ -621,8 +719,11 @@ ble_error_t nRF5xGap::connect(
}
#else
/* For NRF_SD_BLE_API_VERSION >= 3 nRF5xGap::setWhitelist setups the whitelist. */

#if (NRF_SD_BLE_API_VERSION >= 6)
scanParams.filter_policy |= (whitelistAddressesSize) ? 1 : 0;
#else
scanParams.use_whitelist = (whitelistAddressesSize) ? 1 : 0;
#endif

if (_privacy_enabled) {
bool enable_resolution =
Expand Down Expand Up @@ -651,6 +752,10 @@ ble_error_t nRF5xGap::connect(
scanParams.timeout = _scanningParams.getTimeout(); /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
}

#if NRF_SD_BLE_API_VERSION >= 6
m_resume_scanning = false;
#endif

#if NRF_SD_BLE_API_VERSION >= 5
uint32_t rc = sd_ble_gap_connect(addr_ptr, &scanParams, &connParams, NRF_CONNECTION_TAG);
#else
Expand Down Expand Up @@ -696,6 +801,9 @@ ble_error_t nRF5xGap::setPreferredPhys(
uint8_t preferred_rx_phys = rxPhys? rxPhys->value() : 0;

#ifdef S140
#if (NRF_SD_BLE_API_VERSION) >= 6
/* Set _preferred_tx_phys and _preferred_rx_phys here, used when start advertising or scanning */
#else
ble_opt_t opt = { 0 };
opt.gap_opt.preferred_phys.tx_phys = preferred_tx_phys;
opt.gap_opt.preferred_phys.rx_phys = preferred_rx_phys;
Expand All @@ -716,7 +824,7 @@ ble_error_t nRF5xGap::setPreferredPhys(
default:
return BLE_ERROR_UNSPECIFIED;
}

#endif
#endif

_preferred_tx_phys = preferred_tx_phys;
Expand All @@ -731,7 +839,7 @@ ble_error_t nRF5xGap::setPhy(
const ble::phy_set_t* rxPhys,
CodedSymbolPerBit_t codedSymbol
) {
#ifdef S140
#if defined(S140) && ((NRF_SD_BLE_API_VERSION) < 6)
return BLE_ERROR_NOT_IMPLEMENTED;
#else
// TODO handle coded symbol once supported by the softdevice.
Expand Down Expand Up @@ -841,6 +949,9 @@ ble_error_t nRF5xGap::reset(void)

/* Clear derived class members */
m_connectionHandle = BLE_CONN_HANDLE_INVALID;
#if (NRF_SD_BLE_API_VERSION >= 6)
m_advHandle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
#endif

/* Set the whitelist policy filter modes to IGNORE_WHITELIST */
advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST;
Expand Down Expand Up @@ -1009,7 +1120,25 @@ ble_error_t nRF5xGap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
ble_error_t nRF5xGap::setTxPower(int8_t txPower)
{
unsigned rc;
#if (NRF_SD_BLE_API_VERSION >= 6)
/* FIXME: This has to change API for specified paramter */
uint16_t handle = 0;
rc = NRF_SUCCESS;
if ((handle = getConnectionHandle()) != BLE_CONN_HANDLE_INVALID) {
rc = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, handle, txPower);
}
if ((rc == NRF_SUCCESS) && (m_advHandle != BLE_GAP_ADV_SET_HANDLE_NOT_SET)) {
handle = (uint16_t)m_advHandle;
rc = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, handle, txPower);
}
if (rc == NRF_SUCCESS) {
rc = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT, 0 /* This is ingored for ROLE_SCAN_INIT*/, txPower);
}

if (rc != NRF_SUCCESS) {
#else
if ((rc = sd_ble_gap_tx_power_set(txPower)) != NRF_SUCCESS) {
#endif
switch (rc) {
case NRF_ERROR_BUSY:
return BLE_STACK_BUSY;
Expand Down Expand Up @@ -1560,6 +1689,34 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
);
const uint8_t* peer_address = evt.peer_addr.addr;

#if (NRF_SD_BLE_API_VERSION >= 6)
GapAdvertisingParams::AdvertisingType_t type;
if (evt.type.connectable && !evt.type.directed) {
type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED;
} else if (evt.type.connectable && evt.type.directed) {
type = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED;
} else if (evt.type.scannable && !evt.type.directed) {
type = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED;
} else if (!evt.type.connectable && !evt.type.directed) {
type = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED;
} else {
// wrong condition
}
processAdvertisementReport(
peer_address,
evt.rssi,
(evt.type.scan_response? 1 : 0),
type,
evt.data.len,
evt.data.p_data,
peer_addr_type
);

/* If no action for connecting, must call sd_ble_gap_scan_start() aging for resuming scanning */
if (m_resume_scanning) {
sd_ble_gap_scan_start(NULL, &m_scan_buffer);
}
#else
processAdvertisementReport(
peer_address,
evt.rssi,
Expand All @@ -1569,6 +1726,7 @@ void nRF5xGap::on_advertising_packet(const ble_gap_evt_adv_report_t &evt) {
evt.data,
peer_addr_type
);
#endif
}

ble_error_t nRF5xGap::get_role(ble::connection_handle_t connection, Role_t& role) {
Expand Down Expand Up @@ -1652,7 +1810,6 @@ void nRF5xGap::on_phy_update(
);
}

#ifndef S140
void nRF5xGap::on_phy_update_request(
Handle_t connection,
const ble_gap_evt_phy_update_request_t& evt
Expand All @@ -1672,7 +1829,6 @@ void nRF5xGap::on_phy_update_request(

sd_ble_gap_phy_update(connection, &phys);
}
#endif



Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,18 @@ class nRF5xGap : public ::Gap, public ble::pal::ConnectionEventMonitor {
void release_all_connections_role();

void on_phy_update(Handle_t connection, const ble_gap_evt_phy_update_t& evt);
// FIXME: remove guard when S140 updated
#ifndef S140
void on_phy_update_request(Handle_t connection, const ble_gap_evt_phy_update_request_t& evt);

#if (NRF_SD_BLE_API_VERSION) >= 6
uint8_t m_advHandle;
/*
Note: The advertising data must be kept alive in memory until advertising is terminated. Not doing so will lead to undefined behavior.
Note: Updating advertising data while advertising can only be done by providing new advertising data buffers.
*/
ble_gap_adv_data_t m_adv_data;
uint8_t m_raw_scan_buffer[BLE_GAP_SCAN_BUFFER_MIN];
ble_data_t m_scan_buffer;
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() */
#endif

uint16_t m_connectionHandle;
Expand Down
Loading