Skip to content

Commit d8b90c0

Browse files
committed
Now builds on stable.
Tested working with probe-rs CLI. Slightly larger binary, but I can live with that for not having to use nightly rust.
1 parent 7bb71a0 commit d8b90c0

File tree

6 files changed

+22
-39
lines changed

6 files changed

+22
-39
lines changed

.cargo/config

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
[unstable]
2-
build-std = ["core"]
3-
build-std-features = ["panic_immediate_abort"]
4-
51
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
62

73
rustflags = [
84
"-C", "link-arg=--nmagic",
95
"-C", "link-arg=-Tlink.x",
106

117
# Code-size optimizations.
12-
"-Z", "trap-unreachable=no",
138
"-C", "inline-threshold=5",
149
"-C", "no-vectorize-loops",
1510
"-C", "force-frame-pointers=no",

.github/workflows/ci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ env:
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
16-
1715
steps:
1816
- uses: actions/checkout@v2
1917
- name: Install Dependencies
2018
run: |
21-
sudo apt update
22-
rustup component add rust-src
2319
cargo install cargo-binutils
24-
rustup component add llvm-tools-preview
2520
- name: Build
2621
run: |
2722
./build.sh

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,27 @@ It implements the CMSIS-Pack ABI, so it's compatible with any tools that use it,
55

66
## Dependencies
77

8-
Run the following requirements:
8+
Run the following to install the requirements:
9+
910
```bash
10-
cargo install cargo-binutils && rustup component add llvm-tools-preview rust-src
11+
cargo install cargo-binutils
1112
```
12-
## Building
1313

14-
Building requires nightly Rust.
14+
The `rust-toolchain` file will get you the targets and components you need.
15+
16+
## Building
1517

1618
Just run `build.sh`. It spits out the flash algo in the probe-rs YAML format:
1719

18-
flash-algo$ ./build.sh
20+
```console
21+
flash-algo$ ./build.sh
1922
instructions: sLUUIACIGUoBRguI...wRwAgcEc=
2023
pc_init: 0x00000000
2124
pc_uninit: 0x0000007c
2225
pc_program_page: 0x00000088
2326
pc_erase_sector: 0x00000084
2427
pc_erase_all: 0x00000080
28+
```
2529

2630
## Hacking
2731

@@ -30,7 +34,7 @@ the glue functions for a given struct implementing it. This is generic for all c
3034

3135
`main.rs` has the actual implementation for RP2040.
3236

33-
# License
37+
## License
3438

3539
This thingy is licensed under either of
3640

rust-toolchain

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
nightly
1+
[toolchain]
2+
channel = "stable"
3+
components = [ "llvm-tools" ]
4+
profile = "minimal"
5+
targets = ["thumbv6m-none-eabi"]

src/algo.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![macro_use]
22

3-
43
use core::arch::asm;
54
use core::num::NonZeroU32;
65

@@ -12,10 +11,6 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
1211
}
1312
}
1413

15-
pub const FUNCTION_ERASE: u32 = 1;
16-
pub const FUNCTION_PROGRAM: u32 = 2;
17-
pub const FUNCTION_VERIFY: u32 = 3;
18-
1914
pub type ErrorCode = NonZeroU32;
2015

2116
pub trait FlashAlgo: Sized + 'static {

src/main.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,19 @@
33

44
mod algo;
55

6-
use core::mem;
76
use core::mem::MaybeUninit;
87

98
use self::algo::*;
109

1110
fn find_func<T>(tag: [u8; 2]) -> T {
12-
let tag = u16::from_le_bytes(tag);
13-
11+
let tag = u16::from_le_bytes(tag) as u32;
12+
type RomTableLookupFn = unsafe extern "C" fn(table: *const u16, code: u32) -> usize;
1413
unsafe {
15-
let mut entry = *(0x00000014 as *const u16) as *const u16;
16-
loop {
17-
let entry_tag = entry.read();
18-
if entry_tag == 0 {
19-
panic!("Func not found");
20-
}
21-
entry = entry.add(1);
22-
let entry_addr = entry.read();
23-
entry = entry.add(1);
24-
if entry_tag == tag {
25-
return mem::transmute_copy(&(entry_addr as u32));
26-
}
27-
}
14+
let lookup_func = core::ptr::read(0x0000_0018 as *const u16) as usize;
15+
let lookup_func: RomTableLookupFn = core::mem::transmute(lookup_func);
16+
let table = core::ptr::read(0x0000_00014 as *const u16) as usize;
17+
let result = lookup_func(table as *const u16, tag);
18+
core::mem::transmute_copy(&result)
2819
}
2920
}
3021

@@ -58,7 +49,6 @@ algo!(RP2040Algo);
5849

5950
const BLOCK_SIZE: u32 = 65536;
6051
const SECTOR_SIZE: u32 = 4096;
61-
const PAGE_SIZE: u32 = 256;
6252
const BLOCK_ERASE_CMD: u8 = 0xd8;
6353
const FLASH_BASE: u32 = 0x1000_0000;
6454

0 commit comments

Comments
 (0)