Skip to content

Commit 56e2752

Browse files
bors[bot]Sandra ter Maat
andauthored
Merge #386
386: Nrf5340 netcore r=jonas-schievink a=Sandraak Added support for the nrf5340-netcore. This support consists mostly of cfg annotations and some very small adjustments. Co-authored-by: Sandra ter Maat <[email protected]>
2 parents 5233608 + edffa59 commit 56e2752

File tree

26 files changed

+288
-83
lines changed

26 files changed

+288
-83
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Fixed the nvmc erase procedure on nRF91 & nRF53 ([#387])
6+
- Added support for the nrf5340-net-core.
67

78
## [0.15.0]
89

Cargo.ci.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"nrf52840-hal",
1010
"nrf52840-hal-tests",
1111
"nrf5340-app-hal",
12+
"nrf5340-net-hal",
1213
"nrf9160-hal",
1314
"examples/*",
1415
]

nrf-hal-common/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ version = "0.11.0"
6464
optional = true
6565
version = "0.11.0"
6666

67+
[dependencies.nrf5340-net-pac]
68+
optional = true
69+
version = "0.11.0"
70+
6771
[dependencies.nrf9160-pac]
6872
optional = true
6973
version = "0.11.0"
@@ -85,4 +89,5 @@ doc = []
8589
52833 = ["nrf52833-pac", "nrf-usbd"]
8690
52840 = ["nrf52840-pac", "nrf-usbd"]
8791
5340-app = ["nrf5340-app-pac"]
92+
5340-net = ["nrf5340-net-pac"]
8893
9160 = ["nrf9160-pac"]

nrf-hal-common/src/adc.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ where
9191
5 => self.0.config.modify(|_, w| w.psel().analog_input5()),
9292
6 => self.0.config.modify(|_, w| w.psel().analog_input6()),
9393
7 => self.0.config.modify(|_, w| w.psel().analog_input7()),
94-
8 => self.0.config.modify(|_, w| w.inpsel().supply_one_third_prescaling()),
95-
9 => self.0.config.modify(|_, w| w.inpsel().supply_two_thirds_prescaling()),
94+
8 => self
95+
.0
96+
.config
97+
.modify(|_, w| w.inpsel().supply_one_third_prescaling()),
98+
9 => self
99+
.0
100+
.config
101+
.modify(|_, w| w.inpsel().supply_two_thirds_prescaling()),
96102
// This can never happen the only analog pins have already been defined
97103
// PAY CLOSE ATTENTION TO ANY CHANGES TO THIS IMPL OR THE `channel_mappings!` MACRO
98104
_ => unsafe { unreachable_unchecked() },
@@ -105,7 +111,9 @@ where
105111

106112
self.0.events_end.write(|w| unsafe { w.bits(0) });
107113
// Restore original input selection
108-
self.0.config.modify(|_, w| w.inpsel().variant(original_inpsel.variant().unwrap()));
114+
self.0
115+
.config
116+
.modify(|_, w| w.inpsel().variant(original_inpsel.variant().unwrap()));
109117

110118
// Max resolution is 10 bits so casting is always safe
111119
Ok(self.0.result.read().result().bits() as i16)

nrf-hal-common/src/ccm.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,26 @@
4545
//! encryption/decryption. The scratch slice must have a minimum length of 43 bytes, or
4646
//! (16 + `Packet Length`) bytes, whatever is largest.
4747
48+
#[cfg(not(feature = "5340-net"))]
4849
use crate::{
4950
pac::{AAR, CCM},
5051
slice_in_ram,
5152
};
53+
54+
#[cfg(feature = "5340-net")]
55+
use crate::{
56+
pac::{AAR_NS as AAR, CCM_NS as CCM},
57+
slice_in_ram,
58+
};
59+
5260
use core::sync::atomic::{compiler_fence, Ordering};
5361

54-
#[cfg(not(feature = "51"))]
62+
#[cfg(not(any(feature = "51", feature = "5340-net")))]
5563
use crate::pac::ccm::mode::{DATARATE_A, LENGTH_A};
5664

65+
#[cfg(feature = "5340-net")]
66+
use crate::pac::ccm_ns::mode::{DATARATE_A, LENGTH_A};
67+
5768
const MINIMUM_SCRATCH_AREA_SIZE: usize = 43;
5869
const HEADER_SIZE: usize = 3;
5970
const LENGTH_HEADER_INDEX: usize = 1;
@@ -69,15 +80,22 @@ pub enum DataRate {
6980
_1Mbit,
7081
#[cfg(not(feature = "51"))]
7182
_2Mbit,
83+
#[cfg(feature = "5340-net")]
84+
_125Kbps,
85+
#[cfg(feature = "5340-net")]
86+
_500Kbps,
7287
}
7388

7489
#[cfg(not(feature = "51"))]
7590
impl From<DataRate> for DATARATE_A {
7691
fn from(data_rate: DataRate) -> Self {
77-
if data_rate == DataRate::_1Mbit {
78-
DATARATE_A::_1MBIT
79-
} else {
80-
DATARATE_A::_2MBIT
92+
match data_rate {
93+
DataRate::_1Mbit => DATARATE_A::_1MBIT,
94+
DataRate::_2Mbit => DATARATE_A::_2MBIT,
95+
#[cfg(feature = "5340-net")]
96+
DataRate::_125Kbps => DATARATE_A::_125KBPS,
97+
#[cfg(feature = "5340-net")]
98+
DataRate::_500Kbps => DATARATE_A::_500KBPS,
8199
}
82100
}
83101
}
@@ -253,7 +271,8 @@ impl Ccm {
253271
feature = "52840",
254272
feature = "52833",
255273
feature = "52811",
256-
feature = "52810"
274+
feature = "52810",
275+
feature = "5340-net"
257276
))]
258277
// NOTE(unsafe) Any 8bits pattern is safe to write to this register
259278
self.regs
@@ -382,7 +401,8 @@ impl Ccm {
382401
feature = "52840",
383402
feature = "52833",
384403
feature = "52811",
385-
feature = "52810"
404+
feature = "52810",
405+
feature = "5340-net"
386406
))]
387407
// NOTE(unsafe) Any 8bits pattern is safe to write to this register
388408
self.regs

nrf-hal-common/src/clocks.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Configuration and control of the High and Low Frequency Clock sources.
22
3-
#[cfg(any(feature = "9160", feature = "5340-app"))]
3+
#[cfg(any(feature = "9160", feature = "5340-app", feature = "5340-net"))]
44
use crate::pac::CLOCK_NS as CLOCK;
55

6-
#[cfg(not(any(feature = "9160", feature = "5340-app")))]
6+
#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "5340-net")))]
77
use crate::pac::CLOCK;
88

99
// ZST Type States
@@ -156,7 +156,12 @@ impl<H, L> Clocks<H, L, LfOscStopped> {
156156
}
157157

158158
/// Use the internal RC Oscillator for the low frequency clock source.
159-
#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))]
159+
#[cfg(not(any(
160+
feature = "9160",
161+
feature = "5340-app",
162+
feature = "5340-net",
163+
feature = "51"
164+
)))]
160165
pub fn set_lfclk_src_rc(self) -> Clocks<H, Internal, LfOscStopped> {
161166
self.periph
162167
.lfclksrc
@@ -170,7 +175,12 @@ impl<H, L> Clocks<H, L, LfOscStopped> {
170175
}
171176

172177
/// Generate the Low Frequency clock from the high frequency clock source.
173-
#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))]
178+
#[cfg(not(any(
179+
feature = "9160",
180+
feature = "5340-app",
181+
feature = "5340-net",
182+
feature = "51"
183+
)))]
174184
pub fn set_lfclk_src_synth(self) -> Clocks<H, LfOscSynthesized, LfOscStopped> {
175185
self.periph
176186
.lfclksrc
@@ -184,7 +194,12 @@ impl<H, L> Clocks<H, L, LfOscStopped> {
184194
}
185195

186196
/// Use an external crystal to drive the low frequency clock.
187-
#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))]
197+
#[cfg(not(any(
198+
feature = "9160",
199+
feature = "5340-app",
200+
feature = "5340-net",
201+
feature = "51"
202+
)))]
188203
pub fn set_lfclk_src_external(
189204
self,
190205
cfg: LfOscConfiguration,

nrf-hal-common/src/ecb.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
//!
33
//! The ECB encryption block supports 128 bit AES encryption (encryption only, not decryption).
44
5+
#[cfg(not(feature = "5340-net"))]
56
use crate::pac::ECB;
7+
#[cfg(feature = "5340-net")]
8+
use crate::pac::ECB_NS as ECB;
9+
610
use core::sync::atomic::{compiler_fence, Ordering};
711

812
/// Error type to represent a sharing conflict during encryption.

nrf-hal-common/src/gpio.rs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ pub enum Port {
4040
/// Port 0 Secure, available on nRF53
4141
#[cfg(any(feature = "5340-app"))]
4242
Port0Secure,
43-
44-
/// Port 1, only available on some nRF52 MCUs.
45-
#[cfg(any(feature = "52833", feature = "52840"))]
43+
/// Port 1, only available on some nRF52 MCUs and nRF5340.
44+
#[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))]
4645
Port1,
4746
}
4847

@@ -63,18 +62,26 @@ pub struct Pin<MODE> {
6362
#[cfg(feature = "51")]
6463
use crate::pac::{gpio, GPIO as P0};
6564

66-
#[cfg(any(feature = "5340-app", feature = "9160"))]
65+
#[cfg(any(feature = "5340-app", feature = "5340-net", feature = "9160"))]
6766
use crate::pac::{p0_ns as gpio, P0_NS as P0};
6867

6968
#[cfg(feature = "5340-app")]
7069
use crate::pac::P0_S;
7170

72-
#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))]
71+
#[cfg(not(any(
72+
feature = "9160",
73+
feature = "5340-app",
74+
feature = "5340-net",
75+
feature = "51"
76+
)))]
7377
use crate::pac::{p0 as gpio, P0};
7478

7579
#[cfg(any(feature = "52833", feature = "52840"))]
7680
use crate::pac::P1;
7781

82+
#[cfg(feature = "5340-net")]
83+
use crate::pac::P1_NS as P1;
84+
7885
use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
7986
use void::Void;
8087

@@ -84,7 +91,7 @@ impl<MODE> Pin<MODE> {
8491
Port::Port0 => 0x00,
8592
#[cfg(any(feature = "5340-app"))]
8693
Port::Port0Secure => 0x20,
87-
#[cfg(any(feature = "52833", feature = "52840"))]
94+
#[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))]
8895
Port::Port1 => 0x20,
8996
};
9097
Self {
@@ -102,20 +109,30 @@ impl<MODE> Pin<MODE> {
102109

103110
#[inline]
104111
pub fn pin(&self) -> u8 {
105-
#[cfg(any(feature = "52833", feature = "52840", feature = "5340-app"))]
112+
#[cfg(any(
113+
feature = "52833",
114+
feature = "52840",
115+
feature = "5340-app",
116+
feature = "5340-net"
117+
))]
106118
{
107119
self.pin_port & 0x1f
108120
}
109121

110-
#[cfg(not(any(feature = "52833", feature = "52840", feature = "5340-app")))]
122+
#[cfg(not(any(
123+
feature = "52833",
124+
feature = "52840",
125+
feature = "5340-app",
126+
feature = "5340-net"
127+
)))]
111128
{
112129
self.pin_port
113130
}
114131
}
115132

116133
#[inline]
117134
pub fn port(&self) -> Port {
118-
#[cfg(any(feature = "52833", feature = "52840"))]
135+
#[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))]
119136
{
120137
if self.pin_port & 0x20 == 0 {
121138
Port::Port0
@@ -132,8 +149,12 @@ impl<MODE> Pin<MODE> {
132149
Port::Port0Secure
133150
}
134151
}
135-
136-
#[cfg(not(any(feature = "52833", feature = "52840", feature = "5340-app")))]
152+
#[cfg(not(any(
153+
feature = "52833",
154+
feature = "52840",
155+
feature = "5340-app",
156+
feature = "5340-net"
157+
)))]
137158
{
138159
Port::Port0
139160
}
@@ -147,9 +168,9 @@ impl<MODE> Pin<MODE> {
147168
fn block(&self) -> &gpio::RegisterBlock {
148169
let ptr = match self.port() {
149170
Port::Port0 => P0::ptr(),
150-
#[cfg(any(feature = "5340-app"))]
171+
#[cfg(feature = "5340-app")]
151172
Port::Port0Secure => P0_S::ptr(),
152-
#[cfg(any(feature = "52833", feature = "52840"))]
173+
#[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))]
153174
Port::Port1 => P1::ptr(),
154175
};
155176

@@ -339,10 +360,15 @@ pub enum OpenDrainConfig {
339360
#[cfg(feature = "51")]
340361
use crate::pac::gpio::pin_cnf;
341362

342-
#[cfg(any(feature = "5340-app", feature = "9160"))]
363+
#[cfg(any(feature = "5340-app", feature = "5340-net", feature = "9160"))]
343364
use crate::pac::p0_ns::pin_cnf;
344365

345-
#[cfg(not(any(feature = "9160", feature = "5340-app", feature = "51")))]
366+
#[cfg(not(any(
367+
feature = "9160",
368+
feature = "5340-app",
369+
feature = "5340-net",
370+
feature = "51"
371+
)))]
346372
use crate::pac::p0::pin_cnf;
347373

348374
impl OpenDrainConfig {
@@ -647,7 +673,7 @@ gpio!(P0, p0, p0, Port::Port0, [
647673

648674
// The p1 types are present in the p0 module generated from the
649675
// svd, but we want to export them in a p1 module from this crate.
650-
#[cfg(any(feature = "52833", feature = "52840"))]
676+
#[cfg(any(feature = "52833", feature = "52840", feature = "5340-net"))]
651677
gpio!(P1, p0, p1, Port::Port1, [
652678
P1_00: (p1_00, 0, Disconnected),
653679
P1_01: (p1_01, 1, Disconnected),
@@ -667,7 +693,7 @@ gpio!(P1, p0, p1, Port::Port1, [
667693
P1_15: (p1_15, 15, Disconnected),
668694
]);
669695

670-
#[cfg(any(feature = "5340-app"))]
696+
#[cfg(feature = "5340-app")]
671697
gpio!(P0_S, p0, p0_s, Port::Port0Secure, [
672698
P0_00: (p0_00, 0, Disconnected),
673699
P0_01: (p0_01, 1, Disconnected),

0 commit comments

Comments
 (0)