Skip to content

Commit 0c20b08

Browse files
committed
Add feature to include FlashDevice device description
1 parent f8ca8ec commit 0c20b08

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ name = "flash-algo"
1717
test = false
1818
bench = false
1919

20+
[features]
21+
device_description = []
22+
2023
[profile.dev]
2124
codegen-units = 1
2225
debug = 2

link.x

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SECTIONS {
2525

2626
*(.sdata)
2727
*(.sdata.*)
28-
28+
2929
*(.bss)
3030
*(.bss.*)
3131

@@ -35,6 +35,17 @@ SECTIONS {
3535
. = ALIGN(4);
3636
}
3737

38+
/*
39+
* The device description is usually in DevDscr section, but adding it to
40+
* PrgData in order to satisfy tools that need this section.
41+
*/
42+
PrgData : {
43+
KEEP(*(.DevDscr))
44+
KEEP(*(.DevDscr.*))
45+
46+
. = ALIGN(4);
47+
}
48+
3849
/DISCARD/ : {
3950
/* Unused exception related info that only wastes space */
4051
*(.ARM.exidx);

src/main.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,49 @@ algorithm!(RP2Algo, {
152152
const BLOCK_SIZE: u32 = 65536;
153153
const SECTOR_SIZE: u32 = 4096;
154154
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 = ".DevDscr"]
175+
pub static FlashDevice: FlashDevice = FlashDevice {
176+
version: 1, // Version 1.01
177+
device_name: [
178+
0x52, 0x61, 0x73, 0x70, 0x65, 0x72, 0x72, 0x79, 0x20, 0x50, 0x69, 0x20, 0x52, 0x50, 0x32,
179+
0x30, 0x34, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
184+
0x00, 0x00, 0x00, 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,
187+
], // "Rasperry Pi RP2040"
188+
device_type: 5, // External SPI
189+
device_address: FLASH_BASE, // Default device start address
190+
size_device: 16 * 1024 * 1024, // Total Size of device (16 MiB)
191+
size_page: PAGE_SIZE, // Programming page size
192+
reserved: 0, // Must be zero
193+
val_empty: 0xFF, // Content of erase memory
194+
timeout_program: 500, // 500 ms
195+
timeout_erase: 5000, // 5 s
196+
sectors: [SECTOR_SIZE, FLASH_BASE, 0xFFFFFFFF, 0xFFFFFFFF],
197+
};
155198

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

0 commit comments

Comments
 (0)