File tree Expand file tree Collapse file tree 6 files changed +85
-0
lines changed Expand file tree Collapse file tree 6 files changed +85
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ set -euxo pipefail
4
+
5
+ # remove existing blobs because otherwise this will append object files to the old blobs
6
+ rm -f bin/* .a
7
+
8
+ riscv64-unknown-elf-gcc -ggdb3 -fdebug-prefix-map=$( pwd) =/hifive1 -c -mabi=ilp32 -march=rv32imac flash.S -o bin/flash.o
9
+ riscv64-unknown-elf-ar crs bin/flash.a bin/flash.o
10
+
11
+ rm bin/flash.o
Original file line number Diff line number Diff line change @@ -42,4 +42,10 @@ fn main() {
42
42
}
43
43
44
44
fs:: copy ( "hifive1-link.x" , out_dir. join ( "hifive1-link.x" ) ) . unwrap ( ) ;
45
+
46
+ // Copy library with flash setup code
47
+ let name = env:: var ( "CARGO_PKG_NAME" ) . unwrap ( ) ;
48
+ fs:: copy ( "bin/flash.a" , out_dir. join ( format ! ( "lib{}.a" , name) ) ) . unwrap ( ) ;
49
+ println ! ( "cargo:rustc-link-lib=static={}" , name) ;
50
+ println ! ( "cargo:rerun-if-changed=bin/flash.a" ) ;
45
51
}
Original file line number Diff line number Diff line change
1
+ .cfi_sections .debug_frame
2
+
3
+ .section .data ._setup_is25lp
4
+ .global _setup_is25lp
5
+ .cfi_startproc
6
+ _setup_is25lp:
7
+ li a1 , 0x10014000 // QSPI0 base address
8
+
9
+ // Disable mapped region
10
+ sw zero,96 (a1 ) // fctrl.en = 0
11
+
12
+ // Construct ffmt value for 4 dummy cycles
13
+ li a2 , 0x00BB1447
14
+
15
+ beqz a0 , 2f
16
+
17
+ // We need to set 8 dummy cycles instead of 4 .
18
+ // Issue a "Set Read Parameters" command.
19
+
20
+ li a0 ,2
21
+ sw a0 ,24 (a1 ) // csmode = HOLD
22
+ li a0 ,0xC0
23
+ sw a0 ,72 (a1 ) // txdata = 0xC0
24
+ li a0 ,0xF0
25
+ sw a0 ,72 (a1 ) // txdata = 0xF0
26
+ sw zero,24 (a1 ) // csmode = AUTO
27
+
28
+ // Discard two response bytes
29
+ 1 : lw a0 ,76 (a1 )
30
+ bltz a0 ,1b
31
+ 1 : lw a0 ,76 (a1 )
32
+ bltz a0 ,1b
33
+
34
+ addi a2 ,a2 ,0x40 // ffmt: 4 -> 8 dummy cycles
35
+ 2 :
36
+ sw a2 ,100 (a1 ) // Write ffmt
37
+
38
+ // Enable mapped region
39
+ li a0 , 1
40
+ sw a0 ,96 (a1 ) // fctrl.en = 1
41
+ ret
42
+
43
+
44
+ .cfi_endproc
45
+ .size _setup_is25lp, . - _setup_is25lp
Original file line number Diff line number Diff line change
1
+ //! On-board SPI Flash
2
+
3
+ use e310x_hal:: e310x:: QSPI0 ;
4
+ use e310x_hal:: clock:: Clocks ;
5
+
6
+ /// Configure SPI Flash interface to maximum supported speed
7
+ #[ inline( always) ]
8
+ pub fn configure_spi_flash ( qspi : & QSPI0 , clocks : & Clocks ) {
9
+ unsafe {
10
+ extern "C" {
11
+ fn _setup_is25lp ( dummy8 : bool ) ;
12
+ }
13
+
14
+ if clocks. coreclk ( ) . 0 <= 208_000_000 {
15
+ _setup_is25lp ( false )
16
+ } else {
17
+ _setup_is25lp ( true )
18
+ }
19
+ }
20
+ qspi. sckdiv . modify ( |_, w| unsafe { w. div ( ) . bits ( 0 ) } ) ;
21
+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ pub use e310x_hal as hal;
8
8
pub mod clock;
9
9
pub use clock:: configure as configure_clocks;
10
10
11
+ pub mod flash;
12
+
11
13
#[ cfg( any( feature = "board-hifive1" , feature = "board-hifive1-revb" ) ) ]
12
14
pub mod led;
13
15
#[ cfg( any( feature = "board-hifive1" , feature = "board-hifive1-revb" ) ) ]
You can’t perform that action at this time.
0 commit comments