Skip to content

Commit e6fee86

Browse files
authored
feat(nrf-ble): add ble support for nrf52 MCUs (ariel-os#1074)
2 parents 3912e83 + 939b3a9 commit e6fee86

File tree

14 files changed

+442
-31
lines changed

14 files changed

+442
-31
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ jobs:
7474
uses: dtolnay/rust-toolchain@master
7575
with:
7676
toolchain: ${{ steps.get_toolchain.outputs.toolchain }}
77-
# Required for checking ariel-os-esp
78-
targets: riscv32imac-unknown-none-elf
77+
# Required for checking ariel-os-esp and ariel-os-nrf
78+
targets: riscv32imac-unknown-none-elf, thumbv7em-none-eabi
7979
components: clippy, rustfmt
8080

8181
- name: rust cache
@@ -182,20 +182,23 @@ jobs:
182182
--
183183
--deny warnings
184184
185-
- run: echo 'RUSTFLAGS=--cfg context="nrf52840"' >> $GITHUB_ENV
185+
- run: echo 'RUSTFLAGS=--cfg context="nrf52840" --cfg context="nrf52"' >> $GITHUB_ENV
186186
- name: clippy for nRF
187187
uses: clechasseur/rs-clippy-check@v3
188188
with:
189189
args: |
190190
--verbose
191191
--locked
192192
--features "
193+
ble-central,
194+
ble-peripheral,
193195
embassy-nrf/nrf52840,
194196
external-interrupts,
195197
i2c,
196198
spi,
197199
"
198200
-p ariel-os-nrf
201+
--target=thumbv7em-none-eabi
199202
--
200203
--deny warnings
201204

Cargo.lock

Lines changed: 127 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ serde = { version = "1.0.197", default-features = false }
149149
static_cell = { version = "2.1.1", default-features = false }
150150
trouble-host = "0.1"
151151
bt-hci = { version = "0.2.0" }
152+
nrf-sdc = { git = "https://github.com/alexmoon/nrf-sdc.git", rev = "551a95436e999b4290b4a33383aa3d6747b63dd9" }
152153

153154
[workspace.lints.rust]
154155
# rustc lints are documented here: https://doc.rust-lang.org/rustc/lints/listing/index.html

laze-project.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,20 +250,26 @@ contexts:
250250
parent: nrf52
251251
selects:
252252
- cortex-m4f
253+
provides:
254+
- has_nrf_ble
253255
env:
254256
PROBE_RS_CHIP: nrf52832_xxAA
255257

256258
- name: nrf52833
257259
parent: nrf52
258260
selects:
259261
- cortex-m4f
262+
provides:
263+
- has_nrf_ble
260264
env:
261265
PROBE_RS_CHIP: nrf52833_xxAA
262266

263267
- name: nrf52840
264268
parent: nrf52
265269
selects:
266270
- cortex-m4f
271+
provides:
272+
- has_nrf_ble
267273
env:
268274
PROBE_RS_CHIP: nrf52840_xxAA
269275

@@ -1136,6 +1142,15 @@ modules:
11361142
RUSTFLAGS:
11371143
- --cfg capability=\"hw/ble\"
11381144

1145+
- name: has_nrf_ble
1146+
help: Marks an incompatibility of nrf devices with the interrupt executor (MPSL crashing)
1147+
selects:
1148+
- hwrng
1149+
provides:
1150+
- has_ble
1151+
conflicts:
1152+
- executor-interrupt
1153+
11391154
- name: ble-peripheral
11401155
help: Enables BLE peripheral functionality
11411156
selects:

src/ariel-os-embassy-common/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ embedded-hal = { workspace = true }
1919
embedded-hal-async = { workspace = true }
2020
const-sha1 = { version = "0.3.0", default-features = false }
2121
trouble-host = { workspace = true, optional = true }
22+
static_cell = { workspace = true, optional = true }
2223

2324
[features]
2425
## Enables GPIO interrupt support.
@@ -36,4 +37,4 @@ executor-thread = []
3637

3738
_test = ["i2c", "spi", "external-interrupts"]
3839

39-
ble = ["dep:trouble-host"]
40+
ble = ["dep:static_cell", "dep:trouble-host"]

src/ariel-os-embassy-common/src/ble.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
//! Common BLE types to be used across different HALs.
22
3+
use static_cell::StaticCell;
4+
use trouble_host::HostResources;
5+
6+
/// Maximum Transmission Unit (MTU) for BLE connections. 27 should work for all BLE versions.
7+
///
8+
/// Since bluetooth 4.2, this can be increased to 251 bytes.
9+
// TODO: add the ability to configure this value.
10+
pub const MTU: usize = 27;
11+
12+
/// Maximum number of concurrent connections to be handled by the BLE stack, minimum 1.
13+
pub const MAX_CONNS: usize = 1;
14+
/// Maximum number of concurrent channels to be handled by the BLE stack (not including GATT), minimum 1.
15+
pub const MAX_CHANNELS: usize = 1;
16+
17+
static HOST_RESOURCES: StaticCell<BleHostResources> = StaticCell::new();
18+
19+
/// Alias for the BLE host resources, setting the generic parameters to the constants for convenience.
20+
pub type BleHostResources = HostResources<MAX_CONNS, MAX_CHANNELS, MTU>;
21+
22+
/// Initializes the BLE host resources.
23+
///
24+
/// Call this function to get the `HostResources` instance that can be used to initialize the trouBLE stack.
25+
pub fn get_ble_host_resources() -> &'static mut BleHostResources {
26+
HOST_RESOURCES.init(HostResources::new())
27+
}
28+
329
/// Configuration for the BLE stack.
430
///
531
/// You can customize it using the `ble-config-override` feature.

src/ariel-os-embassy/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ wifi-esp = ["ariel-os-hal/wifi-esp", "net", "wifi"]
118118
eth = []
119119
eth-stm32 = ["ariel-os-hal/eth-stm32", "net", "eth"]
120120

121-
ble = ["ariel-os-hal/ble", "dep:trouble-host", "ariel-os-embassy-common/ble"]
121+
ble = [
122+
"ariel-os-hal/ble",
123+
"dep:trouble-host",
124+
"ariel-os-embassy-common/ble",
125+
# Some HALs need hwrng to initialize the BLE stack.
126+
"hwrng",
127+
]
122128
ble-peripheral = ["ble", "ariel-os-hal/ble-peripheral"]
123129
ble-central = ["ble", "ariel-os-hal/ble-central"]
124130

src/ariel-os-hal/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ usb = [
6767
"ariel-os-stm32/usb",
6868
]
6969

70-
ble = ["dep:bt-hci", "dep:embedded-io", "dep:trouble-host"]
71-
ble-peripheral = []
72-
ble-central = []
70+
ble = ["dep:bt-hci", "dep:embedded-io", "dep:trouble-host", "ariel-os-nrf/ble"]
71+
ble-peripheral = ["ariel-os-nrf/ble-peripheral"]
72+
ble-central = ["ariel-os-nrf/ble-central"]
7373

7474
hwrng = [
7575
"ariel-os-esp/hwrng",

0 commit comments

Comments
 (0)