Code Monkey home page Code Monkey logo

bluenrg's People

Contributors

antoinevg avatar barafael avatar berkus avatar danielgallagher0 avatar rasendubi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bluenrg's Issues

Error WouldBlock

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);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.