Skip to content

Commit 17b9b33

Browse files
committed
inline assembly for flash
1 parent 0901b55 commit 17b9b33

File tree

7 files changed

+51
-93
lines changed

7 files changed

+51
-93
lines changed

.travis.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
9+
- Use inline assembly instead of binary blobs for flash
910

1011
## [v0.12.0] - 2023-03-28
1112
- Update e310x-hal to v0.11 with new svd2rust generated code

assemble.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

bin/flash.a

-2.17 KB
Binary file not shown.

build.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,4 @@ fn main() {
4444

4545
fs::copy("hifive1-link.x", out_dir.join("hifive1-link.x")).unwrap();
4646
println!("cargo:rerun-if-changed=hifive1-link.x");
47-
48-
// Copy library with flash setup code
49-
let name = env::var("CARGO_PKG_NAME").unwrap();
50-
fs::copy("bin/flash.a", out_dir.join(format!("lib{}.a", name))).unwrap();
51-
println!("cargo:rustc-link-lib=static={}", name);
52-
println!("cargo:rerun-if-changed=bin/flash.a");
5347
}

flash.S

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/flash.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,56 @@
33
use e310x_hal::clock::Clocks;
44
use e310x_hal::e310x::QSPI0;
55

6+
#[cfg(target_arch = "riscv32")]
7+
core::arch::global_asm!(
8+
r#"
9+
.cfi_sections .debug_frame
10+
11+
.section .data._setup_is25lp
12+
.global _setup_is25lp
13+
.cfi_startproc
14+
_setup_is25lp:
15+
li a1, 0x10014000 // QSPI0 base address
16+
17+
// Disable mapped region
18+
sw zero,96(a1) // fctrl.en = 0
19+
20+
// Construct ffmt value for 4 dummy cycles
21+
li a2, 0x00BB1447
22+
23+
beqz a0, 2f
24+
25+
// We need to set 8 dummy cycles instead of 4.
26+
// Issue a "Set Read Parameters" command.
27+
28+
li a0,2
29+
sw a0,24(a1) // csmode = HOLD
30+
li a0,0xC0
31+
sw a0,72(a1) // txdata = 0xC0
32+
li a0,0xF0
33+
sw a0,72(a1) // txdata = 0xF0
34+
sw zero,24(a1) // csmode = AUTO
35+
36+
// Discard two response bytes
37+
1: lw a0,76(a1)
38+
bltz a0,1b
39+
1: lw a0,76(a1)
40+
bltz a0,1b
41+
42+
addi a2,a2,0x40 // ffmt: 4 -> 8 dummy cycles
43+
2:
44+
sw a2,100(a1) // Write ffmt
45+
46+
// Enable mapped region
47+
li a0, 1
48+
sw a0,96(a1) // fctrl.en = 1
49+
ret
50+
51+
.cfi_endproc
52+
.size _setup_is25lp, . - _setup_is25lp
53+
"#
54+
);
55+
656
/// Configure SPI Flash interface to maximum supported speed
757
#[inline(always)]
858
pub fn configure_spi_flash(qspi: &QSPI0, clocks: &Clocks) {

0 commit comments

Comments
 (0)