Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion hal-bind/atomic-once-cell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ impl<T> AtomicOnceCell<T> {

pub fn set<'a>(&'a self, new: &'a T) -> &'a T {
self.ptr
.store((new as *const T).cast_mut(), Ordering::SeqCst);
.store(core::ptr::from_ref::<T>(new).cast_mut(), Ordering::SeqCst);
new
}
}

impl<T> Default for AtomicOnceCell<T> {
fn default() -> Self {
Self::new()
}
}
2 changes: 1 addition & 1 deletion monazite-rt/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where
let dma_config = DmaConfig::default()
.memory_increment(true)
.circular_buffer(true);
let dma_buf = unsafe { core::slice::from_raw_parts_mut(buf as *mut u16, buf.len()) };
let dma_buf = unsafe { core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()) };
let mut transfer: Transfer<_, _, _, _, _> =
Transfer::init(dma_stream, adc, dma_buf, None, dma_config);

Expand Down
8 changes: 7 additions & 1 deletion monazite-rt/src/defmt_rtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ unsafe impl defmt::Logger for Logger {
INTERRUPTS_ACTIVE.store(primask.is_active(), Ordering::Relaxed);

// safety: accessing the `static mut` is OK because we have disabled interrupts.
unsafe { ENCODER.start_frame(do_write) }
#[allow(static_mut_refs)]
unsafe {
ENCODER.start_frame(do_write);
}
}

unsafe fn flush() {}

unsafe fn release() {
// safety: accessing the `static mut` is OK because we have disabled interrupts.
#[allow(static_mut_refs)]
ENCODER.end_frame(do_write);

TAKEN.store(false, Ordering::Relaxed);
Expand All @@ -50,12 +54,14 @@ unsafe impl defmt::Logger for Logger {

unsafe fn write(bytes: &[u8]) {
// safety: accessing the `static mut` is OK because we have disabled interrupts.
#[allow(static_mut_refs)]
ENCODER.write(bytes, do_write);
}
}

fn do_write(bytes: &[u8]) {
unsafe {
#[allow(static_mut_refs)]
if let Some(c) = &mut CHANNEL {
c.write(bytes);
}
Expand Down
8 changes: 8 additions & 0 deletions monazite-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ fn init_wdt(res: resources::Wdt) {
fn init_ramecc(res: resources::Ramecc) -> ramecc::RamScrubber {
#[link_section = ".sram1.eccbuf"]
static mut ECC_DST_BUFFER: MaybeUninit<[u32; 1]> = MaybeUninit::uninit();
// This buf is not referenced by multiple sources simultaneously.
#[allow(static_mut_refs)]
let ecc_dst_buf = unsafe { ECC_DST_BUFFER.write([0; 1]) };

let ecc_stats = singleton!(: ramecc::EccStats = ramecc::EccStats::default()).unwrap();
Expand Down Expand Up @@ -429,6 +431,8 @@ fn init_iflash(res: resources::Iflash) -> &'static iflash::Iflash {
#[no_mangle]
#[link_section = ".sram1.iflashbuf"]
static mut IFLASH_BUF: MaybeUninit<[u8; 128]> = MaybeUninit::uninit();
// singleton! guarantees that only one instance can reference at a time.
#[allow(static_mut_refs)]
let iflash_buf = unsafe { IFLASH_BUF.write([0; 128]) };

let iflash = iflash::Iflash::new(res.flash, iflash_buf);
Expand Down Expand Up @@ -470,6 +474,8 @@ fn init_adc(res: resources::Adc, shared: &mut resources::Shared) {
#[link_section = ".sram1.adcbuf"]
static mut ADC_BUFFER: MaybeUninit<[u16; crate::adc::TOTAL_CHANNEL_NUM]> =
MaybeUninit::uninit();
// singleton! guarantees that only one instance can reference at a time.
#[allow(static_mut_refs)]
let adc_buf = unsafe { ADC_BUFFER.write([0; crate::adc::TOTAL_CHANNEL_NUM]) };
let adc2 = hal::adc::Adc::adc2(
res.adc2,
Expand Down Expand Up @@ -498,6 +504,8 @@ fn init_thermometer(res: resources::Thermometer, shared: &mut resources::Shared)
// adc3 for thermometer
#[link_section = ".sram1.thermobuf"]
static mut THERMO_BUFFER: MaybeUninit<[u16; 1]> = MaybeUninit::uninit();
// singleton! guarantees that only one instance can reference at a time.
#[allow(static_mut_refs)]
let buf = unsafe { THERMO_BUFFER.write([0; 1]) };
let adc3 = hal::adc::Adc::adc3(
res.adc3,
Expand Down
2 changes: 1 addition & 1 deletion monazite-rt/src/thermometer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
let dma_config = DmaConfig::default()
.memory_increment(false)
.circular_buffer(true);
let dma_buf = unsafe { core::slice::from_raw_parts_mut(buf as *mut u16, buf.len()) };
let dma_buf = unsafe { core::slice::from_raw_parts_mut(buf.as_mut_ptr(), buf.len()) };
let mut transfer: Transfer<_, _, _, _, _> =
Transfer::init(dma_stream, adc, dma_buf, None, dma_config);

Expand Down
Loading