aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias <[email protected]>2023-04-18 13:48:37 +0200
committerMathias <[email protected]>2023-04-18 13:48:37 +0200
commit1c68c62ebdbfdad0ad0a9cc8d7718baf6a3c94e8 (patch)
treed9a2af386bf3890a07c8ceb912237fb56e5af32d
parent46227bec1e948ea89de7d4e8a8dc98df5d7a25f0 (diff)
Implement embedded-storage traits for full flash struct
-rw-r--r--embassy-stm32/src/flash/common.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs
index 1189e447e..95fe26126 100644
--- a/embassy-stm32/src/flash/common.rs
+++ b/embassy-stm32/src/flash/common.rs
@@ -162,6 +162,35 @@ impl FlashRegion {
162 } 162 }
163} 163}
164 164
165impl embedded_storage::nor_flash::ErrorType for Flash<'_> {
166 type Error = Error;
167}
168
169impl embedded_storage::nor_flash::ReadNorFlash for Flash<'_> {
170 const READ_SIZE: usize = 1;
171
172 fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
173 self.blocking_read(offset, bytes)
174 }
175
176 fn capacity(&self) -> usize {
177 FLASH_SIZE
178 }
179}
180
181impl embedded_storage::nor_flash::NorFlash for Flash<'_> {
182 const WRITE_SIZE: usize = 8;
183 const ERASE_SIZE: usize = 2048;
184
185 fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
186 self.blocking_write(offset, bytes)
187 }
188
189 fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
190 self.blocking_erase(from, to)
191 }
192}
193
165foreach_flash_region! { 194foreach_flash_region! {
166 ($type_name:ident, $write_size:literal, $erase_size:literal) => { 195 ($type_name:ident, $write_size:literal, $erase_size:literal) => {
167 impl crate::_generated::flash_regions::$type_name<'_> { 196 impl crate::_generated::flash_regions::$type_name<'_> {