Skip to content

Reorganize SoftDevices for NRF52 series #6826

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 2 commits into from
May 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 67 additions & 13 deletions targets/TARGET_NORDIC/TARGET_NRF5x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ First, create a new entry in `mbed-os/targets/targets.json` using the template b
"inherits": [""],
"release_versions": ["5"],
"device_name": ""
},
}
}
```

Where `target_name` is the name of the new target, `inherits` can be either `MCU_NRF52832` or `MCU_NRF52840`, and `device_name` is the ID specifying actual RAM and flash size, for example, `nRF52832_xxAA` and `nRF52840_xxAA`. The `release_version` specifies that the target is compatible with Mbed OS 5.
Where `target_name` is the name of the new target, `inherits` can be either `MCU_NRF52832` or `MCU_NRF52840`, and `device_name` is the ID specifying actual RAM and flash size, for example, `nRF52832_xxAA` and `nRF52840_xxAA`. The `release_version` specifies that the target is compatible with Mbed OS 5.

This entry enables the new target in the Mbed OS build system.

Next, add optional target specific configuration in `mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/mbed_lib.json`.
Next, add optional target specific configuration in `mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/mbed_lib.json`.

```json
{
Expand All @@ -40,11 +40,11 @@ The optional configuration includes specifying errata fixes specific for the MCU
LF clock source configuration is used for MCU startup initialization and the BLE SoftDevice LF clock configuration (if BLE libraries is used). Advanced configurations are used only for the BLE SoftDevice LF clock configuration.

Default clock source is XTAL oscillator. There are three options that can be configured as the clock source:
- NRF_LF_SRC_XTAL
- NRF_LF_SRC_RC
- NRF_LF_SRC_SYNTH
- NRF_LF_SRC_XTAL
- NRF_LF_SRC_RC
- NRF_LF_SRC_SYNTH

Set `lf_clock_src` to what is most suitable for the target. This value can later be overridden by the user application if necessary.
Set `lf_clock_src` to what is most suitable for the target. This value can later be overridden by the user application if necessary.


## Mbed HAL Implementation Details
Expand All @@ -62,15 +62,15 @@ When instantiating a new Mbed SPI object or I2C object, the object will be assig

1. The driver will look up the pins in the configuration table and pick a pre-assigned instance.
1. If the pins can't be found in the configuration table, the driver will check if a hardware instance has already been assigned to those pins so that objects using the same pins will share the same instance.
1. If no instance has been assigned, the driver will look for a free instane. For I2C objects instances are assigned from 0 to 1. For SPI objects instances are assigned from 2 to 0. This ensures that no matter the order of instantiation the first three objects can be guaranteed to be on separate instances no matter the pins being used.
1. If no instance has been assigned, the driver will look for a free instane. For I2C objects instances are assigned from 0 to 1. For SPI objects instances are assigned from 2 to 0. This ensures that no matter the order of instantiation the first three objects can be guaranteed to be on separate instances no matter the pins being used.
1. If no unused instance can be found, objects not sharing any pins will be assigned to the same default instance, which is `Instance 0` for I2C and `Instance 2` for SPI.

#### Customization

A custom configuration table can be provided by overriding the weakly defined default empty table. In the example below, I2C objects using pins `p1` and `p2` for `SDA` and `SCL` will always be assigned to `Instance 1` and SPI objects using pins `p3`, `p4`, `p5` for `MOSI`, `MISO`, and `CLOCK` will be assigned to `Instance 2` and SPI objects using pins `p6`, `p7`, and `p8` will be assigned to `Instance 0`. The custom configuration table must always be terminated with a row of `NC`.

```
const PinMapI2C PinMap_I2C[] = {
const PinMapI2C PinMap_I2C[] = {
{p1, p2, 1},
{NC, NC, NC}
};
Expand All @@ -86,7 +86,7 @@ The tables must be placed in a C compilation file.

#### Concurrency

1. When called from the same thread, it is safe to assign I2C and SPI objects to the same instance.
1. When called from the same thread, it is safe to assign I2C and SPI objects to the same instance.
1. If an instance is being used exclusively for either I2C or SPI, the objects can safely be called from multiple threads.
1. If an instance is being used for both I2C and SPI, the user must provide thread safety between the objects.

Expand All @@ -99,7 +99,7 @@ The serial implementation uses the UARTE module which works exclusively through
1. Rx DMA buffer, pre-loaded in EasyDMA for automatic switchover.
1. Rx FIFO buffer, for serving data to the application.

When the first DMA buffer is full or flushed the interrupt handler will automatically copy the DMA buffer to the FIFO buffer. This happens in interrupt context to avoid data loss and with UARTE interrupts set at the highest priority. The FIFO buffer is backed by the Nordic atomic fifo, which can be read and written to safely without disabling interrupts.
When the first DMA buffer is full or flushed the interrupt handler will automatically copy the DMA buffer to the FIFO buffer. This happens in interrupt context to avoid data loss and with UARTE interrupts set at the highest priority. The FIFO buffer is backed by the Nordic atomic fifo, which can be read and written to safely without disabling interrupts.

#### Customization

Expand Down Expand Up @@ -128,7 +128,7 @@ All DMA buffers are the same size and must be at least 5 bytes due to hardware r
For the NRF52840, UARTE instances are assigned based on pins and calling order. Serial objects with the same pin configurations will go to the same instance. A custom configuration table can be provided by overriding the weakly defined default empty table. In the example below, serial objects using pins `p1` and `p2` for `Tx` and `Rx` will always be assigned to `Instance 1` and serial objects using pins `p3` and `p4` for `Tx` and `Rx` will be assigned to `Instance 0` regardless of calling order. The custom configuration table must always be terminated with a row of `NC`.

```
const PinMapI2C PinMap_UART[] = {
const PinMapI2C PinMap_UART[] = {
{p1, p2, 1},
{p3, p4, 0},
{NC, NC, NC}
Expand All @@ -149,5 +149,59 @@ The RTC2 ISR is set at the lowest interrupt priority to ensure that UARTE interr
* The UARTE hardware only supports 8-bit, None/Even parity, and 1 stop bit.
* The asynchronous read and write implementation currently only support 255 byte transfers.
* The EasyDMA hardware can only read from RAM, which means all Tx buffers must reside in RAM. If a Tx buffer residing in flash is passed to the asynchronous write function, the function will try to copy the Tx buffer to a temporary internal buffer and transmit the data from there.
* It is not possible to do an asynchronous write from flash and receive non-asynchronously at the same time since the non-asynchronous receive buffer is being used as the temporary transmission buffer.
* It is not possible to do an asynchronous write from flash and receive non-asynchronously at the same time since the non-asynchronous receive buffer is being used as the temporary transmission buffer.

## SoftDevice

SoftDevices are treated as bootloaders and automatically combined by the tools. Available SoftDevices:

* TARGET_SOFTDEVICE_COMMON
* TARGET_SOFTDEVICE_S112
* TARGET_SOFTDEVICE_S132_FULL (MBR + SoftDevice, default)
* TARGET_SOFTDEVICE_S132_OTA (SoftDevice only, for firmware updates)
* TARGET_SOFTDEVICE_S132_MBR (MBR only, for bootloader builds)
* TARGET_SOFTDEVICE_S140_FULL (MBR + SoftDevice, default)
* TARGET_SOFTDEVICE_S140_OTA (SoftDevice only, for firmware updates)
* TARGET_SOFTDEVICE_S140_MBR (MBR only, for bootloader builds)
* TARGET_SOFTDEVICE_NONE

NRF52832 uses the S132 SoftDevice and NRF52840 uses the S140 SoftDevice.

The X_OTA and X_MBR binaries are obtained from the original X_FULL SoftDevice by splitting it in an MBR part and a SoftDevice part. The MBR is needed for the bootloader and the SoftDevice for firmware updates.

### Changing SoftDevice

By default, all applications are built with the FULL SoftDevice. This can be changed by modifying the application's `mbed_app.json` configuration file.

Build application without SoftDevice:

```
"target_overrides": {
"*": {
"target.extra_labels_remove": ["SOFTDEVICE_COMMON", "SOFTDEVICE_X_FULL"],
"target.extra_labels_add": ["SOFTDEVICE_NONE"]
}
}
```

Build application for firmware update using SoftDevice X:

```
"target_overrides": {
"*": {
"target.extra_labels_remove": ["SOFTDEVICE_X_FULL"],
"target.extra_labels_add": ["SOFTDEVICE_X_OTA"]
}
}
```

Build bootloader without SoftDevice X:

```
"target_overrides": {
"*": {
"target.extra_labels_remove": ["SOFTDEVICE_COMMON", "SOFTDEVICE_X_FULL"],
"target.extra_labels_add": ["SOFTDEVICE_X_MBR"]
}
}
```
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"name": "softdevice",
"config": {
},
"macros": [
"SOFTDEVICE_PRESENT=1",
"S132",
"BLE_STACK_SUPPORT_REQD",
"S132",
"BLE_STACK_SUPPORT_REQD",
"NRF_SDH_CLOCK_LF_SRC=1",
"NRF_SDH_CLOCK_LF_RC_CTIV=0",
"NRF_SDH_CLOCK_LF_RC_TEMP_CTIV=0",
Expand Down Expand Up @@ -36,8 +34,7 @@
"NRF_SDH_BLE_STACK_OBSERVER_PRIO=0",
"NRF_SDH_SOC_STACK_OBSERVER_PRIO=0",
"FDS_BACKEND=2",
"SWI_DISABLE1=1",
"NRF_LOG_ENABLED=0"
"SWI_DISABLE1=1"
],
"target_overrides": {
"*": {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Copyright (c) 2007 - 2017, Nordic Semiconductor ASA
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form, except as embedded into a Nordic
Semiconductor ASA integrated circuit in a product or a software update for
such product, must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

3. Neither the name of Nordic Semiconductor ASA nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

4. This software, with or without modification, must only be used with a
Nordic Semiconductor ASA integrated circuit.

5. Any software provided in binary form under this license must not be reverse
engineered, decompiled, modified and/or disassembled.

THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Copyright (c) 2007 - 2017, Nordic Semiconductor ASA
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form, except as embedded into a Nordic
Semiconductor ASA integrated circuit in a product or a software update for
such product, must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

3. Neither the name of Nordic Semiconductor ASA nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

4. This software, with or without modification, must only be used with a
Nordic Semiconductor ASA integrated circuit.

5. Any software provided in binary form under this license must not be reverse
engineered, decompiled, modified and/or disassembled.

THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
:2000000000040020E90800007D050000C908000087050000910500009B05000000000000B6
:200020000000000000000000000000000D090000A505000000000000AF050000B90500008E
:20004000C3050000CD050000D7050000E1050000EB050000F5050000FF0500000906000047
:20006000130600001D06000027060000310600003B060000450600004F06000059060000A0
:20008000630600006D06000077060000810600008B060000950600009F060000A906000000
:2000A000B3060000BD060000C7060000D1060000DB060000E5060000EF060000F906000060
:2000C000030700000D07000017070000210700002B070000350700003F07000049070000B8
:2000E000530700005D07000067070000710700007B070000850700008F0700009907000018
:20010000A30700001FB500F003F88DE80F001FBD00F0E0BB1FB56FF00100009040100390E4
:20012000029001904FF010208069000B420900F01F045DF822300120A04083434DF82230D6
:20014000684600F045F91FBDF0B54FF6FF734FF4B4751A466E1E11E0A94201D3344600E029
:200160000C46091B30F8027B641E3B441A44F9D19CB204EB134394B204EB12420029EBD13A
:2001800098B200EB134002EB124140EA0140F0BDDE4992B00446D1E90001CDE91001FF2229
:2001A0004021684600F03CFB94E80F008DE80F00684610A902E004C841F8042D8842FAD1E6
:2001C00010216846FFF7C0FF1090AA208DF84400FFF7A0FF00F0F3F84FF01024A06910223A
:2001E0006946803000F002F9A069082210A900F0FDF800F0D8F84FF080510A694969006887
:200200004A43824201D8102070470020704710B5D0E900214FF0805002EB810302694469BF
:200220006243934209D84FF01022536903EB81030169406941438B4201D9092010BD5069D7
:20024000401C01D0002010BD0F2010BD70B501680446AF4D4FF01020072952D2DFE801F039
:20026000330419293C1E2500D4E9026564682946304600F0CDF82A462146304600F0B6F811
:20028000AA002146304600F09FFA002800D0032070BD00F051FB4FF4805007E0201DFFF79D
:2002A000AAFF0028F4D100F047FB60682860002070BD241D94E80700920000F085FA0028EC
:2002C000F6D00E2070BD8069401C12D0201DFFF79EFF0028F6D109E08069401C09D0201DD3
:2002E000FFF789FF0028EDD1606820B12046FFF74FFF042070BDFFF70DFF00F060F800F0CC
:2003000052F8072070BD10B50C46182802D00120086010BD2068FFF799FF206010BD4FF01E
:200320001024A069401C05D0A569A66980353079AA2808D06069401C2DD060690068401C7B
:2003400029D060692CE010212846FFF7FDFE316881421CD1A16901F18002C03105E030B1C1
:2003600008CA51F8040D984201D1012000E000208A42F4D158B1286810B1042803D0FEE7B5
:20038000284600F057F862496868086008E000F016F800F008F84FF480500168491C01D045
:2003A00000F0A4FAFEE7BFF34F8F5A4801685A4A01F4E06111430160BFF34F8FFEE74FF0EC
:2003C00010208169491C02D0806900F0AEB87047524A01681160121D416811604F4A816895
:2003E00010321160111DC068086070472DE9F04117460D460646002406E03046296800F091
:20040000A7F8641C2D1D361DBC42F6D3BDE8F08170B50C4605464FF4806608E0284600F012
:2004200084F8B44205D3A4F5806405F58055002CF4D170BD4168044609B1012500E0002530
:200440004FF010267069A268920000F0BDF9C8B1204600F01AF89DB17669A56864684FF4E2
:20046000002084420AD2854208D229463046FFF7CFFF2A4621463046FFF7B8FFFFF79FFFE2
:20048000FFF791FFFFF746FEF8E72DE9FF414FF01024616980680D0B01EB800000F6FF7059
:2004A000010B002000900190029002460390684601230BE0560902F01F0C50F8267003FA6E
:2004C0000CFC47EA0C0740F82670521CAA42F1D30AE04A0901F01F0650F8225003FA06F6DE
:2004E000354340F82250491C8029F2D3A169090B4A0901F01F0150F822408B409C4340F8F9
:200500002240FFF765FFBDE8FF8100005C090000000000200CED00E00400FA050006004053
:20052000144801680029FCD07047134A0221116010490B68002BFCD00F4B1B1D186008681C
:200540000028FCD00020106008680028FCD07047094B10B501221A60064A1468002CFCD082
:20056000016010680028FCD00020186010680028FCD010BD00E4014004E5014008208F498E
:2005800009680958084710208C4909680958084714208A4909680958084718208749096873
:2005A0000958084730208549096809580847382082490968095808473C2080490968095811
:2005C000084740207D4909680958084744207B4909680958084748207849096809580847F2
:2005E0004C207649096809580847502073490968095808475420714909680958084758209B
:200600006E490968095808475C206C49096809580847602069490968095808476420674929
:20062000096809580847682064490968095808476C20624909680958084770205F49096842
:200640000958084774205D4909680958084778205A490968095808477C2058490968095824
:20066000084780205549096809580847842053490968095808478820504909680958084709
:200680008C204E4909680958084790204B4909680958084794204949096809580847982072
:2006A00046490968095808479C204449096809580847A0204149096809580847A4203F4969
:2006C000096809580847A8203C49096809580847AC203A49096809580847B020374909685A
:2006E00009580847B4203549096809580847B8203249096809580847BC203049096809583C
:200700000847C0202D49096809580847C4202B49096809580847C820284909680958084720
:20072000CC202649096809580847D0202349096809580847D4202149096809580847D82049
:200740001E49096809580847DC201C49096809580847E0201949096809580847E4201749A8
:20076000096809580847E8201449096809580847EC201249096809580847F0200F49096871
:2007800009580847F4200D49096809580847F8200A49096809580847FC2008490968095853
:2007A00008475FF480700549096809580847000003480449024A034B70470000000000202F
:2007C000680900006809000040EA010310B59B070FD1042A0DD310C808C9121F9C42F8D034
:2007E00020BA19BA884201D9012010BD4FF0FF3010BD1AB1D30703D0521C07E0002010BDC5
:2008000010F8013B11F8014B1B1B07D110F8013B11F8014B1B1B01D1921EF1D1184610BDF3
:2008200002F0FF0343EA032242EA024200F005B87047704770474FF000020429C0F0128080
:2008400010F0030C00F01B80CCF1040CBCF1020F18BF00F8012BA8BF20F8022BA1EB0C0133
:2008600000F00DB85FEAC17C24BF00F8012B00F8012B48BF00F8012B70474FF0000200B53A
:20088000134694469646203922BFA0E80C50A0E80C50B1F12001BFF4F7AF090728BFA0E8AC
:2008A0000C5048BF0CC05DF804EB890028BF40F8042B08BF704748BF20F8022B11F0804F54
:2008C00018BF00F8012B7047014B1B68DB6818470000002009480A497047FFF7FBFFFFF794
:2008E00011FC00BD20BFFDE7064B1847064A1060016881F30888406800470000680900002E
:20090000680900001F030000000000201EF0040F0CBFEFF30881EFF30981886902380078BE
:20092000182803D100E00000074A1047074A12682C3212681047000000B5054B1B68054A4A
:200940009B58984700BD000007030000000000205809000004000000001000000000000069
:0809600000FFFFFF0090D0032F
:00000001FF
Loading