The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
Improve the shutdown functionality, such that a call to ble.shutdown() from
the user application clears the API and nRF5x state and NOT only the
SoftDevice. To achieve this the following changes are introduced:
* Add a protected member cleanup() to nRF5xGap, nRF5xGattClient,
nRF5xGattServer, nRF5xSecurityManager and nRF5xServiceDiscovery.
* Modify the shutdown() implementation in nRF5xn such that it also calls the
static member shutdown() exposed by the BLE API in Gap.h, SecurityManager.h,
GattClient.h and GattServer.h.
* Modify nRF5xGattClient, nRF5xGattServer and nRF5xSecurityManager
classes so that they dynamically create their respective objects only if
needed. Previously the GattClient, GattServer and SecurityManager objects were
declared as static, which means that they were always present even though they
were not always needed. This increases memory consumption unnecessarily.
Furthermore, pointers to the object instances are stored in static members of
the classes as specified by the BLE API base classes. This ensures that
calls to shutdown do not require calls to getInstance() functions that would
otherwise result in undesired memory allocations.
* nRF5xGap object is always needed, so this remains allocated statically. But
the reference in Gap is pointed to this object.
The shutdown procedure is as follows:
1. The user calls ble.shutdown() which executes the code in nRF5xn::shutdown()
1. The SoftDevice is shutdown
1. The static members of Gap.h, SecurityManager.h, GattClient.h and
GattServer.h are called to clean up their own state.
If at any point an error occur during the last step, BLE_ERROR_INVALID_STATE is
Previously the concepts of initLength and lenth were clearly separated.
However, this was at the cost of registering all characteristics in the
SoftDevice as having variable length. Clearly, this is not the desired
behaviour. Therefore, an additional field '_hasVariableLen' is added to the
GattAttribute to address the problem. Also, the GattAttribute and
GattCharacteristic constructors have been modified to take a boolean that
**NOTE:** Changes to this module will cause projects to fail the build stage
if changes to the BLE_API are not published first.
In previous versions of BLE_API the GattCharacteristic initLen parameter is
named minLen as well. When the characteristic is committed to the SoftDevice
the value of initial length is also used as the minimum length of the
characteristic value. Furthermore, the test (max_length == min_length) is used
to determine whether the characteristic value has variable length. This is
slightly confusing and also causes problems if the user wishes to use a
characteristic with variable length but the initial lenght is equal to max
To solve this problem the characteristic is now always committed to the
SoftDevice as variable. Furthermore, the API only maintains the current lenght
and the max length i.e. the field initialLen in the GattAttribute is removed.
In nRF5xGattServer all calls to getInitialLength() are removed and replaced
* This change requires updates to ble.
* Ideally we would like the characteristics to be declared as 'variable' only
when necessary, but this requires changing the signature of the
GattCharacteristic and GattAttribute constructors. Therefore, it will be part
of a separate pull request.
The ble-nrf51822 implementation of the BLE API executes callbacks for radio
notification events at very high priority. This functionality is replaced by
executing the radio notification callback at a lower priority. When using
mbed OS the callback is posted through minar. In mbed classic the callback is
executed directly, but from a lower priority. Note that minar or callback
execution in mbed classic could not be posted/generated directly from the
radio notification handler because this causes race conditions that may lead
to a hard-fault. Alternatively, a Timeout was used to post the callback in
another context with lower priority.
Fix terminate discovery (the replacement of the discovery was done after
the call to terminate).
When searching for a running discovery, dismiss results where the
characteristic is equal to the default characteristic value
Add support of DiscoveredCharacteristic last handle in the characteristic
The ble-nrf51822 implementation of the BLE API generated callbacks for radio
notification events without using the minar scheduler and at very high
priority. This functionality is replaced by posting events through minar
when YOTTA_CFG_MBED_OS is defined. Note that minar could not be used directly
to post callbacks because radio notification events are handled at very high
priority, which caused a hard-fault when minar tries to enter a critical
section. Alternatively, a Timeout was used to post the callback in another
context with lower priority.
Change assembly sequence that starts the Nordic bootloader to remove
MOV instruction before cheks of IPSR. The MOV might be translated into a ADDS
that could change the APSR and cause a wrong branch to be taken.
The assemble sequence within an mbedOS application that starts the nordic
bootloader was being modified by the compiler. The result is that DFU enabled
applications could never start the bootloader correctly. This is because the
GCC compiler was translating a MOV instruction into a ADDS, which sets the
conditional flags in APSR before a conditional branch was executed. The result
of the incorrect branch caused the program to believe that it was in interrupt
mode when this was not the case.
Currently it just blindly writes beyond the end of the array, leading to impossible-to-find bugs.
It doesn't help that the limit on the number of characteristics doesn't seem to be documented anywhere.
S110 compatibility is already present, but this patch adds proper handling
of observer/central related features:
* Gap::startScan will return BLE_ERRROR_NOT_IMPLEMENTED (instead of
* nRF5xGattClient uses the default GattClient implementation when S110 is
in use. All if its methods return NOT_IMPLEMENTED.
Example: for an application that acts as both a central and a peripheral,
using S110 will make the ble.gap().startScan() call return
BLE_ERROR_NOT_IMPLEMENTED, and advertisement features will continue
In addition, with GCC, this patch will free 344 bytes of RAM and 2504
bytes of flash.
Instead of relying on build macros to know which oscillator we're
supposedly using, check the value of LFCLKSRC register. This way, we can
trust mbed's init code to fallback on the internal clock if the user
specified a wrong target.
This change, along with the mbed patch that selects clock source
dynamically, will allow lots of application to still run and provide
FOTA, when the wrong Nordic platform is specified.
Signed-off-by: Jean-Philippe Brucker <firstname.lastname@example.org>