From 2b2149406ba4e695ebe265dc65aea222b6dbdf52 Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Sat, 14 Dec 2024 16:59:14 +0100 Subject: [PATCH] allow static_mut_refs --- examples/dma.rs | 6 +++++- examples/ethernet-nucleo-h743zi2.rs | 2 ++ examples/ethernet-rtic-nucleo-h723zg.rs | 4 ++++ examples/ethernet-rtic-stm32h735g-dk.rs | 4 ++++ examples/ethernet-rtic-stm32h747i-disco.rs | 4 ++++ examples/ethernet-stm32h747i-disco.rs | 2 ++ examples/i2c4_bdma.rs | 6 +++++- examples/mdma.rs | 6 +++++- examples/mdma_bursts.rs | 7 ++++++- examples/sai_dma_passthru.rs | 7 +++++++ examples/serial-dma.rs | 5 ++++- examples/spi-dma-rtic.rs | 5 ++++- examples/spi-dma.rs | 5 ++++- examples/usb_passthrough.rs | 2 ++ examples/usb_phy_serial_interrupt.rs | 8 +++++++- examples/usb_rtic.rs | 1 + examples/usb_serial.rs | 1 + 17 files changed, 67 insertions(+), 8 deletions(-) diff --git a/examples/dma.rs b/examples/dma.rs index c1ec1762..66bf8e6c 100644 --- a/examples/dma.rs +++ b/examples/dma.rs @@ -66,7 +66,10 @@ fn main() -> ! { value.as_mut_ptr().write(rng.gen().unwrap()); } } - unsafe { SOURCE_BUFFER.assume_init_mut() } + #[allow(static_mut_refs)] // TODO: Fix this + unsafe { + SOURCE_BUFFER.assume_init_mut() + } }; // Save a copy on the stack so we can check it later let source_buffer_cloned = *source_buffer; @@ -102,6 +105,7 @@ fn main() -> ! { while !transfer.get_transfer_complete_flag() {} // Now the target memory is actually initialised + #[allow(static_mut_refs)] // TODO: Fix this let target_buffer: &'static mut [u32; 20] = unsafe { TARGET_BUFFER.assume_init_mut() }; diff --git a/examples/ethernet-nucleo-h743zi2.rs b/examples/ethernet-nucleo-h743zi2.rs index 917f56d8..787ca35c 100644 --- a/examples/ethernet-nucleo-h743zi2.rs +++ b/examples/ethernet-nucleo-h743zi2.rs @@ -114,6 +114,7 @@ fn main() -> ! { let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS); let (_eth_dma, eth_mac) = unsafe { + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.write(ethernet::DesRing::new()); ethernet::new( @@ -131,6 +132,7 @@ fn main() -> ! { rmii_txd0, rmii_txd1, ), + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.assume_init_mut(), mac_addr, ccdr.peripheral.ETH1MAC, diff --git a/examples/ethernet-rtic-nucleo-h723zg.rs b/examples/ethernet-rtic-nucleo-h723zg.rs index b155bec7..4927115c 100644 --- a/examples/ethernet-rtic-nucleo-h723zg.rs +++ b/examples/ethernet-rtic-nucleo-h723zg.rs @@ -164,6 +164,7 @@ mod app { let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS); let (eth_dma, eth_mac) = unsafe { + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.write(ethernet::DesRing::new()); ethernet::new( @@ -181,6 +182,7 @@ mod app { rmii_txd0, rmii_txd1, ), + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.assume_init_mut(), mac_addr, ccdr.peripheral.ETH1MAC, @@ -198,6 +200,7 @@ mod app { // unsafe: mutable reference to static storage, we only do this once let store = unsafe { + #[allow(static_mut_refs)] // TODO: Fix this let store_ptr = STORE.as_mut_ptr(); // Initialise the socket_storage field. Using `write` instead of @@ -208,6 +211,7 @@ mod app { // Now that all fields are initialised we can safely use // assume_init_mut to return a mutable reference to STORE + #[allow(static_mut_refs)] // TODO: Fix this STORE.assume_init_mut() }; diff --git a/examples/ethernet-rtic-stm32h735g-dk.rs b/examples/ethernet-rtic-stm32h735g-dk.rs index 9cedf52b..d7449504 100644 --- a/examples/ethernet-rtic-stm32h735g-dk.rs +++ b/examples/ethernet-rtic-stm32h735g-dk.rs @@ -158,6 +158,7 @@ mod app { let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS); let (eth_dma, eth_mac) = unsafe { + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.write(ethernet::DesRing::new()); ethernet::new( @@ -175,6 +176,7 @@ mod app { rmii_txd0, rmii_txd1, ), + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.assume_init_mut(), mac_addr, ccdr.peripheral.ETH1MAC, @@ -192,6 +194,7 @@ mod app { // unsafe: mutable reference to static storage, we only do this once let store = unsafe { + #[allow(static_mut_refs)] // TODO: Fix this let store_ptr = STORE.as_mut_ptr(); // Initialise the socket_storage field. Using `write` instead of @@ -202,6 +205,7 @@ mod app { // Now that all fields are initialised we can safely use // assume_init_mut to return a mutable reference to STORE + #[allow(static_mut_refs)] // TODO: Fix this STORE.assume_init_mut() }; diff --git a/examples/ethernet-rtic-stm32h747i-disco.rs b/examples/ethernet-rtic-stm32h747i-disco.rs index 682fa111..43cdc6a3 100644 --- a/examples/ethernet-rtic-stm32h747i-disco.rs +++ b/examples/ethernet-rtic-stm32h747i-disco.rs @@ -168,6 +168,7 @@ mod app { let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS); let (eth_dma, eth_mac) = unsafe { + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.write(ethernet::DesRing::new()); ethernet::new( @@ -185,6 +186,7 @@ mod app { rmii_txd0, rmii_txd1, ), + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.assume_init_mut(), mac_addr, ccdr.peripheral.ETH1MAC, @@ -202,6 +204,7 @@ mod app { // unsafe: mutable reference to static storage, we only do this once let store = unsafe { + #[allow(static_mut_refs)] // TODO: Fix this let store_ptr = STORE.as_mut_ptr(); // Initialise the socket_storage field. Using `write` instead of @@ -212,6 +215,7 @@ mod app { // Now that all fields are initialised we can safely use // assume_init_mut to return a mutable reference to STORE + #[allow(static_mut_refs)] // TODO: Fix this STORE.assume_init_mut() }; diff --git a/examples/ethernet-stm32h747i-disco.rs b/examples/ethernet-stm32h747i-disco.rs index e4c1a199..7fd027bc 100644 --- a/examples/ethernet-stm32h747i-disco.rs +++ b/examples/ethernet-stm32h747i-disco.rs @@ -87,6 +87,7 @@ fn main() -> ! { let mac_addr = smoltcp::wire::EthernetAddress::from_bytes(&MAC_ADDRESS); let (_eth_dma, eth_mac) = unsafe { + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.write(ethernet::DesRing::new()); ethernet::new( @@ -104,6 +105,7 @@ fn main() -> ! { rmii_txd0, rmii_txd1, ), + #[allow(static_mut_refs)] // TODO: Fix this DES_RING.assume_init_mut(), mac_addr, ccdr.peripheral.ETH1MAC, diff --git a/examples/i2c4_bdma.rs b/examples/i2c4_bdma.rs index e6402567..50e596ec 100644 --- a/examples/i2c4_bdma.rs +++ b/examples/i2c4_bdma.rs @@ -104,7 +104,10 @@ fn main() -> ! { Transfer::init( streams.0, i2c, - unsafe { BUFFER.assume_init_mut() }, + #[allow(static_mut_refs)] // TODO: Fix this + unsafe { + BUFFER.assume_init_mut() + }, None, config, ); @@ -136,6 +139,7 @@ fn I2C4_EV() { info!("I2C transfer complete!"); // Look at BUFFER, which we expect to be initialised + #[allow(static_mut_refs)] // TODO: Fix this let buffer: &'static [u8; 10] = unsafe { BUFFER.assume_init_mut() }; assert_eq!(buffer[0], 0xBE); diff --git a/examples/mdma.rs b/examples/mdma.rs index 4d176461..348d780f 100644 --- a/examples/mdma.rs +++ b/examples/mdma.rs @@ -61,7 +61,10 @@ fn main() -> ! { value.as_mut_ptr().write(0x11223344u32); } } - unsafe { SOURCE_BUFFER.assume_init_mut() } + #[allow(static_mut_refs)] // TODO: Fix this + unsafe { + SOURCE_BUFFER.assume_init_mut() + } }; // @@ -118,6 +121,7 @@ fn main() -> ! { // // Reset source buffer + #[allow(static_mut_refs)] // TODO: Fix this let source_buffer = unsafe { SOURCE_BUFFER.assume_init_mut() }; *source_buffer = [0xAABBCCDD; 200]; diff --git a/examples/mdma_bursts.rs b/examples/mdma_bursts.rs index bfcd6083..2b6c3641 100644 --- a/examples/mdma_bursts.rs +++ b/examples/mdma_bursts.rs @@ -73,7 +73,10 @@ fn main() -> ! { value.as_mut_ptr().write(0x11223344u32); } } - unsafe { SOURCE_BUFFER.assume_init_mut() } + #[allow(static_mut_refs)] // TODO: Fix this + unsafe { + SOURCE_BUFFER.assume_init_mut() + } }; // NOTE(unsafe): TARGET_BUFFER must also be initialised to prevent undefined @@ -92,8 +95,10 @@ fn main() -> ! { let mut transfer: Transfer<_, _, MemoryToMemory, _, _> = { // unsafe: Both source and destination live at least as long as this // transfer + #[allow(static_mut_refs)] // TODO: Fix this let source: &'static mut [u32; 200] = unsafe { SOURCE_BUFFER.assume_init_mut() }; + #[allow(static_mut_refs)] // TODO: Fix this let target: &'static mut [u32; 200] = unsafe { TARGET_BUFFER.assume_init_mut() }; // uninitialised memory diff --git a/examples/sai_dma_passthru.rs b/examples/sai_dma_passthru.rs index ca6c14c9..c4d2952b 100644 --- a/examples/sai_dma_passthru.rs +++ b/examples/sai_dma_passthru.rs @@ -110,6 +110,7 @@ fn main() -> ! { dma::dma::StreamsTuple::new(dp.DMA1, ccdr.peripheral.DMA1); // dma1 stream 0 + #[allow(static_mut_refs)] // TODO: Fix this let tx_buffer: &'static mut [u32; DMA_BUFFER_LENGTH] = unsafe { TX_BUFFER.assume_init_mut() }; // uninitialised memory let dma_config = dma::dma::DmaConfig::default() @@ -128,6 +129,7 @@ fn main() -> ! { ); // dma1 stream 1 + #[allow(static_mut_refs)] // TODO: Fix this let rx_buffer: &'static mut [u32; DMA_BUFFER_LENGTH] = unsafe { RX_BUFFER.assume_init_mut() }; // uninitialised memory let dma_config = dma_config @@ -179,6 +181,7 @@ fn main() -> ! { static mut TRANSFER_DMA1_STR1: MaybeUninit> = MaybeUninit::uninit(); unsafe { + #[allow(static_mut_refs)] // TODO: Fix this TRANSFER_DMA1_STR1.write(None); } @@ -220,6 +223,7 @@ fn main() -> ! { >; unsafe { + #[allow(static_mut_refs)] // TODO: Fix this TRANSFER_DMA1_STR1.write(Some(dma1_str1)); // drops previous None info!( "{:?}, {:?}", @@ -230,13 +234,16 @@ fn main() -> ! { #[interrupt] fn DMA1_STR1() { + #[allow(static_mut_refs)] // TODO: Fix this let tx_buffer: &'static mut [u32; DMA_BUFFER_LENGTH] = unsafe { TX_BUFFER.assume_init_mut() }; + #[allow(static_mut_refs)] // TODO: Fix this let rx_buffer: &'static mut [u32; DMA_BUFFER_LENGTH] = unsafe { RX_BUFFER.assume_init_mut() }; let stereo_block_length = tx_buffer.len() / 2; + #[allow(static_mut_refs)] // TODO: Fix this if let Some(transfer) = unsafe { TRANSFER_DMA1_STR1.assume_init_mut() } { let skip = if transfer.get_half_transfer_flag() { diff --git a/examples/serial-dma.rs b/examples/serial-dma.rs index c61a36e2..1621fe0d 100644 --- a/examples/serial-dma.rs +++ b/examples/serial-dma.rs @@ -89,7 +89,10 @@ fn main() -> ! { value.as_mut_ptr().write(i as u8 + 96); // 0x60, 0x61, 0x62... } } - unsafe { SHORT_BUFFER.assume_init_mut() } + #[allow(static_mut_refs)] // TODO: Fix this + unsafe { + SHORT_BUFFER.assume_init_mut() + } }; // view u32 buffer as u8. Endianess is undefined (little-endian on STM32H7) let long_buffer: &'static mut [u8; 0x2_0010] = { diff --git a/examples/spi-dma-rtic.rs b/examples/spi-dma-rtic.rs index bd78229c..47f243e6 100644 --- a/examples/spi-dma-rtic.rs +++ b/examples/spi-dma-rtic.rs @@ -107,7 +107,10 @@ mod app { } } - unsafe { BUFFER.assume_init_mut() } + #[allow(static_mut_refs)] // TODO: Fix this + unsafe { + BUFFER.assume_init_mut() + } }; let streams = hal::dma::dma::StreamsTuple::new( diff --git a/examples/spi-dma.rs b/examples/spi-dma.rs index b3a59a2e..40f17dea 100644 --- a/examples/spi-dma.rs +++ b/examples/spi-dma.rs @@ -91,7 +91,10 @@ fn main() -> ! { value.as_mut_ptr().write(i as u8 + 96); // 0x60, 0x61, 0x62... } } - unsafe { SHORT_BUFFER.assume_init_mut() } + #[allow(static_mut_refs)] // TODO: Fix this + unsafe { + SHORT_BUFFER.assume_init_mut() + } }; // view u32 buffer as u8. Endianess is undefined (little-endian on STM32H7) let long_buffer: &'static mut [u8; 0x2_0010] = { diff --git a/examples/usb_passthrough.rs b/examples/usb_passthrough.rs index f7f68f80..7052b44e 100644 --- a/examples/usb_passthrough.rs +++ b/examples/usb_passthrough.rs @@ -89,6 +89,7 @@ fn main() -> ! { } // Port 1 + #[allow(static_mut_refs)] // TODO: Fix this let usb1_bus = UsbBus::new(usb1, unsafe { EP_MEMORY_1.assume_init_mut() }); let mut serial1 = usbd_serial::SerialPort::new(&usb1_bus); let mut usb1_dev = @@ -102,6 +103,7 @@ fn main() -> ! { .build(); // Port 2 + #[allow(static_mut_refs)] // TODO: Fix this let usb2_bus = UsbBus::new(usb2, unsafe { EP_MEMORY_2.assume_init_mut() }); let mut serial2 = usbd_serial::SerialPort::new(&usb2_bus); let mut usb2_dev = diff --git a/examples/usb_phy_serial_interrupt.rs b/examples/usb_phy_serial_interrupt.rs index 90b2533a..e25e8dc5 100644 --- a/examples/usb_phy_serial_interrupt.rs +++ b/examples/usb_phy_serial_interrupt.rs @@ -157,11 +157,17 @@ unsafe fn main() -> ! { } } - USB_BUS_ALLOCATOR = Some(UsbBus::new(usb, USB_MEMORY_1.assume_init_mut())); + #[allow(static_mut_refs)] // TODO: Fix this + { + USB_BUS_ALLOCATOR = + Some(UsbBus::new(usb, USB_MEMORY_1.assume_init_mut())); + } + #[allow(static_mut_refs)] // TODO: Fix this let usb_serial = usbd_serial::SerialPort::new(USB_BUS_ALLOCATOR.as_ref().unwrap()); + #[allow(static_mut_refs)] // TODO: Fix this let usb_dev = UsbDeviceBuilder::new( USB_BUS_ALLOCATOR.as_ref().unwrap(), UsbVidPid(VID, PID), diff --git a/examples/usb_rtic.rs b/examples/usb_rtic.rs index 418bb8b6..1c6a210e 100644 --- a/examples/usb_rtic.rs +++ b/examples/usb_rtic.rs @@ -95,6 +95,7 @@ mod app { } // Now we may assume that EP_MEMORY is initialised + #[allow(static_mut_refs)] // TODO: Fix this let usb_bus = cortex_m::singleton!( : usb_device::class_prelude::UsbBusAllocator> = UsbBus::new(usb, unsafe { EP_MEMORY.assume_init_mut() }) diff --git a/examples/usb_serial.rs b/examples/usb_serial.rs index ed9100b4..90dff296 100644 --- a/examples/usb_serial.rs +++ b/examples/usb_serial.rs @@ -85,6 +85,7 @@ fn main() -> ! { } // Now we may assume that EP_MEMORY is initialised + #[allow(static_mut_refs)] // TODO: Fix this let usb_bus = UsbBus::new(usb, unsafe { EP_MEMORY.assume_init_mut() }); let mut serial = usbd_serial::SerialPort::new(&usb_bus);