Skip to content

Commit 28bf094

Browse files
Add an MbedOS target for the IF MCU on V2.2.
1 parent b9d10eb commit 28bf094

File tree

5 files changed

+160
-64
lines changed

5 files changed

+160
-64
lines changed

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
- [Features](#features)
66
- [Requirements](#requirements)
7-
- [Using Mbed](#using-mbed)
8-
- [Using Make](#using-make)
7+
- [Building This Project](#building-this-project)
98
- [Visual Studio Code](#visual-studio-code)
109
- [Using NFC](#using-nfc)
1110
- [License](#license)
@@ -23,21 +22,17 @@ This is a basic Mbed OS project for [micro:bit V2](https://microbit.org/new-micr
2322
- [Arm GCC](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
2423
- v7.3.1 is the oldest and v10.2.1 the last tested versions
2524
- Python 3
26-
- pip (version >= 10.0)
2725
- [Mbed CLI](https://github.com/ARMmbed/mbed-cli)
2826
- v1.10.2 is last tested version
27+
- Can be installed using one of the methods from the official documentation:
28+
https://os.mbed.com/docs/mbed-os/v6.15/build-tools/install-and-set-up.html
29+
- The installers are outdated and not recommended
30+
- If installed via pip a virtual environment is recommended
2931

3032

31-
## Using Mbed
33+
## Building This Project
3234

33-
### Install dependencies
34-
35-
Install mbed-cli using one of the methods from the official documentation:
36-
https://os.mbed.com/docs/mbed-os/v6.15/build-tools/install-and-set-up.html
37-
38-
The manual installation (in a Python 3 virtual environment) is the prefer method.
39-
40-
### Multiple targets
35+
### Available Targets
4136

4237
As there are multiple revisions of the nRF52 board we are using multiple mbed
4338
targets.
@@ -57,6 +52,12 @@ right side of the edge connector.
5752

5853
The branch `mbedos-softdevice` contains older targets.
5954

55+
#### Interface MCU
56+
57+
The micro:bit V2.2 contains an nRF52 microcontroller as the
58+
[Interface MCU](https://tech.microbit.org/software/daplink-interface/) and Mbed
59+
OS targets has been created
60+
6061
### Initialise
6162

6263
Note that for the `mbed target ...` line you should select the right target
@@ -71,10 +72,10 @@ mbed toolchain GCC_ARM
7172
mbed deploy
7273
```
7374

74-
If it fails to install some of the Python dependencies on the last command (
75-
`mbed deploy`) you can try again manually.
75+
If it fails to install some of the Python dependencies on the last command
76+
(`mbed deploy`) you can try to install them manually.
7677

77-
Run in the Python environment that has `mbed-cli` installed:
78+
Run this command in the Python environment that has `mbed-cli` installed:
7879

7980
```
8081
pip install -r mbed-os/requirements.txt
@@ -104,12 +105,13 @@ delete the mbed cache by removing `~/.mbed/`.
104105
### Mbed OS Version
105106

106107
This repo is currently configured Mbed OS to version
107-
[6.13.0]((https://github.com/ARMmbed/mbed-os/releases/tag/mbed-os-6.14.0)).
108+
[6.13.0](https://github.com/ARMmbed/mbed-os/releases/tag/mbed-os-6.13.0).
108109

109110
The branch `mbedos-softdevice` (commit
110111
`9e185e9388cdd634ac4cc38f92a0bbf73af9c5b3`) is configured to
111112
[v5.12.4](https://github.com/ARMmbed/mbed-os/releases/tag/mbed-os-5.12.4), as
112-
this is the last Mbed OS version to support the Nordic Soft Device (BLE stack).
113+
this is the last Mbed OS version to support the Nordic Soft Device BLE stack
114+
before it was switched to the Cordio BLE stack.
113115

114116
### Mbed OS RTOS
115117

TARGET_NRF52_MICROBIT_v1_43/PinNames.h

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,25 @@ typedef enum {
156156
P1_14 = p46,
157157
P1_15 = p47,
158158

159-
// Buttons A and B
159+
// Not connected
160+
NC = (int)0xFFFFFFFF,
161+
162+
// Buttons
163+
#if defined(TARGET_NRF52_MICROBIT_V2_IF_833)
164+
BUTTON1 = P1_9,
165+
BUTTON_RESET = BUTTON1,
166+
#elif defined(TARGET_NRF52_MICROBIT_V2_IF_820)
167+
BUTTON1 = P0_6,
168+
BUTTON_RESET = BUTTON1,
169+
#else
160170
BUTTON1 = P0_14,
161171
BUTTON2 = P0_23,
162172
BUTTONA = BUTTON1,
163173
BUTTONB = BUTTON2,
174+
#endif
164175

176+
// Target MCU only pins
177+
#if !defined(MICROBIT_IF)
165178
// LED matrix
166179
ROW_1 = P0_21,
167180
ROW_2 = P0_22,
@@ -179,63 +192,112 @@ typedef enum {
179192
RING1 = P0_3,
180193
RING2 = P0_4,
181194

182-
// GPIO
183-
GPIO1 = P0_10,
184-
GPIO2 = P0_9,
185-
GPIO3 = P1_2,
186-
GPIO4 = P0_12,
195+
// Free edge connector GPIOs
196+
GPIO1 = P0_10, // Edge connector pin 8
197+
GPIO2 = P0_9, // Edge connector pin 9
198+
GPIO3 = P1_2, // Edge connector pin 16
199+
GPIO4 = P0_12, // Edge connector pin 12
187200

188201
// Audio
189202
SPEAKER = P0_0,
190203
MIC = P0_5,
191204
RUN_MIC = P0_20,
205+
#endif
192206

193-
// Other micro:bit specific pins
207+
// Interface MCU only pins
208+
#if defined(TARGET_NRF52_MICROBIT_V2_IF_833)
209+
LED1 = P0_15,
210+
LED2 = P0_17,
211+
#elif defined(TARGET_NRF52_MICROBIT_V2_IF_820)
212+
LED1 = P0_14,
213+
LED2 = P0_15,
214+
#endif
215+
216+
// Other micro:bit specific pins common to Interface and Target
217+
#if defined(TARGET_NRF52_MICROBIT_V2_IF_833)
218+
COMBINED_SENSOR_INT = P0_9,
219+
#elif defined(TARGET_NRF52_MICROBIT_V2_IF_820)
220+
COMBINED_SENSOR_INT = P0_16,
221+
#else
194222
COMBINED_SENSOR_INT = P0_25,
223+
#endif
195224

196225
// UART
226+
#if defined(TARGET_NRF52_MICROBIT_V2_IF_833)
227+
// TODO: Add UART TX and RX pins
228+
RX_PIN_NUMBER = NC,
229+
TX_PIN_NUMBER = NC,
230+
// mBed interface Pins
231+
CONSOLE_TX = NC,
232+
CONSOLE_RX = NC,
233+
STDIO_UART_TX = NC,
234+
STDIO_UART_RX = NC,
235+
#elif defined(TARGET_NRF52_MICROBIT_V2_IF_820)
236+
// TODO: Add UART TX and RX pins
237+
RX_PIN_NUMBER = NC,
238+
TX_PIN_NUMBER = NC,
239+
// mBed interface Pins
240+
CONSOLE_TX = NC,
241+
CONSOLE_RX = NC,
242+
STDIO_UART_TX = NC,
243+
STDIO_UART_RX = NC,
244+
#else
197245
RX_PIN_NUMBER = P1_8,
198246
TX_PIN_NUMBER = P0_6,
199-
CTS_PIN_NUMBER = p7,
200-
RTS_PIN_NUMBER = p5,
201-
202247
// mBed interface Pins
203248
CONSOLE_TX = TX_PIN_NUMBER,
204249
CONSOLE_RX = RX_PIN_NUMBER,
205250
STDIO_UART_TX = TX_PIN_NUMBER,
206251
STDIO_UART_RX = RX_PIN_NUMBER,
252+
#endif
253+
254+
CTS_PIN_NUMBER = NC,
255+
RTS_PIN_NUMBER = NC,
256+
// mBed interface Pins
207257
STDIO_UART_CTS = CTS_PIN_NUMBER,
208258
STDIO_UART_RTS = RTS_PIN_NUMBER,
209259

260+
#if defined(MICROBIT_IF)
261+
SPI_PSELMOSI0 = NC,
262+
SPI_PSELMISO0 = NC,
263+
SPI_PSELSS0 = NC,
264+
SPI_PSELSCK0 = NC,
265+
#else
210266
SPI_PSELMOSI0 = P0_13,
211267
SPI_PSELMISO0 = P0_1,
212268
SPI_PSELSS0 = P1_2,
213269
SPI_PSELSCK0 = P0_17,
270+
#endif
214271

272+
#if defined(TARGET_NRF52_MICROBIT_V2_IF_833)
273+
// TODO: Include the internal I2C pins
274+
#elif defined(TARGET_NRF52_MICROBIT_V2_IF_820)
275+
// TODO: Include the internal I2C pins
276+
#else
277+
// Internal I2C
215278
I2C_SDA0 = P0_16,
216279
I2C_SCL0 = P0_8,
217280

281+
// External I2C at the edge connector
218282
I2C_SDA1 = P1_0,
219283
I2C_SCL1 = P0_26,
284+
#endif
220285

221286
/**** QSPI pins ****/
222-
QSPI1_IO0 = P0_20,
223-
QSPI1_IO1 = P0_21,
224-
QSPI1_IO2 = P0_22,
225-
QSPI1_IO3 = P0_23,
226-
QSPI1_SCK = P0_19,
227-
QSPI1_CSN = P0_17,
287+
QSPI1_IO0 = NC,
288+
QSPI1_IO1 = NC,
289+
QSPI1_IO2 = NC,
290+
QSPI1_IO3 = NC,
291+
QSPI1_SCK = NC,
292+
QSPI1_CSN = NC,
228293

229294
/**** QSPI FLASH pins ****/
230-
QSPI_FLASH1_IO0 = QSPI1_IO0,
231-
QSPI_FLASH1_IO1 = QSPI1_IO1,
232-
QSPI_FLASH1_IO2 = QSPI1_IO2,
233-
QSPI_FLASH1_IO3 = QSPI1_IO3,
234-
QSPI_FLASH1_SCK = QSPI1_SCK,
235-
QSPI_FLASH1_CSN = QSPI1_CSN,
236-
237-
// Not connected
238-
NC = (int)0xFFFFFFFF
295+
QSPI_FLASH1_IO0 = NC,
296+
QSPI_FLASH1_IO1 = NC,
297+
QSPI_FLASH1_IO2 = NC,
298+
QSPI_FLASH1_IO3 = NC,
299+
QSPI_FLASH1_SCK = NC,
300+
QSPI_FLASH1_CSN = NC,
239301
} PinName;
240302

241303
typedef enum {

custom_targets.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"NRF52_PAN_62",
4848
"NRF52_PAN_63",
4949
"NRF52_PAN_64",
50-
"CONFIG_NFCT_PINS_AS_GPIOS"
50+
"CONFIG_NFCT_PINS_AS_GPIOS",
51+
"MICROBIT_TARGET"
5152
],
5253
"device_has_remove": ["ITM"],
5354
"overrides": {
@@ -68,5 +69,24 @@
6869
},
6970
"NRF52_MICROBIT_v2": {
7071
"inherits": ["NRF52_MICROBIT_v1_43"]
72+
},
73+
"NRF52_MICROBIT_V2_IF_820": {
74+
"inherits": ["NRF52_MICROBIT_v1_43"],
75+
"core": "Cortex-M4",
76+
"extra_labels_remove": [
77+
],
78+
"macros_add": [
79+
"MICROBIT_IF"
80+
],
81+
"macros_remove": [
82+
"MICROBIT_TARGET"
83+
],
84+
"static_memory_defines": true,
85+
"mbed_app_start": "0x8000",
86+
"mbed_app_size": "0x17000",
87+
"mbed_ram_size": "0x8000"
88+
},
89+
"NRF52_MICROBIT_V2_IF_833": {
90+
"inherits": ["NRF52_MICROBIT_V2_IF_820"]
7191
}
7292
}

mbed_app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"NRF52_MICROBIT_v1_47": {
2121
},
2222
"NRF52_MICROBIT_v2": {
23+
},
24+
"NRF52_MICROBIT_V2_IF_820": {
25+
},
26+
"NRF52_MICROBIT_V2_IF_833": {
2327
}
2428
}
2529
}

source/main.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 Micro:bit Educational Foundation and contributors
2+
* Copyright 2020-2022 Micro:bit Educational Foundation and contributors
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,28 +16,35 @@
1616
*/
1717
#include "mbed.h"
1818

19-
DigitalOut rows[5] = {
20-
DigitalOut(ROW_1, 0),
21-
DigitalOut(ROW_2, 0),
22-
DigitalOut(ROW_3, 0),
23-
DigitalOut(ROW_4, 0),
24-
DigitalOut(ROW_5, 0)
25-
};
26-
DigitalOut cols[5] = {
27-
DigitalOut(COL_1, 1),
28-
DigitalOut(COL_2, 1),
29-
DigitalOut(COL_3, 1),
30-
DigitalOut(COL_4, 1),
31-
DigitalOut(COL_5, 1)
32-
};
33-
34-
#ifdef LED1
35-
DigitalOut led(LED1);
19+
#if defined(MICROBIT_TARGET)
20+
// Main micro:bit target has access to the LED matrix and on-board features
21+
DigitalOut rows[5] = {
22+
DigitalOut(ROW_1, 0),
23+
DigitalOut(ROW_2, 0),
24+
DigitalOut(ROW_3, 0),
25+
DigitalOut(ROW_4, 0),
26+
DigitalOut(ROW_5, 0)
27+
};
28+
DigitalOut cols[5] = {
29+
DigitalOut(COL_1, 1),
30+
DigitalOut(COL_2, 1),
31+
DigitalOut(COL_3, 1),
32+
DigitalOut(COL_4, 1),
33+
DigitalOut(COL_5, 1)
34+
};
35+
bool led1;
36+
bool led2;
3637
#else
37-
bool led;
38+
// The nRF52833 DK and micro:bit V2.2 IF MCU have access to direct LEDs
39+
bool rows[5];
40+
bool cols[5];
41+
DigitalOut led1(LED1, 0);
42+
DigitalOut led2(LED2, 1);
3843
#endif
3944

4045
int main(void) {
46+
// Infinite loop to blink the matrix LEDs if built for the target MCU or
47+
// to toggle the orange and red USB LEDs if built for the interface MCU
4148
while (true) {
4249
for (int i = 0; i < 5; i++) {
4350
rows[i] = 1;
@@ -50,10 +57,11 @@ int main(void) {
5057
if (prev_j < 0) prev_j = 4;
5158
cols[prev_j] = 1;
5259

60+
led1 = !led1;
61+
led2 = !led2;
62+
5363
ThisThread::sleep_for(250);
5464
//wait_us(250000);
55-
56-
led = !led;
5765
}
5866
}
5967
}

0 commit comments

Comments
 (0)