Skip to content

Commit dcfb7f3

Browse files
committed
fix warning: taking a mutable reference to a const item
1 parent 2366617 commit dcfb7f3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/peripheral/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
5858
use core::marker::PhantomData;
5959
use core::ops;
60+
use core::ptr::NonNull;
6061

6162
use crate::interrupt;
6263

@@ -408,12 +409,12 @@ unsafe impl Send for ICB {}
408409

409410
impl ICB {
410411
/// Pointer to the register block
411-
pub const PTR: *mut icb::RegisterBlock = 0xE000_E004 as *mut _;
412+
pub const PTR: NonNull<icb::RegisterBlock> = unsafe { NonNull::new_unchecked(0xE000_E004 as *mut _) };
412413

413414
/// Returns a pointer to the register block (to be deprecated in 0.7)
414415
#[inline(always)]
415416
pub const fn ptr() -> *mut icb::RegisterBlock {
416-
Self::PTR
417+
Self::PTR.as_ptr()
417418
}
418419
}
419420

@@ -422,14 +423,14 @@ impl ops::Deref for ICB {
422423

423424
#[inline(always)]
424425
fn deref(&self) -> &Self::Target {
425-
unsafe { &*Self::PTR }
426+
unsafe { Self::PTR.as_ref() }
426427
}
427428
}
428429

429430
impl ops::DerefMut for ICB {
430431
#[inline(always)]
431432
fn deref_mut(&mut self) -> &mut Self::Target {
432-
unsafe { &mut *Self::PTR }
433+
unsafe { &mut *Self::ptr() }
433434
}
434435
}
435436

@@ -443,12 +444,12 @@ unsafe impl Send for ITM {}
443444
#[cfg(all(not(armv6m), not(armv8m_base)))]
444445
impl ITM {
445446
/// Pointer to the register block
446-
pub const PTR: *mut itm::RegisterBlock = 0xE000_0000 as *mut _;
447+
pub const PTR: NonNull<itm::RegisterBlock> = unsafe { NonNull::new_unchecked(0xE000_0000 as *mut _) };
447448

448449
/// Returns a pointer to the register block (to be deprecated in 0.7)
449450
#[inline(always)]
450451
pub const fn ptr() -> *mut itm::RegisterBlock {
451-
Self::PTR
452+
Self::PTR.as_ptr()
452453
}
453454
}
454455

@@ -458,15 +459,15 @@ impl ops::Deref for ITM {
458459

459460
#[inline(always)]
460461
fn deref(&self) -> &Self::Target {
461-
unsafe { &*Self::PTR }
462+
unsafe { Self::PTR.as_ref() }
462463
}
463464
}
464465

465466
#[cfg(all(not(armv6m), not(armv8m_base)))]
466467
impl ops::DerefMut for ITM {
467468
#[inline(always)]
468469
fn deref_mut(&mut self) -> &mut Self::Target {
469-
unsafe { &mut *Self::PTR }
470+
unsafe { &mut *Self::ptr() }
470471
}
471472
}
472473

0 commit comments

Comments
 (0)