Skip to content
Open
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
31 changes: 17 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ default = ["ms"]
ms = []

[dependencies]
stm32wb-hal = { version = "0.1.1" }
nb = "0.1.1"
stm32wb-hal = { version = "0.1.14" }
nb = "1.0"
bluetooth-hci = "0.1"
bitflags = "1.0"
bbqueue = "0.4.8"
bitflags = "1.3"
bbqueue = "0.4"

[dependencies.embedded-hal]
version = "0.2.3"
Expand All @@ -32,18 +32,17 @@ default-features = false

# For examples
[dev-dependencies]
cortex-m = "0.6.2"
# Need explicit features here
stm32wb-hal = { version = "0.1.14" , features=["xG-package", "stm32-usbd"]}
cortex-m = "0.6.7"
stm32wb-pac = "0.2"
as-slice = "0.1"
bit_field = "0.10.0"
heapless = "0.5.3"
nb = "0.1"
cortex-m-rtfm = "0.5"
as-slice = "0.2"
bit_field = "0.10"
heapless = "0.7.5"
nb = "1.0"
cortex-m-rtic = "0.5"
panic-halt = "0.2.0"
panic-reset = "0.1.0"
panic-semihosting = "0.5.0"
cortex-m-semihosting = { version = "0.3.5", features = ["jlink-quirks"] }
cortex-m-rt = "0.6.6"
cortex-m-rt = "0.6.7"
usb-device = "0.2"
usbd-serial = "0.1.0"

Expand All @@ -55,3 +54,7 @@ codegen-units = 1
codegen-units = 1
debug = true
lto = true

[patch.crates-io]
# The Tiwalun demos required this, but we _probably_ don't unless we need those few attributes that were updated
bluetooth-hci = { git = "https://github.com/danielgallagher0/bluetooth-hci", branch = "master" }
27 changes: 14 additions & 13 deletions examples/eddystone_beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#![no_std]
#![allow(non_snake_case)]

extern crate panic_reset;
extern crate stm32wb_hal as hal;
use panic_halt as _;
use stm32wb_hal as hal;

use bbqueue::{consts::U514, BBBuffer, ConstBBBuffer};
use core::time::Duration;

use cortex_m_rt::exception;
use heapless::spsc::{MultiCore, Queue};
use heapless::spsc::{Queue};
use nb::block;
use rtfm::app;
use rtic::app;

use hal::{
flash::FlashExt,
Expand Down Expand Up @@ -48,21 +49,20 @@ use stm32wb55::{
};

pub type HciCommandsQueue =
Queue<fn(&mut RadioCoprocessor<'static>, &BleContext), heapless::consts::U32, u8, MultiCore>;
// Needs to hold two packets, at least 257 bytes for biggest possible HCI BLE event + header
Queue<fn(&mut RadioCoprocessor<'static, U514>, &BleContext), 32>;

// Setup Eddystone beacon to advertise this URL:
// https://www.rust-lang.org
const EDDYSTONE_URL_PREFIX: EddystoneUrlScheme = EddystoneUrlScheme::Https;
const EDDYSTONE_URL: &[u8] = b"www.rust-lang.com";
const EDDYSTONE_URL_PREFIX: EddystoneUrlScheme = EddystoneUrlScheme::HttpsWww;
const EDDYSTONE_URL: &[u8] = b"rust-lang.com";

/// Advertisement interval in milliseconds.
const ADV_INTERVAL_MS: u64 = 250;

/// TX power at 0 m range. Used for range approximation.
const CALIBRATED_TX_POWER_AT_0_M: u8 = -22_i8 as u8;

// Need to be at least 257 bytes to hold biggest possible HCI BLE event + header
const BLE_DATA_BUF_SIZE: usize = 257 * 2;
const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7;

#[derive(Debug, Default)]
Expand All @@ -75,14 +75,13 @@ pub struct BleContext {
#[app(device = stm32wb_hal::pac, peripherals = true)]
const APP: () = {
struct Resources {
rc: RadioCoprocessor<'static>,
rc: RadioCoprocessor<'static, U514>,
hci_commands_queue: HciCommandsQueue,
ble_context: BleContext,
}

#[init]
fn init(cx: init::Context) -> init::LateResources {
static mut BLE_DATA_BUF: [u8; BLE_DATA_BUF_SIZE] = [0u8; BLE_DATA_BUF_SIZE];

let dp = cx.device;
let mut rcc = dp.RCC.constrain();
Expand Down Expand Up @@ -141,11 +140,13 @@ const APP: () = {
ll_only: 0,
hw_version: 0,
};
let rc = RadioCoprocessor::new(&mut BLE_DATA_BUF[..], mbox, ipcc, config);
static BB: BBBuffer<U514> = BBBuffer(ConstBBBuffer::new());
let (producer, consumer) = BB.try_split().unwrap();
let rc = RadioCoprocessor::new(producer, consumer, mbox, ipcc, config);

init::LateResources {
rc,
hci_commands_queue: HciCommandsQueue::u8(),
hci_commands_queue: HciCommandsQueue::new(),
ble_context: BleContext::default(),
}
}
Expand Down
33 changes: 15 additions & 18 deletions examples/ibeacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#![no_std]
#![allow(non_snake_case)]

extern crate panic_reset;
extern crate stm32wb_hal as hal;
use panic_halt as _;
use stm32wb_hal as hal;

use bbqueue::{consts::U514, BBBuffer, ConstBBBuffer};
use core::time::Duration;

use cortex_m_rt::exception;
use heapless::spsc::{MultiCore, Queue};
use heapless::spsc::Queue;
use nb::block;
use rtfm::app;
use rtic::app;

use hal::{
flash::FlashExt,
Expand Down Expand Up @@ -47,8 +48,7 @@ use stm32wb55::{
RadioCoprocessor,
};

pub type HciCommandsQueue =
Queue<fn(&mut RadioCoprocessor<'static>, &BleContext), heapless::consts::U32, u8, MultiCore>;
pub type HciCommandsQueue = Queue<fn(&mut RadioCoprocessor<'static, U514>, &BleContext), 32>;

// Apple iBeacon UUID specific for your application.
// You can use https://yupana-engineering.com/online-uuid-to-c-array-converter to convert
Expand All @@ -62,10 +62,7 @@ const ADV_INTERVAL_MS: u64 = 250;

/// TX power at 0 m range. Used for range approximation.
const CALIBRATED_TX_POWER_AT_0_M: u8 = 193;

// Need to be at least 257 bytes to hold biggest possible HCI BLE event + header
const BLE_DATA_BUF_SIZE: usize = 257 * 2;
const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7;
const BLE_GAP_DEVICE_NAME: &[u8] = b"BEACON";

#[derive(Debug, Default)]
pub struct BleContext {
Expand All @@ -77,15 +74,13 @@ pub struct BleContext {
#[app(device = stm32wb_hal::pac, peripherals = true)]
const APP: () = {
struct Resources {
rc: RadioCoprocessor<'static>,
rc: RadioCoprocessor<'static, U514>,
hci_commands_queue: HciCommandsQueue,
ble_context: BleContext,
}

#[init]
fn init(cx: init::Context) -> init::LateResources {
static mut BLE_DATA_BUF: [u8; BLE_DATA_BUF_SIZE] = [0u8; BLE_DATA_BUF_SIZE];

let dp = cx.device;
let mut rcc = dp.RCC.constrain();
rcc.set_stop_wakeup_clock(StopWakeupClock::HSI16);
Expand Down Expand Up @@ -143,11 +138,13 @@ const APP: () = {
ll_only: 0,
hw_version: 0,
};
let rc = RadioCoprocessor::new(&mut BLE_DATA_BUF[..], mbox, ipcc, config);
static BB: BBBuffer<U514> = BBBuffer(ConstBBBuffer::new());
let (producer, consumer) = BB.try_split().unwrap();
let rc = RadioCoprocessor::new(producer, consumer, mbox, ipcc, config);

init::LateResources {
rc,
hci_commands_queue: HciCommandsQueue::u8(),
hci_commands_queue: HciCommandsQueue::new(),
ble_context: BleContext::default(),
}
}
Expand Down Expand Up @@ -181,7 +178,7 @@ const APP: () = {
}
}

/// Sets up Eddystone BLE beacon service.
/// Sets up beacon service.
#[task(resources = [rc, hci_commands_queue], spawn = [exec_hci])]
fn setup(mut cx: setup::Context) {
cx.resources
Expand Down Expand Up @@ -330,7 +327,7 @@ fn init_gap_and_gatt(hci_commands_queue: &mut HciCommandsQueue) {
.ok();
hci_commands_queue
.enqueue(|rc, _| {
rc.init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH)
rc.init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME.len() as u8)
.expect("GAP init")
})
.ok();
Expand All @@ -340,7 +337,7 @@ fn init_gap_and_gatt(hci_commands_queue: &mut HciCommandsQueue) {
service_handle: cx.service_handle.expect("service handle to be set"),
characteristic_handle: cx.dev_name_handle.expect("dev name handle to be set"),
offset: 0,
value: b"BEACON",
value: BLE_GAP_DEVICE_NAME,
})
.unwrap()
})
Expand Down
12 changes: 6 additions & 6 deletions examples/transparent_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#![no_std]
#![allow(non_snake_case)]

extern crate panic_semihosting;
extern crate stm32wb_hal as hal;
use panic_halt as _;
use stm32wb_hal as hal;

use cortex_m_rt::exception;

use rtfm::app;
use rtic::app;

use hal::flash::FlashExt;
use hal::prelude::*;
Expand Down Expand Up @@ -233,14 +233,14 @@ const APP: () = {
if let Ok(cmd) = cmd {
match &cmd {
TlPacketType::AclData => {
cortex_m_semihosting::hprintln!("Got ACL DATA cmd").unwrap();
//cortex_m_semihosting::hprintln!("Got ACL DATA cmd").unwrap();

// Destination buffer: ble table, phci_acl_data_buffer, acldataserial field
todo!()
}

TlPacketType::SysCmd => {
cortex_m_semihosting::hprintln!("Got SYS cmd").unwrap();
//cortex_m_semihosting::hprintln!("Got SYS cmd").unwrap();

// Destination buffer: SYS table, pcmdbuffer, cmdserial field
todo!()
Expand All @@ -261,7 +261,7 @@ const APP: () = {
}
}
} else {
cortex_m_semihosting::hprintln!("Got unknown cmd 0x{:02x}", cmd_code).unwrap();
//cortex_m_semihosting::hprintln!("Got unknown cmd 0x{:02x}", cmd_code).unwrap();
}
}

Expand Down