{"record":{"id":"fc9ab53f3d2fba03","repo":"embassy-rs/embassy","slug":"period-cannot-exceed-microseconds","errorCode":null,"errorMessage":"Period cannot exceed {} microseconds","messagePattern":"Period cannot exceed (.+?) microseconds","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-rp/src/watchdog.rs","lineNumber":91,"sourceCode":"    // Configure which hardware will be reset by the watchdog\n    // (everything except ROSC, XOSC)\n    fn configure_wdog_reset_triggers(&self) {\n        let psm = pac::PSM;\n        psm.wdsel().write_value(pac::psm::regs::Wdsel(\n            0x0001ffff & !(0x01 << 0usize) & !(0x01 << 1usize),\n        ));\n    }\n\n    /// Feed the watchdog timer\n    pub fn feed(&mut self, timeout: Duration) {\n        #[cfg(feature = \"rp2040\")]\n        const MAX_PERIOD: u32 = 0xFFFFFF / 2;\n        #[cfg(feature = \"_rp235x\")]\n        const MAX_PERIOD: u32 = 0xFFFFFF;\n\n        let timeout_us = timeout.as_micros();\n        if timeout_us > (MAX_PERIOD) as u64 {\n            panic!(\"Period cannot exceed {} microseconds\", MAX_PERIOD);\n        }\n        let timeout_us = timeout_us as u32;\n\n        // Due to a logic error, the watchdog decrements by 2 and\n        // the load value must be compensated; see RP2040-E1\n        // This errata is fixed in the RP235x\n        let load_value = if cfg!(feature = \"rp2040\") {\n            timeout_us * 2\n        } else {\n            timeout_us\n        };\n\n        self.load_counter(load_value)\n    }\n\n    /// Start the watchdog timer\n    pub fn start(&mut self, initial_timeout: Duration) {\n        self.enable(false);","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-rp/src/watchdog.rs#L73-L109","documentation":"The watchdog period is stored in a 24-bit load register, and on RP2040 the counter decrements by 2 due to errata RP2040-E1, halving the effective maximum. `Watchdog::start`/`feed` computes the microsecond timeout and panics if it exceeds MAX_PERIOD (0xFFFFFF/2 us on RP2040, 0xFFFFFF us on RP235x) because the requested period cannot be represented in the hardware register.","triggerScenarios":"Calling `watchdog.start(Duration)` with a timeout whose microsecond value exceeds 8,388,607 us (~8.39 s) on RP2040 or 16,777,215 us (~16.78 s) on RP235x.","commonSituations":"Configuring a 10-second or 30-second watchdog on RP2040 assuming the full 24-bit range; porting RP235x watchdog timings back to RP2040 where the errata halves the limit; computing the timeout from a config value without clamping.","solutions":["Clamp or validate the watchdog timeout to <= 8_388_607 microseconds (8.386 s) on RP2040 before calling start","Use a shorter watchdog period and feed it more frequently from a scheduled task","Implement a software watchdog chain: hardware watchdog at a short period fed by a task that checks a longer logical deadline","On RP235x you get the full 0xFFFFFF (~16.7 s) range since the errata is fixed"],"exampleFix":"// before\nwatchdog.start(Duration::from_secs(15)); // panics on RP2040\n// after\nconst MAX_PERIOD_US: u64 = 0xFFFFFF / 2;\nlet period = Duration::from_secs(15).min(Duration::from_micros(MAX_PERIOD_US));\nwatchdog.start(period); // ~8.39s max on RP2040","handlingStrategy":"validation","validationCode":"fn watchdog_period_ok(d: std::time::Duration) -> bool {\n    const MAX_PERIOD_US: u64 = 0xFFFFFF / 2; // RP2040; RP235x: 0xFFFFFF\n    d.as_micros() <= MAX_PERIOD_US\n}","typeGuard":null,"tryCatchPattern":"// panic in no_std: clamp before start\nwatchdog.start(d.min(Duration::from_micros(0xFFFFFF / 2)));","preventionTips":["Clamp watchdog timeouts to 8_388_607 us on RP2040 at the config boundary","Remember RP2040-E1 halves the effective range versus RP235x","Feed the watchdog from a task on a period well below the hardware limit"],"tags":["embedded","rp2040","watchdog","timeout"],"backgroundTag":"value-out-of-range","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}