1
1
// This example is to test the SPI without any external devices.
2
2
// It puts "Hello world!" on the mosi-line and logs whatever is received on the miso-line to the info level.
3
3
// 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
4
6
5
7
#![ no_main]
6
8
#![ no_std]
7
9
8
10
use crate :: hal:: {
9
- delay:: DelayFromCountDownTimer ,
10
11
prelude:: * ,
11
12
pwr:: PwrExt ,
12
13
rcc:: Config ,
13
14
spi,
14
15
stm32:: Peripherals ,
15
- time:: { ExtU32 , RateExtU32 } ,
16
- timer:: Timer ,
16
+ time:: RateExtU32 ,
17
17
} ;
18
18
19
19
use cortex_m_rt:: entry;
@@ -32,19 +32,22 @@ fn main() -> ! {
32
32
let dp = Peripherals :: take ( ) . unwrap ( ) ;
33
33
let rcc = dp. RCC . constrain ( ) ;
34
34
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
+ ) ;
38
39
39
40
// let gpioa = dp.GPIOA.split(&mut rcc);
40
41
let gpioa = dp. GPIOA . split ( & mut rcc) ;
41
42
let sclk = gpioa. pa5 . into_alternate ( ) ;
42
43
let miso = gpioa. pa6 . into_alternate ( ) ;
43
44
let mosi = gpioa. pa7 . into_alternate ( ) ;
44
45
46
+ // 1/8 SPI/SysClk ratio seems to be the upper limit for continuous transmission one bit at a
47
+ // time
45
48
let mut spi = dp
46
49
. 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) ;
48
51
let mut cs = gpioa. pa8 . into_push_pull_output ( ) ;
49
52
cs. set_high ( ) . unwrap ( ) ;
50
53
@@ -57,14 +60,11 @@ fn main() -> ! {
57
60
spi. flush ( ) . unwrap ( ) ;
58
61
cs. set_high ( ) . unwrap ( ) ;
59
62
60
- info ! ( "Received {:?}" , core:: str :: from_utf8( received) . ok( ) ) ;
61
- delay_tim2. delay_ms ( 10_u16 ) ;
62
-
63
63
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 ( ) ;
65
65
cs. set_high ( ) . unwrap ( ) ;
66
+ info ! ( "Received {:?}" , core:: str :: from_utf8( received) . ok( ) ) ;
66
67
67
- // info!("{:?}", core::str::from_utf8(received).ok());
68
68
loop {
69
69
cortex_m:: asm:: nop ( ) ;
70
70
}
0 commit comments