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:
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.
(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.
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.
This implements an interface to reading and writing to the internal flash memory. This implements the
NorFlash
traits from theembedded-storage
crate.The interface is inspired by the interfaces used in the
stm32f4xx-hal
and thestm32g0xx-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:0x08008001
) will lead to a panic due to the slice index being out of range.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.