1
+ //! This example shows off the using the SPI with the DMA engine
2
+ //!
3
+ //! For more docs, see https://docs.rs/stm32h7xx-hal/latest/stm32h5xx_hal/spi/index.html
4
+ //!
1
5
#![ deny( warnings) ]
2
6
#![ no_main]
3
7
#![ no_std]
@@ -11,7 +15,7 @@ use cortex_m_semihosting::debug;
11
15
use stm32h5xx_hal:: {
12
16
pac,
13
17
prelude:: * ,
14
- spi:: { self , Config as SpiConfig , Spi , dma :: DuplexDmaTransfer } ,
18
+ spi:: { self , dma :: DuplexDmaTransfer , Config as SpiConfig } ,
15
19
} ;
16
20
17
21
static mut SOURCE_BYTES : MaybeUninit < [ u8 ; 40 ] > = MaybeUninit :: uninit ( ) ;
@@ -45,13 +49,12 @@ fn main() -> ! {
45
49
46
50
let dp = pac:: Peripherals :: take ( ) . unwrap ( ) ;
47
51
48
- // Constrain and Freeze power
49
- log:: info!( "Setup PWR... " ) ;
52
+ // Select highest power mode for max possible clock frequency
50
53
let pwr = dp. PWR . constrain ( ) ;
51
- let pwrcfg = pwr. freeze ( ) ;
54
+ let pwrcfg = pwr. vos0 ( ) . freeze ( ) ;
52
55
53
- // Constrain and Freeze clock
54
- log :: info! ( "Setup RCC... " ) ;
56
+ // Configure system PLLs and clocks - choose a PLL1 output so 1MHz SPI clock can be exactly
57
+ // derived from it
55
58
let rcc = dp. RCC . constrain ( ) ;
56
59
let ccdr = rcc
57
60
. sys_ck ( 192 . MHz ( ) )
@@ -62,14 +65,16 @@ fn main() -> ! {
62
65
// GPIOB in the RCC register.
63
66
let gpiob = dp. GPIOB . split ( ccdr. peripheral . GPIOB ) ;
64
67
68
+ // This example requires that MISO is connected to MOSI via a jumper (pins 28 and 26 on CN10
69
+ // header on NUCLEO-H503RB)
65
70
let sck = gpiob. pb13 . into_alternate ( ) ;
66
71
let miso = gpiob. pb14 . into_alternate ( ) ;
67
72
let mosi = gpiob. pb15 . into_alternate ( ) ;
68
73
69
74
log:: info!( "stm32h5xx-hal example - SPI DMA" ) ;
70
75
71
76
// Initialise the SPI peripheral.
72
- let mut spi: Spi < _ , u8 > = dp. SPI2 . spi (
77
+ let mut spi = dp. SPI2 . spi (
73
78
( sck, miso, mosi) ,
74
79
SpiConfig :: new ( spi:: MODE_0 ) ,
75
80
1 . MHz ( ) ,
@@ -83,7 +88,8 @@ fn main() -> ! {
83
88
let tx_ch = channels. 0 ;
84
89
let rx_ch = channels. 1 ;
85
90
86
- let mut transfer = DuplexDmaTransfer :: new ( & mut spi, tx_ch, rx_ch, source_buf, dest_buf) ;
91
+ let mut transfer =
92
+ DuplexDmaTransfer :: new ( & mut spi, tx_ch, rx_ch, source_buf, dest_buf) ;
87
93
transfer. start ( ) . unwrap ( ) ;
88
94
transfer. wait_for_complete ( ) . unwrap ( ) ;
89
95
let ( _, _, source_buf, dest_buf) = transfer. free ( ) . unwrap ( ) ;
0 commit comments