embassy icon indicating copy to clipboard operation
embassy copied to clipboard

embassy_boot BlockingFirmwareUpdater::prepare_update() needs more time then possible with Watchdog (RP PicoW)

Open kolbma opened this issue 1 year ago • 2 comments

I'm stumbling at the moment over some strange stuff.
I've 2 RP PicoW boards.
While board A has no problem with the code:

watchdog.feed();
let writer = updater
    .prepare_update()
    .map_err(|err| {
        error!("flash-update: {:?}", err);
    })
    .unwrap();
debug!("flash-update: writer available");

It is far quicker then the 8 watchdog seconds. (~2 seconds)

The board B hangs in updater.prepare_update() and is reset by watchdog.
With disabled watchdog board B works, too. But it needs indeed about 10 seconds to continue.

Next to this there is no difference detectable for me when writing flash to the 2 boards with the usual tools.

kolbma avatar Nov 24 '24 13:11 kolbma

Is there any tracing I can somehow activate to see what it is doing in the 10 seconds exactly?

I've enabled defmt feature for everything I could find, but there is only the following:

TRACE DFU: 0xe6000 - 0x1c6000
└─ embassy_boot::firmware_updater::blocking::{impl#0}::from_linkerfile_blocking @ .cargo/git/checkouts/embassy-9312dcb0ed774b29/c9abff5/embassy-boot/src/firmware_updater/blocking.rs:68  
TRACE STATE: 0x6000 - 0x7000
└─ embassy_boot::firmware_updater::blocking::{impl#0}::from_linkerfile_blocking @.cargo/git/checkouts/embassy-9312dcb0ed774b29/c9abff5/embassy-boot/src/firmware_updater/blocking.rs:75  
INFO  flash-update: preparing
└─ rp2040w_santas_sleigh::flash_update::flash_update @ src/flash_update.rs:100 
TRACE Reading from 0x10006000 to 0x10006001
└─ embassy_rp::flash::{impl#4}::blocking_read @ .cargo/git/checkouts/embassy-9312dcb0ed774b29/c9abff5/embassy-rp/src/flash.rs:128 
TRACE Erasing from 0x100e6000 to 0x101c6000
└─ embassy_rp::flash::{impl#4}::blocking_erase @ .cargo/git/checkouts/embassy-9312dcb0ed774b29/c9abff5/embassy-rp/src/flash.rs:152 
DEBUG flash-update: writer available

With started watchdog it never comes to the last line, with commented out watchdog start I get the above.

kolbma avatar Nov 24 '24 17:11 kolbma

For async (which also just uses the blocking impl) the following fixes it (assuming you have watchdog feeding elsewhere:

diff --git a/embassy-rp/src/flash.rs b/embassy-rp/src/flash.rs
index 7cc8f0c1d..27b04f0b8 100644
--- a/embassy-rp/src/flash.rs
+++ b/embassy-rp/src/flash.rs
@@ -403,6 +403,7 @@ impl<'d, T: Instance, M: Mode, const FLASH_SIZE: usize> NorFlash for Flash<'d, T
     const ERASE_SIZE: usize = ERASE_SIZE;
 
     fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
+
         self.blocking_erase(from, to)
     }
 
@@ -433,7 +434,11 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> embedded_storage_async::nor_flash
     const ERASE_SIZE: usize = ERASE_SIZE;
 
     async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
-        self.blocking_erase(from, to)
+        for start in (from..to).step_by(4 * 8192) {
+            self.blocking_erase(start, (start + 4*8192).min(to))?;
+            embassy_futures::yield_now().await;
+        }
+        Ok(())
     }
 
     async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {

i404788 avatar Nov 20 '25 10:11 i404788