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

Remapping flash traits to use base traits #42

Closed
wants to merge 1 commit into from

Conversation

ryan-summers
Copy link
Member

This PR reworks the NorFlash traits to use the Storage and ReadStorage base traits. That way, a library can accept a Storage or ReadStorage object without caring what the underlying storage type is.

I also added blanket &mut implementations for the Storage and ReadStorage traits.

@Dirbaio
Copy link
Contributor

Dirbaio commented Nov 16, 2023

NorFlash is more restrictive: write() has "must erase first, must only write once after erase" restrictions. Storage is less restrictive, it models "just an array of bytes" so write() can write whatever at any time without caring about erases.

If a lib expects a Storage, it won't respect NOR flash restrictions, so passing it a NorFlash won't work.

We already have RmwNorFlashStorage to convert from NorFlash to Storage. It translates Storage::write() operations into the more restrictive NorFlash::write/erase(), reading an entire sector, modifying, erasing and writing it back if needed.

@ryan-summers
Copy link
Member Author

This is a very good point that I hadn't considered.

RmwNotFlash seems like mostly what I want, but the downside is that the STM32 parts use a flash sector size of 128KB, so buffering a flash page on the stack blows up.

I wonder if we can consider another structure that doesn't preserve other contents in the page? But there's obvious risks to that as well.

@ryan-summers
Copy link
Member Author

Closing this for the reasons outlined above. We may want to yank the ErrorType trait out as well, but there's no need for that right now.

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

Successfully merging this pull request may close these issues.

2 participants