Skip to content

Commit

Permalink
spi_slave example
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Apr 20, 2023
1 parent 1178ec4 commit 5979572
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- Split USART and UART implementations
- Split SPI master and slave implementations [#609]
- Split USART and UART implementations [#608]
- Add `lapce` editor settings [#601]
- Use `enum`s for alternate peripheral pins [#594]
- Added missing U(S)ART DMA traits for HAL serial types [#593]
Expand All @@ -25,6 +26,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#599]: https://github.com/stm32-rs/stm32f4xx-hal/pull/599
[#601]: https://github.com/stm32-rs/stm32f4xx-hal/pull/601
[#603]: https://github.com/stm32-rs/stm32f4xx-hal/pull/603
[#608]: https://github.com/stm32-rs/stm32f4xx-hal/pull/608
[#609]: https://github.com/stm32-rs/stm32f4xx-hal/pull/609

## [v0.15.0] - 2023-03-13

Expand Down
50 changes: 50 additions & 0 deletions examples/spi_slave.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#![no_main]
#![no_std]

use panic_halt as _;

use crate::hal::spi::{Mode, Phase, Polarity};
use crate::hal::{pac, prelude::*};
use cortex_m::asm;
use cortex_m_rt::entry;
use stm32f4xx_hal as hal;

/// SPI mode
pub const MODE: Mode = Mode {
phase: Phase::CaptureOnFirstTransition,
polarity: Polarity::IdleLow,
};

#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();

let rcc = p.RCC.constrain();
let _clocks = rcc.cfgr.freeze();

let gpioa = p.GPIOA.split();

let sck = gpioa.pa5;
let miso = gpioa.pa6;
let mosi = gpioa.pa7;

// clock speed is determined by the master
let mut spi = p
.SPI1
.spi_slave((sck, miso, mosi, Some(gpioa.pa4.into())), MODE);
// alternativelly you could use software `chip select`
// let mut spi = SpiSlave::new(p.SPI1, (sck, miso, mosi, None), MODE);
// spi.set_internal_nss(false);

let mut data = [0x1];
// this will block until the master starts the clock
spi.transfer_in_place(&mut data).unwrap();

// when you reach this breakpoint you'll be able to inspect the variable `data` which contains the
// data sent by the master
asm::bkpt();

loop {
continue;
}
}
14 changes: 0 additions & 14 deletions src/gpio/alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,7 @@ pub mod spi1 {
],

<Nss> for [
#[cfg(any(
feature = "gpio-f410",
feature = "gpio-f411",
feature = "gpio-f412",
feature = "gpio-f413",
feature = "gpio-f446"
))]
PA4<5>,
#[cfg(any(
feature = "gpio-f410",
feature = "gpio-f411",
feature = "gpio-f412",
feature = "gpio-f413",
feature = "gpio-f446"
))]
PA15<5>,
],
}
Expand Down

0 comments on commit 5979572

Please sign in to comment.