Skip to content

Commit 23cc395

Browse files
committed
Update spi-hal-one example/benchmark
1 parent 2668fd7 commit 23cc395

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

examples/spi-hal-one.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// This example is to test the SPI without any external devices.
22
// It puts "Hello world!" on the mosi-line and logs whatever is received on the miso-line to the info level.
33
// The idea is that you should connect miso and mosi, so you will also receive "Hello world!".
4+
// It also transmits the data again using the old implementation, so those with a logic analyzer
5+
// can appreciate the effects of prefilling the TX FIFO
46

57
#![no_main]
68
#![no_std]
79

810
use crate::hal::{
9-
delay::DelayFromCountDownTimer,
1011
prelude::*,
1112
pwr::PwrExt,
1213
rcc::Config,
1314
spi,
1415
stm32::Peripherals,
15-
time::{ExtU32, RateExtU32},
16-
timer::Timer,
16+
time::RateExtU32,
1717
};
1818

1919
use cortex_m_rt::entry;
@@ -32,19 +32,22 @@ fn main() -> ! {
3232
let dp = Peripherals::take().unwrap();
3333
let rcc = dp.RCC.constrain();
3434
let pwr = dp.PWR.constrain().freeze();
35-
let mut rcc = rcc.freeze(Config::hsi(), pwr);
36-
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
37-
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
35+
let mut rcc = rcc.freeze(
36+
Config::hsi(),
37+
pwr
38+
);
3839

3940
// let gpioa = dp.GPIOA.split(&mut rcc);
4041
let gpioa = dp.GPIOA.split(&mut rcc);
4142
let sclk = gpioa.pa5.into_alternate();
4243
let miso = gpioa.pa6.into_alternate();
4344
let mosi = gpioa.pa7.into_alternate();
4445

46+
// 1/8 SPI/SysClk ratio seems to be the upper limit for continuous transmission one bit at a
47+
// time
4548
let mut spi = dp
4649
.SPI1
47-
.spi((sclk, miso, mosi), spi::MODE_0, 400.kHz(), &mut rcc);
50+
.spi((sclk, miso, mosi), spi::MODE_0, 2.MHz(), &mut rcc);
4851
let mut cs = gpioa.pa8.into_push_pull_output();
4952
cs.set_high().unwrap();
5053

@@ -57,14 +60,11 @@ fn main() -> ! {
5760
spi.flush().unwrap();
5861
cs.set_high().unwrap();
5962

60-
info!("Received {:?}", core::str::from_utf8(received).ok());
61-
delay_tim2.delay_ms(10_u16);
62-
6363
cs.set_low().unwrap();
64-
embedded_hal::blocking::spi::Write::write(&mut spi, received).unwrap();
64+
embedded_hal::blocking::spi::Write::write(&mut spi, MESSAGE).unwrap();
6565
cs.set_high().unwrap();
66+
info!("Received {:?}", core::str::from_utf8(received).ok());
6667

67-
// info!("{:?}", core::str::from_utf8(received).ok());
6868
loop {
6969
cortex_m::asm::nop();
7070
}

0 commit comments

Comments
 (0)