1
- //! Basic blinking LEDs example using mtime/mtimecmp registers for "sleep" in a loop.
2
- //! Blinks each led once and goes to the next one .
1
+ //! Basic blinking LED example using mtime/mtimecmp registers for "sleep" in a loop.
2
+ //! Blinks the blue LED of RED-V board .
3
3
4
4
#![ no_std]
5
5
#![ no_main]
6
6
7
7
use hifive1:: {
8
8
clock,
9
- hal:: { e310x :: CLINT , prelude:: * , DeviceResources } ,
10
- pin, sprintln, Led ,
9
+ hal:: { prelude:: * , DeviceResources } ,
10
+ pin, sprintln, stdout , Led ,
11
11
} ;
12
12
extern crate panic_halt;
13
13
14
14
#[ riscv_rt:: entry]
15
15
fn main ( ) -> ! {
16
16
let dr = DeviceResources :: take ( ) . unwrap ( ) ;
17
+ let cp = dr. core_peripherals ;
17
18
let p = dr. peripherals ;
18
19
let pins = dr. pins ;
19
20
20
21
// Configure clocks
21
22
let clocks = clock:: configure ( p. PRCI , p. AONCLK , 320 . mhz ( ) . into ( ) ) ;
22
23
23
24
// Configure UART for stdout
24
- hifive1 :: stdout:: configure (
25
+ stdout:: configure (
25
26
p. UART0 ,
26
27
pin ! ( pins, uart0_tx) ,
27
28
pin ! ( pins, uart0_rx) ,
@@ -33,13 +34,13 @@ fn main() -> ! {
33
34
let pin = pin ! ( pins, led_blue) ;
34
35
let mut led = pin. into_inverted_output ( ) ;
35
36
36
- // Get the sleep struct from CLINT
37
- let mut sleep = CLINT :: delay ( ) ;
37
+ // Get the MTIMER peripheral from CLINT
38
+ let mut mtimer = cp . clint . mtimer ( ) ;
38
39
39
40
const STEP : u32 = 1000 ; // 1s
40
41
loop {
41
42
Led :: toggle ( & mut led) ;
42
43
sprintln ! ( "LED toggled. New state: {}" , led. is_on( ) ) ;
43
- sleep . delay_ms ( STEP ) ;
44
+ mtimer . delay_ms ( STEP ) ;
44
45
}
45
46
}
0 commit comments