diff options
| author | Derek Hageman <[email protected]> | 2023-07-25 15:54:33 -0600 |
|---|---|---|
| committer | Derek Hageman <[email protected]> | 2023-07-28 16:50:54 -0600 |
| commit | 7ed9e29326e42bf286b4f7c5883ef216cfb21531 (patch) | |
| tree | 7df710710db22c9ba77c6149be6a78aa5d7c7d23 /embassy-boot | |
| parent | e3cc0d168c1455d63df55f758cd875d78120f04d (diff) | |
rp: add async flash
Implement an async flash mode using the XIP background best effort
read interface. Only reads are actually async, write and erase remain
blocking.
Diffstat (limited to 'embassy-boot')
| -rw-r--r-- | embassy-boot/rp/src/lib.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/embassy-boot/rp/src/lib.rs b/embassy-boot/rp/src/lib.rs index 25329f9e9..35fc104ec 100644 --- a/embassy-boot/rp/src/lib.rs +++ b/embassy-boot/rp/src/lib.rs | |||
| @@ -6,7 +6,7 @@ mod fmt; | |||
| 6 | #[cfg(feature = "nightly")] | 6 | #[cfg(feature = "nightly")] |
| 7 | pub use embassy_boot::FirmwareUpdater; | 7 | pub use embassy_boot::FirmwareUpdater; |
| 8 | pub use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareUpdaterConfig, State}; | 8 | pub use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, BootLoaderConfig, FirmwareUpdaterConfig, State}; |
| 9 | use embassy_rp::flash::{Flash, ERASE_SIZE}; | 9 | use embassy_rp::flash::{Blocking, Flash, ERASE_SIZE}; |
| 10 | use embassy_rp::peripherals::{FLASH, WATCHDOG}; | 10 | use embassy_rp::peripherals::{FLASH, WATCHDOG}; |
| 11 | use embassy_rp::watchdog::Watchdog; | 11 | use embassy_rp::watchdog::Watchdog; |
| 12 | use embassy_time::Duration; | 12 | use embassy_time::Duration; |
| @@ -58,14 +58,14 @@ impl<ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, const BUFFER_SIZE: usize> | |||
| 58 | 58 | ||
| 59 | /// A flash implementation that will feed a watchdog when touching flash. | 59 | /// A flash implementation that will feed a watchdog when touching flash. |
| 60 | pub struct WatchdogFlash<'d, const SIZE: usize> { | 60 | pub struct WatchdogFlash<'d, const SIZE: usize> { |
| 61 | flash: Flash<'d, FLASH, SIZE>, | 61 | flash: Flash<'d, FLASH, Blocking, SIZE>, |
| 62 | watchdog: Watchdog, | 62 | watchdog: Watchdog, |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | impl<'d, const SIZE: usize> WatchdogFlash<'d, SIZE> { | 65 | impl<'d, const SIZE: usize> WatchdogFlash<'d, SIZE> { |
| 66 | /// Start a new watchdog with a given flash and watchdog peripheral and a timeout | 66 | /// Start a new watchdog with a given flash and watchdog peripheral and a timeout |
| 67 | pub fn start(flash: FLASH, watchdog: WATCHDOG, timeout: Duration) -> Self { | 67 | pub fn start(flash: FLASH, watchdog: WATCHDOG, timeout: Duration) -> Self { |
| 68 | let flash: Flash<'_, FLASH, SIZE> = Flash::new(flash); | 68 | let flash = Flash::<_, Blocking, SIZE>::new(flash); |
| 69 | let mut watchdog = Watchdog::new(watchdog); | 69 | let mut watchdog = Watchdog::new(watchdog); |
| 70 | watchdog.start(timeout); | 70 | watchdog.start(timeout); |
| 71 | Self { flash, watchdog } | 71 | Self { flash, watchdog } |
| @@ -73,12 +73,12 @@ impl<'d, const SIZE: usize> WatchdogFlash<'d, SIZE> { | |||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | impl<'d, const SIZE: usize> ErrorType for WatchdogFlash<'d, SIZE> { | 75 | impl<'d, const SIZE: usize> ErrorType for WatchdogFlash<'d, SIZE> { |
| 76 | type Error = <Flash<'d, FLASH, SIZE> as ErrorType>::Error; | 76 | type Error = <Flash<'d, FLASH, Blocking, SIZE> as ErrorType>::Error; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | impl<'d, const SIZE: usize> NorFlash for WatchdogFlash<'d, SIZE> { | 79 | impl<'d, const SIZE: usize> NorFlash for WatchdogFlash<'d, SIZE> { |
| 80 | const WRITE_SIZE: usize = <Flash<'d, FLASH, SIZE> as NorFlash>::WRITE_SIZE; | 80 | const WRITE_SIZE: usize = <Flash<'d, FLASH, Blocking, SIZE> as NorFlash>::WRITE_SIZE; |
| 81 | const ERASE_SIZE: usize = <Flash<'d, FLASH, SIZE> as NorFlash>::ERASE_SIZE; | 81 | const ERASE_SIZE: usize = <Flash<'d, FLASH, Blocking, SIZE> as NorFlash>::ERASE_SIZE; |
| 82 | 82 | ||
| 83 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { | 83 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { |
| 84 | self.watchdog.feed(); | 84 | self.watchdog.feed(); |
| @@ -91,7 +91,7 @@ impl<'d, const SIZE: usize> NorFlash for WatchdogFlash<'d, SIZE> { | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | impl<'d, const SIZE: usize> ReadNorFlash for WatchdogFlash<'d, SIZE> { | 93 | impl<'d, const SIZE: usize> ReadNorFlash for WatchdogFlash<'d, SIZE> { |
| 94 | const READ_SIZE: usize = <Flash<'d, FLASH, SIZE> as ReadNorFlash>::READ_SIZE; | 94 | const READ_SIZE: usize = <Flash<'d, FLASH, Blocking, SIZE> as ReadNorFlash>::READ_SIZE; |
| 95 | fn read(&mut self, offset: u32, data: &mut [u8]) -> Result<(), Self::Error> { | 95 | fn read(&mut self, offset: u32, data: &mut [u8]) -> Result<(), Self::Error> { |
| 96 | self.watchdog.feed(); | 96 | self.watchdog.feed(); |
| 97 | self.flash.read(offset, data) | 97 | self.flash.read(offset, data) |
