Merge #521
521: Stm32 SPI HIL test r=Dirbaio a=Dirbaio Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
f0c2c5caa0
@ -11,7 +11,7 @@ use embassy_stm32::Peripherals;
|
|||||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
#[embassy::main]
|
#[embassy::main(config = "config()")]
|
||||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
@ -34,12 +34,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
let _a = Output::new(&mut a, Level::Low, Speed::Low);
|
let _a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_low().unwrap());
|
assert!(b.is_low().unwrap());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let _a = Output::new(&mut a, Level::High, Speed::Low);
|
let _a = Output::new(&mut a, Level::High, Speed::Low);
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_high().unwrap());
|
assert!(b.is_high().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,41 +50,48 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
// no pull, the status is undefined
|
// no pull, the status is undefined
|
||||||
|
|
||||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_low().unwrap());
|
assert!(b.is_low().unwrap());
|
||||||
a.set_high().unwrap();
|
a.set_high().unwrap();
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_high().unwrap());
|
assert!(b.is_high().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test input pulldown
|
// Test input pulldown
|
||||||
{
|
{
|
||||||
let b = Input::new(&mut b, Pull::Down);
|
let b = Input::new(&mut b, Pull::Down);
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_low().unwrap());
|
assert!(b.is_low().unwrap());
|
||||||
|
|
||||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_low().unwrap());
|
assert!(b.is_low().unwrap());
|
||||||
a.set_high().unwrap();
|
a.set_high().unwrap();
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_high().unwrap());
|
assert!(b.is_high().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test input pullup
|
// Test input pullup
|
||||||
{
|
{
|
||||||
let b = Input::new(&mut b, Pull::Up);
|
let b = Input::new(&mut b, Pull::Up);
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_high().unwrap());
|
assert!(b.is_high().unwrap());
|
||||||
|
|
||||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_low().unwrap());
|
assert!(b.is_low().unwrap());
|
||||||
a.set_high().unwrap();
|
a.set_high().unwrap();
|
||||||
cortex_m::asm::delay(1000);
|
delay();
|
||||||
assert!(b.is_high().unwrap());
|
assert!(b.is_high().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Test OK");
|
info!("Test OK");
|
||||||
cortex_m::asm::bkpt();
|
cortex_m::asm::bkpt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn delay() {
|
||||||
|
#[cfg(feature = "stm32h755zi")]
|
||||||
|
cortex_m::asm::delay(10000);
|
||||||
|
#[cfg(not(feature = "stm32h755zi"))]
|
||||||
|
cortex_m::asm::delay(1000);
|
||||||
|
}
|
||||||
|
46
tests/stm32/src/bin/spi.rs
Normal file
46
tests/stm32/src/bin/spi.rs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
#[path = "../example_common.rs"]
|
||||||
|
mod example_common;
|
||||||
|
use defmt::assert_eq;
|
||||||
|
use embassy::executor::Spawner;
|
||||||
|
use embassy_stm32::dma::NoDma;
|
||||||
|
use embassy_stm32::spi::{self, Spi};
|
||||||
|
use embassy_stm32::time::Hertz;
|
||||||
|
use embassy_stm32::Peripherals;
|
||||||
|
use embedded_hal::blocking::spi::Transfer;
|
||||||
|
use example_common::*;
|
||||||
|
|
||||||
|
#[embassy::main(config = "config()")]
|
||||||
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||||
|
info!("Hello World!");
|
||||||
|
|
||||||
|
#[cfg(not(feature = "stm32h755zi"))]
|
||||||
|
let (sck, mosi, miso) = (p.PA5, p.PA7, p.PA6);
|
||||||
|
#[cfg(feature = "stm32h755zi")]
|
||||||
|
let (sck, mosi, miso) = (p.PA5, p.PB5, p.PA6);
|
||||||
|
|
||||||
|
let mut spi = Spi::new(
|
||||||
|
p.SPI1,
|
||||||
|
sck, // Arduino D13
|
||||||
|
mosi, // Arduino D11
|
||||||
|
miso, // Arduino D12
|
||||||
|
NoDma,
|
||||||
|
NoDma,
|
||||||
|
Hertz(1_000_000),
|
||||||
|
spi::Config::default(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE];
|
||||||
|
|
||||||
|
// Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor.
|
||||||
|
// so we should get the data we sent back.
|
||||||
|
let mut buf = data;
|
||||||
|
spi.transfer(&mut buf).unwrap();
|
||||||
|
assert_eq!(buf, data);
|
||||||
|
|
||||||
|
info!("Test OK");
|
||||||
|
cortex_m::asm::bkpt();
|
||||||
|
}
|
@ -10,7 +10,7 @@ use embassy::time::{Duration, Instant, Timer};
|
|||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
#[embassy::main]
|
#[embassy::main(config = "config()")]
|
||||||
async fn main(_spawner: Spawner, _p: Peripherals) {
|
async fn main(_spawner: Spawner, _p: Peripherals) {
|
||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#![macro_use]
|
#![macro_use]
|
||||||
|
|
||||||
use defmt_rtt as _; // global logger
|
use defmt_rtt as _;
|
||||||
|
#[allow(unused)]
|
||||||
|
use embassy_stm32::time::Hertz;
|
||||||
|
use embassy_stm32::Config;
|
||||||
use panic_probe as _;
|
use panic_probe as _;
|
||||||
|
|
||||||
pub use defmt::*;
|
pub use defmt::*;
|
||||||
@ -15,3 +18,16 @@ defmt::timestamp! {"{=u64}", {
|
|||||||
n as u64
|
n as u64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn config() -> Config {
|
||||||
|
#[allow(unused_mut)]
|
||||||
|
let mut config = Config::default();
|
||||||
|
|
||||||
|
#[cfg(feature = "stm32h755zi")]
|
||||||
|
{
|
||||||
|
config.rcc.sys_ck = Some(Hertz(400_000_000));
|
||||||
|
config.rcc.pll1.q_ck = Some(Hertz(100_000_000));
|
||||||
|
}
|
||||||
|
|
||||||
|
config
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user