Skip to content

Commit b521579

Browse files
committed
Port puzzle and loopback firmware to new HAL
1 parent 83402ed commit b521579

File tree

16 files changed

+2139
-1053
lines changed

16 files changed

+2139
-1053
lines changed

justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ build-qemu-uart-driver-ferrocene:
7373
build-radio-app:
7474
cd nrf52-code/radio-app && cargo build --release
7575

76+
build-hal-app:
77+
cd nrf52-code/hal-app && cargo build --release
78+
7679
build-usb-app:
7780
cd nrf52-code/usb-app && cargo build --release
7881
cd nrf52-code/usb-app-solutions && cargo build --release
@@ -90,7 +93,7 @@ build-puzzle-fw:
9093
build-loopback-fw:
9194
cd nrf52-code/loopback-fw && cargo build --release
9295

93-
build-nrf52-code: build-radio-app build-usb-app test-usb-lib build-puzzle-fw build-loopback-fw
96+
build-nrf52-code: build-radio-app build-usb-app test-usb-lib build-puzzle-fw build-loopback-fw build-hal-app
9497

9598
assemble version:
9699
echo "Making ./rust-exercises-{{ version }}..."

nrf52-code/boards/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Cargo.lock
1+
Cargo.lock
2+
target

nrf52-code/boards/dk-solution/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nrf52-code/boards/dk-solution/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use core::{
1515
hint::spin_loop,
16-
sync::atomic::{self, AtomicU32, Ordering},
16+
sync::atomic::{self, AtomicBool, AtomicU32, Ordering},
1717
time::Duration,
1818
};
1919

@@ -51,7 +51,7 @@ pub struct Board {
5151
/// Radio interface
5252
#[cfg(feature = "radio")]
5353
pub radio: crate::radio::Radio<'static>,
54-
/// USBD (Universal Serial Bus Device) peripheral
54+
/// Raw register block for the USBD peripheral.
5555
#[cfg(any(feature = "advanced", feature = "usbd"))]
5656
pub usbd: hal::pac::usbd::Usbd,
5757
/// POWER (Power Supply) peripheral
@@ -319,10 +319,15 @@ pub enum Error {
319319
DoubleInit = 1,
320320
}
321321

322+
// Atomic flag to detect double initialization of the HAL.
323+
static HAL_INIT: AtomicBool = AtomicBool::new(false);
324+
322325
/// Initializes the board
323-
///
324-
/// This return an `Err`or if called more than once
325326
pub fn init() -> Result<Board, Error> {
327+
if HAL_INIT.swap(true, Ordering::Relaxed) {
328+
return Err(Error::DoubleInit);
329+
}
330+
326331
// NOTE: this branch runs at most once
327332
#[cfg(feature = "advanced")]
328333
static EP0IN_BUF: GroundedArrayCell<u8, 64> = GroundedArrayCell::const_init();

nrf52-code/boards/dk/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use core::{
1313
hint::spin_loop,
14-
sync::atomic::{self, AtomicU32, Ordering},
14+
sync::atomic::{self, AtomicBool, AtomicU32, Ordering},
1515
time::Duration,
1616
};
1717

@@ -47,7 +47,7 @@ pub struct Board {
4747
/// Radio interface
4848
#[cfg(feature = "radio")]
4949
pub radio: crate::radio::Radio<'static>,
50-
/// USBD (Universal Serial Bus Device) peripheral
50+
/// Raw register block for the USBD peripheral.
5151
#[cfg(any(feature = "advanced", feature = "usbd"))]
5252
pub usbd: hal::pac::usbd::Usbd,
5353
/// POWER (Power Supply) peripheral
@@ -291,10 +291,15 @@ pub enum Error {
291291
DoubleInit = 1,
292292
}
293293

294+
// Atomic flag to detect double initialization of the HAL.
295+
static HAL_INIT: AtomicBool = AtomicBool::new(false);
296+
294297
/// Initializes the board
295-
///
296-
/// This return an `Err`or if called more than once
297-
pub fn init() -> Result<Board, Error> {
298+
pub fn init() -> Result<Board, Error>{
299+
if HAL_INIT.swap(true, Ordering::Relaxed) {
300+
return Err(Error::DoubleInit);
301+
}
302+
298303
// NOTE: this branch runs at most once
299304
#[cfg(feature = "advanced")]
300305
static EP0IN_BUF: GroundedArrayCell<u8, 64> = GroundedArrayCell::const_init();

0 commit comments

Comments
 (0)