aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Munns <[email protected]>2025-11-17 16:38:32 +0100
committerJames Munns <[email protected]>2025-11-17 16:38:57 +0100
commit02285c2153d22f2c0c93a4ce920cdebc03f18658 (patch)
tree5fc094d362baa29d2e58185a6416e40b7adaaf0a
parenta0c8e2d0299f3ae8eb24cd264d2b8e87f2bce464 (diff)
Correct clk/rst field logic
-rw-r--r--examples/memory.x4
-rw-r--r--examples/src/lib.rs2
-rw-r--r--src/clocks/mod.rs28
-rw-r--r--src/lib.rs5
4 files changed, 21 insertions, 18 deletions
diff --git a/examples/memory.x b/examples/memory.x
index f4263a412..528545b64 100644
--- a/examples/memory.x
+++ b/examples/memory.x
@@ -1,5 +1,5 @@
1MEMORY 1MEMORY
2{ 2{
3 FLASH : ORIGIN = 0x20000000, LENGTH = 64K 3 FLASH : ORIGIN = 0x20000000, LENGTH = 80K
4 RAM : ORIGIN = 0x20010000, LENGTH = 64K 4 RAM : ORIGIN = 0x20014000, LENGTH = 48K
5} 5}
diff --git a/examples/src/lib.rs b/examples/src/lib.rs
index 2018a3c25..4bb334da5 100644
--- a/examples/src/lib.rs
+++ b/examples/src/lib.rs
@@ -5,7 +5,7 @@
5//! These live with the examples so the HAL stays generic. 5//! These live with the examples so the HAL stays generic.
6 6
7use hal::{clocks, pins}; 7use hal::{clocks, pins};
8use {embassy_mcxa as hal, panic_probe as _}; 8use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
9 9
10/// Initialize clocks and pin muxing for UART2 debug console. 10/// Initialize clocks and pin muxing for UART2 debug console.
11/// Safe to call multiple times; writes are idempotent for our use. 11/// Safe to call multiple times; writes are idempotent for our use.
diff --git a/src/clocks/mod.rs b/src/clocks/mod.rs
index 74a1f1a1f..e02840592 100644
--- a/src/clocks/mod.rs
+++ b/src/clocks/mod.rs
@@ -821,44 +821,44 @@ impl ClockOperator<'_> {
821/// This macro is used to implement the [`Gate`] trait for a given peripheral 821/// This macro is used to implement the [`Gate`] trait for a given peripheral
822/// that is controlled by the MRCC peripheral. 822/// that is controlled by the MRCC peripheral.
823macro_rules! impl_cc_gate { 823macro_rules! impl_cc_gate {
824 ($name:ident, $reg:ident, $field:ident, $config:ty) => { 824 ($name:ident, $clk_reg:ident, $rst_reg:ident, $field:ident, $config:ty) => {
825 impl Gate for crate::peripherals::$name { 825 impl Gate for crate::peripherals::$name {
826 type MrccPeriphConfig = $config; 826 type MrccPeriphConfig = $config;
827 827
828 #[inline] 828 #[inline]
829 unsafe fn enable_clock() { 829 unsafe fn enable_clock() {
830 let mrcc = unsafe { pac::Mrcc0::steal() }; 830 let mrcc = unsafe { pac::Mrcc0::steal() };
831 mrcc.$reg().modify(|_, w| w.$field().enabled()); 831 mrcc.$clk_reg().modify(|_, w| w.$field().enabled());
832 } 832 }
833 833
834 #[inline] 834 #[inline]
835 unsafe fn disable_clock() { 835 unsafe fn disable_clock() {
836 let mrcc = unsafe { pac::Mrcc0::steal() }; 836 let mrcc = unsafe { pac::Mrcc0::steal() };
837 mrcc.$reg().modify(|_r, w| w.$field().disabled()); 837 mrcc.$clk_reg().modify(|_r, w| w.$field().disabled());
838 } 838 }
839 839
840 #[inline] 840 #[inline]
841 fn is_clock_enabled() -> bool { 841 fn is_clock_enabled() -> bool {
842 let mrcc = unsafe { pac::Mrcc0::steal() }; 842 let mrcc = unsafe { pac::Mrcc0::steal() };
843 mrcc.$reg().read().$field().is_enabled() 843 mrcc.$clk_reg().read().$field().is_enabled()
844 } 844 }
845 845
846 #[inline] 846 #[inline]
847 unsafe fn release_reset() { 847 unsafe fn release_reset() {
848 let mrcc = unsafe { pac::Mrcc0::steal() }; 848 let mrcc = unsafe { pac::Mrcc0::steal() };
849 mrcc.$reg().modify(|_, w| w.$field().enabled()); 849 mrcc.$rst_reg().modify(|_, w| w.$field().enabled());
850 } 850 }
851 851
852 #[inline] 852 #[inline]
853 unsafe fn assert_reset() { 853 unsafe fn assert_reset() {
854 let mrcc = unsafe { pac::Mrcc0::steal() }; 854 let mrcc = unsafe { pac::Mrcc0::steal() };
855 mrcc.$reg().modify(|_, w| w.$field().disabled()); 855 mrcc.$rst_reg().modify(|_, w| w.$field().disabled());
856 } 856 }
857 857
858 #[inline] 858 #[inline]
859 fn is_reset_released() -> bool { 859 fn is_reset_released() -> bool {
860 let mrcc = unsafe { pac::Mrcc0::steal() }; 860 let mrcc = unsafe { pac::Mrcc0::steal() };
861 mrcc.$reg().read().$field().is_enabled() 861 mrcc.$rst_reg().read().$field().is_enabled()
862 } 862 }
863 } 863 }
864 }; 864 };
@@ -874,14 +874,14 @@ pub(crate) mod gate {
874 // other than enabling through the MRCC gate. Currently, these peripherals will 874 // other than enabling through the MRCC gate. Currently, these peripherals will
875 // ALWAYS return `Ok(0)` when calling [`enable_and_reset()`] and/or 875 // ALWAYS return `Ok(0)` when calling [`enable_and_reset()`] and/or
876 // [`SPConfHelper::post_enable_config()`]. 876 // [`SPConfHelper::post_enable_config()`].
877 impl_cc_gate!(PORT1, mrcc_glb_cc1, port1, NoConfig); 877 impl_cc_gate!(PORT1, mrcc_glb_cc1, mrcc_glb_rst1, port1, NoConfig);
878 impl_cc_gate!(PORT2, mrcc_glb_cc1, port2, NoConfig); 878 impl_cc_gate!(PORT2, mrcc_glb_cc1, mrcc_glb_rst1, port2, NoConfig);
879 impl_cc_gate!(PORT3, mrcc_glb_cc1, port3, NoConfig); 879 impl_cc_gate!(PORT3, mrcc_glb_cc1, mrcc_glb_rst1, port3, NoConfig);
880 impl_cc_gate!(GPIO3, mrcc_glb_cc2, gpio3, NoConfig); 880 impl_cc_gate!(GPIO3, mrcc_glb_cc2, mrcc_glb_rst2, gpio3, NoConfig);
881 881
882 // These peripherals DO have meaningful configuration, and could fail if the system 882 // These peripherals DO have meaningful configuration, and could fail if the system
883 // clocks do not match their needs. 883 // clocks do not match their needs.
884 impl_cc_gate!(OSTIMER0, mrcc_glb_cc1, ostimer0, OsTimerConfig); 884 impl_cc_gate!(OSTIMER0, mrcc_glb_cc1, mrcc_glb_rst1, ostimer0, OsTimerConfig);
885 impl_cc_gate!(LPUART2, mrcc_glb_cc0, lpuart2, LpuartConfig); 885 impl_cc_gate!(LPUART2, mrcc_glb_cc0, mrcc_glb_rst0, lpuart2, LpuartConfig);
886 impl_cc_gate!(ADC1, mrcc_glb_cc1, adc1, AdcConfig); 886 impl_cc_gate!(ADC1, mrcc_glb_cc1, mrcc_glb_rst1, adc1, AdcConfig);
887} 887}
diff --git a/src/lib.rs b/src/lib.rs
index 1bf54a98b..86c0dc45b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -47,7 +47,6 @@ pub use rtc::Rtc0 as Rtc0Token;
47 47
48/// Initialize HAL with configuration (mirrors embassy-imxrt style). Minimal: just take peripherals. 48/// Initialize HAL with configuration (mirrors embassy-imxrt style). Minimal: just take peripherals.
49/// Also applies configurable NVIC priority for the OSTIMER OS_EVENT interrupt (no enabling). 49/// Also applies configurable NVIC priority for the OSTIMER OS_EVENT interrupt (no enabling).
50#[allow(unused_variables)]
51pub fn init(cfg: crate::config::Config) -> Peripherals { 50pub fn init(cfg: crate::config::Config) -> Peripherals {
52 let peripherals = Peripherals::take(); 51 let peripherals = Peripherals::take();
53 // Apply user-configured priority early; enabling is left to examples/apps 52 // Apply user-configured priority early; enabling is left to examples/apps
@@ -56,6 +55,10 @@ pub fn init(cfg: crate::config::Config) -> Peripherals {
56 crate::interrupt::RTC.set_priority(cfg.rtc_interrupt_priority); 55 crate::interrupt::RTC.set_priority(cfg.rtc_interrupt_priority);
57 // Apply user-configured priority early; enabling is left to examples/apps 56 // Apply user-configured priority early; enabling is left to examples/apps
58 crate::interrupt::ADC1.set_priority(cfg.adc_interrupt_priority); 57 crate::interrupt::ADC1.set_priority(cfg.adc_interrupt_priority);
58
59 // Configure clocks
60 crate::clocks::init(cfg.clock_cfg).unwrap();
61
59 peripherals 62 peripherals
60} 63}
61 64