diff --git a/CHANGELOG.md b/CHANGELOG.md index 191ebeb2..14a969fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Fixed the nvmc erase procedure on nRF91 & nRF53 ([#387]) +- Added support for the nrf5340-net-core. ## [0.15.0] diff --git a/Cargo.ci.toml b/Cargo.ci.toml index c40523df..c561df5a 100644 --- a/Cargo.ci.toml +++ b/Cargo.ci.toml @@ -9,6 +9,7 @@ members = [ "nrf52840-hal", "nrf52840-hal-tests", "nrf5340-app-hal", + "nrf5340-net-hal", "nrf9160-hal", "examples/*", ] diff --git a/nrf-hal-common/Cargo.toml b/nrf-hal-common/Cargo.toml index 3e2cd30f..a4ae1992 100644 --- a/nrf-hal-common/Cargo.toml +++ b/nrf-hal-common/Cargo.toml @@ -64,6 +64,10 @@ version = "0.11.0" optional = true version = "0.11.0" +[dependencies.nrf5340-net-pac] +optional = true +version = "0.11.0" + [dependencies.nrf9160-pac] optional = true version = "0.11.0" @@ -85,4 +89,5 @@ doc = [] 52833 = ["nrf52833-pac", "nrf-usbd"] 52840 = ["nrf52840-pac", "nrf-usbd"] 5340-app = ["nrf5340-app-pac"] +5340-net = ["nrf5340-net-pac"] 9160 = ["nrf9160-pac"] diff --git a/nrf-hal-common/src/adc.rs b/nrf-hal-common/src/adc.rs index b8a64e0d..d9d09f4b 100644 --- a/nrf-hal-common/src/adc.rs +++ b/nrf-hal-common/src/adc.rs @@ -91,8 +91,14 @@ where 5 => self.0.config.modify(|_, w| w.psel().analog_input5()), 6 => self.0.config.modify(|_, w| w.psel().analog_input6()), 7 => self.0.config.modify(|_, w| w.psel().analog_input7()), - 8 => self.0.config.modify(|_, w| w.inpsel().supply_one_third_prescaling()), - 9 => self.0.config.modify(|_, w| w.inpsel().supply_two_thirds_prescaling()), + 8 => self + .0 + .config + .modify(|_, w| w.inpsel().supply_one_third_prescaling()), + 9 => self + .0 + .config + .modify(|_, w| w.inpsel().supply_two_thirds_prescaling()), // This can never happen the only analog pins have already been defined // PAY CLOSE ATTENTION TO ANY CHANGES TO THIS IMPL OR THE `channel_mappings!` MACRO _ => unsafe { unreachable_unchecked() }, @@ -105,7 +111,9 @@ where self.0.events_end.write(|w| unsafe { w.bits(0) }); // Restore original input selection - self.0.config.modify(|_, w| w.inpsel().variant(original_inpsel.variant().unwrap())); + self.0 + .config + .modify(|_, w| w.inpsel().variant(original_inpsel.variant().unwrap())); // Max resolution is 10 bits so casting is always safe Ok(self.0.result.read().result().bits() as i16) diff --git a/nrf-hal-common/src/ccm.rs b/nrf-hal-common/src/ccm.rs index e85d2f43..d972169a 100644 --- a/nrf-hal-common/src/ccm.rs +++ b/nrf-hal-common/src/ccm.rs @@ -45,15 +45,26 @@ //! encryption/decryption. The scratch slice must have a minimum length of 43 bytes, or //! (16 + `Packet Length`) bytes, whatever is largest. +#[cfg(not(feature = "5340-net"))] use crate::{ pac::{AAR, CCM}, slice_in_ram, }; + +#[cfg(feature = "5340-net")] +use crate::{ + pac::{AAR_NS as AAR, CCM_NS as CCM}, + slice_in_ram, +}; + use core::sync::atomic::{compiler_fence, Ordering}; -#[cfg(not(feature = "51"))] +#[cfg(not(any(feature = "51", feature = "5340-net")))] use crate::pac::ccm::mode::{DATARATE_A, LENGTH_A}; +#[cfg(feature = "5340-net")] +use crate::pac::ccm_ns::mode::{DATARATE_A, LENGTH_A}; + const MINIMUM_SCRATCH_AREA_SIZE: usize = 43; const HEADER_SIZE: usize = 3; const LENGTH_HEADER_INDEX: usize = 1; @@ -69,15 +80,22 @@ pub enum DataRate { _1Mbit, #[cfg(not(feature = "51"))] _2Mbit, + #[cfg(feature = "5340-net")] + _125Kbps, + #[cfg(feature = "5340-net")] + _500Kbps, } #[cfg(not(feature = "51"))] impl From for DATARATE_A { fn from(data_rate: DataRate) -> Self { - if data_rate == DataRate::_1Mbit { - DATARATE_A::_1MBIT - } else { - DATARATE_A::_2MBIT + match data_rate { + DataRate::_1Mbit => DATARATE_A::_1MBIT, + DataRate::_2Mbit => DATARATE_A::_2MBIT, + #[cfg(feature = "5340-net")] + DataRate::_125Kbps => DATARATE_A::_125KBPS, + #[cfg(feature = "5340-net")] + DataRate::_500Kbps => DATARATE_A::_500KBPS, } } } @@ -253,7 +271,8 @@ impl Ccm { feature = "52840", feature = "52833", feature = "52811", - feature = "52810" + feature = "52810", + feature = "5340-net" ))] // NOTE(unsafe) Any 8bits pattern is safe to write to this register self.regs @@ -382,7 +401,8 @@ impl Ccm { feature = "52840", feature = "52833", feature = "52811", - feature = "52810" + feature = "52810", + feature = "5340-net" ))] // NOTE(unsafe) Any 8bits pattern is safe to write to this register self.regs diff --git a/nrf-hal-common/src/clocks.rs b/nrf-hal-common/src/clocks.rs index ca79d386..fa8210b2 100644 --- a/nrf-hal-common/src/clocks.rs +++ b/nrf-hal-common/src/clocks.rs @@ -1,9 +1,9 @@ //! Configuration and control of the High and Low Frequency Clock sources. -#[cfg(any(feature = "9160", feature = "5340-app"))] +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] use crate::pac::CLOCK_NS as CLOCK; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::CLOCK; // ZST Type States @@ -156,7 +156,12 @@ impl Clocks { } /// Use the internal RC Oscillator for the low frequency clock source. - #[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))] + #[cfg(not(any( + feature = "9160", + feature = "5340-app", + feature = "5340-net", + feature = "51" + )))] pub fn set_lfclk_src_rc(self) -> Clocks { self.periph .lfclksrc @@ -170,7 +175,12 @@ impl Clocks { } /// Generate the Low Frequency clock from the high frequency clock source. - #[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))] + #[cfg(not(any( + feature = "9160", + feature = "5340-app", + feature = "5340-net", + feature = "51" + )))] pub fn set_lfclk_src_synth(self) -> Clocks { self.periph .lfclksrc @@ -184,7 +194,12 @@ impl Clocks { } /// Use an external crystal to drive the low frequency clock. - #[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))] + #[cfg(not(any( + feature = "9160", + feature = "5340-app", + feature = "5340-net", + feature = "51" + )))] pub fn set_lfclk_src_external( self, cfg: LfOscConfiguration, diff --git a/nrf-hal-common/src/ecb.rs b/nrf-hal-common/src/ecb.rs index 3cdd8b20..14b58cfe 100644 --- a/nrf-hal-common/src/ecb.rs +++ b/nrf-hal-common/src/ecb.rs @@ -2,7 +2,11 @@ //! //! The ECB encryption block supports 128 bit AES encryption (encryption only, not decryption). +#[cfg(not(feature = "5340-net"))] use crate::pac::ECB; +#[cfg(feature = "5340-net")] +use crate::pac::ECB_NS as ECB; + use core::sync::atomic::{compiler_fence, Ordering}; /// Error type to represent a sharing conflict during encryption. diff --git a/nrf-hal-common/src/gpio.rs b/nrf-hal-common/src/gpio.rs index 48023c27..3cde62d9 100644 --- a/nrf-hal-common/src/gpio.rs +++ b/nrf-hal-common/src/gpio.rs @@ -40,9 +40,8 @@ pub enum Port { /// Port 0 Secure, available on nRF53 #[cfg(any(feature = "5340-app"))] Port0Secure, - - /// Port 1, only available on some nRF52 MCUs. - #[cfg(any(feature = "52833", feature = "52840"))] + /// Port 1, only available on some nRF52 MCUs and nRF5340. + #[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))] Port1, } @@ -63,18 +62,26 @@ pub struct Pin { #[cfg(feature = "51")] use crate::pac::{gpio, GPIO as P0}; -#[cfg(any(feature = "5340-app", feature = "9160"))] +#[cfg(any(feature = "5340-app", feature = "5340-net", feature = "9160"))] use crate::pac::{p0_ns as gpio, P0_NS as P0}; #[cfg(feature = "5340-app")] use crate::pac::P0_S; -#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))] +#[cfg(not(any( + feature = "9160", + feature = "5340-app", + feature = "5340-net", + feature = "51" +)))] use crate::pac::{p0 as gpio, P0}; #[cfg(any(feature = "52833", feature = "52840"))] use crate::pac::P1; +#[cfg(feature = "5340-net")] +use crate::pac::P1_NS as P1; + use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; use void::Void; @@ -84,7 +91,7 @@ impl Pin { Port::Port0 => 0x00, #[cfg(any(feature = "5340-app"))] Port::Port0Secure => 0x20, - #[cfg(any(feature = "52833", feature = "52840"))] + #[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))] Port::Port1 => 0x20, }; Self { @@ -102,12 +109,22 @@ impl Pin { #[inline] pub fn pin(&self) -> u8 { - #[cfg(any(feature = "52833", feature = "52840", feature = "5340-app"))] + #[cfg(any( + feature = "52833", + feature = "52840", + feature = "5340-app", + feature = "5340-net" + ))] { self.pin_port & 0x1f } - #[cfg(not(any(feature = "52833", feature = "52840", feature = "5340-app")))] + #[cfg(not(any( + feature = "52833", + feature = "52840", + feature = "5340-app", + feature = "5340-net" + )))] { self.pin_port } @@ -115,7 +132,7 @@ impl Pin { #[inline] pub fn port(&self) -> Port { - #[cfg(any(feature = "52833", feature = "52840"))] + #[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))] { if self.pin_port & 0x20 == 0 { Port::Port0 @@ -132,8 +149,12 @@ impl Pin { Port::Port0Secure } } - - #[cfg(not(any(feature = "52833", feature = "52840", feature = "5340-app")))] + #[cfg(not(any( + feature = "52833", + feature = "52840", + feature = "5340-app", + feature = "5340-net" + )))] { Port::Port0 } @@ -147,9 +168,9 @@ impl Pin { fn block(&self) -> &gpio::RegisterBlock { let ptr = match self.port() { Port::Port0 => P0::ptr(), - #[cfg(any(feature = "5340-app"))] + #[cfg(feature = "5340-app")] Port::Port0Secure => P0_S::ptr(), - #[cfg(any(feature = "52833", feature = "52840"))] + #[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))] Port::Port1 => P1::ptr(), }; @@ -339,10 +360,15 @@ pub enum OpenDrainConfig { #[cfg(feature = "51")] use crate::pac::gpio::pin_cnf; -#[cfg(any(feature = "5340-app", feature = "9160"))] +#[cfg(any(feature = "5340-app", feature = "5340-net", feature = "9160"))] use crate::pac::p0_ns::pin_cnf; -#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))] +#[cfg(not(any( + feature = "9160", + feature = "5340-app", + feature = "5340-net", + feature = "51" +)))] use crate::pac::p0::pin_cnf; impl OpenDrainConfig { @@ -647,7 +673,7 @@ gpio!(P0, p0, p0, Port::Port0, [ // The p1 types are present in the p0 module generated from the // svd, but we want to export them in a p1 module from this crate. -#[cfg(any(feature = "52833", feature = "52840"))] +#[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))] gpio!(P1, p0, p1, Port::Port1, [ P1_00: (p1_00, 0, Disconnected), P1_01: (p1_01, 1, Disconnected), @@ -667,7 +693,7 @@ gpio!(P1, p0, p1, Port::Port1, [ P1_15: (p1_15, 15, Disconnected), ]); -#[cfg(any(feature = "5340-app"))] +#[cfg(feature = "5340-app")] gpio!(P0_S, p0, p0_s, Port::Port0Secure, [ P0_00: (p0_00, 0, Disconnected), P0_01: (p0_01, 1, Disconnected), diff --git a/nrf-hal-common/src/gpiote.rs b/nrf-hal-common/src/gpiote.rs index 8526f790..ec665b15 100644 --- a/nrf-hal-common/src/gpiote.rs +++ b/nrf-hal-common/src/gpiote.rs @@ -6,20 +6,23 @@ #[cfg(feature = "51")] use crate::pac::GPIO as P0; -#[cfg(feature = "9160")] +#[cfg(any(feature = "9160", feature = "5340-net"))] use crate::pac::P0_NS as P0; -#[cfg(not(any(feature = "51", feature = "9160")))] +#[cfg(not(any(feature = "51", feature = "9160", feature = "5340-net")))] use crate::pac::P0; #[cfg(any(feature = "52833", feature = "52840"))] use crate::pac::P1; +#[cfg(feature = "5340-net")] +use crate::pac::P1_NS as P1; + use crate::gpio::{ Floating, Input, Level, OpenDrain, Output, Pin, Port, PullDown, PullUp, PushPull, }; -#[cfg(not(feature = "9160"))] +#[cfg(not(any(feature = "9160", feature = "5340-net")))] use { crate::pac::gpiote::{EVENTS_IN, EVENTS_PORT, TASKS_OUT}, crate::pac::GPIOTE, @@ -31,7 +34,13 @@ use { crate::pac::GPIOTE1_NS as GPIOTE, }; -#[cfg(not(any(feature = "51", feature = "9160")))] +#[cfg(feature = "5340-net")] +use { + crate::pac::gpiote_ns::{EVENTS_IN, EVENTS_PORT, TASKS_CLR, TASKS_OUT, TASKS_SET}, + crate::pac::GPIOTE_NS as GPIOTE, +}; + +#[cfg(not(any(feature = "51", feature = "9160", feature = "5340-net")))] use crate::pac::gpiote::{TASKS_CLR, TASKS_SET}; #[cfg(not(feature = "51"))] @@ -296,7 +305,7 @@ fn config_port_event_pin(pin: &P, sense: PortEventSense) { &(*{ match pin.port() { Port::Port0 => P0::ptr(), - #[cfg(any(feature = "52833", feature = "52840"))] + #[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))] Port::Port1 => P1::ptr(), } }) @@ -363,7 +372,7 @@ fn config_channel_task_pin( TaskOutPolarity::Toggle => w.polarity().toggle(), }; - #[cfg(any(feature = "52833", feature = "52840"))] + #[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))] { match pin.port() { Port::Port0 => w.port().clear_bit(), diff --git a/nrf-hal-common/src/lib.rs b/nrf-hal-common/src/lib.rs index 100a10fa..15082f9e 100644 --- a/nrf-hal-common/src/lib.rs +++ b/nrf-hal-common/src/lib.rs @@ -27,6 +27,9 @@ pub use nrf52840_pac as pac; #[cfg(feature = "5340-app")] pub use nrf5340_app_pac as pac; +#[cfg(feature = "5340-net")] +pub use nrf5340_net_pac as pac; + #[cfg(feature = "9160")] pub use nrf9160_pac as pac; @@ -35,7 +38,12 @@ pub mod adc; #[cfg(not(any(feature = "9160", feature = "5340-app")))] pub mod ccm; pub mod clocks; -#[cfg(not(any(feature = "51", feature = "9160", feature = "5340-app")))] +#[cfg(not(any( + feature = "51", + feature = "9160", + feature = "5340-app", + feature = "5340-net" +)))] pub mod comp; #[cfg(not(feature = "51"))] pub mod delay; @@ -44,7 +52,12 @@ pub mod ecb; pub mod gpio; #[cfg(not(feature = "5340-app"))] pub mod gpiote; -#[cfg(not(any(feature = "51", feature = "52810", feature = "52811")))] +#[cfg(not(any( + feature = "51", + feature = "52810", + feature = "52811", + feature = "5340-net" +)))] pub mod i2s; #[cfg(any(feature = "52833", feature = "52840"))] pub mod ieee802154; @@ -52,23 +65,29 @@ pub mod ieee802154; feature = "52811", feature = "52810", feature = "9160", - feature = "5340-app" + feature = "5340-app", + feature = "5340-net" )))] pub mod lpcomp; #[cfg(not(feature = "51"))] pub mod nvmc; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] pub mod ppi; -#[cfg(not(feature = "51"))] +#[cfg(not(any(feature = "51", feature = "5340-net")))] pub mod pwm; -#[cfg(not(any(feature = "51", feature = "9160", feature = "5340-app")))] +#[cfg(not(any( + feature = "51", + feature = "9160", + feature = "5340-app", + feature = "5340-net" +)))] pub mod qdec; #[cfg(not(any(feature = "9160", feature = "5340-app")))] pub mod rng; pub mod rtc; -#[cfg(not(feature = "51"))] +#[cfg(not(any(feature = "51", feature = "5340-net")))] pub mod saadc; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] pub mod spi; #[cfg(not(feature = "51"))] pub mod spim; @@ -88,7 +107,7 @@ pub mod twis; pub mod uart; #[cfg(not(feature = "51"))] pub mod uarte; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] pub mod uicr; #[cfg(feature = "nrf-usbd")] pub mod usbd; @@ -98,7 +117,7 @@ pub mod prelude { pub use crate::hal::digital::v2::*; pub use crate::hal::prelude::*; - #[cfg(not(any(feature = "9160", feature = "5340-app")))] + #[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] pub use crate::ppi::{ConfigurablePpi, Ppi}; pub use crate::time::U32Ext; } @@ -121,7 +140,7 @@ pub mod target_constants { pub const EASY_DMA_SIZE: usize = (1 << 16) - 1; #[cfg(feature = "52840")] pub const EASY_DMA_SIZE: usize = (1 << 16) - 1; - #[cfg(feature = "5340-app")] + #[cfg(any(feature = "5340-app", feature = "5340-net"))] pub const EASY_DMA_SIZE: usize = (1 << 16) - 1; #[cfg(feature = "9160")] pub const EASY_DMA_SIZE: usize = (1 << 12) - 1; @@ -187,7 +206,7 @@ pub use crate::timer::Timer; #[cfg(feature = "51")] pub use crate::adc::Adc; -#[cfg(not(feature = "51"))] +#[cfg(not(any(feature = "51", feature = "5340-net")))] pub use crate::saadc::Saadc; #[cfg(feature = "51")] diff --git a/nrf-hal-common/src/nvmc.rs b/nrf-hal-common/src/nvmc.rs index eb021499..3ff55087 100644 --- a/nrf-hal-common/src/nvmc.rs +++ b/nrf-hal-common/src/nvmc.rs @@ -2,13 +2,13 @@ use core::ops::Deref; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::nvmc; -#[cfg(any(feature = "9160", feature = "5340-app"))] +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] use crate::pac::nvmc_ns as nvmc; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::NVMC; -#[cfg(any(feature = "9160", feature = "5340-app"))] +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] use crate::pac::NVMC_NS as NVMC; use core::convert::TryInto; @@ -70,13 +70,13 @@ where while !self.nvmc.ready.read().ready().bit_is_set() {} } - #[cfg(any(feature = "9160", feature = "5340-app"))] + #[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] #[inline] fn wait_write_ready(&self) { while !self.nvmc.readynext.read().readynext().bit_is_set() {} } - #[cfg(not(any(feature = "9160", feature = "5340-app")))] + #[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] #[inline] fn erase_page(&mut self, page_offset: usize) { let bits = &mut (self.storage[page_offset * PAGE_SIZE]) as *mut _ as u32; @@ -84,7 +84,7 @@ where self.wait_ready(); } - #[cfg(any(feature = "9160", feature = "5340-app"))] + #[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] #[inline] fn erase_page(&mut self, page_offset: usize) { self.direct_write_word(page_offset * PAGE_SIZE / WORD_SIZE, 0xffffffff); @@ -93,9 +93,9 @@ where #[inline] fn write_word(&mut self, word_offset: usize, word: u32) { - #[cfg(not(any(feature = "9160", feature = "5340-app")))] + #[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] self.wait_ready(); - #[cfg(any(feature = "9160", feature = "5340-app"))] + #[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] self.wait_write_ready(); self.direct_write_word(word_offset, word); cortex_m::asm::dmb(); diff --git a/nrf-hal-common/src/rng.rs b/nrf-hal-common/src/rng.rs index 924e23a6..322a87a3 100644 --- a/nrf-hal-common/src/rng.rs +++ b/nrf-hal-common/src/rng.rs @@ -4,7 +4,10 @@ use rand_core::{CryptoRng, RngCore}; +#[cfg(not(feature = "5340-net"))] use crate::pac::RNG; +#[cfg(feature = "5340-net")] +use crate::pac::RNG_NS as RNG; /// Interface to the RNG peripheral. /// diff --git a/nrf-hal-common/src/rtc.rs b/nrf-hal-common/src/rtc.rs index c22a32a7..1c287a79 100644 --- a/nrf-hal-common/src/rtc.rs +++ b/nrf-hal-common/src/rtc.rs @@ -2,10 +2,10 @@ use core::ops::Deref; -#[cfg(any(feature = "9160", feature = "5340-app"))] +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] use crate::pac::{rtc0_ns as rtc0, Interrupt, NVIC, RTC0_NS as RTC0, RTC1_NS as RTC1}; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::{rtc0, Interrupt, NVIC, RTC0, RTC1}; #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] diff --git a/nrf-hal-common/src/spim.rs b/nrf-hal-common/src/spim.rs index 8b54d4cc..a43281cf 100644 --- a/nrf-hal-common/src/spim.rs +++ b/nrf-hal-common/src/spim.rs @@ -5,10 +5,10 @@ use core::ops::Deref; use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; -#[cfg(any(feature = "9160", feature = "5340-app"))] +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] use crate::pac::{spim0_ns as spim0, SPIM0_NS as SPIM0}; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::{spim0, SPIM0}; pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; diff --git a/nrf-hal-common/src/spis.rs b/nrf-hal-common/src/spis.rs index 2e4c7c12..621c3155 100644 --- a/nrf-hal-common/src/spis.rs +++ b/nrf-hal-common/src/spis.rs @@ -7,7 +7,7 @@ use core::{ sync::atomic::{compiler_fence, Ordering}, }; -#[cfg(any(feature = "9160", feature = "5340-app"))] +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] use crate::pac::{ spis0_ns::{ self as spis0, EVENTS_ACQUIRED, EVENTS_END, EVENTS_ENDRX, TASKS_ACQUIRE, TASKS_RELEASE, @@ -15,7 +15,7 @@ use crate::pac::{ SPIS0_NS as SPIS0, }; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::{ spis0::{self, EVENTS_ACQUIRED, EVENTS_END, EVENTS_ENDRX, TASKS_ACQUIRE, TASKS_RELEASE}, SPIS0, @@ -616,11 +616,17 @@ pub struct Pins { mod sealed { pub trait Sealed {} impl Sealed for super::SPIS0 {} - #[cfg(not(any(feature = "9160", feature = "5340-app", feature = "52810")))] + #[cfg(not(any( + feature = "9160", + feature = "5340-app", + feature = "5340-net", + feature = "52810" + )))] impl Sealed for super::SPIS1 {} #[cfg(not(any( feature = "9160", feature = "5340-app", + feature = "5340-net", feature = "52811", feature = "52810" )))] @@ -635,13 +641,14 @@ impl Instance for SPIS0 { #[cfg(not(any( feature = "9160", feature = "5340-app", + feature = "5340-net", feature = "52811", feature = "52810" )))] const INTERRUPT: Interrupt = Interrupt::SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0; #[cfg(feature = "9160")] const INTERRUPT: Interrupt = Interrupt::UARTE0_SPIM0_SPIS0_TWIM0_TWIS0; - #[cfg(feature = "5340-app")] + #[cfg(any(feature = "5340-app", feature = "5340-net"))] const INTERRUPT: Interrupt = Interrupt::SERIAL0; #[cfg(feature = "52810")] const INTERRUPT: Interrupt = Interrupt::SPIM0_SPIS0_SPI0; @@ -649,7 +656,12 @@ impl Instance for SPIS0 { const INTERRUPT: Interrupt = Interrupt::TWIM0_TWIS0_TWI0_SPIM0_SPIS0_SPI0; } -#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "52810")))] +#[cfg(not(any( + feature = "9160", + feature = "5340-app", + feature = "5340-net", + feature = "52810" +)))] impl Instance for SPIS1 { #[cfg(not(feature = "52811"))] const INTERRUPT: Interrupt = Interrupt::SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1; @@ -660,6 +672,7 @@ impl Instance for SPIS1 { #[cfg(not(any( feature = "9160", feature = "5340-app", + feature = "5340-net", feature = "52811", feature = "52810" )))] diff --git a/nrf-hal-common/src/temp.rs b/nrf-hal-common/src/temp.rs index f95df2ca..1285731b 100644 --- a/nrf-hal-common/src/temp.rs +++ b/nrf-hal-common/src/temp.rs @@ -1,6 +1,10 @@ //! Temperature sensor interface. +#[cfg(not(feature = "5340-net"))] use crate::pac::TEMP; +#[cfg(feature = "5340-net")] +use crate::pac::TEMP_NS as TEMP; + use fixed::types::I30F2; use void::Void; diff --git a/nrf-hal-common/src/timer.rs b/nrf-hal-common/src/timer.rs index 2bf5f1b4..e45b2fe8 100644 --- a/nrf-hal-common/src/timer.rs +++ b/nrf-hal-common/src/timer.rs @@ -2,7 +2,7 @@ //! //! See product specification, chapter 24. -#[cfg(any(feature = "9160", feature = "5340-app"))] +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] use crate::pac::{ timer0_ns::{ RegisterBlock as RegBlock0, EVENTS_COMPARE, TASKS_CAPTURE, TASKS_CLEAR, TASKS_COUNT, @@ -11,7 +11,7 @@ use crate::pac::{ Interrupt, TIMER0_NS as TIMER0, TIMER1_NS as TIMER1, TIMER2_NS as TIMER2, }; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::{ timer0::{ RegisterBlock as RegBlock0, EVENTS_COMPARE, TASKS_CAPTURE, TASKS_CLEAR, TASKS_COUNT, diff --git a/nrf-hal-common/src/twim.rs b/nrf-hal-common/src/twim.rs index bf71063c..086a984c 100644 --- a/nrf-hal-common/src/twim.rs +++ b/nrf-hal-common/src/twim.rs @@ -7,12 +7,13 @@ use core::ops::Deref; use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] +use crate::pac::{twim0_ns as twim0, TWIM0_NS as TWIM0}; + #[cfg(any(feature = "9160", feature = "5340-app"))] -use crate::pac::{ - twim0_ns as twim0, TWIM0_NS as TWIM0, TWIM1_NS as TWIM1, TWIM2_NS as TWIM2, TWIM3_NS as TWIM3, -}; +use crate::pac::{TWIM1_NS as TWIM1, TWIM2_NS as TWIM2, TWIM3_NS as TWIM3}; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::{twim0, TWIM0}; #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] @@ -181,7 +182,7 @@ where return Err(Error::DataNack); } if err.overrun().is_received() { - return Err(Error::DataNack); + return Err(Error::Overrun); } Ok(()) } diff --git a/nrf-hal-common/src/twis.rs b/nrf-hal-common/src/twis.rs index 91ccae5a..6b62dbd4 100644 --- a/nrf-hal-common/src/twis.rs +++ b/nrf-hal-common/src/twis.rs @@ -6,10 +6,10 @@ use core::{ sync::atomic::{compiler_fence, Ordering::SeqCst}, }; -#[cfg(any(feature = "9160", feature = "5340-app"))] +#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] use crate::pac::{twis0_ns as twis0, P0_NS as P0, TWIS0_NS as TWIS0}; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::{twis0, P0, TWIS0}; #[cfg(any(feature = "52832", feature = "52833", feature = "52840"))] @@ -551,11 +551,12 @@ impl Instance for TWIS0 { #[cfg(not(any( feature = "9160", feature = "5340-app", + feature = "5340-net", feature = "52810", feature = "52811" )))] const INTERRUPT: Interrupt = Interrupt::SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0; - #[cfg(feature = "5340-app")] + #[cfg(any(feature = "5340-app", feature = "5340-net"))] const INTERRUPT: Interrupt = Interrupt::SERIAL0; #[cfg(feature = "9160")] const INTERRUPT: Interrupt = Interrupt::UARTE0_SPIM0_SPIS0_TWIM0_TWIS0; diff --git a/nrf-hal-common/src/uarte.rs b/nrf-hal-common/src/uarte.rs index f42ce392..4d688584 100644 --- a/nrf-hal-common/src/uarte.rs +++ b/nrf-hal-common/src/uarte.rs @@ -18,10 +18,13 @@ use crate::pac::UARTE1; #[cfg(feature = "9160")] use crate::pac::{uarte0_ns as uarte0, UARTE0_NS as UARTE0, UARTE1_NS as UARTE1}; +#[cfg(any(feature = "5340-app", feature = "5340-net"))] +use crate::pac::{uarte0_ns as uarte0, UARTE0_NS as UARTE0}; + #[cfg(feature = "5340-app")] -use crate::pac::{uarte0_ns as uarte0, UARTE0_NS as UARTE0, UARTE1_NS as UARTE1}; +use crate::pac::UARTE1_NS as UARTE1; -#[cfg(not(any(feature = "9160", feature = "5340-app")))] +#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))] use crate::pac::{uarte0, UARTE0}; use crate::gpio::{Floating, Input, Output, Pin, PushPull}; diff --git a/nrf-hal-common/src/wdt.rs b/nrf-hal-common/src/wdt.rs index 9f93bf99..41f1f2a4 100644 --- a/nrf-hal-common/src/wdt.rs +++ b/nrf-hal-common/src/wdt.rs @@ -6,7 +6,7 @@ use cfg_if::cfg_if; cfg_if! { - if #[cfg(feature = "9160")] { + if #[cfg(any(feature = "9160", feature = "5340-net"))] { use crate::pac::WDT_NS as WDT; } else if #[cfg(feature = "5340-app")] { use crate::pac::WDT0_NS as WDT; @@ -214,7 +214,7 @@ where #[inline(always)] pub fn is_active(&self) -> bool { cfg_if! { - if #[cfg(any(feature = "9160", feature = "5340-app"))] { + if #[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))] { self.wdt.runstatus.read().runstatuswdt().bit_is_set() } else { self.wdt.runstatus.read().runstatus().bit_is_set() diff --git a/nrf5340-net-hal/Cargo.toml b/nrf5340-net-hal/Cargo.toml new file mode 100644 index 00000000..bbe1206c --- /dev/null +++ b/nrf5340-net-hal/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "nrf5340-net-hal" +version = "0.15.0" +description = "HAL for nRF5340 net SoC" +readme = "../README.md" + +repository = "https://github.com/nrf-rs/nrf-hal" + +categories = ["embedded", "hardware-support", "no-std"] +keywords = ["arm", "cortex-m", "nrf53", "hal", "nrf5340"] +license = "MIT OR Apache-2.0" +edition = "2018" + +[dependencies] +nrf5340-net-pac = "0.11.0" + +[dependencies.nrf-hal-common] +path = "../nrf-hal-common" +default-features = false +features = ["5340-net"] +version = "=0.15.0" + +[dependencies.embedded-hal] +features = ["unproven"] +version = "0.2.3" + +[features] +doc = [] +rt = ["nrf5340-net-pac/rt"] +default = ["rt"] diff --git a/nrf5340-net-hal/build.rs b/nrf5340-net-hal/build.rs new file mode 100644 index 00000000..88f7fef8 --- /dev/null +++ b/nrf5340-net-hal/build.rs @@ -0,0 +1,17 @@ +use std::env; +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put the linker script somewhere the linker can find it + let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); + File::create(out.join("memory.x")) + .unwrap() + .write_all(include_bytes!("memory.x")) + .unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=memory.x"); +} diff --git a/nrf5340-net-hal/memory.x b/nrf5340-net-hal/memory.x new file mode 100644 index 00000000..7af63d8c --- /dev/null +++ b/nrf5340-net-hal/memory.x @@ -0,0 +1,6 @@ +MEMORY +{ + FLASH : ORIGIN = 0x01000000, LENGTH = 256K + RAM : ORIGIN = 0x21000000, LENGTH = 64K +} + diff --git a/nrf5340-net-hal/src/lib.rs b/nrf5340-net-hal/src/lib.rs new file mode 100644 index 00000000..9afd96ae --- /dev/null +++ b/nrf5340-net-hal/src/lib.rs @@ -0,0 +1,18 @@ +#![no_std] +#![doc(html_root_url = "https://docs.rs/nrf5340-net-hal/0.15.0")] + +use embedded_hal as hal; +pub use nrf_hal_common::*; + +pub mod prelude { + pub use crate::hal::prelude::*; + pub use crate::time::U32Ext; + pub use nrf_hal_common::prelude::*; +} +pub use crate::clocks::Clocks; +pub use crate::delay::Delay; +pub use crate::rtc::Rtc; +pub use crate::spim::Spim; +pub use crate::timer::Timer; +pub use crate::twim::Twim; +pub use crate::uarte::Uarte; diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 52f45dd0..c853fb0d 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -4,6 +4,7 @@ pub static HALS: &[(&str, &str)] = &[ ("nrf51-hal", "thumbv6m-none-eabi"), ("nrf9160-hal", "thumbv8m.main-none-eabihf"), ("nrf5340-app-hal", "thumbv8m.main-none-eabihf"), + ("nrf5340-net-hal", "thumbv8m.main-none-eabihf"), ("nrf52810-hal", "thumbv7em-none-eabi"), ("nrf52811-hal", "thumbv7em-none-eabi"), ("nrf52832-hal", "thumbv7em-none-eabihf"), @@ -48,7 +49,7 @@ pub fn feature_to_target(feat: &str) -> &str { match feat { "51" => "thumbv6m-none-eabi", "52810" | "52811" => "thumbv7em-none-eabi", - "9160" | "5340-app" => "thumbv8m.main-none-eabihf", + "9160" | "5340-app" | "5340-net" => "thumbv8m.main-none-eabihf", _ if feat.starts_with("52") => "thumbv7em-none-eabihf", _ => panic!("unknown Cargo feature `{}`", feat), }