Skip to content

Commit 3612f0d

Browse files
committed
Fix SPLL as well
1 parent 5542f73 commit 3612f0d

4 files changed

Lines changed: 74 additions & 21 deletions

File tree

embassy-mcxa/src/clocks/config.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ pub struct ClocksConfig {
133133
#[cfg(not(feature = "sosc-as-gpio"))]
134134
pub sosc: Option<SoscConfig>,
135135
/// SPLL
136-
#[cfg(feature = "mcxa2xx")]
137136
pub spll: Option<SpllConfig>,
138137
}
139138

@@ -294,7 +293,6 @@ pub enum MainClockSource {
294293
#[cfg(all(feature = "mcxa5xx", not(feature = "rosc-32k-as-gpio")))]
295294
RoscOsc32K,
296295
/// Clock derived from `pll1_clk`, via the internal PLL
297-
#[cfg(feature = "mcxa2xx")]
298296
SPll1,
299297
}
300298

@@ -352,6 +350,7 @@ pub enum SpllSource {
352350
/// Fast Internal Oscillator (45MHz)
353351
// NOTE: Figure 69 says "firc_45mhz"/"clk_45m", not "fro_hf_gated",
354352
// so this is is always 45MHz.
353+
#[cfg(feature = "mcxa2xx")]
355354
Firc,
356355
/// S Internal Oscillator (12M)
357356
Sirc,
@@ -673,7 +672,6 @@ impl Default for ClocksConfig {
673672
osc32k: None,
674673
#[cfg(not(feature = "sosc-as-gpio"))]
675674
sosc: None,
676-
#[cfg(feature = "mcxa2xx")]
677675
spll: None,
678676
}
679677
}

embassy-mcxa/src/clocks/mod.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ use periph_helpers::{PreEnableParts, SPConfHelper};
5050
use crate::chips::{ClockLimits, clock_limits};
5151
use crate::pac;
5252
use crate::pac::cmc::vals::CkctrlCkmode;
53-
use crate::pac::scg::vals::{Erefs, Range, Scs, SirccsrLk, Sircerr, Sircvld, SosccsrLk, Soscerr};
54-
#[cfg(feature = "mcxa2xx")]
5553
use crate::pac::scg::vals::{
56-
Fircacc, FircaccIe, FirccsrLk, Fircerr, FircerrIe, Fircsten, Fircvld, FreqSel, Source, SpllLock, SpllcsrLk,
57-
Spllerr, Spllsten, TrimUnlock,
54+
Erefs, Range, Scs, SirccsrLk, Sircerr, Sircvld, SosccsrLk, Soscerr, Source, SpllLock, SpllcsrLk, Spllerr, Spllsten,
55+
TrimUnlock,
5856
};
57+
#[cfg(feature = "mcxa2xx")]
58+
use crate::pac::scg::vals::{Fircacc, FircaccIe, FirccsrLk, Fircerr, FircerrIe, Fircsten, Fircvld, FreqSel};
5959
use crate::pac::spc::vals::{
6060
ActiveCfgBgmode, ActiveCfgCoreldoVddDs, ActiveCfgCoreldoVddLvl, LpCfgBgmode, LpCfgCoreldoVddLvl, Vsm,
6161
};
62-
use crate::pac::syscon::vals::{AhbclkdivUnstab, FrolfdivHalt, FrolfdivReset, FrolfdivUnstab};
63-
#[cfg(feature = "mcxa2xx")]
6462
use crate::pac::syscon::vals::{
65-
FrohfdivHalt, FrohfdivReset, FrohfdivUnstab, Pll1clkdivHalt, Pll1clkdivReset, Pll1clkdivUnstab,
63+
AhbclkdivUnstab, FrolfdivHalt, FrolfdivReset, FrolfdivUnstab, Pll1clkdivHalt, Pll1clkdivReset, Pll1clkdivUnstab,
6664
};
65+
#[cfg(feature = "mcxa2xx")]
66+
use crate::pac::syscon::vals::{FrohfdivHalt, FrohfdivReset, FrohfdivUnstab};
6767
pub mod config;
6868
pub mod periph_helpers;
6969

@@ -134,7 +134,6 @@ pub fn init(settings: ClocksConfig) -> Result<(), ClockError> {
134134

135135
#[cfg(not(feature = "sosc-as-gpio"))]
136136
operator.configure_sosc()?;
137-
#[cfg(feature = "mcxa2xx")]
138137
operator.configure_spll()?;
139138

140139
// Finally, setup main clock
@@ -314,7 +313,6 @@ unsafe fn restart_active_only_clocks(_cs: &CriticalSection) {
314313
}
315314

316315
// Ensure SPLL is up and running
317-
#[cfg(feature = "mcxa2xx")]
318316
if let Some(spll) = clocks.pll1_clk.as_ref()
319317
&& !matches!(spll.power, PoweredClock::AlwaysEnabled)
320318
{
@@ -490,11 +488,9 @@ pub struct Clocks {
490488
pub cpu_system_clk: Option<Clock>,
491489

492490
/// `pll1_clk` is the output of the main system PLL, `pll1`.
493-
#[cfg(feature = "mcxa2xx")]
494491
pub pll1_clk: Option<Clock>,
495492

496493
/// `pll1_clk_div` is a configurable frequency clock, sourced from `pll1_clk`
497-
#[cfg(feature = "mcxa2xx")]
498494
pub pll1_clk_div: Option<Clock>,
499495
}
500496

@@ -871,14 +867,12 @@ impl Clocks {
871867
}
872868

873869
/// Ensure the `pll1_clk` clock is active and valid at the given power state.
874-
#[cfg(feature = "mcxa2xx")]
875870
#[inline]
876871
pub fn ensure_pll1_clk_active(&self, at_level: &PoweredClock) -> Result<u32, ClockError> {
877872
self.ensure_clock_active(&self.pll1_clk, "pll1_clk", at_level)
878873
}
879874

880875
/// Ensure the `pll1_clk_div` clock is active and valid at the given power state.
881-
#[cfg(feature = "mcxa2xx")]
882876
#[inline]
883877
pub fn ensure_pll1_clk_div_active(&self, at_level: &PoweredClock) -> Result<u32, ClockError> {
884878
self.ensure_clock_active(&self.pll1_clk_div, "pll1_clk_div", at_level)
@@ -1706,7 +1700,6 @@ impl ClockOperator<'_> {
17061700
Ok(())
17071701
}
17081702

1709-
#[cfg(feature = "mcxa2xx")]
17101703
fn configure_spll(&mut self) -> Result<(), ClockError> {
17111704
// # Vocab
17121705
//
@@ -1740,6 +1733,7 @@ impl ClockOperator<'_> {
17401733
.as_ref()
17411734
.map(|c| (c, Source::SOSC))
17421735
.ok_or("sosc not active"),
1736+
#[cfg(feature = "mcxa2xx")]
17431737
config::SpllSource::Firc => self
17441738
.clocks
17451739
.clk_45m
@@ -2094,7 +2088,6 @@ impl ClockOperator<'_> {
20942088
MainClockSource::RoscFro16K => (Scs::ROSC, "fro16k", self.clocks.clk_16k_vdd_core.as_ref()),
20952089
#[cfg(all(feature = "mcxa5xx", not(feature = "rosc-32k-as-gpio")))]
20962090
MainClockSource::RoscOsc32K => (Scs::ROSC, "osc32k", self.clocks.clk_32k_vdd_core.as_ref()),
2097-
#[cfg(feature = "mcxa2xx")]
20982091
MainClockSource::SPll1 => (Scs::SPLL, "pll1_clk", self.clocks.pll1_clk.as_ref()),
20992092
};
21002093
let Some(main_clk_src) = clk else {

embassy-mcxa/src/clocks/periph_helpers/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ pub enum CTimerClockSel {
305305
/// clk_1m/FRO_LF divided by 12
306306
Clk1M,
307307
/// Internal PLL output, with configurable divisor
308-
#[cfg(feature = "mcxa2xx")]
309308
Pll1ClkDiv,
310309
/// Disabled
311310
None,
@@ -399,10 +398,16 @@ impl SPConfHelper for CTimerConfig {
399398

400399
(freq, mux)
401400
}
402-
#[cfg(feature = "mcxa2xx")]
403401
CTimerClockSel::Pll1ClkDiv => {
404402
let freq = clocks.ensure_pll1_clk_div_active(&self.power)?;
405-
(freq, CtimerClkselMux::CLKROOT_FUNC_6)
403+
404+
// TODO: fix PAC names for consistency
405+
#[cfg(feature = "mcxa2xx")]
406+
let mux = CtimerClkselMux::CLKROOT_FUNC_6;
407+
#[cfg(feature = "mcxa5xx")]
408+
let mux = CtimerClkselMux::I6_CLKROOT_SPLL_DIV;
409+
410+
(freq, mux)
406411
}
407412
CTimerClockSel::None => {
408413
// no ClkrootFunc7, just write manually for now
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//! Similar to blinky, but clocked with external SOSC
2+
//!
3+
//! This will probably go away once we have the CLKOUT peripheral supported.
4+
5+
#![no_std]
6+
#![no_main]
7+
8+
use embassy_executor::Spawner;
9+
use embassy_mcxa::clocks::PoweredClock;
10+
use embassy_mcxa::clocks::config::{MainClockSource, SpllConfig, SpllMode, SpllSource};
11+
use embassy_time::Timer;
12+
use hal::gpio::{DriveStrength, Level, Output, SlewRate};
13+
use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
14+
15+
#[embassy_executor::main]
16+
async fn main(_spawner: Spawner) {
17+
let mut cfg = hal::config::Config::default();
18+
cfg.clock_cfg.spll = Some(SpllConfig {
19+
source: SpllSource::Sirc,
20+
// 12MHz
21+
// 12 x 32 => 384MHz
22+
// 384 / (16 x 2) => 12.0MHz
23+
mode: SpllMode::Mode1b {
24+
m_mult: 32,
25+
p_div: 16,
26+
bypass_p2_div: false,
27+
},
28+
power: PoweredClock::NormalEnabledDeepSleepDisabled,
29+
pll1_clk_div: None,
30+
});
31+
cfg.clock_cfg.main_clock.source = MainClockSource::SPll1;
32+
let p = hal::init(cfg);
33+
34+
defmt::info!("Blink example");
35+
36+
let mut red = Output::new(p.P2_14, Level::High, DriveStrength::Normal, SlewRate::Fast);
37+
let mut green = Output::new(p.P2_22, Level::High, DriveStrength::Normal, SlewRate::Fast);
38+
let mut blue = Output::new(p.P2_23, Level::High, DriveStrength::Normal, SlewRate::Fast);
39+
40+
loop {
41+
defmt::info!("Toggle LEDs");
42+
43+
red.toggle();
44+
Timer::after_millis(250).await;
45+
46+
red.toggle();
47+
green.toggle();
48+
Timer::after_millis(250).await;
49+
50+
green.toggle();
51+
blue.toggle();
52+
Timer::after_millis(250).await;
53+
blue.toggle();
54+
55+
Timer::after_millis(250).await;
56+
}
57+
}

0 commit comments

Comments
 (0)