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

Implement interface to internal flash storage #172

Merged
merged 15 commits into from
Dec 12, 2023

Conversation

JanekGraff
Copy link
Contributor

This implements an interface to reading and writing to the internal flash memory. This implements the NorFlash traits from the embedded-storage crate.

The interface is inspired by the interfaces used in the stm32f4xx-hal and the stm32g0xx-hal.

The interface could definitely use some clean up and I'm open to suggestions on that matter. Especially the handling of writing to addresses not aligned to the native write size is something I'm not sure about. The stm32g0xx-hal has a different approach for this, but their approach has some problems in my opinion:

  1. Trying to write data that is shorter than the unaligned size (e.g. writing 3 Bytes to 0x08008001) will lead to a panic due to the slice index being out of range.
  2. (I'm not 100% sure about this) It seems like they will write unaligned data to an address that is in front of the address given by the user, which is not intuitive in my opinion.
  3. Passing an unaligned address to the write function will lead to some of the data in front of the address being overwritten.

The reasons above are why i choose the approach of returning an Error instead of trying to pad the data into native writes.

I also provided a basic example of how to use the flash interface.

The CI checks of this PR will fail until #170 (or an alternative solution) is merged.

Copy link
Member

@therealprof therealprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@therealprof therealprof merged commit 72b0bea into stm32-rs:master Dec 12, 2023
6 checks passed
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