danielgallagher0 / bluenrg Goto Github PK
View Code? Open in Web Editor NEWDevice crate for STMicro's BlueNRG-based Bluetooth RF modules
License: Apache License 2.0
Device crate for STMicro's BlueNRG-based Bluetooth RF modules
License: Apache License 2.0
Hey!
First of all thanks for the crate! Saving my life. (I would love to help btw)
So I found a post on 219design on some code using this lib and together with the tests here I'm piecing an example together.
Unfortunately I'm encountering the aforementioned error on running any command on the with_spi
block (more specifically on line 98). Latest one I tried was read_local_version_information
. If I introduce the block!
macro, it stays there forever :/
I'm usin a STN32L433RC-P
board with a X-Nucleo-BNRG2A1
shield.
Code dump (just in case):
It initializes a bunch of stuff and then blinks a LED on the main loop.
In the middle I'm trying to call the BT module
#![no_std]
#![no_main]
// use panic_halt as _;
use panic_semihosting as _;
use cortex_m;
use cortex_m_rt as rt;
use embedded_hal as ehal;
use stm32l4xx_hal as hal;
use cortex_m_semihosting::hprintln;
use ehal::spi::{Mode, Phase, Polarity};
use hal::{delay::Delay, prelude::*, stm32};
use rt::{entry, exception, ExceptionFrame};
use bluenrg::BlueNRG;
use bluetooth_hci::host::Hci;
// SPI mode
pub const MODE: Mode = Mode {
polarity: Polarity::IdleLow,
phase: Phase::CaptureOnFirstTransition,
};
#[entry]
fn main() -> ! {
hprintln!("start").unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32::Peripherals::take().unwrap();
// ???
dp.RCC.ahb2enr.write(|w| w.gpioaen().set_bit());
let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
let mut pwr = dp.PWR.constrain(&mut rcc.apb1r1);
let clocks = rcc.cfgr.freeze(&mut flash.acr, &mut pwr);
let mut gpioa = dp.GPIOA.split(&mut rcc.ahb2);
let mut gpiob = dp.GPIOB.split(&mut rcc.ahb2);
let mut led = gpiob
.pb13
.into_push_pull_output(&mut gpiob.moder, &mut gpiob.otyper);
let mut timer = Delay::new(cp.SYST, clocks);
//==========================================
// SPI
hprintln!("enable spi").unwrap();
let mut dc = gpiob
.pb1
.into_push_pull_output(&mut gpiob.moder, &mut gpiob.otyper);
let sck = gpioa.pa5.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
let miso = gpioa.pa6.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
let mosi = gpioa.pa7.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
dc.set_low().ok();
let mut spi = hal::spi::Spi::spi1(
dp.SPI1,
(sck, miso, mosi),
MODE,
1.mhz(),
clocks,
&mut rcc.apb2,
);
hprintln!("create spi interface").unwrap();
//==========================================
// BLUETOOTH
let data_ready = gpioa
.pa0
.into_pull_down_input(&mut gpioa.moder, &mut gpioa.pupdr);
let chip_select = gpioa
.pa1
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);
let reset_pin = gpioa
.pa8
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper);
let mut rx_buffer: [u8; 128] = [0; 128];
let mut bnrg = BlueNRG::new(&mut rx_buffer, chip_select, data_ready, reset_pin);
match bnrg.with_spi(&mut spi, |c| c.read_local_version_information()) {
Ok(r) => hprintln!("ok: {:#?}", r).unwrap(),
Err(e) => hprintln!("err: {:#?}", e).unwrap(),
};
hprintln!("create bt interface").unwrap();
//==========================================
let mut i = 0;
loop {
hprintln!("loop {}", i).unwrap();
i += 1;
timer.delay_ms(500 as u32);
led.set_high().ok();
timer.delay_ms(500 as u32);
led.set_low().ok();
}
}
#[exception]
fn HardFault(ef: &ExceptionFrame) -> ! {
panic!("{:#?}", ef);
}
as per https://www.st.com/en/wireless-connectivity/bluenrg-ms.html
Is there something even newer?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.