Skip to content

Commit b2bfad7

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

File tree

3 files changed

+13
-57
lines changed

3 files changed

+13
-57
lines changed

Cargo.toml

Lines changed: 1 addition & 4 deletions
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

@@ -17,9 +17,6 @@ name = "flash-algo"
1717
test = false
1818
bench = false
1919

20-
[features]
21-
device_description = []
22-
2320
[profile.dev]
2421
codegen-units = 1
2522
debug = 2

link.x

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ SECTIONS {
4545
. = ALIGN(4);
4646
}
4747

48-
DevDscr : {
49-
KEEP(*(.DevDscr))
50-
KEEP(*(.DevDscr.*))
51-
52-
. = ALIGN(4);
48+
/* Description of the flash algorithm */
49+
DeviceData . : {
50+
/* The device data content is only for external tools,
51+
* and usually not referenced by the code.
52+
*
53+
* The KEEP statement ensures it's not removed by accident.
54+
*/
55+
KEEP(*(DeviceData))
5356
}
5457

5558
/DISCARD/ : {

src/main.rs

Lines changed: 4 additions & 48 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,54 +156,6 @@ 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-
}
171-
172-
#[cfg(feature = "device_description")]
173-
#[no_mangle]
174-
#[link_section = ".PrgData"]
175-
pub static dummy: u32 = 0;
176-
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-
};
203159

204160
impl FlashAlgorithm for RP2Algo {
205161
fn new(_address: u32, _clock: u32, _function: Function) -> Result<Self, ErrorCode> {

0 commit comments

Comments
 (0)