{"record":{"id":"532bcf986932856c","repo":"embassy-rs/embassy","slug":"clocks-have-not-been-initialized","errorCode":null,"errorMessage":"Clocks have not been initialized","messagePattern":"Clocks have not been initialized","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"embassy-mcxa/src/rtc/mcxa2xx.rs","lineNumber":261,"sourceCode":"    info: &'static Info,\n    _freq: u32,\n    _wg: Option<WakeGuard>,\n}\n\nimpl<'a> Rtc<'a> {\n    /// Create a new instance of the real time clock.\n    pub fn new<T: Instance>(\n        _inst: Peri<'a, T>,\n        _irq: impl crate::interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'a,\n        config: Config,\n    ) -> Self {\n        let info = T::info();\n\n        // The RTC is NOT gated by the MRCC, but we DO need to make sure the 16k clock\n        // on the vsys domain is active\n        let clocks = with_clocks(|c| c.clk_16k_vsys.clone());\n        let clk = match clocks {\n            None => panic!(\"Clocks have not been initialized\"),\n            Some(None) => panic!(\"Clocks initialized, but clk_16k_vsys not active\"),\n            Some(Some(clk)) => clk,\n        };\n\n        let mut inst = Self {\n            info,\n            _inst: PhantomData,\n            _freq: clk.frequency,\n            _wg: WakeGuard::for_power(&clk.power),\n        };\n\n        inst.set_configuration(&config);\n\n        // Enable RTC interrupt\n        T::Interrupt::unpend();\n        unsafe { T::Interrupt::enable() };\n\n        inst","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-mcxa/src/rtc/mcxa2xx.rs#L243-L279","documentation":"The RTC driver needs the 16 kHz VSYS-domain clock to be registered with the embassy clock manager before `Rtc::new()` runs. `with_clocks` returns `None` when no clock configuration exists at all, meaning `clock_init`/clock setup was never called, so the driver panics rather than running against unknown timing.","triggerScenarios":"Constructing `Rtc::new(...)` before any clock initialization (no `embassy-mcxa::clocks::init`/`init_clocks` call, or it runs after RTC creation), e.g. calling RTC::new at the very top of main.","commonSituations":"Adding an RTC driver to an existing project whose clock setup was copied from a different chip variant; reordering main so RTC::new precedes clock init; forgetting clocks entirely in a minimal test program.","solutions":["Initialize clocks before creating the RTC (call the chip's clock init, e.g. `embassy_mcxa::clocks::init(...)` / `init_clocks`, as first step of main).","Ensure the clock config enables the 16k vsys clock (clk_16k_vsys) or you will hit the next panic ('clk_16k_vsys not active') instead.","Compare startup order with the board's embassy example (rtc example) to confirm init sequence."],"exampleFix":"// before\nfn main() {\n    let rtc = Rtc::new(p.RTC, Default::default()); // panics: clocks not initialized\n}\n// after\nfn main() {\n    embassy_mcxa::clocks::init(&config.clocks /* with clk_16k_vsys enabled */);\n    let rtc = Rtc::new(p.RTC, Default::default());\n}","handlingStrategy":"validation","validationCode":"// Ensure clock init runs before any peripheral construction:\nembassy_mcxa::clocks::init(clock_config); // first line of main\nlet rtc = Rtc::new(p.RTC, Default::default()); // after init","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Follow the board example's startup order: clocks first, then peripherals.","Never construct drivers before embassy clock init in main.","Add a comment/comment-check that RTC depends on clk_16k_vsys."],"tags":["embedded","rust","rtc","clocks","init-order"],"backgroundTag":"missing-required-config","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"}