Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type of addresses: mix of u32 and usize. #27

Open
Dirbaio opened this issue Mar 30, 2022 · 5 comments
Open

Type of addresses: mix of u32 and usize. #27

Dirbaio opened this issue Mar 30, 2022 · 5 comments

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented Mar 30, 2022

The WRITE_SIZE, ERASE_SIZE etc are usize:

But the addresses are u32:

fn read<'a>(&'a mut self, offset: u32, bytes: &'a mut [u8]) -> Self::ReadFuture<'a>;

This makes doing math on addresses quite annoying: it needs a lot of casts. I sort of lean towards unifying this on usize, since slice lengths are usize and we can't change that.

@rmja
Copy link
Contributor

rmja commented Apr 4, 2023

Agreed that this should be unified, but to u32:) There are various 16 bit mcu's with more than 64k flash (e.g. MSP430F5529). They need to be able to address their entire internal flash.

EDIT: After some though I can see why the types are split. WRITE_SIZE is usize because it is guaranteed to represent some size that can always fit in memory, and that probably makes it more correct to have it stay as usize. That is not true for the flash addresses and ERASE_SIZE.

@rmja
Copy link
Contributor

rmja commented May 23, 2023

The one that should have its type changed is ReadNorFlash::capacity(). It should return u32.

@chrysn
Copy link

chrysn commented Oct 22, 2023

Would it make sense to have an associated size type? A hard u32 rules out applying this to large SD cards, but a hard u64 may be unacceptable overhead for other applications.

@Dirbaio
Copy link
Contributor Author

Dirbaio commented Oct 22, 2023

large SD cards are not NOR flash though, you don't have to first "erase" a sector to write. You can't write individual words in a sector either. They're best modeled as some "block device" trait where all you do is "read block", "write block". How common is it to have >4GB actual NOR flash devices?

@chrysn
Copy link

chrysn commented Oct 23, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants