88#![ no_main]
99
1010use panic_semihosting as _;
11- use stm32f4xx_hal as hal;
11+ use stm32f4xx_hal:: { self as hal, rcc :: Config } ;
1212
1313use crate :: hal:: {
1414 gpio:: { Edge , Input , PA0 } ,
1515 interrupt, pac,
1616 prelude:: * ,
17- rcc:: { Clocks , Rcc } ,
17+ rcc:: Rcc ,
1818 spi:: { Mode , Phase , Polarity , Spi } ,
1919 timer:: { CounterUs , Event , FTimer , Flag , Timer } ,
2020} ;
@@ -84,14 +84,12 @@ fn main() -> ! {
8484 let cp = cortex_m:: peripheral:: Peripherals :: take ( ) . unwrap ( ) ;
8585 dp. RCC . apb2enr ( ) . write ( |w| w. syscfgen ( ) . enabled ( ) ) ;
8686
87- let rcc = dp. RCC . constrain ( ) ;
87+ let mut rcc = setup_clocks ( dp. RCC ) ;
8888
89- let clocks = setup_clocks ( rcc) ;
89+ let mut syscfg = dp . SYSCFG . constrain ( & mut rcc) ;
9090
91- let mut syscfg = dp. SYSCFG . constrain ( ) ;
92-
93- let gpioa = dp. GPIOA . split ( ) ;
94- let gpioe = dp. GPIOE . split ( ) ;
91+ let gpioa = dp. GPIOA . split ( & mut rcc) ;
92+ let gpioe = dp. GPIOE . split ( & mut rcc) ;
9593
9694 let mut board_btn = gpioa. pa0 . into_pull_down_input ( ) ;
9795 board_btn. make_interrupt_source ( & mut syscfg) ;
@@ -117,17 +115,17 @@ fn main() -> ! {
117115 phase : Phase :: CaptureOnFirstTransition ,
118116 } ,
119117 2000 . kHz ( ) ,
120- & clocks ,
118+ & mut rcc ,
121119 ) ;
122120
123121 // Set up the LEDs. On the stm32f429i-disco they are connected to pin PG13 and PG14.
124- let gpiog = dp. GPIOG . split ( ) ;
122+ let gpiog = dp. GPIOG . split ( & mut rcc ) ;
125123 let mut led3 = gpiog. pg13 . into_push_pull_output ( ) ;
126124 let mut led4 = gpiog. pg14 . into_push_pull_output ( ) ;
127125
128126 let dc = gpioe. pe3 . into_push_pull_output ( ) ;
129127 let mut ss = gpioe. pe4 . into_push_pull_output ( ) ;
130- let mut delay = Timer :: syst ( cp. SYST , & clocks) . delay ( ) ;
128+ let mut delay = Timer :: syst ( cp. SYST , & rcc . clocks ) . delay ( ) ;
131129
132130 ss. set_high ( ) ;
133131 delay. delay_ms ( 100 ) ;
@@ -142,7 +140,7 @@ fn main() -> ! {
142140 disp. flush ( ) . unwrap ( ) ;
143141
144142 // Create a 1ms periodic interrupt from TIM2
145- let mut timer = FTimer :: new ( dp. TIM2 , & clocks ) . counter ( ) ;
143+ let mut timer = FTimer :: new ( dp. TIM2 , & mut rcc ) . counter ( ) ;
146144 timer. start ( 1 . secs ( ) ) . unwrap ( ) ;
147145 timer. listen ( Event :: Update ) ;
148146
@@ -223,13 +221,14 @@ fn main() -> ! {
223221 }
224222}
225223
226- fn setup_clocks ( rcc : Rcc ) -> Clocks {
227- rcc. cfgr
228- . hclk ( 180 . MHz ( ) )
229- . sysclk ( 180 . MHz ( ) )
230- . pclk1 ( 45 . MHz ( ) )
231- . pclk2 ( 90 . MHz ( ) )
232- . freeze ( )
224+ fn setup_clocks ( rcc : pac:: RCC ) -> Rcc {
225+ rcc. freeze (
226+ Config :: hsi ( )
227+ . hclk ( 180 . MHz ( ) )
228+ . sysclk ( 180 . MHz ( ) )
229+ . pclk1 ( 45 . MHz ( ) )
230+ . pclk2 ( 90 . MHz ( ) ) ,
231+ )
233232}
234233
235234#[ interrupt]
0 commit comments