Skip to content

Commit 5a0506e

Browse files
committed
Port functionality to updated flash-algorithm crate
1 parent c839f21 commit 5a0506e

File tree

4 files changed

+16
-44
lines changed

4 files changed

+16
-44
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = "0.1.0"
77

88
[dependencies]
99
cortex-m = "0.7.0"
10-
flash-algorithm = { version = "0.4.0", default-features = false, features = [
10+
flash-algorithm = { version = "0.5.0", default-features = false, features = [
1111
"panic-handler",
1212
] }
1313

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ else
99
BASE64_FLAGS="-w0"
1010
fi
1111

12+
# cargo build --release --features device_description
1213
cargo build --release
1314
ELF=target/thumbv6m-none-eabi/release/flash-algo
1415

link.x

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ SECTIONS {
5252
. = ALIGN(4);
5353
}
5454

55+
/* Description of the flash algorithm */
56+
DeviceData . : {
57+
/* The device data content is only for external tools,
58+
* and usually not referenced by the code.
59+
*
60+
* The KEEP statement ensures it's not removed by accident.
61+
*/
62+
KEEP(*(DeviceData))
63+
}
64+
5565
/DISCARD/ : {
5666
/* Unused exception related info that only wastes space */
5767
*(.ARM.exidx);

src/main.rs

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,14 @@ struct RP2Algo {
139139
}
140140

141141
algorithm!(RP2Algo, {
142+
device_name: "Raspberry Pi RP2",
143+
device_type: DeviceType::ExtSpi,
142144
flash_address: 0x1000_0000,
143145
flash_size: 0x0100_0000,
144146
page_size: 0x100,
145147
empty_value: 0xFF,
148+
program_time_out: 500, // 500 ms
149+
erase_time_out: 5000, // 5 s
146150
sectors: [{
147151
size: 0x1000,
148152
address: 0x10000000,
@@ -152,55 +156,12 @@ algorithm!(RP2Algo, {
152156
const BLOCK_SIZE: u32 = 65536;
153157
const SECTOR_SIZE: u32 = 4096;
154158
const BLOCK_ERASE_CMD: u8 = 0xd8;
155-
const FLASH_BASE: u32 = 0x1000_0000;
156-
157-
#[repr(C)]
158-
pub struct FlashDevice {
159-
pub version: u16,
160-
pub device_name: [u8; 128],
161-
pub device_type: u16,
162-
pub device_address: u32,
163-
pub size_device: u32,
164-
pub size_page: u32,
165-
pub reserved: u32,
166-
pub val_empty: u8,
167-
pub timeout_program: u32,
168-
pub timeout_erase: u32,
169-
pub sectors: [u32; 4],
170-
}
171159

172160
#[cfg(feature = "device_description")]
173161
#[no_mangle]
174162
#[link_section = ".PrgData"]
175163
pub static dummy: u32 = 0;
176164

177-
#[cfg(feature = "device_description")]
178-
#[no_mangle]
179-
#[link_section = ".DevDscr"]
180-
pub static FlashDevice: FlashDevice = FlashDevice {
181-
version: 1, // Version 1.01
182-
device_name: [
183-
0x52, 0x61, 0x73, 0x70, 0x65, 0x72, 0x72, 0x79, 0x20, 0x50, 0x69, 0x20, 0x52, 0x50, 0x32,
184-
0x30, 0x34, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
185-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
188-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
189-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
192-
], // "Rasperry Pi RP2040"
193-
device_type: 5, // External SPI
194-
device_address: FLASH_BASE, // Default device start address
195-
size_device: 16 * 1024 * 1024, // Total Size of device (16 MiB)
196-
size_page: PAGE_SIZE, // Programming page size
197-
reserved: 0, // Must be zero
198-
val_empty: 0xFF, // Content of erase memory
199-
timeout_program: 500, // 500 ms
200-
timeout_erase: 5000, // 5 s
201-
sectors: [SECTOR_SIZE, FLASH_BASE, 0xFFFFFFFF, 0xFFFFFFFF],
202-
};
203-
204165
impl FlashAlgorithm for RP2Algo {
205166
fn new(_address: u32, _clock: u32, _function: Function) -> Result<Self, ErrorCode> {
206167
let funcs = ROMFuncs::load()?;

0 commit comments

Comments
 (0)