@@ -65,6 +65,9 @@ compile_error!("feature `reset-pin-as-gpio` is only valid for nRF52 series chips
65
65
#[ cfg( all( feature = "nfc-pins-as-gpio" , not( any( feature = "_nrf52" , feature = "_nrf5340-app" ) ) ) ) ]
66
66
compile_error ! ( "feature `nfc-pins-as-gpio` is only valid for nRF52, or nRF53's application core." ) ;
67
67
68
+ #[ cfg( all( feature = "lfxo-pins-as-gpio" , not( feature = "_nrf5340" ) ) ) ]
69
+ compile_error ! ( "feature `lfxo-pins-as-gpio` is only valid for nRF53 series chips." ) ;
70
+
68
71
// This mod MUST go first, so that the others see its macros.
69
72
pub ( crate ) mod fmt;
70
73
pub ( crate ) mod util;
@@ -282,15 +285,16 @@ pub mod config {
282
285
/// Internal RC oscillator
283
286
InternalRC ,
284
287
/// Synthesized from the high frequency clock source.
285
- #[ cfg( not( any ( feature = "_nrf5340" , feature = " _nrf91") ) ) ]
288
+ #[ cfg( not( feature = "_nrf91" ) ) ]
286
289
Synthesized ,
287
290
/// External source from xtal.
291
+ #[ cfg( not( feature = "lfxo-pins-as-gpio" ) ) ]
288
292
ExternalXtal ,
289
293
/// External source from xtal with low swing applied.
290
- #[ cfg( not( any( feature = "_nrf5340 " , feature = "_nrf91" , feature = "_nrf54l" ) ) ) ]
294
+ #[ cfg( not( any( feature = "lfxo-pins-as-gpio " , feature = "_nrf91" , feature = "_nrf54l" ) ) ) ]
291
295
ExternalLowSwing ,
292
296
/// External source from xtal with full swing applied.
293
- #[ cfg( not( any( feature = "_nrf5340 " , feature = "_nrf91" , feature = "_nrf54l" ) ) ) ]
297
+ #[ cfg( not( any( feature = "lfxo-pins-as-gpio " , feature = "_nrf91" , feature = "_nrf54l" ) ) ) ]
294
298
ExternalFullSwing ,
295
299
}
296
300
@@ -706,6 +710,19 @@ pub fn init(config: config::Config) -> Peripherals {
706
710
}
707
711
}
708
712
713
+ // Workaround for anomaly 140
714
+ #[ cfg( feature = "nrf5340-app-s" ) ]
715
+ if unsafe { ( 0x50032420 as * mut u32 ) . read_volatile ( ) } & 0x80000000 != 0 {
716
+ r. events_lfclkstarted ( ) . write_value ( 0 ) ;
717
+ r. lfclksrc ( )
718
+ . write ( |w| w. set_src ( nrf_pac:: clock:: vals:: Lfclksrc :: LFSYNT ) ) ;
719
+ r. tasks_lfclkstart ( ) . write_value ( 1 ) ;
720
+ while r. events_lfclkstarted ( ) . read ( ) == 0 { }
721
+ r. events_lfclkstarted ( ) . write_value ( 0 ) ;
722
+ r. tasks_lfclkstop ( ) . write_value ( 1 ) ;
723
+ r. lfclksrc ( ) . write ( |w| w. set_src ( nrf_pac:: clock:: vals:: Lfclksrc :: LFRC ) ) ;
724
+ }
725
+
709
726
// Configure LFCLK.
710
727
#[ cfg( not( any( feature = "_nrf51" , feature = "_nrf5340" , feature = "_nrf91" , feature = "_nrf54l" ) ) ) ]
711
728
match config. lfclk_source {
@@ -723,6 +740,36 @@ pub fn init(config: config::Config) -> Peripherals {
723
740
w. set_bypass ( true ) ;
724
741
} ) ,
725
742
}
743
+ #[ cfg( feature = "_nrf5340" ) ]
744
+ {
745
+ #[ allow( unused_mut) ]
746
+ let mut lfxo = false ;
747
+ match config. lfclk_source {
748
+ config:: LfclkSource :: InternalRC => r. lfclksrc ( ) . write ( |w| w. set_src ( pac:: clock:: vals:: Lfclksrc :: LFRC ) ) ,
749
+ config:: LfclkSource :: Synthesized => r. lfclksrc ( ) . write ( |w| w. set_src ( pac:: clock:: vals:: Lfclksrc :: LFSYNT ) ) ,
750
+ #[ cfg( not( feature = "lfxo-pins-as-gpio" ) ) ]
751
+ config:: LfclkSource :: ExternalXtal => lfxo = true ,
752
+ #[ cfg( not( feature = "lfxo-pins-as-gpio" ) ) ]
753
+ config:: LfclkSource :: ExternalLowSwing => lfxo = true ,
754
+ #[ cfg( not( feature = "lfxo-pins-as-gpio" ) ) ]
755
+ config:: LfclkSource :: ExternalFullSwing => {
756
+ #[ cfg( all( feature = "_nrf5340-app" ) ) ]
757
+ pac:: OSCILLATORS . xosc32ki ( ) . bypass ( ) . write ( |w| w. set_bypass ( true ) ) ;
758
+ lfxo = true ;
759
+ }
760
+ }
761
+ if lfxo {
762
+ if cfg ! ( feature = "_s" ) {
763
+ // MCUSEL is only accessible from secure code.
764
+ let p0 = pac:: P0 ;
765
+ p0. pin_cnf ( 0 )
766
+ . write ( |w| w. set_mcusel ( pac:: gpio:: vals:: Mcusel :: PERIPHERAL ) ) ;
767
+ p0. pin_cnf ( 1 )
768
+ . write ( |w| w. set_mcusel ( pac:: gpio:: vals:: Mcusel :: PERIPHERAL ) ) ;
769
+ }
770
+ r. lfclksrc ( ) . write ( |w| w. set_src ( pac:: clock:: vals:: Lfclksrc :: LFXO ) ) ;
771
+ }
772
+ }
726
773
#[ cfg( feature = "_nrf91" ) ]
727
774
match config. lfclk_source {
728
775
config:: LfclkSource :: InternalRC => r. lfclksrc ( ) . write ( |w| w. set_src ( pac:: clock:: vals:: Lfclksrc :: LFRC ) ) ,
0 commit comments