Skip to content

Commit 2313b82

Browse files
committed
Merge pull request #956 from screamerbg/master
nRF51822/nRF51-DK bootloader compile support and related platforms
2 parents 87952c5 + 90b01bb commit 2313b82

File tree

7 files changed

+1037
-18
lines changed

7 files changed

+1037
-18
lines changed

libraries/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/nrf51822_bootloader.hex

Lines changed: 920 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "mbed.h"
2+
#include "test_env.h"
3+
4+
AnalogIn pot1(A0);
5+
AnalogIn pot2(A1);
6+
7+
#define TEST_ITERATIONS 20
8+
#define MEASURE_MIN 0.01
9+
10+
int main(void) {
11+
MBED_HOSTTEST_TIMEOUT(10);
12+
MBED_HOSTTEST_SELECT(default_auto);
13+
MBED_HOSTTEST_DESCRIPTION(AnalogIn potentiometer test);
14+
MBED_HOSTTEST_START("analog_pot");
15+
16+
bool result = false;
17+
float val1, val2;
18+
19+
for (int i = 0; i < TEST_ITERATIONS; i++) {
20+
val1 = pot1.read();
21+
val2 = pot2.read();
22+
23+
const char *succes_str = val1 > MEASURE_MIN || val2 > MEASURE_MIN ? "[OK]" : "[FAIL]";
24+
result = result || (val1 > MEASURE_MIN || val2 > MEASURE_MIN);
25+
printf("Pot values %f, %f\r\n", val1, val2);
26+
wait(0.001);
27+
}
28+
MBED_HOSTTEST_RESULT(result);
29+
}

libraries/tests/mbed/i2c_TMP102/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ TMP102 temperature(p28, p27, 0x90);
2525
defined(TARGET_NUCLEO_F411RE) || \
2626
defined(TARGET_NUCLEO_L053R8) || \
2727
defined(TARGET_NUCLEO_L152RE) || \
28-
defined(TARGET_LPC824)
28+
defined(TARGET_LPC824) || \
29+
defined(TARGET_FF_ARDUINO)
2930
TMP102 temperature(I2C_SDA, I2C_SCL, 0x90);
3031

3132
#else

libraries/tests/mbed/i2c_eeprom_line/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ I2C i2c(I2C_SDA0, I2C_SCL0);
6969
defined(TARGET_NUCLEO_F401RE) || \
7070
defined(TARGET_NUCLEO_F411RE) || \
7171
defined(TARGET_NUCLEO_L053R8) || \
72-
defined(TARGET_NUCLEO_L152RE)
72+
defined(TARGET_NUCLEO_L152RE) || \
73+
defined(TARGET_FF_ARDUINO)
7374
I2C i2c(I2C_SDA, I2C_SCL);
7475

7576
#else

libraries/tests/mbed/i2c_mma7660/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ MMA7660 MMA(p28, p27);
99
#endif
1010

1111
int main() {
12+
MBED_HOSTTEST_TIMEOUT(15);
13+
MBED_HOSTTEST_SELECT(default_auto);
14+
MBED_HOSTTEST_DESCRIPTION(I2C MMA7660 accelerometer);
15+
MBED_HOSTTEST_START("MBED_A13");
16+
1217
if (!MMA.testConnection())
13-
notify_completion(false);
18+
MBED_HOSTTEST_RESULT(false);
1419

1520
for(int i = 0; i < 5; i++) {
1621
printf("x: %f, y: %f, z: %f\r\n", MMA.x(), MMA.y(), MMA.z());
1722
wait(0.2);
1823
}
1924

20-
notify_completion(true);
25+
MBED_HOSTTEST_RESULT(true);
2126
}

workspace_tools/targets.py

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ def __init__(self):
616616
self.core = "Cortex-M4F"
617617
self.extra_labels = ['STM', 'STM32F4', 'STM32F407', 'STM32F407VG']
618618
self.supported_toolchains = ["ARM", "uARM", "GCC_ARM"]
619+
self.supported_form_factors = ["ARDUINO"]
619620

620621
def program_cycle_s(self):
621622
return 2
@@ -723,6 +724,7 @@ def __init__(self):
723724
self.supported_form_factors = ["ARDUINO"]
724725

725726

727+
726728
### Nordic ###
727729

728730
class NRF51822(Target):
@@ -742,8 +744,10 @@ class NRF51822(Target):
742744
'offset' : 0x14000
743745
}
744746
]
747+
EXPECTED_BOOTLOADER_FILENAME = "nrf51822_bootloader.hex"
745748
OUTPUT_EXT = 'hex'
746749
MERGE_SOFT_DEVICE = True
750+
MERGE_BOOTLOADER = False
747751

748752
def __init__(self):
749753
Target.__init__(self)
@@ -762,31 +766,50 @@ def init_hooks(self, hook, toolchain_name):
762766

763767
@staticmethod
764768
def binary_hook(t_self, resources, elf, binf):
769+
# Scan to find the actual paths of soft device and bootloader files
770+
sdf = None
771+
blf = None
765772
for hexf in resources.hex_files:
766-
found = False
767-
for softdeviceAndOffsetEntry in NRF51822.EXPECTED_SOFTDEVICES_WITH_OFFSETS:
768-
if hexf.find(softdeviceAndOffsetEntry['name']) != -1:
769-
found = True
770-
break
771-
if found:
772-
break
773-
else:
773+
if hexf.find(t_self.target.EXPECTED_BOOTLOADER_FILENAME) != -1:
774+
blf = hexf
775+
else:
776+
for softdeviceAndOffsetEntry in t_self.target.EXPECTED_SOFTDEVICES_WITH_OFFSETS:
777+
if hexf.find(softdeviceAndOffsetEntry['name']) != -1:
778+
sdf = hexf
779+
break
780+
781+
if sdf is None:
774782
t_self.debug("Hex file not found. Aborting.")
775783
return
776784

777785
# Merge user code with softdevice
778-
t_self.debug("Patching Hex file %s" % softdeviceAndOffsetEntry['name'])
779786
from intelhex import IntelHex
780787
binh = IntelHex()
781788
binh.loadbin(binf, offset=softdeviceAndOffsetEntry['offset'])
782789

783790
if t_self.target.MERGE_SOFT_DEVICE is True:
784-
sdh = IntelHex(hexf)
791+
t_self.debug("Merge SoftDevice file %s" % softdeviceAndOffsetEntry['name'])
792+
sdh = IntelHex(sdf)
785793
binh.merge(sdh)
786794

795+
if t_self.target.MERGE_BOOTLOADER is True and blf is not None:
796+
t_self.debug("Merge BootLoader file %s" % t_self.target.EXPECTED_BOOTLOADER_FILENAME)
797+
blh = IntelHex(blf)
798+
binh.merge(blh)
799+
787800
with open(binf.replace(".bin", ".hex"), "w") as f:
788801
binh.tofile(f, format='hex')
789802

803+
class NRF51822_BOOT(NRF51822):
804+
def __init__(self):
805+
NRF51822.__init__(self)
806+
self.core = "Cortex-M0"
807+
self.extra_labels = ["NORDIC", "NRF51822_MKIT", "MCU_NRF51822", "MCU_NORDIC_16K", "NRF51822"]
808+
self.macros = ['TARGET_NRF51822', 'TARGET_OTA_ENABLED']
809+
self.supported_toolchains = ["ARM", "GCC_ARM"]
810+
self.MERGE_SOFT_DEVICE = True
811+
self.MERGE_BOOTLOADER = True
812+
790813
class NRF51822_OTA(NRF51822):
791814
def __init__(self):
792815
NRF51822.__init__(self)
@@ -803,6 +826,16 @@ def __init__(self):
803826
self.macros = ['TARGET_NRF51822']
804827
self.supported_form_factors = ["ARDUINO"]
805828

829+
class NRF51_DK_BOOT(NRF51822):
830+
def __init__(self):
831+
NRF51822.__init__(self)
832+
self.core = "Cortex-M0"
833+
self.extra_labels = ['NORDIC', 'MCU_NRF51822', 'MCU_NORDIC_32K', 'NRF51_DK']
834+
self.macros = ['TARGET_NRF51822', 'TARGET_NRF51_DK', 'TARGET_OTA_ENABLED']
835+
self.supported_toolchains = ["ARM", "GCC_ARM"]
836+
self.MERGE_SOFT_DEVICE = True
837+
self.MERGE_BOOTLOADER = True
838+
806839
class NRF51_DK_OTA(NRF51822):
807840
def __init__(self):
808841
NRF51822.__init__(self)
@@ -831,10 +864,18 @@ def __init__(self):
831864
self.extra_labels = ['NORDIC', 'MCU_NRF51822', 'MCU_NORDIC_16K']
832865
self.macros = ['TARGET_NRF51822']
833866

867+
class SEEED_TINY_BLE_BOOT(NRF51822):
868+
def __init__(self):
869+
NRF51822.__init__(self)
870+
self.extra_labels = ['NORDIC', 'MCU_NRF51822', 'MCU_NORDIC_16K', 'SEEED_TINY_BLE']
871+
self.macros = ['TARGET_NRF51822', 'TARGET_SEEED_TINY_BLE', 'TARGET_OTA_ENABLED']
872+
self.MERGE_SOFT_DEVICE = True
873+
self.MERGE_BOOTLOADER = True
874+
834875
class SEEED_TINY_BLE_OTA(NRF51822):
835876
def __init__(self):
836877
NRF51822.__init__(self)
837-
self.extra_labels = ['NORDIC', 'MCU_NRF51822', 'MCU_NORDIC_16K']
878+
self.extra_labels = ['NORDIC', 'MCU_NRF51822', 'MCU_NORDIC_16K', 'SEEED_TINY_BLE']
838879
self.macros = ['TARGET_NRF51822', 'TARGET_SEEED_TINY_BLE', 'TARGET_OTA_ENABLED']
839880
self.MERGE_SOFT_DEVICE = False
840881

@@ -890,6 +931,12 @@ def __init__(self):
890931
self.core = "Cortex-M0"
891932
self.extra_labels = ['NORDIC', 'MCU_NRF51822', 'MCU_NORDIC_16K', 'DELTA_DFCM_NNN40']
892933
self.MERGE_SOFT_DEVICE = False
934+
class DELTA_DFCM_NNN40_OTA(NRF51822):
935+
def __init__(self):
936+
NRF51822.__init__(self)
937+
self.core = "Cortex-M0"
938+
self.extra_labels = ['NORDIC', 'MCU_NRF51822', 'MCU_NORDIC_16K', 'DELTA_DFCM_NNN40']
939+
self.MERGE_SOFT_DEVICE = False
893940

894941

895942
### ARM ###
@@ -1046,13 +1093,16 @@ def program_cycle_s(self):
10461093

10471094
### Nordic ###
10481095
NRF51822(),
1096+
NRF51822_BOOT(), # nRF51822
10491097
NRF51822_OTA(), # nRF51822
10501098
NRF51_DK(),
1099+
NRF51_DK_BOOT(), # nRF51822
10511100
NRF51_DK_OTA(), # nRF51822
10521101
NRF51_DONGLE(),
10531102
ARCH_BLE(), # nRF51822
1054-
SEEED_TINY_BLE(),
1055-
SEEED_TINY_BLE_OTA(),
1103+
SEEED_TINY_BLE(), # nRF51822
1104+
SEEED_TINY_BLE_BOOT(),# nRF51822
1105+
SEEED_TINY_BLE_OTA(),# nRF51822
10561106
HRM1017(), # nRF51822
10571107
RBLAB_NRF51822(),# nRF51822
10581108
RBLAB_BLENANO(),# nRF51822

workspace_tools/tests.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
* LPC1*: (p17 <-> p18 )
6060
* KL25Z: (PTE30 <-> PTC2)
6161
62+
* analog_pot (AnalogIn):
63+
* Arduino headers: (A0, A1)
64+
6265
* SD (SPI):
6366
* LPC1*: (mosi=p11 , miso=p12 , sclk=p13 , cs=p14 )
6467
* KL25Z: (mosi=PTD2, miso=PTD3, sclk=PTD1, cs=PTD0)
@@ -72,6 +75,7 @@
7275
* i2c_eeprom:
7376
* LPC1*: (SDA=p28 , SCL=p27)
7477
* KL25Z: (SDA=PTE0, SCL=PTE1)
78+
7579
"""
7680
TESTS = [
7781
# Automated MBED tests
@@ -165,9 +169,10 @@
165169
"peripherals": ["SD"]
166170
},
167171
{
168-
"id": "MBED_A13", "description": "I2C MMA7660",
172+
"id": "MBED_A13", "description": "I2C MMA7660 accelerometer",
169173
"source_dir": join(TEST_DIR, "mbed", "i2c_MMA7660"),
170174
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, join(PERIPHERALS, 'MMA7660')],
175+
"automated": True,
171176
"peripherals": ["MMA7660"]
172177
},
173178
{
@@ -251,6 +256,14 @@
251256
"automated": True,
252257
"duration": 10,
253258
},
259+
{
260+
"id": "MBED_A26", "description": "AnalogIn potentiometer test",
261+
"source_dir": join(TEST_DIR, "mbed", "analog_pot"),
262+
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
263+
"peripherals": ["analog_pot"],
264+
"automated": True,
265+
"duration": 10,
266+
},
254267
{
255268
"id": "MBED_BLINKY", "description": "Blinky",
256269
"source_dir": join(TEST_DIR, "mbed", "blinky"),

0 commit comments

Comments
 (0)