aboutsummaryrefslogtreecommitdiff
path: root/embassy-nxp/src/lib.rs
diff options
context:
space:
mode:
authori509VCB <[email protected]>2025-07-22 16:16:00 +0000
committerGitHub <[email protected]>2025-07-22 16:16:00 +0000
commit908e016524e1802b736664d84ca2da6ea908444d (patch)
tree2a4d3d28329c94a97d59b7208ccb60d28631f83e /embassy-nxp/src/lib.rs
parenta5984a8298491ea748693783275d95286a481394 (diff)
parent1ad5d5a771d5109a763361454fb724b85ae25fdd (diff)
Merge pull request #4419 from i509VCB/rt1011
nxp: Add MIMXRT1011 GPIO and time driver
Diffstat (limited to 'embassy-nxp/src/lib.rs')
-rw-r--r--embassy-nxp/src/lib.rs87
1 files changed, 82 insertions, 5 deletions
diff --git a/embassy-nxp/src/lib.rs b/embassy-nxp/src/lib.rs
index 1abaca708..a715770c4 100644
--- a/embassy-nxp/src/lib.rs
+++ b/embassy-nxp/src/lib.rs
@@ -1,12 +1,19 @@
1#![no_std] 1#![no_std]
2 2
3pub mod fmt; 3// This mod MUST go first, so that the others see its macros.
4pub(crate) mod fmt;
5
4pub mod gpio; 6pub mod gpio;
5#[cfg(feature = "lpc55")] 7#[cfg(feature = "lpc55")]
6pub mod pint; 8pub mod pint;
7 9
10#[cfg(feature = "_time_driver")]
11#[cfg_attr(feature = "time-driver-pit", path = "time_driver/pit.rs")]
12mod time_driver;
13
8// This mod MUST go last, so that it sees all the `impl_foo!` macros 14// This mod MUST go last, so that it sees all the `impl_foo!` macros
9#[cfg_attr(feature = "lpc55", path = "chips/lpc55.rs")] 15#[cfg_attr(feature = "lpc55", path = "chips/lpc55.rs")]
16#[cfg_attr(feature = "mimxrt1011", path = "chips/mimxrt1011.rs")]
10mod chip; 17mod chip;
11 18
12#[cfg(feature = "unstable-pac")] 19#[cfg(feature = "unstable-pac")]
@@ -22,13 +29,66 @@ pub use embassy_hal_internal::{Peri, PeripheralType};
22/// 29///
23/// This should only be called once and at startup, otherwise it panics. 30/// This should only be called once and at startup, otherwise it panics.
24pub fn init(_config: config::Config) -> Peripherals { 31pub fn init(_config: config::Config) -> Peripherals {
25 #[cfg(feature = "lpc55")] 32 // Do this first, so that it panics if user is calling `init` a second time
33 // before doing anything important.
34 let peripherals = Peripherals::take();
35
36 #[cfg(feature = "mimxrt1011")]
26 { 37 {
27 gpio::init(); 38 // The RT1010 Reference manual states that core clock root must be switched before
28 pint::init(); 39 // reprogramming PLL2.
40 pac::CCM.cbcdr().modify(|w| {
41 w.set_periph_clk_sel(pac::ccm::vals::PeriphClkSel::PERIPH_CLK_SEL_1);
42 });
43
44 while matches!(
45 pac::CCM.cdhipr().read().periph_clk_sel_busy(),
46 pac::ccm::vals::PeriphClkSelBusy::PERIPH_CLK_SEL_BUSY_1
47 ) {}
48
49 info!("Core clock root switched");
50
51 // 480 * 18 / 24 = 360
52 pac::CCM_ANALOG.pfd_480().modify(|x| x.set_pfd2_frac(12));
53
54 //480*18/24(pfd0)/4
55 pac::CCM_ANALOG.pfd_480().modify(|x| x.set_pfd0_frac(24));
56 pac::CCM.cscmr1().modify(|x| x.set_flexspi_podf(3.into()));
57
58 // CPU Core
59 pac::CCM_ANALOG.pfd_528().modify(|x| x.set_pfd3_frac(18));
60 cortex_m::asm::delay(500_000);
61
62 // Clock core clock with PLL 2.
63 pac::CCM
64 .cbcdr()
65 .modify(|x| x.set_periph_clk_sel(pac::ccm::vals::PeriphClkSel::PERIPH_CLK_SEL_0)); // false
66
67 while matches!(
68 pac::CCM.cdhipr().read().periph_clk_sel_busy(),
69 pac::ccm::vals::PeriphClkSelBusy::PERIPH_CLK_SEL_BUSY_1
70 ) {}
71
72 pac::CCM
73 .cbcmr()
74 .write(|v| v.set_pre_periph_clk_sel(pac::ccm::vals::PrePeriphClkSel::PRE_PERIPH_CLK_SEL_0));
75
76 // TODO: Some for USB PLLs
77
78 // DCDC clock?
79 pac::CCM.ccgr6().modify(|v| v.set_cg0(1));
29 } 80 }
30 81
31 crate::Peripherals::take() 82 #[cfg(any(feature = "lpc55", rt1xxx))]
83 gpio::init();
84
85 #[cfg(feature = "lpc55")]
86 pint::init();
87
88 #[cfg(feature = "_time_driver")]
89 time_driver::init();
90
91 peripherals
32} 92}
33 93
34/// HAL configuration for the NXP board. 94/// HAL configuration for the NXP board.
@@ -36,3 +96,20 @@ pub mod config {
36 #[derive(Default)] 96 #[derive(Default)]
37 pub struct Config {} 97 pub struct Config {}
38} 98}
99
100#[allow(unused)]
101struct BitIter(u32);
102
103impl Iterator for BitIter {
104 type Item = u32;
105
106 fn next(&mut self) -> Option<Self::Item> {
107 match self.0.trailing_zeros() {
108 32 => None,
109 b => {
110 self.0 &= !(1 << b);
111 Some(b)
112 }
113 }
114 }
115}