@@ -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( any( 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,24 @@ 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( any( feature = "_nrf91" ) ) ) ]
286
289
Synthesized ,
287
290
/// External source from xtal.
291
+ #[ cfg( not( all( feature = "_nrf5340" , 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(
295
+ all( feature = "_nrf5340" , feature = "lfxo-pins-as-gpio" ) ,
296
+ feature = "_nrf91" ,
297
+ feature = "_nrf54l"
298
+ ) ) ) ]
291
299
ExternalLowSwing ,
292
300
/// External source from xtal with full swing applied.
293
- #[ cfg( not( any( feature = "_nrf5340" , feature = "_nrf91" , feature = "_nrf54l" ) ) ) ]
301
+ #[ cfg( not( any(
302
+ all( feature = "_nrf5340" , feature = "lfxo-pins-as-gpio" ) ,
303
+ feature = "_nrf91" ,
304
+ feature = "_nrf54l"
305
+ ) ) ) ]
294
306
ExternalFullSwing ,
295
307
}
296
308
@@ -706,6 +718,19 @@ pub fn init(config: config::Config) -> Peripherals {
706
718
}
707
719
}
708
720
721
+ // Workaround for anomaly 140
722
+ #[ cfg( feature = "nrf5340-app-s" ) ]
723
+ if unsafe { ( 0x50032420 as * mut u32 ) . read_volatile ( ) } & 0x80000000 != 0 {
724
+ r. events_lfclkstarted ( ) . write_value ( 0 ) ;
725
+ r. lfclksrc ( )
726
+ . write ( |w| w. set_src ( nrf_pac:: clock:: vals:: Lfclksrc :: LFSYNT ) ) ;
727
+ r. tasks_lfclkstart ( ) . write_value ( 1 ) ;
728
+ while r. events_lfclkstarted ( ) . read ( ) == 0 { }
729
+ r. events_lfclkstarted ( ) . write_value ( 0 ) ;
730
+ r. tasks_lfclkstop ( ) . write_value ( 1 ) ;
731
+ r. lfclksrc ( ) . write ( |w| w. set_src ( nrf_pac:: clock:: vals:: Lfclksrc :: LFRC ) ) ;
732
+ }
733
+
709
734
// Configure LFCLK.
710
735
#[ cfg( not( any( feature = "_nrf51" , feature = "_nrf5340" , feature = "_nrf91" , feature = "_nrf54l" ) ) ) ]
711
736
match config. lfclk_source {
@@ -723,6 +748,36 @@ pub fn init(config: config::Config) -> Peripherals {
723
748
w. set_bypass ( true ) ;
724
749
} ) ,
725
750
}
751
+ #[ cfg( feature = "_nrf5340" ) ]
752
+ {
753
+ #[ allow( unused_mut) ]
754
+ let mut lfxo = false ;
755
+ match config. lfclk_source {
756
+ config:: LfclkSource :: InternalRC => r. lfclksrc ( ) . write ( |w| w. set_src ( pac:: clock:: vals:: Lfclksrc :: LFRC ) ) ,
757
+ config:: LfclkSource :: Synthesized => r. lfclksrc ( ) . write ( |w| w. set_src ( pac:: clock:: vals:: Lfclksrc :: LFSYNT ) ) ,
758
+ #[ cfg( not( feature = "lfxo-pins-as-gpio" ) ) ]
759
+ config:: LfclkSource :: ExternalXtal => lfxo = true ,
760
+ #[ cfg( not( feature = "lfxo-pins-as-gpio" ) ) ]
761
+ config:: LfclkSource :: ExternalLowSwing => lfxo = true ,
762
+ #[ cfg( not( feature = "lfxo-pins-as-gpio" ) ) ]
763
+ config:: LfclkSource :: ExternalFullSwing => {
764
+ #[ cfg( all( feature = "_nrf5340-app" ) ) ]
765
+ pac:: OSCILLATORS . xosc32ki ( ) . bypass ( ) . write ( |w| w. set_bypass ( true ) ) ;
766
+ lfxo = true ;
767
+ }
768
+ }
769
+ if lfxo {
770
+ if cfg ! ( feature = "_s" ) {
771
+ // MCUSEL is only accessible from secure code.
772
+ let p0 = pac:: P0 ;
773
+ p0. pin_cnf ( 0 )
774
+ . write ( |w| w. set_mcusel ( pac:: gpio:: vals:: Mcusel :: PERIPHERAL ) ) ;
775
+ p0. pin_cnf ( 1 )
776
+ . write ( |w| w. set_mcusel ( pac:: gpio:: vals:: Mcusel :: PERIPHERAL ) ) ;
777
+ }
778
+ r. lfclksrc ( ) . write ( |w| w. set_src ( pac:: clock:: vals:: Lfclksrc :: LFXO ) ) ;
779
+ }
780
+ }
726
781
#[ cfg( feature = "_nrf91" ) ]
727
782
match config. lfclk_source {
728
783
config:: LfclkSource :: InternalRC => r. lfclksrc ( ) . write ( |w| w. set_src ( pac:: clock:: vals:: Lfclksrc :: LFRC ) ) ,
0 commit comments