From b33b8775926ca670d7abb0a52bd41064fab5fffa Mon Sep 17 00:00:00 2001 From: Kirill Mikhailov <62840029+playfulFence@users.noreply.github.com> Date: Tue, 22 Apr 2025 12:39:11 +0200 Subject: [PATCH] Bump edition to 2024, bump MSRV to 1.85 (#3391) * inter-state * inter-state (2) * warnings fix * fix warnings * fmt + changelogs * another unsafe extern "C" doode * real fmt now * MSRV + format * Ignore unsafe_op_in_unsafe_fn lint for now in esp-hal and esp-wifi * msrv + fmt * ugh.... * get lcd_cam example right * expr_2021 -> expr experiment * gagagugu * reviews * more unneeded unsafes (help) * finish esp-hal unsafe cleanup * each unsafe call is marked separately fmt * should be good now (?) * piece was never an option... * dumb --- .github/workflows/ci.yml | 2 +- esp-alloc/CHANGELOG.md | 1 + esp-alloc/Cargo.toml | 8 +- esp-alloc/src/allocators.rs | 16 +- esp-alloc/src/lib.rs | 56 ++-- esp-backtrace/CHANGELOG.md | 1 + esp-backtrace/Cargo.toml | 8 +- esp-backtrace/build.rs | 2 +- esp-backtrace/src/lib.rs | 18 +- esp-backtrace/src/xtensa.rs | 5 +- esp-bootloader-esp-idf/CHANGELOG.md | 2 + esp-bootloader-esp-idf/Cargo.toml | 8 +- esp-bootloader-esp-idf/build.rs | 2 +- esp-bootloader-esp-idf/src/lib.rs | 8 +- esp-bootloader-esp-idf/src/rom.rs | 2 +- esp-build/CHANGELOG.md | 2 + esp-build/Cargo.toml | 4 +- esp-build/src/lib.rs | 6 +- esp-config/CHANGELOG.md | 1 + esp-config/Cargo.toml | 8 +- esp-config/src/generate/validator.rs | 2 +- esp-config/src/generate/value.rs | 2 +- esp-config/src/lib.rs | 6 +- esp-hal-embassy/CHANGELOG.md | 2 + esp-hal-embassy/Cargo.toml | 8 +- esp-hal-embassy/build.rs | 2 +- esp-hal-embassy/src/executor/interrupt.rs | 2 +- esp-hal-embassy/src/executor/mod.rs | 2 +- esp-hal-embassy/src/lib.rs | 2 +- esp-hal-embassy/src/time_driver.rs | 66 ++-- esp-hal-embassy/src/timer_queue.rs | 2 +- esp-hal-procmacros/CHANGELOG.md | 1 + esp-hal-procmacros/Cargo.toml | 4 +- esp-hal-procmacros/src/blocking.rs | 2 +- esp-hal-procmacros/src/builder.rs | 6 +- esp-hal-procmacros/src/embassy.rs | 6 +- esp-hal-procmacros/src/interrupt.rs | 26 +- esp-hal-procmacros/src/lp_core.rs | 18 +- esp-hal-procmacros/src/ram.rs | 19 +- esp-hal/CHANGELOG.md | 1 + esp-hal/Cargo.toml | 8 +- esp-hal/build.rs | 5 +- esp-hal/src/aes/esp32.rs | 2 +- esp-hal/src/aes/esp32cX.rs | 2 +- esp-hal/src/aes/esp32s2.rs | 2 +- esp-hal/src/aes/esp32s3.rs | 2 +- esp-hal/src/aes/mod.rs | 8 +- esp-hal/src/analog/adc/riscv.rs | 12 +- esp-hal/src/assist_debug.rs | 2 +- esp-hal/src/clock/clocks_ll/esp32h2.rs | 6 +- esp-hal/src/dma/buffers.rs | 6 +- esp-hal/src/dma/gdma.rs | 2 +- esp-hal/src/dma/m2m.rs | 6 +- esp-hal/src/dma/mod.rs | 38 +-- esp-hal/src/dma/pdma/copy.rs | 2 +- esp-hal/src/dma/pdma/crypto.rs | 2 +- esp-hal/src/dma/pdma/mod.rs | 4 +- esp-hal/src/ecc.rs | 10 +- esp-hal/src/gpio/etm.rs | 2 +- esp-hal/src/gpio/interconnect.rs | 8 +- esp-hal/src/gpio/lp_io.rs | 4 +- esp-hal/src/gpio/mod.rs | 13 +- esp-hal/src/i2c/lp_i2c.rs | 2 +- esp-hal/src/i2c/master/mod.rs | 10 +- esp-hal/src/i2s/master.rs | 18 +- esp-hal/src/i2s/parallel.rs | 10 +- esp-hal/src/interrupt/mod.rs | 2 +- esp-hal/src/interrupt/riscv.rs | 160 +++++----- esp-hal/src/interrupt/xtensa.rs | 120 +++---- esp-hal/src/lcd_cam/cam.rs | 6 +- esp-hal/src/lcd_cam/lcd/dpi.rs | 10 +- esp-hal/src/lcd_cam/lcd/i8080.rs | 14 +- esp-hal/src/lcd_cam/mod.rs | 10 +- esp-hal/src/ledc/channel.rs | 2 +- esp-hal/src/lib.rs | 12 +- esp-hal/src/macros.rs | 8 +- esp-hal/src/mcpwm/operator.rs | 5 +- esp-hal/src/otg_fs.rs | 4 +- esp-hal/src/parl_io.rs | 12 +- esp-hal/src/pcnt/channel.rs | 2 +- esp-hal/src/peripheral.rs | 28 +- esp-hal/src/rmt.rs | 6 +- esp-hal/src/rng.rs | 4 +- esp-hal/src/rom/crc.rs | 12 +- esp-hal/src/rom/md5.rs | 4 +- esp-hal/src/rom/mod.rs | 12 +- esp-hal/src/rsa/esp32.rs | 4 +- esp-hal/src/rsa/esp32cX.rs | 4 +- esp-hal/src/rsa/esp32sX.rs | 4 +- esp-hal/src/rsa/mod.rs | 6 +- esp-hal/src/rtc_cntl/mod.rs | 2 +- esp-hal/src/rtc_cntl/rtc/esp32c6.rs | 16 +- esp-hal/src/rtc_cntl/rtc/esp32h2.rs | 4 +- esp-hal/src/rtc_cntl/sleep/esp32.rs | 2 +- esp-hal/src/rtc_cntl/sleep/esp32c2.rs | 2 +- esp-hal/src/rtc_cntl/sleep/esp32c3.rs | 2 +- esp-hal/src/rtc_cntl/sleep/esp32c6.rs | 10 +- esp-hal/src/rtc_cntl/sleep/esp32s2.rs | 2 +- esp-hal/src/rtc_cntl/sleep/esp32s3.rs | 2 +- esp-hal/src/soc/esp32/cpu_control.rs | 44 +-- esp-hal/src/soc/esp32/mod.rs | 54 ++-- esp-hal/src/soc/esp32/psram.rs | 4 +- esp-hal/src/soc/esp32/regi2c.rs | 6 +- esp-hal/src/soc/esp32c2/efuse/mod.rs | 6 +- esp-hal/src/soc/esp32c2/gpio.rs | 8 +- esp-hal/src/soc/esp32c2/regi2c.rs | 6 +- esp-hal/src/soc/esp32c3/efuse/mod.rs | 6 +- esp-hal/src/soc/esp32c3/gpio.rs | 6 +- esp-hal/src/soc/esp32c3/regi2c.rs | 6 +- esp-hal/src/soc/esp32c6/efuse/mod.rs | 6 +- esp-hal/src/soc/esp32c6/lp_core.rs | 2 +- esp-hal/src/soc/esp32c6/regi2c.rs | 8 +- esp-hal/src/soc/esp32h2/regi2c.rs | 8 +- esp-hal/src/soc/esp32s2/mod.rs | 76 +++-- esp-hal/src/soc/esp32s2/psram.rs | 14 +- esp-hal/src/soc/esp32s2/regi2c.rs | 2 +- esp-hal/src/soc/esp32s3/cpu_control.rs | 39 +-- esp-hal/src/soc/esp32s3/efuse/mod.rs | 6 +- esp-hal/src/soc/esp32s3/gpio.rs | 2 +- esp-hal/src/soc/esp32s3/mod.rs | 102 +++--- esp-hal/src/soc/esp32s3/psram.rs | 19 +- esp-hal/src/soc/esp32s3/regi2c.rs | 6 +- esp-hal/src/spi/master.rs | 48 +-- esp-hal/src/spi/slave.rs | 24 +- esp-hal/src/sync.rs | 54 ++-- esp-hal/src/timer/mod.rs | 6 +- esp-hal/src/timer/systimer.rs | 2 +- esp-hal/src/touch.rs | 8 +- esp-hal/src/twai/mod.rs | 20 +- esp-hal/src/uart.rs | 10 +- esp-hal/src/usb_serial_jtag.rs | 6 +- esp-ieee802154/CHANGELOG.md | 2 + esp-ieee802154/Cargo.toml | 4 +- esp-ieee802154/build.rs | 2 +- esp-ieee802154/src/raw.rs | 8 +- esp-lp-hal/CHANGELOG.md | 1 + esp-lp-hal/Cargo.toml | 4 +- esp-lp-hal/src/i2c.rs | 8 +- esp-lp-hal/src/lib.rs | 40 +-- esp-lp-hal/src/uart.rs | 6 +- esp-metadata/CHANGELOG.md | 2 + esp-metadata/Cargo.toml | 4 +- esp-metadata/src/generate_cfg.rs | 2 +- esp-println/CHANGELOG.md | 2 + esp-println/Cargo.toml | 8 +- esp-println/build.rs | 4 +- esp-println/src/defmt.rs | 46 +-- esp-println/src/lib.rs | 18 +- esp-riscv-rt/CHANGELOG.md | 2 + esp-riscv-rt/Cargo.toml | 8 +- esp-riscv-rt/src/lib.rs | 54 ++-- esp-storage/CHANGELOG.md | 2 + esp-storage/Cargo.toml | 8 +- esp-storage/build.rs | 5 +- esp-storage/src/common.rs | 6 +- esp-storage/src/esp32.rs | 28 +- esp-storage/src/esp32s3.rs | 8 +- esp-storage/src/lib.rs | 4 +- esp-wifi/CHANGELOG.md | 2 + esp-wifi/Cargo.toml | 8 +- esp-wifi/build.rs | 2 +- esp-wifi/src/ble/btdm.rs | 112 ++++--- esp-wifi/src/ble/controller/mod.rs | 4 +- esp-wifi/src/ble/mod.rs | 6 +- esp-wifi/src/ble/npl.rs | 294 ++++++++++-------- esp-wifi/src/ble/os_adapter_esp32.rs | 78 ++--- esp-wifi/src/ble/os_adapter_esp32c2.rs | 38 ++- esp-wifi/src/ble/os_adapter_esp32c3.rs | 78 +++-- esp-wifi/src/ble/os_adapter_esp32c6.rs | 40 ++- esp-wifi/src/ble/os_adapter_esp32h2.rs | 40 ++- esp-wifi/src/ble/os_adapter_esp32s3.rs | 70 ++--- .../common_adapter/common_adapter_esp32.rs | 86 ++--- .../common_adapter/common_adapter_esp32c2.rs | 60 ++-- .../common_adapter/common_adapter_esp32c3.rs | 66 ++-- .../common_adapter/common_adapter_esp32c6.rs | 66 ++-- .../common_adapter/common_adapter_esp32h2.rs | 60 ++-- .../common_adapter/common_adapter_esp32s2.rs | 74 +++-- .../common_adapter/common_adapter_esp32s3.rs | 68 ++-- esp-wifi/src/common_adapter/mod.rs | 152 +++++---- esp-wifi/src/compat/common.rs | 47 +-- esp-wifi/src/compat/malloc.rs | 46 +-- esp-wifi/src/compat/misc.rs | 22 +- esp-wifi/src/compat/mod.rs | 28 +- esp-wifi/src/compat/timer_compat.rs | 9 +- esp-wifi/src/esp_now/mod.rs | 42 +-- esp-wifi/src/lib.rs | 9 +- esp-wifi/src/preempt.rs | 16 +- esp-wifi/src/preempt_builtin/timer/riscv.rs | 4 +- esp-wifi/src/preempt_builtin/timer/xtensa.rs | 6 +- esp-wifi/src/radio/radio_esp32.rs | 10 +- esp-wifi/src/radio/radio_esp32c2.rs | 8 +- esp-wifi/src/radio/radio_esp32c3.rs | 10 +- esp-wifi/src/radio/radio_esp32c6.rs | 8 +- esp-wifi/src/radio/radio_esp32h2.rs | 4 +- esp-wifi/src/radio/radio_esp32s2.rs | 4 +- esp-wifi/src/radio/radio_esp32s3.rs | 8 +- esp-wifi/src/wifi/event.rs | 7 +- esp-wifi/src/wifi/internal.rs | 14 +- esp-wifi/src/wifi/mod.rs | 160 +++++----- esp-wifi/src/wifi/os_adapter.rs | 182 ++++++----- esp-wifi/src/wifi/os_adapter_esp32.rs | 25 +- esp-wifi/src/wifi/os_adapter_esp32c2.rs | 9 +- esp-wifi/src/wifi/os_adapter_esp32c3.rs | 9 +- esp-wifi/src/wifi/os_adapter_esp32c6.rs | 8 +- esp-wifi/src/wifi/os_adapter_esp32h2.rs | 8 +- esp-wifi/src/wifi/os_adapter_esp32s2.rs | 24 +- esp-wifi/src/wifi/os_adapter_esp32s3.rs | 16 +- examples/Cargo.toml | 2 +- examples/src/bin/debug_assist.rs | 2 +- examples/src/bin/dma_extmem2mem.rs | 6 +- examples/src/bin/embassy_multicore.rs | 2 +- .../src/bin/embassy_multicore_interrupt.rs | 4 +- examples/src/bin/embassy_multiprio.rs | 8 +- examples/src/bin/embassy_serial.rs | 2 +- examples/src/bin/embassy_spi.rs | 2 +- examples/src/bin/embassy_usb_serial.rs | 4 +- examples/src/bin/embassy_usb_serial_jtag.rs | 2 +- examples/src/bin/etm_timer.rs | 4 +- examples/src/bin/hmac.rs | 8 +- examples/src/bin/spi_loopback.rs | 2 +- examples/src/bin/spi_loopback_dma_psram.rs | 2 +- examples/src/bin/spi_slave_dma.rs | 2 +- examples/src/bin/touch.rs | 2 +- examples/src/bin/twai.rs | 2 +- examples/src/bin/wifi_80211_tx.rs | 2 +- examples/src/bin/wifi_access_point.rs | 6 +- .../src/bin/wifi_access_point_with_sta.rs | 4 +- examples/src/bin/wifi_ble.rs | 6 +- examples/src/bin/wifi_coex.rs | 8 +- examples/src/bin/wifi_embassy_access_point.rs | 4 +- .../bin/wifi_embassy_access_point_with_sta.rs | 4 +- examples/src/bin/wifi_embassy_bench.rs | 8 +- examples/src/bin/wifi_embassy_ble.rs | 4 +- examples/src/bin/wifi_embassy_dhcp.rs | 4 +- examples/src/bin/wifi_embassy_esp_now.rs | 6 +- .../src/bin/wifi_embassy_esp_now_duplex.rs | 4 +- examples/src/bin/wifi_esp_now.rs | 2 +- hil-test/Cargo.toml | 2 +- hil-test/src/lib.rs | 4 +- hil-test/tests/aes_dma.rs | 2 +- hil-test/tests/critical_section.rs | 2 +- hil-test/tests/delay_async.rs | 2 +- hil-test/tests/dma_mem2mem.rs | 2 +- hil-test/tests/ecc.rs | 27 +- hil-test/tests/embassy_interrupt_executor.rs | 2 +- hil-test/tests/embassy_interrupt_spi_dma.rs | 6 +- hil-test/tests/embassy_timers_executors.rs | 4 +- hil-test/tests/gpio.rs | 2 +- hil-test/tests/gpio_custom_handler.rs | 4 +- hil-test/tests/i2c.rs | 2 +- hil-test/tests/i2s.rs | 2 +- hil-test/tests/init.rs | 2 +- hil-test/tests/interrupt.rs | 4 +- hil-test/tests/lcd_cam.rs | 6 +- hil-test/tests/lcd_cam_i8080.rs | 6 +- hil-test/tests/lcd_cam_i8080_async.rs | 4 +- hil-test/tests/parl_io.rs | 21 +- hil-test/tests/parl_io_tx.rs | 4 +- hil-test/tests/parl_io_tx_async.rs | 4 +- hil-test/tests/pcnt.rs | 2 +- hil-test/tests/qspi.rs | 6 +- hil-test/tests/rsa.rs | 6 +- hil-test/tests/rsa_async.rs | 6 +- hil-test/tests/spi_full_duplex.rs | 2 +- hil-test/tests/spi_half_duplex_read.rs | 4 +- hil-test/tests/spi_half_duplex_write.rs | 6 +- hil-test/tests/spi_half_duplex_write_psram.rs | 6 +- hil-test/tests/spi_slave.rs | 4 +- hil-test/tests/storage_read_app_desc.rs | 4 +- hil-test/tests/systimer.rs | 4 +- hil-test/tests/twai.rs | 2 +- hil-test/tests/uart.rs | 4 +- hil-test/tests/uart_async.rs | 2 +- hil-test/tests/uart_tx_rx_async.rs | 4 +- qa-test/Cargo.toml | 2 +- qa-test/src/bin/embassy_executor_benchmark.rs | 4 +- qa-test/src/bin/i2c_display.rs | 4 +- qa-test/src/bin/lcd_cam_ov2640.rs | 4 +- qa-test/src/bin/lcd_dpi.rs | 6 +- qa-test/src/bin/lcd_i8080.rs | 10 +- qa-test/src/bin/qspi_flash.rs | 2 +- qa-test/src/bin/sleep_timer.rs | 2 +- qa-test/src/bin/sleep_timer_ext0.rs | 4 +- qa-test/src/bin/sleep_timer_ext1.rs | 4 +- qa-test/src/bin/sleep_timer_lpio.rs | 4 +- qa-test/src/bin/sleep_timer_rtcio.rs | 4 +- .../spi_halfduplex_read_manufacturer_id.rs | 2 +- xtask/Cargo.toml | 2 +- xtask/src/lib.rs | 1 + xtask/src/main.rs | 2 +- xtensa-lx-rt-proc-macros/Cargo.toml | 4 +- xtensa-lx-rt-proc-macros/src/lib.rs | 12 +- xtensa-lx-rt/CHANGELOG.md | 2 + xtensa-lx-rt/Cargo.toml | 8 +- xtensa-lx-rt/build.rs | 2 +- xtensa-lx-rt/src/exception/context.rs | 20 +- xtensa-lx-rt/src/lib.rs | 126 ++++---- xtensa-lx/CHANGELOG.md | 2 + xtensa-lx/Cargo.toml | 8 +- xtensa-lx/src/interrupt.rs | 38 ++- xtensa-lx/src/lib.rs | 36 ++- 301 files changed, 2569 insertions(+), 2105 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55c0cc131..51aaae035 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ on: env: CARGO_TERM_COLOR: always GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MSRV: "1.84.0" + MSRV: "1.85.0" DEFMT_LOG: trace # Cancel any currently running workflows from the same PR, branch, or diff --git a/esp-alloc/CHANGELOG.md b/esp-alloc/CHANGELOG.md index 21b97c6ba..c7f7b10b5 100644 --- a/esp-alloc/CHANGELOG.md +++ b/esp-alloc/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `AnyMemory`, `InternalMemory`, `ExternalMemory` allocators. (#3318) ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) ### Fixed diff --git a/esp-alloc/Cargo.toml b/esp-alloc/Cargo.toml index 0bd6bef8a..3dea8b962 100644 --- a/esp-alloc/Cargo.toml +++ b/esp-alloc/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-alloc" version = "0.7.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "A heap allocator for Espressif devices" documentation = "https://docs.espressif.com/projects/rust/esp-alloc/latest/" keywords = ["allocator", "embedded", "esp32", "espressif", "memory"] @@ -14,6 +14,10 @@ license = "MIT OR Apache-2.0" default-target = "riscv32imc-unknown-none-elf" features = ["nightly"] +[lib] +bench = false +test = false + [dependencies] allocator-api2 = { version = "0.2.0", default-features = false } defmt = { version = "0.3.10", optional = true } diff --git a/esp-alloc/src/allocators.rs b/esp-alloc/src/allocators.rs index 4753ed2b4..227b62f7c 100644 --- a/esp-alloc/src/allocators.rs +++ b/esp-alloc/src/allocators.rs @@ -24,7 +24,9 @@ unsafe impl Allocator for EspHeap { } unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { - crate::HEAP.dealloc(ptr.as_ptr(), layout); + unsafe { + crate::HEAP.dealloc(ptr.as_ptr(), layout); + } } } @@ -37,7 +39,9 @@ unsafe impl Allocator for AnyMemory { } unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { - crate::HEAP.dealloc(ptr.as_ptr(), layout); + unsafe { + crate::HEAP.dealloc(ptr.as_ptr(), layout); + } } } @@ -50,7 +54,9 @@ unsafe impl Allocator for InternalMemory { } unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { - crate::HEAP.dealloc(ptr.as_ptr(), layout); + unsafe { + crate::HEAP.dealloc(ptr.as_ptr(), layout); + } } } @@ -63,6 +69,8 @@ unsafe impl Allocator for ExternalMemory { } unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { - crate::HEAP.dealloc(ptr.as_ptr(), layout); + unsafe { + crate::HEAP.dealloc(ptr.as_ptr(), layout); + } } } diff --git a/esp-alloc/src/lib.rs b/esp-alloc/src/lib.rs index c0f7baa19..7e4237809 100644 --- a/esp-alloc/src/lib.rs +++ b/esp-alloc/src/lib.rs @@ -275,10 +275,12 @@ impl HeapRegion { size: usize, capabilities: EnumSet, ) -> Self { - let mut heap = Heap::empty(); - heap.init(heap_bottom, size); + unsafe { + let mut heap = Heap::empty(); + heap.init(heap_bottom, size); - Self { heap, capabilities } + Self { heap, capabilities } + } } /// Return stats for the current memory region @@ -599,35 +601,37 @@ impl EspHeap { unsafe impl GlobalAlloc for EspHeap { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - self.alloc_caps(EnumSet::empty(), layout) + unsafe { self.alloc_caps(EnumSet::empty(), layout) } } unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { - if ptr.is_null() { - return; - } + unsafe { + if ptr.is_null() { + return; + } - critical_section::with(|cs| { - #[cfg(feature = "internal-heap-stats")] - let before = self.used(); - let mut regions = self.heap.borrow_ref_mut(cs); - let mut iter = (*regions).iter_mut(); + critical_section::with(|cs| { + #[cfg(feature = "internal-heap-stats")] + let before = self.used(); + let mut regions = self.heap.borrow_ref_mut(cs); + let mut iter = (*regions).iter_mut(); - while let Some(Some(region)) = iter.next() { - if region.heap.bottom() <= ptr && region.heap.top() >= ptr { - region.heap.deallocate(NonNull::new_unchecked(ptr), layout); + while let Some(Some(region)) = iter.next() { + if region.heap.bottom() <= ptr && region.heap.top() >= ptr { + region.heap.deallocate(NonNull::new_unchecked(ptr), layout); + } } - } - #[cfg(feature = "internal-heap-stats")] - { - let mut internal_heap_stats = self.internal_heap_stats.borrow_ref_mut(cs); - drop(regions); - // We need to call `used()` because [linked_list_allocator::Heap] does internal - // size alignment so we cannot use the size provided by the - // layout. - internal_heap_stats.total_freed += before - self.used(); - } - }) + #[cfg(feature = "internal-heap-stats")] + { + let mut internal_heap_stats = self.internal_heap_stats.borrow_ref_mut(cs); + drop(regions); + // We need to call `used()` because [linked_list_allocator::Heap] does internal + // size alignment so we cannot use the size provided by the + // layout. + internal_heap_stats.total_freed += before - self.used(); + } + }) + } } } diff --git a/esp-backtrace/CHANGELOG.md b/esp-backtrace/CHANGELOG.md index b57a5b80a..896604231 100644 --- a/esp-backtrace/CHANGELOG.md +++ b/esp-backtrace/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - The `arch::backtrace` function now returns a `Backtrace` struct (#3280) +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) ### Fixed diff --git a/esp-backtrace/Cargo.toml b/esp-backtrace/Cargo.toml index d5eb6ed92..c7603e6ca 100644 --- a/esp-backtrace/Cargo.toml +++ b/esp-backtrace/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-backtrace" version = "0.15.1" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Bare-metal backtrace support for Espressif devices" documentation = "https://docs.espressif.com/projects/rust/esp-backtrace/latest/" keywords = ["backtrace", "embedded", "esp32", "espressif"] @@ -14,6 +14,10 @@ license = "MIT OR Apache-2.0" default-target = "riscv32imc-unknown-none-elf" features = ["esp32c3", "panic-handler", "exception-handler", "println", "esp-println/uart"] +[lib] +bench = false +test = false + [dependencies] cfg-if = "1.0.0" defmt = { version = "0.3.10", optional = true } diff --git a/esp-backtrace/build.rs b/esp-backtrace/build.rs index aeb1f4fa1..525dd0267 100644 --- a/esp-backtrace/build.rs +++ b/esp-backtrace/build.rs @@ -1,5 +1,5 @@ use esp_build::assert_unique_used_features; -use esp_config::{generate_config, ConfigOption, Stability, Value}; +use esp_config::{ConfigOption, Stability, Value, generate_config}; fn main() { // Ensure that only a single chip is specified: diff --git a/esp-backtrace/src/lib.rs b/esp-backtrace/src/lib.rs index bb6da47c2..0ad8ce8e3 100644 --- a/esp-backtrace/src/lib.rs +++ b/esp-backtrace/src/lib.rs @@ -90,7 +90,9 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! { let backtrace = Backtrace::capture(); #[cfg(target_arch = "riscv32")] if backtrace.frames().is_empty() { - println!("No backtrace available - make sure to force frame-pointers. (see https://crates.io/crates/esp-backtrace)"); + println!( + "No backtrace available - make sure to force frame-pointers. (see https://crates.io/crates/esp-backtrace)" + ); } for frame in backtrace.frames() { println!("0x{:x}", frame.program_counter()); @@ -100,8 +102,8 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! { } #[cfg(all(feature = "exception-handler", target_arch = "xtensa"))] -#[no_mangle] -#[link_section = ".rwtext"] +#[unsafe(no_mangle)] +#[unsafe(link_section = ".rwtext")] unsafe fn __user_exception(cause: arch::ExceptionCause, context: arch::Context) { pre_backtrace(); @@ -117,7 +119,7 @@ unsafe fn __user_exception(cause: arch::ExceptionCause, context: arch::Context) } #[cfg(all(feature = "exception-handler", target_arch = "riscv32"))] -#[export_name = "ExceptionHandler"] +#[unsafe(export_name = "ExceptionHandler")] fn exception_handler(context: &arch::TrapFrame) -> ! { pre_backtrace(); @@ -163,7 +165,9 @@ fn exception_handler(context: &arch::TrapFrame) -> ! { let backtrace = Backtrace::from_sp(context.s0 as u32); let frames = backtrace.frames(); if frames.is_empty() { - println!("No backtrace available - make sure to force frame-pointers. (see https://crates.io/crates/esp-backtrace)"); + println!( + "No backtrace available - make sure to force frame-pointers. (see https://crates.io/crates/esp-backtrace)" + ); } for frame in backtrace.frames() { println!("0x{:x}", frame.program_counter()); @@ -233,7 +237,7 @@ fn halt() -> ! { cfg_if::cfg_if! { if #[cfg(feature = "custom-halt")] { // call custom code - extern "Rust" { + unsafe extern "Rust" { fn custom_halt() -> !; } unsafe { custom_halt() } @@ -285,7 +289,7 @@ fn halt() -> ! { fn pre_backtrace() { #[cfg(feature = "custom-pre-backtrace")] { - extern "Rust" { + unsafe extern "Rust" { fn custom_pre_backtrace(); } unsafe { custom_pre_backtrace() } diff --git a/esp-backtrace/src/xtensa.rs b/esp-backtrace/src/xtensa.rs index 83b322427..9b88b5bd3 100644 --- a/esp-backtrace/src/xtensa.rs +++ b/esp-backtrace/src/xtensa.rs @@ -102,7 +102,10 @@ pub enum ExceptionCause { impl Display for ExceptionCause { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { if *self == Self::Cp0Disabled { - write!(f, "Cp0Disabled (Access to the floating point coprocessor is not allowed. You may want to enable the `float-save-restore` feature of the `xtensa-lx-rt` crate.)") + write!( + f, + "Cp0Disabled (Access to the floating point coprocessor is not allowed. You may want to enable the `float-save-restore` feature of the `xtensa-lx-rt` crate.)" + ) } else { write!(f, "{:?}", self) } diff --git a/esp-bootloader-esp-idf/CHANGELOG.md b/esp-bootloader-esp-idf/CHANGELOG.md index 85a3ff99a..6ab92fac4 100644 --- a/esp-bootloader-esp-idf/CHANGELOG.md +++ b/esp-bootloader-esp-idf/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed ### Removed diff --git a/esp-bootloader-esp-idf/Cargo.toml b/esp-bootloader-esp-idf/Cargo.toml index 05c9cbaa9..17c5c4bdd 100644 --- a/esp-bootloader-esp-idf/Cargo.toml +++ b/esp-bootloader-esp-idf/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-bootloader-esp-idf" version = "0.1.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Functionality related to the esp-idf bootloader" documentation = "https://docs.espressif.com/projects/rust/esp-bootloader-esp-idf/latest/" keywords = ["esp32", "espressif", "no-std"] @@ -13,6 +13,10 @@ license = "MIT OR Apache-2.0" [package.metadata.docs.rs] default-target = "riscv32imac-unknown-none-elf" +[lib] +bench = false +test = false + [dependencies] defmt = { version = "0.3.10", optional = true } document-features = "0.2.11" diff --git a/esp-bootloader-esp-idf/build.rs b/esp-bootloader-esp-idf/build.rs index dbda337f3..7768c1cac 100644 --- a/esp-bootloader-esp-idf/build.rs +++ b/esp-bootloader-esp-idf/build.rs @@ -1,7 +1,7 @@ use std::env; use chrono::{TimeZone, Utc}; -use esp_config::{generate_config, ConfigOption, Stability, Validator, Value}; +use esp_config::{ConfigOption, Stability, Validator, Value, generate_config}; fn main() { let build_time = match env::var("SOURCE_DATE_EPOCH") { diff --git a/esp-bootloader-esp-idf/src/lib.rs b/esp-bootloader-esp-idf/src/lib.rs index c23e46cb2..5b2c3ee12 100644 --- a/esp-bootloader-esp-idf/src/lib.rs +++ b/esp-bootloader-esp-idf/src/lib.rs @@ -43,9 +43,9 @@ pub mod ota; // We run tests on the host which happens to be MacOS machines and mach-o // doesn't like `link-sections` this way #[cfg(not(target_os = "macos"))] -#[link_section = ".espressif.metadata"] +#[unsafe(link_section = ".espressif.metadata")] #[used] -#[export_name = "bootloader.NAME"] +#[unsafe(export_name = "bootloader.NAME")] static OTA_FEATURE: [u8; 7] = *b"ESP-IDF"; /// ESP-IDF compatible application descriptor @@ -305,8 +305,8 @@ macro_rules! esp_app_desc { $min_efuse_blk_rev_full: expr, $max_efuse_blk_rev_full: expr ) => { - #[export_name = "esp_app_desc"] - #[link_section = ".rodata_desc.appdesc"] + #[unsafe(export_name = "esp_app_desc")] + #[unsafe(link_section = ".rodata_desc.appdesc")] pub static ESP_APP_DESC: $crate::EspAppDesc = $crate::EspAppDesc::new_internal( $version, $project_name, diff --git a/esp-bootloader-esp-idf/src/rom.rs b/esp-bootloader-esp-idf/src/rom.rs index 3e47bbb0e..3f16192ad 100644 --- a/esp-bootloader-esp-idf/src/rom.rs +++ b/esp-bootloader-esp-idf/src/rom.rs @@ -6,7 +6,7 @@ impl Crc32 { } pub fn crc(&self, data: &[u8]) -> u32 { - extern "C" { + unsafe extern "C" { fn esp_rom_crc32_le(crc: u32, buf: *const u8, len: u32) -> u32; } diff --git a/esp-build/CHANGELOG.md b/esp-build/CHANGELOG.md index 74b29bbef..1e7af52ce 100644 --- a/esp-build/CHANGELOG.md +++ b/esp-build/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed ### Removed diff --git a/esp-build/Cargo.toml b/esp-build/Cargo.toml index 3a22ff78d..06d1d3caf 100644 --- a/esp-build/Cargo.toml +++ b/esp-build/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-build" version = "0.2.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Build utilities for esp-hal" documentation = "https://docs.espressif.com/projects/rust/esp-build/latest/" repository = "https://github.com/esp-rs/esp-hal" diff --git a/esp-build/src/lib.rs b/esp-build/src/lib.rs index e8bb1220f..4e333cf83 100644 --- a/esp-build/src/lib.rs +++ b/esp-build/src/lib.rs @@ -6,7 +6,7 @@ use std::io::Write as _; use proc_macro::TokenStream; use quote::ToTokens; -use syn::{parse_macro_input, punctuated::Punctuated, LitStr, Token}; +use syn::{LitStr, Token, parse_macro_input, punctuated::Punctuated}; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; /// Print a build error and terminate the process. @@ -113,7 +113,7 @@ pub fn assert_unique_used_features(input: TokenStream) -> TokenStream { // ---------------------------------------------------------------------------- // Helper Functions -fn impl_unique_features(features: &[LitStr], expectation: &str) -> impl ToTokens { +fn impl_unique_features(features: &[LitStr], expectation: &str) -> impl ToTokens + use<> { let pairs = unique_pairs(features); let unique_cfgs = pairs .iter() @@ -133,7 +133,7 @@ ERROR: expected {expectation} enabled feature from feature group: } } -fn impl_used_features(features: &[LitStr], expectation: &str) -> impl ToTokens { +fn impl_used_features(features: &[LitStr], expectation: &str) -> impl ToTokens + use<> { let message = format!( r#" ERROR: expected {expectation} enabled feature from feature group: diff --git a/esp-config/CHANGELOG.md b/esp-config/CHANGELOG.md index 6ac0549ab..aa8c85014 100644 --- a/esp-config/CHANGELOG.md +++ b/esp-config/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `generate_config` now takes a slice of `ConfigOption`s instead of tuples. (#3362) +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) ### Fixed diff --git a/esp-config/Cargo.toml b/esp-config/Cargo.toml index 1c2a14123..e6d145471 100644 --- a/esp-config/Cargo.toml +++ b/esp-config/Cargo.toml @@ -1,13 +1,17 @@ [package] name = "esp-config" version = "0.3.1" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Configure projects using esp-hal and related packages" documentation = "https://docs.espressif.com/projects/rust/esp-config/latest/" repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" +[lib] +bench = false +test = false + [dependencies] document-features = "0.2.10" serde = { version = "1.0.197", features = ["derive"], optional = true } diff --git a/esp-config/src/generate/validator.rs b/esp-config/src/generate/validator.rs index 5b327ecea..642e04f19 100644 --- a/esp-config/src/generate/validator.rs +++ b/esp-config/src/generate/validator.rs @@ -2,7 +2,7 @@ use std::{io::Write, ops::Range}; use serde::Serialize; -use super::{snake_case, value::Value, Error}; +use super::{Error, snake_case, value::Value}; type CustomValidatorFn = Box Result<(), Error>>; diff --git a/esp-config/src/generate/value.rs b/esp-config/src/generate/value.rs index 5747cca4e..01c419687 100644 --- a/esp-config/src/generate/value.rs +++ b/esp-config/src/generate/value.rs @@ -25,7 +25,7 @@ impl Value { _ => { return Err(Error::parse(format!( "Expected 'true' or 'false', found: '{s}'" - ))) + ))); } }, Value::Integer(_) => { diff --git a/esp-config/src/lib.rs b/esp-config/src/lib.rs index 0c61bf25f..c573c549d 100644 --- a/esp-config/src/lib.rs +++ b/esp-config/src/lib.rs @@ -9,12 +9,12 @@ mod generate; #[cfg(feature = "build")] pub use generate::{ - generate_config, - validator::Validator, - value::Value, ConfigOption, Error, Stability, + generate_config, + validator::Validator, + value::Value, }; /// Parse the value of an environment variable as a [bool] at compile time. diff --git a/esp-hal-embassy/CHANGELOG.md b/esp-hal-embassy/CHANGELOG.md index b66cb3cb5..69f23d2b3 100644 --- a/esp-hal-embassy/CHANGELOG.md +++ b/esp-hal-embassy/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Re-added the `multiple-integrated` timer queue flavour (#3166) +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Changed ### Fixed diff --git a/esp-hal-embassy/Cargo.toml b/esp-hal-embassy/Cargo.toml index bdbb43065..68726c4f7 100644 --- a/esp-hal-embassy/Cargo.toml +++ b/esp-hal-embassy/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-hal-embassy" version = "0.7.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Embassy support for esp-hal" documentation = "https://docs.espressif.com/projects/rust/esp-hal-embassy/latest/" keywords = ["async", "embedded", "esp32", "espressif"] @@ -14,6 +14,10 @@ license = "MIT OR Apache-2.0" default-target = "riscv32imac-unknown-none-elf" features = ["esp32c6"] +[lib] +bench = false +test = false + [dependencies] critical-section = "1.2.0" defmt = { version = "0.3.10", optional = true } diff --git a/esp-hal-embassy/build.rs b/esp-hal-embassy/build.rs index b734b515f..96b8dca57 100644 --- a/esp-hal-embassy/build.rs +++ b/esp-hal-embassy/build.rs @@ -1,7 +1,7 @@ use std::{error::Error as StdError, str::FromStr}; use esp_build::assert_unique_used_features; -use esp_config::{generate_config, ConfigOption, Stability, Validator, Value}; +use esp_config::{ConfigOption, Stability, Validator, Value, generate_config}; use esp_metadata::{Chip, Config}; fn main() -> Result<(), Box> { diff --git a/esp-hal-embassy/src/executor/interrupt.rs b/esp-hal-embassy/src/executor/interrupt.rs index d3b939c72..fc0d4ef71 100644 --- a/esp-hal-embassy/src/executor/interrupt.rs +++ b/esp-hal-embassy/src/executor/interrupt.rs @@ -4,7 +4,7 @@ use core::{cell::UnsafeCell, mem::MaybeUninit}; use embassy_executor::SendSpawner; use esp_hal::{ - interrupt::{self, software::SoftwareInterrupt, InterruptHandler}, + interrupt::{self, InterruptHandler, software::SoftwareInterrupt}, system::Cpu, }; use portable_atomic::{AtomicUsize, Ordering}; diff --git a/esp-hal-embassy/src/executor/mod.rs b/esp-hal-embassy/src/executor/mod.rs index 361ffc9e9..9a4e0c103 100644 --- a/esp-hal-embassy/src/executor/mod.rs +++ b/esp-hal-embassy/src/executor/mod.rs @@ -8,7 +8,7 @@ use crate::timer_queue::TimerQueue; mod interrupt; mod thread; -#[export_name = "__pender"] +#[unsafe(export_name = "__pender")] fn __pender(context: *mut ()) { use esp_hal::interrupt::software::SoftwareInterrupt; diff --git a/esp-hal-embassy/src/lib.rs b/esp-hal-embassy/src/lib.rs index 25f58921d..25e8ea0c2 100644 --- a/esp-hal-embassy/src/lib.rs +++ b/esp-hal-embassy/src/lib.rs @@ -54,7 +54,7 @@ mod fmt; #[cfg(not(feature = "esp32"))] use esp_hal::timer::systimer::Alarm; -use esp_hal::timer::{timg::Timer as TimgTimer, AnyTimer}; +use esp_hal::timer::{AnyTimer, timg::Timer as TimgTimer}; pub use macros::embassy_main as main; #[cfg(feature = "executors")] diff --git a/esp-hal-embassy/src/time_driver.rs b/esp-hal-embassy/src/time_driver.rs index 4b0930b3d..c0feb8f10 100644 --- a/esp-hal-embassy/src/time_driver.rs +++ b/esp-hal-embassy/src/time_driver.rs @@ -8,11 +8,11 @@ use core::cell::Cell; use embassy_time_driver::Driver; use esp_hal::{ + Blocking, interrupt::{InterruptHandler, Priority}, sync::Locked, time::{Duration, Instant}, timer::OneShotTimer, - Blocking, }; pub type Timer = OneShotTimer<'static, Blocking>; @@ -228,40 +228,42 @@ impl EmbassyTimer { /// When using a single timer queue, the `priority` parameter is always the /// highest value possible. pub(crate) unsafe fn allocate_alarm(&self, priority: Priority) -> Option { - for (i, alarm) in self.alarms.iter().enumerate() { - let handle = alarm.inner.with(|alarm| { - let AlarmState::Created(interrupt_handler) = alarm.state else { - return None; - }; + unsafe { + for (i, alarm) in self.alarms.iter().enumerate() { + let handle = alarm.inner.with(|alarm| { + let AlarmState::Created(interrupt_handler) = alarm.state else { + return None; + }; - let timer = self.available_timers.with(|available_timers| { - if let Some(timers) = available_timers.take() { - // If the driver is initialized, we can allocate a timer. - // If this fails, we can't do anything about it. - let Some((timer, rest)) = timers.split_first_mut() else { - not_enough_timers(); - }; - *available_timers = Some(rest); - timer - } else { - panic!("schedule_wake called before esp_hal_embassy::init()") - } + let timer = self.available_timers.with(|available_timers| { + if let Some(timers) = available_timers.take() { + // If the driver is initialized, we can allocate a timer. + // If this fails, we can't do anything about it. + let Some((timer, rest)) = timers.split_first_mut() else { + not_enough_timers(); + }; + *available_timers = Some(rest); + timer + } else { + panic!("schedule_wake called before esp_hal_embassy::init()") + } + }); + + alarm.state = AlarmState::initialize( + timer, + InterruptHandler::new(interrupt_handler, priority), + ); + + Some(AlarmHandle::new(i)) }); - alarm.state = AlarmState::initialize( - timer, - InterruptHandler::new(interrupt_handler, priority), - ); - - Some(AlarmHandle::new(i)) - }); - - if handle.is_some() { - return handle; + if handle.is_some() { + return handle; + } } - } - None + None + } } /// Set an alarm to fire at a certain timestamp. @@ -362,7 +364,9 @@ fn not_enough_timers() -> ! { // This is wrapped in a separate function because rustfmt does not like // extremely long strings. Also, if log is used, this avoids storing the string // twice. - panic!("There are not enough timers to allocate a new alarm. Call esp_hal_embassy::init() with the correct number of timers, or consider either using the `single-integrated` or the `generic` timer queue flavors."); + panic!( + "There are not enough timers to allocate a new alarm. Call esp_hal_embassy::init() with the correct number of timers, or consider either using the `single-integrated` or the `generic` timer queue flavors." + ); } pub(crate) fn set_up_alarm(priority: Priority, _ctx: *mut ()) -> AlarmHandle { diff --git a/esp-hal-embassy/src/timer_queue.rs b/esp-hal-embassy/src/timer_queue.rs index dbd01150e..bb344155c 100644 --- a/esp-hal-embassy/src/timer_queue.rs +++ b/esp-hal-embassy/src/timer_queue.rs @@ -12,7 +12,7 @@ use embassy_sync::blocking_mutex::Mutex; use esp_hal::{interrupt::Priority, sync::RawPriorityLimitedMutex}; use queue_impl::RawQueue; -use crate::time_driver::{set_up_alarm, AlarmHandle}; +use crate::time_driver::{AlarmHandle, set_up_alarm}; struct TimerQueueInner { queue: RawQueue, diff --git a/esp-hal-procmacros/CHANGELOG.md b/esp-hal-procmacros/CHANGELOG.md index c69ff3a86..e992cad5b 100644 --- a/esp-hal-procmacros/CHANGELOG.md +++ b/esp-hal-procmacros/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Using the `#handler` macro with a priority of `None` will fail at compile time (#3304) +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) ### Fixed diff --git a/esp-hal-procmacros/Cargo.toml b/esp-hal-procmacros/Cargo.toml index f76e24088..880f14d3e 100644 --- a/esp-hal-procmacros/Cargo.toml +++ b/esp-hal-procmacros/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-hal-procmacros" version = "0.17.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Procedural macros for esp-hal" documentation = "https://docs.espressif.com/projects/rust/esp-hal-procmacros/latest/" repository = "https://github.com/esp-rs/esp-hal" diff --git a/esp-hal-procmacros/src/blocking.rs b/esp-hal-procmacros/src/blocking.rs index 249138a4f..991e82548 100644 --- a/esp-hal-procmacros/src/blocking.rs +++ b/esp-hal-procmacros/src/blocking.rs @@ -3,9 +3,9 @@ use proc_macro::TokenStream; use proc_macro2::Span; use syn::{ + ItemFn, parse::{self}, parse_macro_input, - ItemFn, }; pub fn main(args: TokenStream, input: TokenStream) -> TokenStream { diff --git a/esp-hal-procmacros/src/builder.rs b/esp-hal-procmacros/src/builder.rs index 8ec05a1c4..810735e9b 100644 --- a/esp-hal-procmacros/src/builder.rs +++ b/esp-hal-procmacros/src/builder.rs @@ -1,9 +1,6 @@ use proc_macro::TokenStream; use quote::{format_ident, quote}; use syn::{ - parse::Error as ParseError, - punctuated::Punctuated, - spanned::Spanned, Attribute, Data, DataStruct, @@ -14,6 +11,9 @@ use syn::{ PathSegment, Token, Type, + parse::Error as ParseError, + punctuated::Punctuated, + spanned::Spanned, }; const KNOWN_HELPERS: &[&str] = &[ diff --git a/esp-hal-procmacros/src/embassy.rs b/esp-hal-procmacros/src/embassy.rs index cdc4f1a5a..83671b0e7 100644 --- a/esp-hal-procmacros/src/embassy.rs +++ b/esp-hal-procmacros/src/embassy.rs @@ -2,9 +2,9 @@ use darling::ast::NestedMeta; use main_mod::*; use proc_macro::TokenStream; use syn::{ + Token, parse::{Parse, ParseBuffer}, punctuated::Punctuated, - Token, }; pub struct Args { @@ -30,9 +30,9 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { pub mod main_mod { use std::{cell::RefCell, fmt::Display, thread}; - use darling::{export::NestedMeta, FromMeta}; + use darling::{FromMeta, export::NestedMeta}; use proc_macro2::TokenStream; - use quote::{quote, ToTokens}; + use quote::{ToTokens, quote}; use syn::{ReturnType, Type}; #[derive(Debug, FromMeta)] diff --git a/esp-hal-procmacros/src/interrupt.rs b/esp-hal-procmacros/src/interrupt.rs index f0a7d049e..8a1a638c2 100644 --- a/esp-hal-procmacros/src/interrupt.rs +++ b/esp-hal-procmacros/src/interrupt.rs @@ -1,15 +1,15 @@ -use darling::{ast::NestedMeta, FromMeta}; +use darling::{FromMeta, ast::NestedMeta}; use proc_macro::{Span, TokenStream}; +use proc_macro_crate::{FoundCrate, crate_name}; use proc_macro2::Ident; -use proc_macro_crate::{crate_name, FoundCrate}; use syn::{ - parse::Error as SynError, - spanned::Spanned, AttrStyle, Attribute, ItemFn, ReturnType, Type, + parse::Error as SynError, + spanned::Spanned, }; pub enum WhiteListCaller { @@ -40,18 +40,20 @@ pub fn handler(args: TokenStream, input: TokenStream) -> TokenStream { }; let root = Ident::new( - if let Ok(FoundCrate::Name(ref name)) = crate_name("esp-hal") { - name - } else { - "crate" + match crate_name("esp-hal") { + Ok(FoundCrate::Name(ref name)) => name, + _ => "crate", }, Span::call_site().into(), ); - let priority = if let Some(priority) = args.priority { - quote::quote!( #priority ) - } else { - quote::quote! { #root::interrupt::Priority::min() } + let priority = match args.priority { + Some(priority) => { + quote::quote!( #priority ) + } + _ => { + quote::quote! { #root::interrupt::Priority::min() } + } }; // XXX should we blacklist other attributes? diff --git a/esp-hal-procmacros/src/lp_core.rs b/esp-hal-procmacros/src/lp_core.rs index 60a3b351c..0a0129967 100644 --- a/esp-hal-procmacros/src/lp_core.rs +++ b/esp-hal-procmacros/src/lp_core.rs @@ -4,19 +4,19 @@ use quote::quote; #[cfg(any(feature = "is-lp-core", feature = "is-ulp-core"))] pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { + use proc_macro_crate::{FoundCrate, crate_name}; use proc_macro2::{Ident, Span}; - use proc_macro_crate::{crate_name, FoundCrate}; use quote::format_ident; use syn::{ - parse::Error, - parse_macro_input, - spanned::Spanned, FnArg, GenericArgument, ItemFn, PatType, PathArguments, Type, + parse::Error, + parse_macro_input, + spanned::Spanned, }; pub(crate) fn make_magic_symbol_name(args: &Vec<&PatType>) -> String { @@ -181,9 +181,9 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { quote!( #[allow(non_snake_case)] - #[export_name = "main"] + #[unsafe(export_name = "main")] pub fn __risc_v_rt__main() -> ! { - #[export_name = #magic_symbol_name] + #[unsafe(export_name = #magic_symbol_name)] static ULP_MAGIC: [u32; 0] = [0u32; 0]; unsafe { ULP_MAGIC.as_ptr().read_volatile(); } @@ -209,8 +209,8 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { use object::{File, Object, ObjectSection, ObjectSymbol, Section, SectionKind}; use parse::Error; use proc_macro::Span; - use proc_macro_crate::{crate_name, FoundCrate}; - use syn::{parse, Ident}; + use proc_macro_crate::{FoundCrate, crate_name}; + use syn::{Ident, parse}; let hal_crate = if cfg!(any(feature = "is-lp-core", feature = "is-ulp-core")) { crate_name("esp-lp-hal") @@ -349,7 +349,7 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { static LP_CODE: &[u8] = &[#(#binary),*]; - extern "C" { + unsafe extern "C" { static #rtc_code_start: u32; } diff --git a/esp-hal-procmacros/src/ram.rs b/esp-hal-procmacros/src/ram.rs index 78fd1b76d..63f79d553 100644 --- a/esp-hal-procmacros/src/ram.rs +++ b/esp-hal-procmacros/src/ram.rs @@ -1,8 +1,8 @@ -use darling::{ast::NestedMeta, Error, FromMeta}; +use darling::{Error, FromMeta, ast::NestedMeta}; use proc_macro::{Span, TokenStream}; -use proc_macro2::Ident; use proc_macro_error2::abort; -use syn::{parse, Item}; +use proc_macro2::Ident; +use syn::{Item, parse}; #[derive(Debug, Default, darling::FromMeta)] #[darling(default)] @@ -64,11 +64,11 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { let section = match (is_fn, section_name) { (true, Ok(section_name)) => quote::quote! { - #[link_section = #section_name] + #[unsafe(link_section = #section_name)] #[inline(never)] // make certain function is not inlined }, (false, Ok(section_name)) => quote::quote! { - #[link_section = #section_name] + #[unsafe(link_section = #section_name)] }, (_, Err(_)) => { abort!(Span::call_site(), "Invalid combination of ram arguments"); @@ -83,13 +83,12 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { None }; let trait_check = trait_check.map(|name| { - use proc_macro_crate::{crate_name, FoundCrate}; + use proc_macro_crate::{FoundCrate, crate_name}; let hal = Ident::new( - if let Ok(FoundCrate::Name(ref name)) = crate_name("esp-hal") { - name - } else { - "crate" + match crate_name("esp-hal") { + Ok(FoundCrate::Name(ref name)) => name, + _ => "crate", }, Span::call_site().into(), ); diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 46dba3959..a1097b249 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ESP32-S2: Support for light-/deep-sleep (#3341) - Add DMA memcpy support to the S2 (#3352) - Some config options can now only be set when the `unstable` feature in enabled (#3365) +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) ### Changed diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index 371b73a5c..7e7eeb0f7 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-hal" version = "1.0.0-beta.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Bare-metal HAL for Espressif devices" documentation = "https://docs.espressif.com/projects/rust/esp-hal/latest/" keywords = ["embedded", "embedded-hal", "esp32", "espressif", "hal"] @@ -16,6 +16,10 @@ default-target = "riscv32imac-unknown-none-elf" features = ["esp32c6"] rustdoc-args = ["--cfg", "docsrs"] +[lib] +bench = false +test = false + [dependencies] bitflags = "2.8.0" bytemuck = "1.21.0" diff --git a/esp-hal/build.rs b/esp-hal/build.rs index 8b51998b1..beeeae2c6 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -9,7 +9,7 @@ use std::{ }; use esp_build::assert_unique_used_features; -use esp_config::{generate_config, ConfigOption, Stability, Validator, Value}; +use esp_config::{ConfigOption, Stability, Validator, Value, generate_config}; use esp_metadata::{Chip, Config}; fn main() -> Result<(), Box> { @@ -139,8 +139,7 @@ fn main() -> Result<(), Box> { }, ConfigOption { name: "flip-link", - description: - "Move the stack to start of RAM to get zero-cost stack overflow protection.", + description: "Move the stack to start of RAM to get zero-cost stack overflow protection.", default_value: Value::Bool(false), constraint: None, stability: Stability::Unstable, diff --git a/esp-hal/src/aes/esp32.rs b/esp-hal/src/aes/esp32.rs index fb9929cd8..108c58c4c 100644 --- a/esp-hal/src/aes/esp32.rs +++ b/esp-hal/src/aes/esp32.rs @@ -1,4 +1,4 @@ -use crate::aes::{Aes, Aes128, Aes192, Aes256, AesFlavour, Endianness, Mode, ALIGN_SIZE}; +use crate::aes::{ALIGN_SIZE, Aes, Aes128, Aes192, Aes256, AesFlavour, Endianness, Mode}; impl Aes<'_> { pub(super) fn init(&mut self) { diff --git a/esp-hal/src/aes/esp32cX.rs b/esp-hal/src/aes/esp32cX.rs index 0a035d6a5..b115b8d23 100644 --- a/esp-hal/src/aes/esp32cX.rs +++ b/esp-hal/src/aes/esp32cX.rs @@ -1,4 +1,4 @@ -use crate::aes::{Aes, Aes128, Aes256, AesFlavour, Mode, ALIGN_SIZE}; +use crate::aes::{ALIGN_SIZE, Aes, Aes128, Aes256, AesFlavour, Mode}; impl Aes<'_> { pub(super) fn init(&mut self) { diff --git a/esp-hal/src/aes/esp32s2.rs b/esp-hal/src/aes/esp32s2.rs index 1bed8e522..bf9b5078f 100644 --- a/esp-hal/src/aes/esp32s2.rs +++ b/esp-hal/src/aes/esp32s2.rs @@ -1,4 +1,4 @@ -use crate::aes::{Aes, Aes128, Aes192, Aes256, AesFlavour, Endianness, Mode, ALIGN_SIZE}; +use crate::aes::{ALIGN_SIZE, Aes, Aes128, Aes192, Aes256, AesFlavour, Endianness, Mode}; impl Aes<'_> { pub(super) fn init(&mut self) { diff --git a/esp-hal/src/aes/esp32s3.rs b/esp-hal/src/aes/esp32s3.rs index dbc558267..ed89f0744 100644 --- a/esp-hal/src/aes/esp32s3.rs +++ b/esp-hal/src/aes/esp32s3.rs @@ -1,4 +1,4 @@ -use crate::aes::{Aes, Aes128, Aes256, AesFlavour, Mode, ALIGN_SIZE}; +use crate::aes::{ALIGN_SIZE, Aes, Aes128, Aes256, AesFlavour, Mode}; impl Aes<'_> { pub(super) fn init(&mut self) { diff --git a/esp-hal/src/aes/mod.rs b/esp-hal/src/aes/mod.rs index 30439e6bf..f7a0ff651 100644 --- a/esp-hal/src/aes/mod.rs +++ b/esp-hal/src/aes/mod.rs @@ -108,10 +108,10 @@ impl Key { /// Returns a slice representation of the AES key. fn as_slice(&self) -> &[u8] { match self { - Key::Key16(ref key) => key, + Key::Key16(key) => key, #[cfg(any(esp32, esp32s2))] - Key::Key24(ref key) => key, - Key::Key32(ref key) => key, + Key::Key24(key) => key, + Key::Key32(key) => key, } } } @@ -235,6 +235,7 @@ pub mod dma { use core::mem::ManuallyDrop; use crate::{ + Blocking, aes::{Key, Mode}, dma::{ Channel, @@ -245,7 +246,6 @@ pub mod dma { PeripheralDmaChannel, }, peripherals::AES, - Blocking, }; const ALIGN_SIZE: usize = core::mem::size_of::(); diff --git a/esp-hal/src/analog/adc/riscv.rs b/esp-hal/src/analog/adc/riscv.rs index c4e21c1c2..103c8fc36 100644 --- a/esp-hal/src/analog/adc/riscv.rs +++ b/esp-hal/src/analog/adc/riscv.rs @@ -14,13 +14,13 @@ use super::{AdcCalSource, AdcConfig, Attenuation}; #[cfg(any(esp32c2, esp32c3, esp32c6))] use crate::efuse::Efuse; use crate::{ - analog::adc::asynch::AdcFuture, - interrupt::{InterruptConfigurable, InterruptHandler}, - peripherals::{Interrupt, APB_SARADC}, - soc::regi2c, - system::{GenericPeripheralGuard, Peripheral}, Async, Blocking, + analog::adc::asynch::AdcFuture, + interrupt::{InterruptConfigurable, InterruptHandler}, + peripherals::{APB_SARADC, Interrupt}, + soc::regi2c, + system::{GenericPeripheralGuard, Peripheral}, }; mod calibration; @@ -573,7 +573,7 @@ pub(crate) mod asynch { use portable_atomic::{AtomicU32, Ordering}; use procmacros::handler; - use crate::{asynch::AtomicWaker, peripherals::APB_SARADC, Async}; + use crate::{Async, asynch::AtomicWaker, peripherals::APB_SARADC}; #[cfg(all(adc1, adc2))] static ASYNC_ADC_COUNT: AtomicU32 = AtomicU32::new(0); diff --git a/esp-hal/src/assist_debug.rs b/esp-hal/src/assist_debug.rs index 20e71b7f4..5eb7a74a7 100644 --- a/esp-hal/src/assist_debug.rs +++ b/esp-hal/src/assist_debug.rs @@ -26,7 +26,7 @@ use crate::{ interrupt::InterruptHandler, pac, - peripherals::{Interrupt, ASSIST_DEBUG}, + peripherals::{ASSIST_DEBUG, Interrupt}, }; /// The debug assist driver instance. diff --git a/esp-hal/src/clock/clocks_ll/esp32h2.rs b/esp-hal/src/clock/clocks_ll/esp32h2.rs index 29221a299..be45ae520 100644 --- a/esp-hal/src/clock/clocks_ll/esp32h2.rs +++ b/esp-hal/src/clock/clocks_ll/esp32h2.rs @@ -221,11 +221,7 @@ fn regi2c_enable_block(block: u8) -> usize { } }); - if i2c_sel { - 0 - } else { - 1 - } + if i2c_sel { 0 } else { 1 } } pub(crate) fn regi2c_write_mask(block: u8, _host_id: u8, reg_add: u8, msb: u8, lsb: u8, data: u8) { diff --git a/esp-hal/src/dma/buffers.rs b/esp-hal/src/dma/buffers.rs index 3c320e287..2ae48bd07 100644 --- a/esp-hal/src/dma/buffers.rs +++ b/esp-hal/src/dma/buffers.rs @@ -229,11 +229,7 @@ impl InternalBurstConfig { } const fn max(a: usize, b: usize) -> usize { - if a > b { - a - } else { - b - } + if a > b { a } else { b } } impl BurstConfig { diff --git a/esp-hal/src/dma/gdma.rs b/esp-hal/src/dma/gdma.rs index 50e706735..4c4b8999c 100644 --- a/esp-hal/src/dma/gdma.rs +++ b/esp-hal/src/dma/gdma.rs @@ -22,7 +22,7 @@ use crate::{ dma::*, handler, interrupt::Priority, - peripherals::{pac, Interrupt, DMA}, + peripherals::{DMA, Interrupt, pac}, }; /// An arbitrary GDMA channel diff --git a/esp-hal/src/dma/m2m.rs b/esp-hal/src/dma/m2m.rs index f0e244826..265cd2675 100644 --- a/esp-hal/src/dma/m2m.rs +++ b/esp-hal/src/dma/m2m.rs @@ -12,6 +12,9 @@ use crate::dma::{ DmaEligible, }; use crate::{ + Async, + Blocking, + DriverMode, dma::{ BurstConfig, Channel, @@ -27,9 +30,6 @@ use crate::{ DmaTxBuffer, DmaTxInterrupt, }, - Async, - Blocking, - DriverMode, }; #[cfg(esp32s2)] use crate::{ diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index dc315405e..7372f0e5b 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -61,14 +61,14 @@ pub use self::m2m::*; #[cfg(pdma)] pub use self::pdma::*; use crate::{ + Async, + Blocking, + DriverMode, interrupt::InterruptHandler, peripherals::Interrupt, soc::{is_slice_in_dram, is_valid_memory_address, is_valid_ram_address}, system, system::Cpu, - Async, - Blocking, - DriverMode, }; trait Word: crate::private::Sealed {} @@ -579,9 +579,7 @@ pub use as_mut_byte_array; // TODO: can be removed as soon as DMA is stabilized /// ``` #[macro_export] macro_rules! dma_buffers_chunk_size { - ($rx_size:expr, $tx_size:expr, $chunk_size:expr) => {{ - $crate::dma_buffers_impl!($rx_size, $tx_size, $chunk_size, is_circular = false) - }}; + ($rx_size:expr, $tx_size:expr, $chunk_size:expr) => {{ $crate::dma_buffers_impl!($rx_size, $tx_size, $chunk_size, is_circular = false) }}; ($size:expr, $chunk_size:expr) => { $crate::dma_buffers_chunk_size!($size, $size, $chunk_size) @@ -605,13 +603,9 @@ macro_rules! dma_buffers_chunk_size { /// ``` #[macro_export] macro_rules! dma_circular_buffers_chunk_size { - ($rx_size:expr, $tx_size:expr, $chunk_size:expr) => {{ - $crate::dma_buffers_impl!($rx_size, $tx_size, $chunk_size, is_circular = true) - }}; + ($rx_size:expr, $tx_size:expr, $chunk_size:expr) => {{ $crate::dma_buffers_impl!($rx_size, $tx_size, $chunk_size, is_circular = true) }}; - ($size:expr, $chunk_size:expr) => {{ - $crate::dma_circular_buffers_chunk_size!($size, $size, $chunk_size) - }}; + ($size:expr, $chunk_size:expr) => {{ $crate::dma_circular_buffers_chunk_size!($size, $size, $chunk_size) }}; } /// Convenience macro to create DMA descriptors with specific chunk size @@ -630,9 +624,7 @@ macro_rules! dma_circular_buffers_chunk_size { /// ``` #[macro_export] macro_rules! dma_descriptors_chunk_size { - ($rx_size:expr, $tx_size:expr, $chunk_size:expr) => {{ - $crate::dma_descriptors_impl!($rx_size, $tx_size, $chunk_size, is_circular = false) - }}; + ($rx_size:expr, $tx_size:expr, $chunk_size:expr) => {{ $crate::dma_descriptors_impl!($rx_size, $tx_size, $chunk_size, is_circular = false) }}; ($size:expr, $chunk_size:expr) => { $crate::dma_descriptors_chunk_size!($size, $size, $chunk_size) @@ -656,9 +648,7 @@ macro_rules! dma_descriptors_chunk_size { /// ``` #[macro_export] macro_rules! dma_circular_descriptors_chunk_size { - ($rx_size:expr, $tx_size:expr, $chunk_size:expr) => {{ - $crate::dma_descriptors_impl!($rx_size, $tx_size, $chunk_size, is_circular = true) - }}; + ($rx_size:expr, $tx_size:expr, $chunk_size:expr) => {{ $crate::dma_descriptors_impl!($rx_size, $tx_size, $chunk_size, is_circular = true) }}; ($size:expr, $chunk_size:expr) => { $crate::dma_circular_descriptors_chunk_size!($size, $size, $chunk_size) @@ -1137,7 +1127,7 @@ impl<'a> DescriptorSet<'a> { } /// Returns an iterator over the linked descriptors. - fn linked_iter_mut(&mut self) -> impl Iterator { + fn linked_iter_mut(&mut self) -> impl Iterator + use<'_> { let mut was_last = false; self.descriptors.iter_mut().take_while(move |d| { if was_last { @@ -1916,7 +1906,7 @@ where for des in chain.descriptors.iter() { // we are forcing the DMA alignment to the cache line size // required when we are using dcache - let alignment = crate::soc::cache_get_dcache_line_size() as usize; + let alignment = unsafe { crate::soc::cache_get_dcache_line_size() } as usize; if crate::soc::addr_in_range(des.buffer as usize, psram_range.clone()) { uses_psram = true; // both the size and address of the buffer must be aligned @@ -1926,7 +1916,7 @@ where if des.size() % alignment != 0 { return Err(DmaError::InvalidAlignment(DmaAlignmentError::Size)); } - crate::soc::cache_invalidate_addr(des.buffer as u32, des.size() as u32); + unsafe {crate::soc::cache_invalidate_addr(des.buffer as u32, des.size() as u32); } } } } @@ -2182,7 +2172,7 @@ where for des in chain.descriptors.iter() { // we are forcing the DMA alignment to the cache line size // required when we are using dcache - let alignment = crate::soc::cache_get_dcache_line_size() as usize; + let alignment = unsafe { crate::soc::cache_get_dcache_line_size()} as usize; if crate::soc::addr_in_range(des.buffer as usize, psram_range.clone()) { uses_psram = true; // both the size and address of the buffer must be aligned @@ -2192,7 +2182,7 @@ where if des.size() % alignment != 0 { return Err(DmaError::InvalidAlignment(DmaAlignmentError::Size)); } - crate::soc::cache_writeback_addr(des.buffer as u32, des.size() as u32); + unsafe { crate::soc::cache_writeback_addr(des.buffer as u32, des.size() as u32); } } } } @@ -2206,7 +2196,7 @@ where burst_transfer: BurstConfig::default(), check_owner: Some(false), // enable descriptor write back in circular mode - auto_write_back: !(*chain.last()).next.is_null(), + auto_write_back: !(unsafe { *chain.last() }).next.is_null(), }; self.do_prepare(preparation, peri)?; diff --git a/esp-hal/src/dma/pdma/copy.rs b/esp-hal/src/dma/pdma/copy.rs index 81fd00161..acdae9012 100644 --- a/esp-hal/src/dma/pdma/copy.rs +++ b/esp-hal/src/dma/pdma/copy.rs @@ -4,7 +4,7 @@ use crate::{ asynch::AtomicWaker, dma::*, interrupt::{InterruptHandler, Priority}, - peripherals::{Interrupt, DMA_COPY}, + peripherals::{DMA_COPY, Interrupt}, }; pub(super) type CopyRegisterBlock = crate::pac::copy_dma::RegisterBlock; diff --git a/esp-hal/src/dma/pdma/crypto.rs b/esp-hal/src/dma/pdma/crypto.rs index f610036eb..455e6b2d3 100644 --- a/esp-hal/src/dma/pdma/crypto.rs +++ b/esp-hal/src/dma/pdma/crypto.rs @@ -4,7 +4,7 @@ use crate::{ asynch::AtomicWaker, dma::*, interrupt::Priority, - peripherals::{Interrupt, DMA_CRYPTO}, + peripherals::{DMA_CRYPTO, Interrupt}, }; pub(super) type CryptoRegisterBlock = crate::pac::crypto_dma::RegisterBlock; diff --git a/esp-hal/src/dma/pdma/mod.rs b/esp-hal/src/dma/pdma/mod.rs index 8d81331af..4ce82db62 100644 --- a/esp-hal/src/dma/pdma/mod.rs +++ b/esp-hal/src/dma/pdma/mod.rs @@ -53,12 +53,12 @@ macro_rules! impl_pdma_channel { type Rx = [<$peri DmaRxChannel>]<'d>; type Tx = [<$peri DmaTxChannel>]<'d>; - unsafe fn split_internal(self, _: $crate::private::Internal) -> (Self::Rx, Self::Tx) { + unsafe fn split_internal(self, _: $crate::private::Internal) -> (Self::Rx, Self::Tx) { unsafe { ( [<$peri DmaRxChannel>](Self::steal().into()), [<$peri DmaTxChannel>](Self::steal().into()), ) - } + }} } impl DmaChannelExt for $instance<'_> { diff --git a/esp-hal/src/ecc.rs b/esp-hal/src/ecc.rs index 890e96763..b8d5e4722 100644 --- a/esp-hal/src/ecc.rs +++ b/esp-hal/src/ecc.rs @@ -28,13 +28,13 @@ use core::marker::PhantomData; use crate::{ - interrupt::InterruptHandler, - pac, - peripherals::{Interrupt, ECC}, - reg_access::{AlignmentHelper, SocDependentEndianess}, - system::{self, GenericPeripheralGuard}, Blocking, DriverMode, + interrupt::InterruptHandler, + pac, + peripherals::{ECC, Interrupt}, + reg_access::{AlignmentHelper, SocDependentEndianess}, + system::{self, GenericPeripheralGuard}, }; /// The ECC Accelerator driver instance diff --git a/esp-hal/src/gpio/etm.rs b/esp-hal/src/gpio/etm.rs index f2fcece20..48c28bd1a 100644 --- a/esp-hal/src/gpio/etm.rs +++ b/esp-hal/src/gpio/etm.rs @@ -55,9 +55,9 @@ use core::marker::PhantomData; use crate::{ gpio::{ - interconnect::{InputSignal, OutputSignal}, Level, Pull, + interconnect::{InputSignal, OutputSignal}, }, peripherals::GPIO_SD, private, diff --git a/esp-hal/src/gpio/interconnect.rs b/esp-hal/src/gpio/interconnect.rs index 685d80055..b33e97a34 100644 --- a/esp-hal/src/gpio/interconnect.rs +++ b/esp-hal/src/gpio/interconnect.rs @@ -14,20 +14,20 @@ use crate::{ self, AlternateFunction, AnyPin, + FUNC_IN_SEL_OFFSET, Flex, + GPIO_FUNCTION, + INPUT_SIGNAL_MAX, InputPin, InputSignalType, Level, NoPin, + OUTPUT_SIGNAL_MAX, OutputPin, OutputSignalType, Pin, PinGuard, Pull, - FUNC_IN_SEL_OFFSET, - GPIO_FUNCTION, - INPUT_SIGNAL_MAX, - OUTPUT_SIGNAL_MAX, }, peripherals::GPIO, private::{self, Sealed}, diff --git a/esp-hal/src/gpio/lp_io.rs b/esp-hal/src/gpio/lp_io.rs index 528d3fbc5..52032a94c 100644 --- a/esp-hal/src/gpio/lp_io.rs +++ b/esp-hal/src/gpio/lp_io.rs @@ -201,7 +201,9 @@ macro_rules! lp_gpio { unsafe fn apply_wakeup(&self, wakeup: bool, level: u8) { let lp_io = $crate::peripherals::LP_IO::regs(); lp_io.pin($gpionum).modify(|_, w| { - w.wakeup_enable().bit(wakeup).int_type().bits(level) + unsafe { + w.wakeup_enable().bit(wakeup).int_type().bits(level) + } }); } diff --git a/esp-hal/src/gpio/mod.rs b/esp-hal/src/gpio/mod.rs index a2425f7f1..f233e6cd5 100644 --- a/esp-hal/src/gpio/mod.rs +++ b/esp-hal/src/gpio/mod.rs @@ -61,8 +61,8 @@ use strum::EnumCount; use crate::peripherals::{handle_rtcio, handle_rtcio_with_resistors}; pub use crate::soc::gpio::*; use crate::{ - interrupt::{self, InterruptHandler, Priority, DEFAULT_INTERRUPT_HANDLER}, - peripherals::{handle_gpio_input, handle_gpio_output, Interrupt, GPIO, IO_MUX}, + interrupt::{self, DEFAULT_INTERRUPT_HANDLER, InterruptHandler, Priority}, + peripherals::{GPIO, IO_MUX, Interrupt, handle_gpio_input, handle_gpio_output}, private::{self, Sealed}, }; @@ -1012,6 +1012,7 @@ macro_rules! gpio { $( $gpionum => $crate::if_rtcio_pin!($($type),* {{ #[allow(unused_mut)] + #[allow(unused_unsafe)] let mut $inner = unsafe { $crate::peripherals::[]::steal() }; $code }} else {{ @@ -2132,9 +2133,11 @@ impl RtcPin for AnyPin<'_> { #[cfg(any(esp32c2, esp32c3, esp32c6))] unsafe fn apply_wakeup(&self, wakeup: bool, level: u8) { - handle_rtcio!(self, target, { - RtcPin::apply_wakeup(&target, wakeup, level) - }) + unsafe { + handle_rtcio!(self, target, { + RtcPin::apply_wakeup(&target, wakeup, level) + }) + } } } diff --git a/esp-hal/src/i2c/lp_i2c.rs b/esp-hal/src/i2c/lp_i2c.rs index 96610d9e1..b412d9308 100644 --- a/esp-hal/src/i2c/lp_i2c.rs +++ b/esp-hal/src/i2c/lp_i2c.rs @@ -2,7 +2,7 @@ use crate::{ gpio::lp_io::LowPowerOutputOpenDrain, - peripherals::{LPWR, LP_AON, LP_I2C0, LP_IO, LP_PERI}, + peripherals::{LP_AON, LP_I2C0, LP_IO, LP_PERI, LPWR}, time::Rate, }; diff --git a/esp-hal/src/i2c/master/mod.rs b/esp-hal/src/i2c/master/mod.rs index 516b3531f..acf36e6eb 100644 --- a/esp-hal/src/i2c/master/mod.rs +++ b/esp-hal/src/i2c/master/mod.rs @@ -31,25 +31,25 @@ use embedded_hal::i2c::Operation as EhalOperation; use enumset::{EnumSet, EnumSetType}; use crate::{ + Async, + Blocking, + DriverMode, asynch::AtomicWaker, clock::Clocks, gpio::{ - interconnect::{OutputConnection, PeripheralOutput}, InputSignal, OutputSignal, PinGuard, Pull, + interconnect::{OutputConnection, PeripheralOutput}, }, i2c::{AnyI2c, AnyI2cInner}, interrupt::InterruptHandler, - pac::i2c0::{RegisterBlock, COMD}, + pac::i2c0::{COMD, RegisterBlock}, peripherals::Interrupt, private, system::{PeripheralClockControl, PeripheralGuard}, time::Rate, - Async, - Blocking, - DriverMode, }; cfg_if::cfg_if! { diff --git a/esp-hal/src/i2s/master.rs b/esp-hal/src/i2s/master.rs index b755cae19..b0ffad746 100644 --- a/esp-hal/src/i2s/master.rs +++ b/esp-hal/src/i2s/master.rs @@ -73,8 +73,10 @@ use enumset::{EnumSet, EnumSetType}; use private::*; use crate::{ + Async, + Blocking, + DriverMode, dma::{ - dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx}, Channel, ChannelRx, ChannelTx, @@ -90,15 +92,13 @@ use crate::{ PeripheralTxChannel, ReadBuffer, WriteBuffer, + dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx}, }, gpio::interconnect::PeripheralOutput, i2s::AnyI2s, interrupt::{InterruptConfigurable, InterruptHandler}, system::PeripheralGuard, time::Rate, - Async, - Blocking, - DriverMode, }; #[derive(Debug, EnumSetType)] @@ -678,16 +678,16 @@ mod private { #[cfg(not(i2s1))] use crate::pac::i2s0::RegisterBlock; use crate::{ + DriverMode, dma::{ChannelRx, ChannelTx, DescriptorChain, DmaDescriptor, DmaEligible}, gpio::{ - interconnect::{PeripheralInput, PeripheralOutput}, InputSignal, OutputSignal, + interconnect::{PeripheralInput, PeripheralOutput}, }, i2s::AnyI2sInner, interrupt::InterruptHandler, - peripherals::{Interrupt, I2S0}, - DriverMode, + peripherals::{I2S0, Interrupt}, }; // on ESP32-S3 I2S1 doesn't support all features - use that to avoid using those features // by accident @@ -1784,15 +1784,15 @@ mod private { pub mod asynch { use super::{Error, I2sRx, I2sTx, RegisterAccessPrivate}; use crate::{ + Async, dma::{ - asynch::{DmaRxDoneChFuture, DmaRxFuture, DmaTxDoneChFuture, DmaTxFuture}, DmaEligible, ReadBuffer, RxCircularState, TxCircularState, WriteBuffer, + asynch::{DmaRxDoneChFuture, DmaRxFuture, DmaTxDoneChFuture, DmaTxFuture}, }, - Async, }; impl<'d> I2sTx<'d, Async> { diff --git a/esp-hal/src/i2s/parallel.rs b/esp-hal/src/i2s/parallel.rs index 63758d9cc..027294740 100644 --- a/esp-hal/src/i2s/parallel.rs +++ b/esp-hal/src/i2s/parallel.rs @@ -103,8 +103,10 @@ use core::{ }; use crate::{ + Async, + Blocking, + DriverMode, dma::{ - asynch::DmaTxFuture, Channel, ChannelTx, DmaChannelFor, @@ -112,19 +114,17 @@ use crate::{ DmaError, DmaTxBuffer, PeripheralTxChannel, + asynch::DmaTxFuture, }, gpio::{ - interconnect::{OutputConnection, PeripheralOutput}, OutputSignal, + interconnect::{OutputConnection, PeripheralOutput}, }, i2s::{AnyI2s, AnyI2sInner}, pac::i2s0::RegisterBlock, peripherals::{I2S0, I2S1}, system::PeripheralGuard, time::Rate, - Async, - Blocking, - DriverMode, }; #[doc(hidden)] diff --git a/esp-hal/src/interrupt/mod.rs b/esp-hal/src/interrupt/mod.rs index 03532fda7..49148dda4 100644 --- a/esp-hal/src/interrupt/mod.rs +++ b/esp-hal/src/interrupt/mod.rs @@ -85,7 +85,7 @@ mod xtensa; pub mod software; -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn EspDefaultHandler(_interrupt: crate::peripherals::Interrupt) { panic!("Unhandled interrupt: {:?}", _interrupt); } diff --git a/esp-hal/src/interrupt/riscv.rs b/esp-hal/src/interrupt/riscv.rs index 6fbd47fcf..3cc73e720 100644 --- a/esp-hal/src/interrupt/riscv.rs +++ b/esp-hal/src/interrupt/riscv.rs @@ -12,8 +12,8 @@ //! interrupt15() => Priority::Priority15 //! ``` -pub(crate) use esp_riscv_rt::riscv::interrupt::free; pub use esp_riscv_rt::TrapFrame; +pub(crate) use esp_riscv_rt::riscv::interrupt::free; use riscv::register::{mcause, mtvec}; #[cfg(not(plic))] @@ -24,7 +24,7 @@ pub use self::vectored::*; use super::InterruptStatus; use crate::{ pac, - peripherals::{Interrupt, INTERRUPT_CORE0}, + peripherals::{INTERRUPT_CORE0, Interrupt}, system::Cpu, }; @@ -204,30 +204,32 @@ impl TryFrom for Priority { } /// The interrupts reserved by the HAL -#[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] +#[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub static RESERVED_INTERRUPTS: &[usize] = PRIORITY_TO_INTERRUPT; /// # Safety /// /// This function is called from an assembly trap handler. #[doc(hidden)] -#[link_section = ".trap.rust"] -#[export_name = "_start_trap_rust_hal"] +#[unsafe(link_section = ".trap.rust")] +#[unsafe(export_name = "_start_trap_rust_hal")] pub unsafe extern "C" fn start_trap_rust_hal(trap_frame: *mut TrapFrame) { assert!( mcause::read().is_exception(), "Arrived into _start_trap_rust_hal but mcause is not an exception!" ); - extern "C" { + unsafe extern "C" { fn ExceptionHandler(tf: *mut TrapFrame); } - ExceptionHandler(trap_frame); + unsafe { + ExceptionHandler(trap_frame); + } } #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub fn _setup_interrupts() { - extern "C" { + unsafe extern "C" { static _vector_table: *const u32; } @@ -338,9 +340,11 @@ pub unsafe fn map(_core: Cpu, interrupt: Interrupt, which: CpuInterrupt) { Cpu::AppCpu => crate::soc::registers::INTERRUPT_MAP_BASE_APP_CPU as *mut u32, }; - intr_map_base - .offset(interrupt_number) - .write_volatile(cpu_interrupt_number as u32 + EXTERNAL_INTERRUPT_OFFSET); + unsafe { + intr_map_base + .offset(interrupt_number) + .write_volatile(cpu_interrupt_number as u32 + EXTERNAL_INTERRUPT_OFFSET); + } } /// Get cpu interrupt assigned to peripheral interrupt @@ -349,11 +353,11 @@ unsafe fn assigned_cpu_interrupt(interrupt: Interrupt) -> Option { let interrupt_number = interrupt as isize; let intr_map_base = crate::soc::registers::INTERRUPT_MAP_BASE as *mut u32; - let cpu_intr = intr_map_base.offset(interrupt_number).read_volatile(); + let cpu_intr = unsafe { intr_map_base.offset(interrupt_number).read_volatile() }; if cpu_intr > 0 && cpu_intr != DISABLED_CPU_INTERRUPT { - Some(core::mem::transmute::( - cpu_intr - EXTERNAL_INTERRUPT_OFFSET, - )) + Some(unsafe { + core::mem::transmute::(cpu_intr - EXTERNAL_INTERRUPT_OFFSET) + }) } else { None } @@ -372,17 +376,19 @@ mod vectored { #[doc(hidden)] pub(crate) unsafe fn init_vectoring() { for (prio, num) in PRIORITY_TO_INTERRUPT.iter().enumerate() { - set_kind( - Cpu::current(), - core::mem::transmute::(*num as u32), - InterruptKind::Level, - ); - set_priority( - Cpu::current(), - core::mem::transmute::(*num as u32), - core::mem::transmute::((prio as u8) + 1), - ); - enable_cpu_interrupt(core::mem::transmute::(*num as u32)); + unsafe { + set_kind( + Cpu::current(), + core::mem::transmute::(*num as u32), + InterruptKind::Level, + ); + set_priority( + Cpu::current(), + core::mem::transmute::(*num as u32), + core::mem::transmute::((prio as u8) + 1), + ); + enable_cpu_interrupt(core::mem::transmute::(*num as u32)); + } } } @@ -437,9 +443,11 @@ mod vectored { /// /// This will replace any previously bound interrupt handler pub unsafe fn bind_interrupt(interrupt: Interrupt, handler: unsafe extern "C" fn()) { - let ptr = &pac::__EXTERNAL_INTERRUPTS[interrupt as usize]._handler as *const _ - as *mut unsafe extern "C" fn(); - ptr.write_volatile(handler); + unsafe { + let ptr = &pac::__EXTERNAL_INTERRUPTS[interrupt as usize]._handler as *const _ + as *mut unsafe extern "C" fn(); + ptr.write_volatile(handler); + } } /// Returns the currently bound interrupt handler. @@ -454,7 +462,7 @@ mod vectored { } } - #[no_mangle] + #[unsafe(no_mangle)] #[ram] unsafe fn handle_interrupts(cpu_intr: CpuInterrupt, context: &mut TrapFrame) { let core = Cpu::current(); @@ -471,27 +479,30 @@ mod vectored { for interrupt_nr in configured_interrupts.iterator() { // Don't use `Interrupt::try_from`. It's slower and placed in flash let interrupt: Interrupt = unsafe { core::mem::transmute(interrupt_nr as u16) }; - handle_interrupt(interrupt, context); + unsafe { + handle_interrupt(interrupt, context); + } } } #[inline(always)] unsafe fn handle_interrupt(interrupt: Interrupt, save_frame: &mut TrapFrame) { - extern "C" { + unsafe extern "C" { // defined in each hal fn EspDefaultHandler(interrupt: Interrupt); } - let handler = pac::__EXTERNAL_INTERRUPTS[interrupt as usize]._handler; + let handler = unsafe { pac::__EXTERNAL_INTERRUPTS[interrupt as usize]._handler }; if core::ptr::eq( handler as *const _, EspDefaultHandler as *const unsafe extern "C" fn(), ) { - EspDefaultHandler(interrupt); + unsafe { EspDefaultHandler(interrupt) }; } else { - let handler: fn(&mut TrapFrame) = - core::mem::transmute::(handler); + let handler: fn(&mut TrapFrame) = unsafe { + core::mem::transmute::(handler) + }; handler(save_frame); } } @@ -571,18 +582,18 @@ mod classic { use super::{CpuInterrupt, InterruptKind, Priority}; use crate::{peripherals::INTERRUPT_CORE0, system::Cpu}; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub(super) static DISABLED_CPU_INTERRUPT: u32 = 0; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub(super) static EXTERNAL_INTERRUPT_OFFSET: u32 = 0; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub(super) static PRIORITY_TO_INTERRUPT: &[usize] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; // First element is not used, just there to avoid a -1 in the interrupt handler. - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub(super) static INTERRUPT_TO_PRIORITY: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; @@ -595,7 +606,7 @@ mod classic { let cpu_interrupt_number = which as isize; let intr = INTERRUPT_CORE0::regs(); intr.cpu_int_enable() - .modify(|r, w| w.bits((1 << cpu_interrupt_number) | r.bits())); + .modify(|r, w| unsafe { w.bits((1 << cpu_interrupt_number) | r.bits()) }); } /// Set the interrupt kind (i.e. level or edge) of an CPU interrupt @@ -629,7 +640,7 @@ mod classic { pub unsafe fn set_priority(_core: Cpu, which: CpuInterrupt, priority: Priority) { let intr = INTERRUPT_CORE0::regs(); intr.cpu_int_pri(which as usize) - .write(|w| w.map().bits(priority as u8)); + .write(|w| unsafe { w.map().bits(priority as u8) }); } /// Clear a CPU interrupt @@ -653,41 +664,43 @@ mod classic { #[inline] pub(super) unsafe extern "C" fn priority(cpu_interrupt: CpuInterrupt) -> Priority { let intr = INTERRUPT_CORE0::regs(); - core::mem::transmute::( - intr.cpu_int_pri(cpu_interrupt as usize).read().map().bits(), - ) + unsafe { + core::mem::transmute::( + intr.cpu_int_pri(cpu_interrupt as usize).read().map().bits(), + ) + } } - #[no_mangle] - #[link_section = ".trap"] + #[unsafe(no_mangle)] + #[unsafe(link_section = ".trap")] pub(super) unsafe extern "C" fn _handle_priority() -> u32 { use super::mcause; // Both C6 and H2 have 5 bits of code. The riscv crate masks 31 bits, which then // causes a bounds check to be present. let interrupt_id: usize = mcause::read().bits() & 0x1f; let intr = INTERRUPT_CORE0::regs(); - let interrupt_priority = intr - .cpu_int_pri(0) - .as_ptr() - .add(interrupt_id) - .read_volatile(); + let interrupt_priority = unsafe { + intr.cpu_int_pri(0) + .as_ptr() + .add(interrupt_id) + .read_volatile() + }; let prev_interrupt_priority = intr.cpu_int_thresh().read().bits(); if interrupt_priority < 15 { // leave interrupts disabled if interrupt is of max priority. intr.cpu_int_thresh() - .write(|w| w.bits(interrupt_priority + 1)); // set the prio threshold to 1 more than current interrupt prio - unsafe { - riscv::interrupt::enable(); - } + .write(|w| unsafe { w.bits(interrupt_priority + 1) }); // set the prio threshold to 1 more than current interrupt prio + unsafe { riscv::interrupt::enable() }; } prev_interrupt_priority } - #[no_mangle] - #[link_section = ".trap"] + #[unsafe(no_mangle)] + #[unsafe(link_section = ".trap")] pub(super) unsafe extern "C" fn _restore_priority(stored_prio: u32) { riscv::interrupt::disable(); let intr = INTERRUPT_CORE0::regs(); - intr.cpu_int_thresh().write(|w| w.bits(stored_prio)); + intr.cpu_int_thresh() + .write(|w| unsafe { w.bits(stored_prio) }); } /// Get the current run level (the level below which interrupts are masked). @@ -713,7 +726,7 @@ mod classic { // interrupts at `level` so we set the threshold to `level + 1`. INTERRUPT_CORE0::regs() .cpu_int_thresh() - .write(|w| w.bits(level as u32 + 1)); + .write(|w| unsafe { w.bits(level as u32 + 1) }); prev_interrupt_priority } @@ -724,21 +737,21 @@ mod plic { use super::{CpuInterrupt, InterruptKind, Priority}; use crate::{peripherals::PLIC_MX, system::Cpu}; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub(super) static DISABLED_CPU_INTERRUPT: u32 = 31; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub(super) static EXTERNAL_INTERRUPT_OFFSET: u32 = 0; // don't use interrupts reserved for CLIC (0,3,4,7) // for some reason also CPU interrupt 8 doesn't work by default since it's // disabled after reset - so don't use that, too - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub(super) static PRIORITY_TO_INTERRUPT: &[usize] = &[1, 2, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]; // First element is not used, just there to avoid a -1 in the interrupt handler. - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub(super) static INTERRUPT_TO_PRIORITY: [u8; 20] = [ 0, 1, 2, 0, 0, 3, 4, 0, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ]; @@ -820,10 +833,10 @@ mod plic { .read() .cpu_mxint_pri() .bits(); - core::mem::transmute::(prio) + unsafe { core::mem::transmute::(prio) } } - #[no_mangle] - #[link_section = ".trap"] + #[unsafe(no_mangle)] + #[unsafe(link_section = ".trap")] pub(super) unsafe extern "C" fn _handle_priority() -> u32 { let interrupt_id: usize = super::mcause::read().code(); // MSB is whether its exception or interrupt. let interrupt_priority = PLIC_MX::regs() @@ -841,20 +854,21 @@ mod plic { // leave interrupts disabled if interrupt is of max priority. PLIC_MX::regs() .mxint_thresh() - .write(|w| w.cpu_mxint_thresh().bits(interrupt_priority + 1)); + .write(|w| unsafe { w.cpu_mxint_thresh().bits(interrupt_priority + 1) }); + unsafe { riscv::interrupt::enable(); } } prev_interrupt_priority as u32 } - #[no_mangle] - #[link_section = ".trap"] + #[unsafe(no_mangle)] + #[unsafe(link_section = ".trap")] pub(super) unsafe extern "C" fn _restore_priority(stored_prio: u32) { riscv::interrupt::disable(); PLIC_MX::regs() .mxint_thresh() - .write(|w| w.cpu_mxint_thresh().bits(stored_prio as u8)); + .write(|w| unsafe { w.cpu_mxint_thresh().bits(stored_prio as u8) }); } /// Get the current run level (the level below which interrupts are masked). @@ -884,7 +898,7 @@ mod plic { // interrupts at `level` so we set the threshold to `level + 1`. PLIC_MX::regs() .mxint_thresh() - .write(|w| w.cpu_mxint_thresh().bits(level as u8 + 1)); + .write(|w| unsafe { w.cpu_mxint_thresh().bits(level as u8 + 1) }); prev_interrupt_priority } diff --git a/esp-hal/src/interrupt/xtensa.rs b/esp-hal/src/interrupt/xtensa.rs index f507eaa93..9bfb31144 100644 --- a/esp-hal/src/interrupt/xtensa.rs +++ b/esp-hal/src/interrupt/xtensa.rs @@ -119,7 +119,7 @@ impl CpuInterrupt { } /// The interrupts reserved by the HAL -#[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] +#[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub static RESERVED_INTERRUPTS: &[usize] = &[ CpuInterrupt::Interrupt1LevelPriority1 as _, CpuInterrupt::Interrupt19LevelPriority2 as _, @@ -174,14 +174,16 @@ pub fn enable_direct(interrupt: Interrupt, cpu_interrupt: CpuInterrupt) -> Resul pub unsafe fn map(core: Cpu, interrupt: Interrupt, which: CpuInterrupt) { let interrupt_number = interrupt as isize; let cpu_interrupt_number = which as isize; - let intr_map_base = match core { - Cpu::ProCpu => (*core0_interrupt_peripheral()).pro_mac_intr_map().as_ptr(), - #[cfg(multi_core)] - Cpu::AppCpu => (*core1_interrupt_peripheral()).app_mac_intr_map().as_ptr(), - }; - intr_map_base - .offset(interrupt_number) - .write_volatile(cpu_interrupt_number as u32); + unsafe { + let intr_map_base = match core { + Cpu::ProCpu => (*core0_interrupt_peripheral()).pro_mac_intr_map().as_ptr(), + #[cfg(multi_core)] + Cpu::AppCpu => (*core1_interrupt_peripheral()).app_mac_intr_map().as_ptr(), + }; + intr_map_base + .offset(interrupt_number) + .write_volatile(cpu_interrupt_number as u32); + } } /// Get cpu interrupt assigned to peripheral interrupt @@ -350,12 +352,14 @@ pub(crate) fn current_runlevel() -> Priority { /// runlevel. pub(crate) unsafe fn change_current_runlevel(level: Priority) -> Priority { let token: u32; - match level { - Priority::None => core::arch::asm!("rsil {0}, 0", out(reg) token), - Priority::Priority1 => core::arch::asm!("rsil {0}, 1", out(reg) token), - Priority::Priority2 => core::arch::asm!("rsil {0}, 2", out(reg) token), - Priority::Priority3 => core::arch::asm!("rsil {0}, 3", out(reg) token), - }; + unsafe { + match level { + Priority::None => core::arch::asm!("rsil {0}, 0", out(reg) token), + Priority::Priority1 => core::arch::asm!("rsil {0}, 1", out(reg) token), + Priority::Priority2 => core::arch::asm!("rsil {0}, 2", out(reg) token), + Priority::Priority3 => core::arch::asm!("rsil {0}, 3", out(reg) token), + }; + } let prev_interrupt_priority = token as u8 & 0x0F; @@ -511,9 +515,13 @@ mod vectored { /// /// This will replace any previously bound interrupt handler pub unsafe fn bind_interrupt(interrupt: Interrupt, handler: unsafe extern "C" fn()) { - let ptr = &pac::__INTERRUPTS[interrupt as usize]._handler as *const _ - as *mut unsafe extern "C" fn(); - ptr.write_volatile(handler); + let ptr = unsafe { + &pac::__INTERRUPTS[interrupt as usize]._handler as *const _ + as *mut unsafe extern "C" fn() + }; + unsafe { + ptr.write_volatile(handler); + } } /// Returns the currently bound interrupt handler. @@ -523,7 +531,6 @@ mod vectored { if addr as usize == 0 { return None; } - Some(addr) } } @@ -550,7 +557,7 @@ mod vectored { } // TODO use CpuInterrupt::LevelX.mask() // TODO make it const - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] static CPU_INTERRUPT_LEVELS: [u32; 8] = [ 0b_0000_0000_0000_0000_0000_0000_0000_0000, // Dummy level 0 0b_0000_0000_0000_0110_0011_0111_1111_1111, // Level_1 @@ -561,9 +568,9 @@ mod vectored { 0b_0000_0000_0000_0000_0000_0000_0000_0000, // Level 6 0b_0000_0000_0000_0000_0100_0000_0000_0000, // Level 7 ]; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] static CPU_INTERRUPT_INTERNAL: u32 = 0b_0010_0000_0000_0001_1000_1000_1100_0000; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] static CPU_INTERRUPT_EDGE: u32 = 0b_0111_0000_0100_0000_0000_1100_1000_0000; #[inline] @@ -584,22 +591,28 @@ mod vectored { }) } - #[no_mangle] + #[unsafe(no_mangle)] #[ram] unsafe fn __level_1_interrupt(save_frame: &mut Context) { - handle_interrupts::<1>(save_frame); + unsafe { + handle_interrupts::<1>(save_frame); + } } - #[no_mangle] + #[unsafe(no_mangle)] #[ram] unsafe fn __level_2_interrupt(save_frame: &mut Context) { - handle_interrupts::<2>(save_frame); + unsafe { + handle_interrupts::<2>(save_frame); + } } - #[no_mangle] + #[unsafe(no_mangle)] #[ram] unsafe fn __level_3_interrupt(save_frame: &mut Context) { - handle_interrupts::<3>(save_frame); + unsafe { + handle_interrupts::<3>(save_frame); + } } #[inline(always)] @@ -622,11 +635,13 @@ mod vectored { // If the interrupt is edge triggered, we need to clear the request on the CPU's // side. if ((1 << cpu_interrupt_nr) & CPU_INTERRUPT_EDGE) != 0 { - interrupt::clear(1 << cpu_interrupt_nr); + unsafe { + interrupt::clear(1 << cpu_interrupt_nr); + } } if let Some(handler) = cpu_interrupt_nr_to_cpu_interrupt_handler(cpu_interrupt_nr) { - handler(save_frame); + unsafe { handler(save_frame) }; } } else { let status = if !cfg!(esp32s3) && (cpu_interrupt_mask & CPU_INTERRUPT_EDGE) != 0 { @@ -635,7 +650,7 @@ mod vectored { // If the interrupt is edge triggered, we need to clear the // request on the CPU's side - interrupt::clear(cpu_interrupt_mask & CPU_INTERRUPT_EDGE); + unsafe { interrupt::clear(cpu_interrupt_mask & CPU_INTERRUPT_EDGE) }; // For edge interrupts we cannot rely on the peripherals' interrupt status // registers, therefore call all registered handlers for current level. @@ -651,20 +666,21 @@ mod vectored { // Don't use `Interrupt::try_from`. It's slower and placed in flash let interrupt: Interrupt = unsafe { core::mem::transmute(interrupt_nr as u16) }; - extern "C" { + unsafe extern "C" { // defined in each hal fn EspDefaultHandler(interrupt: Interrupt); } - let handler = pac::__INTERRUPTS[interrupt as usize]._handler; + let handler = unsafe { pac::__INTERRUPTS[interrupt as usize]._handler }; if core::ptr::eq( handler as *const _, EspDefaultHandler as *const unsafe extern "C" fn(), ) { - EspDefaultHandler(interrupt); + unsafe { EspDefaultHandler(interrupt) }; } else { - let handler: fn(&mut Context) = - core::mem::transmute::(handler); + let handler: fn(&mut Context) = unsafe { + core::mem::transmute::(handler) + }; handler(save_frame); } } @@ -674,7 +690,7 @@ mod vectored { #[cfg(esp32)] mod chip_specific { use super::*; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::from( 0b0000_0000_0000_0000_0000_0000_0000_0000, 0b1111_1100_0000_0000_0000_0000_0000_0000, @@ -699,7 +715,7 @@ mod vectored { #[cfg(esp32s2)] mod chip_specific { use super::*; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::from( 0b0000_0000_0000_0000_0000_0000_0000_0000, 0b1100_0000_0000_0000_0000_0000_0000_0000, @@ -727,7 +743,7 @@ mod vectored { #[cfg(esp32s3)] mod chip_specific { use super::*; - #[cfg_attr(place_switch_tables_in_ram, link_section = ".rwtext")] + #[cfg_attr(place_switch_tables_in_ram, unsafe(link_section = ".rwtext"))] pub static INTERRUPT_EDGE: InterruptStatus = InterruptStatus::empty(); #[inline] pub fn interrupt_is_edge(_interrupt: Interrupt) -> bool { @@ -739,34 +755,34 @@ mod vectored { mod raw { use super::*; - extern "C" { + unsafe extern "C" { fn level4_interrupt(save_frame: &mut Context); fn level5_interrupt(save_frame: &mut Context); fn level6_interrupt(save_frame: &mut Context); fn level7_interrupt(save_frame: &mut Context); } - #[no_mangle] - #[link_section = ".rwtext"] + #[unsafe(no_mangle)] + #[unsafe(link_section = ".rwtext")] unsafe fn __level_4_interrupt(save_frame: &mut Context) { - level4_interrupt(save_frame) + unsafe { level4_interrupt(save_frame) } } - #[no_mangle] - #[link_section = ".rwtext"] + #[unsafe(no_mangle)] + #[unsafe(link_section = ".rwtext")] unsafe fn __level_5_interrupt(save_frame: &mut Context) { - level5_interrupt(save_frame) + unsafe { level5_interrupt(save_frame) } } - #[no_mangle] - #[link_section = ".rwtext"] + #[unsafe(no_mangle)] + #[unsafe(link_section = ".rwtext")] unsafe fn __level_6_interrupt(save_frame: &mut Context) { - level6_interrupt(save_frame) + unsafe { level6_interrupt(save_frame) } } - #[no_mangle] - #[link_section = ".rwtext"] + #[unsafe(no_mangle)] + #[unsafe(link_section = ".rwtext")] unsafe fn __level_7_interrupt(save_frame: &mut Context) { - level7_interrupt(save_frame) + unsafe { level7_interrupt(save_frame) } } } diff --git a/esp-hal/src/lcd_cam/cam.rs b/esp-hal/src/lcd_cam/cam.rs index 2b57a0a0a..0acf55b50 100644 --- a/esp-hal/src/lcd_cam/cam.rs +++ b/esp-hal/src/lcd_cam/cam.rs @@ -59,20 +59,20 @@ use core::{ }; use crate::{ + Blocking, clock::Clocks, dma::{ChannelRx, DmaError, DmaPeripheral, DmaRxBuffer, PeripheralRxChannel, RxChannelFor}, gpio::{ - interconnect::{PeripheralInput, PeripheralOutput}, InputSignal, OutputSignal, Pull, + interconnect::{PeripheralInput, PeripheralOutput}, }, - lcd_cam::{calculate_clkm, BitOrder, ByteOrder, ClockError}, + lcd_cam::{BitOrder, ByteOrder, ClockError, calculate_clkm}, pac, peripherals::LCD_CAM, system::{self, GenericPeripheralGuard}, time::Rate, - Blocking, }; /// Generation of GDMA SUC EOF diff --git a/esp-hal/src/lcd_cam/lcd/dpi.rs b/esp-hal/src/lcd_cam/lcd/dpi.rs index 352c51d95..3fc0fff8e 100644 --- a/esp-hal/src/lcd_cam/lcd/dpi.rs +++ b/esp-hal/src/lcd_cam/lcd/dpi.rs @@ -102,22 +102,22 @@ use core::{ }; use crate::{ + Blocking, + DriverMode, clock::Clocks, dma::{ChannelTx, DmaError, DmaPeripheral, DmaTxBuffer, PeripheralTxChannel, TxChannelFor}, - gpio::{interconnect::PeripheralOutput, Level, OutputSignal}, + gpio::{Level, OutputSignal, interconnect::PeripheralOutput}, lcd_cam::{ - calculate_clkm, - lcd::{ClockMode, DelayMode, Lcd, Phase, Polarity}, BitOrder, ByteOrder, ClockError, + calculate_clkm, + lcd::{ClockMode, DelayMode, Lcd, Phase, Polarity}, }, pac, peripherals::LCD_CAM, system::{self, GenericPeripheralGuard}, time::Rate, - Blocking, - DriverMode, }; /// Errors that can occur when configuring the DPI peripheral. diff --git a/esp-hal/src/lcd_cam/lcd/i8080.rs b/esp-hal/src/lcd_cam/lcd/i8080.rs index 3be1bb779..557f483ce 100644 --- a/esp-hal/src/lcd_cam/lcd/i8080.rs +++ b/esp-hal/src/lcd_cam/lcd/i8080.rs @@ -53,33 +53,33 @@ use core::{ fmt::Formatter, marker::PhantomData, - mem::{size_of, ManuallyDrop}, + mem::{ManuallyDrop, size_of}, ops::{Deref, DerefMut}, }; use crate::{ + Blocking, + DriverMode, clock::Clocks, dma::{ChannelTx, DmaError, DmaPeripheral, DmaTxBuffer, PeripheralTxChannel, TxChannelFor}, gpio::{ - interconnect::{OutputConnection, PeripheralOutput}, OutputSignal, + interconnect::{OutputConnection, PeripheralOutput}, }, lcd_cam::{ - calculate_clkm, - lcd::{ClockMode, DelayMode, Phase, Polarity}, BitOrder, ByteOrder, ClockError, Instance, - Lcd, LCD_DONE_WAKER, + Lcd, + calculate_clkm, + lcd::{ClockMode, DelayMode, Phase, Polarity}, }, pac, peripherals::LCD_CAM, system::{self, GenericPeripheralGuard}, time::Rate, - Blocking, - DriverMode, }; /// A configuration error. diff --git a/esp-hal/src/lcd_cam/mod.rs b/esp-hal/src/lcd_cam/mod.rs index a1bb6a300..348ea97fd 100644 --- a/esp-hal/src/lcd_cam/mod.rs +++ b/esp-hal/src/lcd_cam/mod.rs @@ -11,14 +11,14 @@ pub mod lcd; use core::marker::PhantomData; use crate::{ + Async, + Blocking, asynch::AtomicWaker, handler, interrupt::InterruptHandler, lcd_cam::{cam::Cam, lcd::Lcd}, peripherals::{Interrupt, LCD_CAM}, system::{Cpu, GenericPeripheralGuard}, - Async, - Blocking, }; /// Represents a combined LCD and Camera interface. @@ -291,11 +291,7 @@ fn calculate_closest_divider( // https://en.wikipedia.org/wiki/Euclidean_algorithm const fn hcf(a: usize, b: usize) -> usize { - if b != 0 { - hcf(b, a % b) - } else { - a - } + if b != 0 { hcf(b, a % b) } else { a } } struct Fraction { diff --git a/esp-hal/src/ledc/channel.rs b/esp-hal/src/ledc/channel.rs index e682b1929..ef9ff819d 100644 --- a/esp-hal/src/ledc/channel.rs +++ b/esp-hal/src/ledc/channel.rs @@ -12,8 +12,8 @@ use super::timer::{TimerIFace, TimerSpeed}; use crate::{ gpio::{ - interconnect::{OutputConnection, PeripheralOutput}, OutputSignal, + interconnect::{OutputConnection, PeripheralOutput}, }, pac::ledc::RegisterBlock, peripherals::LEDC, diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index 254098383..c05d64269 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -478,7 +478,9 @@ macro_rules! impl_persistable { )+}; } -impl_persistable!(u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize, f32, f64); +impl_persistable!( + u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize, isize, f32, f64 +); impl_persistable!(atomic AtomicU8, AtomicI8, AtomicU16, AtomicI16, AtomicU32, AtomicI32, AtomicUsize, AtomicIsize); unsafe impl Persistable for [T; N] {} @@ -500,14 +502,14 @@ pub mod __macro_implementation { } #[cfg(riscv)] -#[export_name = "hal_main"] +#[unsafe(export_name = "hal_main")] fn hal_main(a0: usize, a1: usize, a2: usize) -> ! { - extern "Rust" { + unsafe extern "Rust" { // This symbol will be provided by the user via `#[entry]` fn main(a0: usize, a1: usize, a2: usize) -> !; } - extern "C" { + unsafe extern "C" { static mut __stack_chk_guard: u32; } @@ -524,7 +526,7 @@ fn hal_main(a0: usize, a1: usize, a2: usize) -> ! { } } -#[export_name = "__stack_chk_fail"] +#[unsafe(export_name = "__stack_chk_fail")] unsafe extern "C" fn stack_chk_fail() { panic!("Stack corruption detected"); } diff --git a/esp-hal/src/macros.rs b/esp-hal/src/macros.rs index 72c8e6517..bce70cf01 100644 --- a/esp-hal/src/macros.rs +++ b/esp-hal/src/macros.rs @@ -123,14 +123,14 @@ macro_rules! any_peripheral { /// /// You must ensure that you're only using one instance of this type at a time. #[inline] - pub unsafe fn clone_unchecked(&self) -> Self { + pub unsafe fn clone_unchecked(&self) -> Self { unsafe { match &self.0 { $( $(#[cfg($variant_meta)])* [< $name Inner >]::$variant(inner) => $name([<$name Inner>]::$variant(inner.clone_unchecked())), )* } - } + }} /// Creates a new peripheral reference with a shorter lifetime. /// @@ -244,9 +244,9 @@ macro_rules! ignore { #[doc(hidden)] macro_rules! metadata { ($category:literal, $key:ident, $value:expr) => { - #[link_section = concat!(".espressif.metadata")] + #[unsafe(link_section = concat!(".espressif.metadata"))] #[used] - #[export_name = concat!($category, ".", stringify!($key))] + #[unsafe(export_name = concat!($category, ".", stringify!($key)))] static $key: [u8; $value.len()] = const { let val_bytes = $value.as_bytes(); let mut val_bytes_array = [0; $value.len()]; diff --git a/esp-hal/src/mcpwm/operator.rs b/esp-hal/src/mcpwm/operator.rs index 56ff23cd1..b60c6f942 100644 --- a/esp-hal/src/mcpwm/operator.rs +++ b/esp-hal/src/mcpwm/operator.rs @@ -14,7 +14,7 @@ use core::marker::PhantomData; use super::PeripheralGuard; use crate::{ gpio::interconnect::{OutputConnection, PeripheralOutput}, - mcpwm::{timer::Timer, PwmPeripheral}, + mcpwm::{PwmPeripheral, timer::Timer}, pac, }; @@ -320,7 +320,8 @@ impl<'d, PWM: PwmPeripheral, const OP: u8, const IS_A: bool> PwmPin<'d, PWM, OP, // SAFETY: // `bits` is a valid bit pattern - ch.gen((!IS_A) as usize).write(|w| unsafe { w.bits(bits) }); + ch.r#gen((!IS_A) as usize) + .write(|w| unsafe { w.bits(bits) }); } /// Set how a new timestamp syncs with the timer diff --git a/esp-hal/src/otg_fs.rs b/esp-hal/src/otg_fs.rs index c78347b35..f152779a4 100644 --- a/esp-hal/src/otg_fs.rs +++ b/esp-hal/src/otg_fs.rs @@ -131,8 +131,6 @@ pub mod asynch { }; pub use embassy_usb_synopsys_otg::Config; use embassy_usb_synopsys_otg::{ - on_interrupt, - otg_v1::Otg, Bus as OtgBus, ControlPipe, Driver as OtgDriver, @@ -142,6 +140,8 @@ pub mod asynch { Out, PhyType, State, + on_interrupt, + otg_v1::Otg, }; use procmacros::handler; diff --git a/esp-hal/src/parl_io.rs b/esp-hal/src/parl_io.rs index 603100a7a..b9b3da758 100644 --- a/esp-hal/src/parl_io.rs +++ b/esp-hal/src/parl_io.rs @@ -132,6 +132,9 @@ use enumset::{EnumSet, EnumSetType}; use private::*; use crate::{ + Async, + Blocking, + DriverMode, dma::{ Channel, ChannelRx, @@ -145,17 +148,14 @@ use crate::{ PeripheralTxChannel, }, gpio::{ - interconnect::{InputConnection, OutputConnection, PeripheralInput, PeripheralOutput}, NoPin, + interconnect::{InputConnection, OutputConnection, PeripheralInput, PeripheralOutput}, }, interrupt::InterruptHandler, parl_io::asynch::interrupt_handler, peripherals::{Interrupt, PARL_IO, PCR}, system::{self, GenericPeripheralGuard}, time::Rate, - Async, - Blocking, - DriverMode, }; const MAX_DMA_SIZE: usize = 65535; @@ -1546,10 +1546,10 @@ pub mod asynch { use procmacros::handler; - use super::{private::Instance, ParlIoRxTransfer, ParlIoTxTransfer}; + use super::{ParlIoRxTransfer, ParlIoTxTransfer, private::Instance}; use crate::{ asynch::AtomicWaker, - dma::{asynch::DmaRxFuture, DmaRxBuffer, DmaTxBuffer}, + dma::{DmaRxBuffer, DmaTxBuffer, asynch::DmaRxFuture}, }; static TX_WAKER: AtomicWaker = AtomicWaker::new(); diff --git a/esp-hal/src/pcnt/channel.rs b/esp-hal/src/pcnt/channel.rs index dc2624ec7..72ec95575 100644 --- a/esp-hal/src/pcnt/channel.rs +++ b/esp-hal/src/pcnt/channel.rs @@ -11,7 +11,7 @@ use core::marker::PhantomData; pub use crate::pac::pcnt::unit::conf0::{CTRL_MODE as CtrlMode, EDGE_MODE as EdgeMode}; use crate::{ - gpio::{interconnect::PeripheralInput, InputSignal}, + gpio::{InputSignal, interconnect::PeripheralInput}, peripherals::PCNT, system::GenericPeripheralGuard, }; diff --git a/esp-hal/src/peripheral.rs b/esp-hal/src/peripheral.rs index 0ddec74a1..17e1fb3c9 100644 --- a/esp-hal/src/peripheral.rs +++ b/esp-hal/src/peripheral.rs @@ -74,7 +74,7 @@ macro_rules! peripherals { /// Returns all the peripherals *once* #[inline] pub(crate) fn take() -> Self { - #[no_mangle] + #[unsafe(no_mangle)] static mut _ESP_HAL_DEVICE_PERIPHERALS: bool = false; critical_section::with(|_| unsafe { @@ -93,17 +93,19 @@ macro_rules! peripherals { /// You must ensure that you're only using one instance of this type at a time. #[inline] pub unsafe fn steal() -> Self { - Self { - $( - $name: $name::steal(), - )* - $( - $unstable_name: $unstable_name::steal(), - )* + unsafe { + Self { + $( + $name: $name::steal(), + )* + $( + $unstable_name: $unstable_name::steal(), + )* - $( - []: []::steal(), - )* + $( + []: []::steal(), + )* + } } } } @@ -182,9 +184,9 @@ macro_rules! create_peripheral { /// You must ensure that you're only using one instance of this type at a time. #[inline] #[allow(dead_code)] - pub unsafe fn clone_unchecked(&self) -> Self { + pub unsafe fn clone_unchecked(&self) -> Self { unsafe { Self::steal() - } + }} /// Creates a new peripheral reference with a shorter lifetime. /// diff --git a/esp-hal/src/rmt.rs b/esp-hal/src/rmt.rs index f76d70f1d..6afd76cae 100644 --- a/esp-hal/src/rmt.rs +++ b/esp-hal/src/rmt.rs @@ -229,18 +229,18 @@ use core::{ use enumset::{EnumSet, EnumSetType}; use crate::{ + Async, + Blocking, asynch::AtomicWaker, gpio::{ - interconnect::{PeripheralInput, PeripheralOutput}, Level, + interconnect::{PeripheralInput, PeripheralOutput}, }, handler, peripherals::{Interrupt, RMT}, soc::constants, system::{self, GenericPeripheralGuard}, time::Rate, - Async, - Blocking, }; /// Errors diff --git a/esp-hal/src/rng.rs b/esp-hal/src/rng.rs index 9af148de3..192f6d0c3 100644 --- a/esp-hal/src/rng.rs +++ b/esp-hal/src/rng.rs @@ -198,10 +198,10 @@ impl<'d> Trng<'d> { /// /// Returns a new `Trng` instance. pub fn new(rng: RNG<'_>, adc: ADC1<'d>) -> Self { - let gen = Rng::new(rng); + let r#gen = Rng::new(rng); crate::soc::trng::ensure_randomness(); Self { - rng: gen, + rng: r#gen, _adc: adc, } } diff --git a/esp-hal/src/rom/crc.rs b/esp-hal/src/rom/crc.rs index 5ca0cc604..83cc51ed6 100644 --- a/esp-hal/src/rom/crc.rs +++ b/esp-hal/src/rom/crc.rs @@ -100,7 +100,7 @@ #[cfg(rom_crc_be)] #[inline(always)] pub fn crc32_be(crc: u32, buf: &[u8]) -> u32 { - extern "C" { + unsafe extern "C" { fn esp_rom_crc32_be(crc: u32, buf: *const u8, len: u32) -> u32; } unsafe { esp_rom_crc32_be(crc, buf.as_ptr(), buf.len() as u32) } @@ -110,7 +110,7 @@ pub fn crc32_be(crc: u32, buf: &[u8]) -> u32 { #[cfg(rom_crc_be)] #[inline(always)] pub fn crc16_be(crc: u16, buf: &[u8]) -> u16 { - extern "C" { + unsafe extern "C" { fn esp_rom_crc16_be(crc: u16, buf: *const u8, len: u32) -> u16; } unsafe { esp_rom_crc16_be(crc, buf.as_ptr(), buf.len() as u32) } @@ -120,7 +120,7 @@ pub fn crc16_be(crc: u16, buf: &[u8]) -> u16 { #[cfg(rom_crc_be)] #[inline(always)] pub fn crc8_be(crc: u8, buf: &[u8]) -> u8 { - extern "C" { + unsafe extern "C" { fn esp_rom_crc8_be(crc: u8, buf: *const u8, len: u32) -> u8; } unsafe { esp_rom_crc8_be(crc, buf.as_ptr(), buf.len() as u32) } @@ -130,7 +130,7 @@ pub fn crc8_be(crc: u8, buf: &[u8]) -> u8 { #[cfg(rom_crc_le)] #[inline(always)] pub fn crc32_le(crc: u32, buf: &[u8]) -> u32 { - extern "C" { + unsafe extern "C" { fn esp_rom_crc32_le(crc: u32, buf: *const u8, len: u32) -> u32; } unsafe { esp_rom_crc32_le(crc, buf.as_ptr(), buf.len() as u32) } @@ -140,7 +140,7 @@ pub fn crc32_le(crc: u32, buf: &[u8]) -> u32 { #[cfg(rom_crc_le)] #[inline(always)] pub fn crc16_le(crc: u16, buf: &[u8]) -> u16 { - extern "C" { + unsafe extern "C" { fn esp_rom_crc16_le(crc: u16, buf: *const u8, len: u32) -> u16; } unsafe { esp_rom_crc16_le(crc, buf.as_ptr(), buf.len() as u32) } @@ -150,7 +150,7 @@ pub fn crc16_le(crc: u16, buf: &[u8]) -> u16 { #[inline(always)] #[cfg(rom_crc_le)] pub fn crc8_le(crc: u8, buf: &[u8]) -> u8 { - extern "C" { + unsafe extern "C" { fn esp_rom_crc8_le(crc: u8, buf: *const u8, len: u32) -> u8; } unsafe { esp_rom_crc8_le(crc, buf.as_ptr(), buf.len() as u32) } diff --git a/esp-hal/src/rom/md5.rs b/esp-hal/src/rom/md5.rs index 88e506be5..2d219b3aa 100644 --- a/esp-hal/src/rom/md5.rs +++ b/esp-hal/src/rom/md5.rs @@ -78,7 +78,7 @@ struct InternalContext { } #[cfg(rom_md5_bsd)] -extern "C" { +unsafe extern "C" { fn esp_rom_md5_init(context: *mut InternalContext); fn esp_rom_md5_update(context: *mut InternalContext, buf: *const c_void, len: u32); fn esp_rom_md5_final(digest: *mut u8, context: *mut InternalContext); @@ -94,7 +94,7 @@ struct InternalContext { } #[cfg(rom_md5_mbedtls)] -extern "C" { +unsafe extern "C" { fn esp_rom_mbedtls_md5_starts_ret(context: *mut InternalContext) -> c_int; fn esp_rom_mbedtls_md5_update_ret( context: *mut InternalContext, diff --git a/esp-hal/src/rom/mod.rs b/esp-hal/src/rom/mod.rs index 1ba9683d0..c84c207fa 100644 --- a/esp-hal/src/rom/mod.rs +++ b/esp-hal/src/rom/mod.rs @@ -33,7 +33,7 @@ pub(crate) mod regi2c; #[inline(always)] pub(crate) fn ets_delay_us(us: u32) { - extern "C" { + unsafe extern "C" { fn ets_delay_us(us: u32); } @@ -43,7 +43,7 @@ pub(crate) fn ets_delay_us(us: u32) { #[allow(unused)] #[inline(always)] pub(crate) fn ets_update_cpu_frequency_rom(ticks_per_us: u32) { - extern "C" { + unsafe extern "C" { fn ets_update_cpu_frequency(ticks_per_us: u32); } @@ -52,7 +52,7 @@ pub(crate) fn ets_update_cpu_frequency_rom(ticks_per_us: u32) { #[inline(always)] pub(crate) fn rtc_get_reset_reason(cpu_num: u32) -> u32 { - extern "C" { + unsafe extern "C" { fn rtc_get_reset_reason(cpu_num: u32) -> u32; } @@ -61,7 +61,7 @@ pub(crate) fn rtc_get_reset_reason(cpu_num: u32) -> u32 { #[inline(always)] pub(crate) fn software_reset_cpu(cpu_num: u32) { - extern "C" { + unsafe extern "C" { fn software_reset_cpu(cpu_num: u32); } @@ -70,7 +70,7 @@ pub(crate) fn software_reset_cpu(cpu_num: u32) { #[inline(always)] pub(crate) fn software_reset() -> ! { - extern "C" { + unsafe extern "C" { fn software_reset() -> !; } @@ -80,7 +80,7 @@ pub(crate) fn software_reset() -> ! { #[cfg(esp32s3)] #[inline(always)] pub(crate) fn ets_set_appcpu_boot_addr(boot_addr: u32) { - extern "C" { + unsafe extern "C" { fn ets_set_appcpu_boot_addr(boot_addr: u32); } diff --git a/esp-hal/src/rsa/esp32.rs b/esp-hal/src/rsa/esp32.rs index ec0eb8d14..d22d6d5d2 100644 --- a/esp-hal/src/rsa/esp32.rs +++ b/esp-hal/src/rsa/esp32.rs @@ -1,13 +1,13 @@ use core::convert::Infallible; use crate::rsa::{ - implement_op, Multi, Rsa, RsaMode, RsaModularExponentiation, RsaModularMultiplication, RsaMultiplication, + implement_op, }; impl Rsa<'_, Dm> { @@ -65,7 +65,7 @@ pub mod operand_sizes { //! Marker types for the operand sizes use paste::paste; - use super::{implement_op, Multi, RsaMode}; + use super::{Multi, RsaMode, implement_op}; implement_op!( (512, multi), diff --git a/esp-hal/src/rsa/esp32cX.rs b/esp-hal/src/rsa/esp32cX.rs index 5066aa812..1cc4438be 100644 --- a/esp-hal/src/rsa/esp32cX.rs +++ b/esp-hal/src/rsa/esp32cX.rs @@ -1,13 +1,13 @@ use core::convert::Infallible; use crate::rsa::{ - implement_op, Multi, Rsa, RsaMode, RsaModularExponentiation, RsaModularMultiplication, RsaMultiplication, + implement_op, }; impl Rsa<'_, Dm> { @@ -123,7 +123,7 @@ pub mod operand_sizes { //! Marker types for the operand sizes use paste::paste; - use super::{implement_op, Multi, RsaMode}; + use super::{Multi, RsaMode, implement_op}; implement_op!( (32, multi), diff --git a/esp-hal/src/rsa/esp32sX.rs b/esp-hal/src/rsa/esp32sX.rs index da637e021..8893cc488 100644 --- a/esp-hal/src/rsa/esp32sX.rs +++ b/esp-hal/src/rsa/esp32sX.rs @@ -1,13 +1,13 @@ use core::convert::Infallible; use crate::rsa::{ - implement_op, Multi, Rsa, RsaMode, RsaModularExponentiation, RsaModularMultiplication, RsaMultiplication, + implement_op, }; impl Rsa<'_, Dm> { @@ -115,7 +115,7 @@ pub mod operand_sizes { //! Marker types for the operand sizes use paste::paste; - use super::{implement_op, Multi, RsaMode}; + use super::{Multi, RsaMode, implement_op}; implement_op!( (32, multi), diff --git a/esp-hal/src/rsa/mod.rs b/esp-hal/src/rsa/mod.rs index 8e93d2130..b476ac2b7 100644 --- a/esp-hal/src/rsa/mod.rs +++ b/esp-hal/src/rsa/mod.rs @@ -24,12 +24,12 @@ use core::{marker::PhantomData, ptr::copy_nonoverlapping}; use crate::{ + Async, + Blocking, interrupt::InterruptHandler, pac, peripherals::{Interrupt, RSA}, system::{Cpu, GenericPeripheralGuard, Peripheral as PeripheralEnable}, - Async, - Blocking, }; #[cfg_attr(esp32s2, path = "esp32sX.rs")] @@ -386,6 +386,7 @@ pub(crate) mod asynch { use procmacros::handler; use crate::{ + Async, asynch::AtomicWaker, peripherals::RSA, rsa::{ @@ -396,7 +397,6 @@ pub(crate) mod asynch { RsaModularMultiplication, RsaMultiplication, }, - Async, }; static WAKER: AtomicWaker = AtomicWaker::new(); diff --git a/esp-hal/src/rtc_cntl/mod.rs b/esp-hal/src/rtc_cntl/mod.rs index 8977c964b..e70c3e5ed 100644 --- a/esp-hal/src/rtc_cntl/mod.rs +++ b/esp-hal/src/rtc_cntl/mod.rs @@ -1272,7 +1272,7 @@ pub fn wakeup_cause() -> SleepSource { // libphy.a can pull this in on some chips, we provide it here in the hal // so that either ieee or esp-wifi gets it for free without duplicating in both -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn rtc_clk_xtal_freq_get() -> i32 { let xtal = RtcClock::xtal_freq(); xtal.mhz() as i32 diff --git a/esp-hal/src/rtc_cntl/rtc/esp32c6.rs b/esp-hal/src/rtc_cntl/rtc/esp32c6.rs index 367adca45..c8dc17461 100644 --- a/esp-hal/src/rtc_cntl/rtc/esp32c6.rs +++ b/esp-hal/src/rtc_cntl/rtc/esp32c6.rs @@ -6,6 +6,8 @@ use strum::FromRepr; use crate::{ clock::{ + Clock, + XtalClock, clocks_ll::{ esp32c6_bbpll_get_freq_mhz, esp32c6_cpu_get_hs_divider, @@ -15,8 +17,6 @@ use crate::{ esp32c6_rtc_update_to_8m, esp32c6_rtc_update_to_xtal_raw, }, - Clock, - XtalClock, }, peripherals::TIMG0, rtc_cntl::RtcClock, @@ -25,27 +25,27 @@ use crate::{ }; unsafe fn pmu<'a>() -> &'a esp32c6::pmu::RegisterBlock { - &*esp32c6::PMU::ptr() + unsafe { &*esp32c6::PMU::ptr() } } unsafe fn modem_lpcon<'a>() -> &'a esp32c6::modem_lpcon::RegisterBlock { - &*esp32c6::MODEM_LPCON::ptr() + unsafe { &*esp32c6::MODEM_LPCON::ptr() } } unsafe fn modem_syscon<'a>() -> &'a esp32c6::modem_syscon::RegisterBlock { - &*esp32c6::MODEM_SYSCON::ptr() + unsafe { &*esp32c6::MODEM_SYSCON::ptr() } } unsafe fn lp_clkrst<'a>() -> &'a esp32c6::lp_clkrst::RegisterBlock { - &*esp32c6::LP_CLKRST::ptr() + unsafe { &*esp32c6::LP_CLKRST::ptr() } } unsafe fn pcr<'a>() -> &'a esp32c6::pcr::RegisterBlock { - &*esp32c6::PCR::ptr() + unsafe { &*esp32c6::PCR::ptr() } } unsafe fn lp_aon<'a>() -> &'a esp32c6::lp_aon::RegisterBlock { - &*esp32c6::LP_AON::ptr() + unsafe { &*esp32c6::LP_AON::ptr() } } fn pmu_power_domain_force_default() { diff --git a/esp-hal/src/rtc_cntl/rtc/esp32h2.rs b/esp-hal/src/rtc_cntl/rtc/esp32h2.rs index c15825036..f80d3977a 100644 --- a/esp-hal/src/rtc_cntl/rtc/esp32h2.rs +++ b/esp-hal/src/rtc_cntl/rtc/esp32h2.rs @@ -1,8 +1,8 @@ use strum::FromRepr; use crate::{ - clock::{clocks_ll::regi2c_write_mask, Clock, XtalClock}, - peripherals::{LPWR, LP_AON, PCR, PMU, TIMG0}, + clock::{Clock, XtalClock, clocks_ll::regi2c_write_mask}, + peripherals::{LP_AON, LPWR, PCR, PMU, TIMG0}, rtc_cntl::RtcClock, time::Rate, }; diff --git a/esp-hal/src/rtc_cntl/sleep/esp32.rs b/esp-hal/src/rtc_cntl/sleep/esp32.rs index 409cede19..e696b125e 100644 --- a/esp-hal/src/rtc_cntl/sleep/esp32.rs +++ b/esp-hal/src/rtc_cntl/sleep/esp32.rs @@ -2,7 +2,7 @@ use super::{Ext0WakeupSource, Ext1WakeupSource, TimerWakeupSource, WakeSource, W use crate::{ gpio::{RtcFunction, RtcPin}, peripherals::{BB, DPORT, I2S0, LPWR, NRX, RTC_IO}, - rtc_cntl::{sleep::WakeupLevel, Clock, Rtc, RtcClock}, + rtc_cntl::{Clock, Rtc, RtcClock, sleep::WakeupLevel}, }; // Approximate mapping of voltages to RTC_CNTL_DBIAS_WAK, RTC_CNTL_DBIAS_SLP, diff --git a/esp-hal/src/rtc_cntl/sleep/esp32c2.rs b/esp-hal/src/rtc_cntl/sleep/esp32c2.rs index c561c50bc..602a88bb2 100644 --- a/esp-hal/src/rtc_cntl/sleep/esp32c2.rs +++ b/esp-hal/src/rtc_cntl/sleep/esp32c2.rs @@ -2,7 +2,7 @@ use super::{TimerWakeupSource, WakeSource, WakeTriggers, WakeupLevel}; use crate::{ gpio::{RtcFunction, RtcPinWithResistors}, peripherals::{APB_CTRL, BB, EXTMEM, GPIO, IO_MUX, LPWR, SPI0, SPI1, SYSTEM}, - rtc_cntl::{sleep::RtcioWakeupSource, Clock, Rtc, RtcClock}, + rtc_cntl::{Clock, Rtc, RtcClock, sleep::RtcioWakeupSource}, soc::regi2c, }; diff --git a/esp-hal/src/rtc_cntl/sleep/esp32c3.rs b/esp-hal/src/rtc_cntl/sleep/esp32c3.rs index cd908adb6..4d3f0dbf4 100644 --- a/esp-hal/src/rtc_cntl/sleep/esp32c3.rs +++ b/esp-hal/src/rtc_cntl/sleep/esp32c3.rs @@ -2,7 +2,7 @@ use super::{TimerWakeupSource, WakeSource, WakeTriggers, WakeupLevel}; use crate::{ gpio::{RtcFunction, RtcPinWithResistors}, peripherals::{APB_CTRL, BB, EXTMEM, FE, FE2, GPIO, IO_MUX, LPWR, NRX, SPI0, SPI1, SYSTEM}, - rtc_cntl::{sleep::RtcioWakeupSource, Clock, Rtc, RtcClock}, + rtc_cntl::{Clock, Rtc, RtcClock, sleep::RtcioWakeupSource}, soc::regi2c, }; diff --git a/esp-hal/src/rtc_cntl/sleep/esp32c6.rs b/esp-hal/src/rtc_cntl/sleep/esp32c6.rs index 74e237f59..f9cd72608 100644 --- a/esp-hal/src/rtc_cntl/sleep/esp32c6.rs +++ b/esp-hal/src/rtc_cntl/sleep/esp32c6.rs @@ -5,8 +5,9 @@ use crate::{ efuse::Efuse, gpio::RtcFunction, rtc_cntl::{ + Rtc, + RtcClock, rtc::{ - rtc_clk_cpu_freq_set_xtal, HpAnalog, HpSysCntlReg, HpSysPower, @@ -14,6 +15,7 @@ use crate::{ LpSysPower, RtcCalSel, SavedClockConfig, + rtc_clk_cpu_freq_set_xtal, }, sleep::{ Ext1WakeupSource, @@ -23,8 +25,6 @@ use crate::{ WakeTriggers, WakeupLevel, }, - Rtc, - RtcClock, }, }; @@ -783,11 +783,11 @@ impl Default for RtcSleepConfig { } unsafe fn pmu<'a>() -> &'a esp32c6::pmu::RegisterBlock { - &*esp32c6::PMU::ptr() + unsafe { &*esp32c6::PMU::ptr() } } unsafe fn lp_aon<'a>() -> &'a esp32c6::lp_aon::RegisterBlock { - &*esp32c6::LP_AON::ptr() + unsafe { &*esp32c6::LP_AON::ptr() } } bitfield::bitfield! { diff --git a/esp-hal/src/rtc_cntl/sleep/esp32s2.rs b/esp-hal/src/rtc_cntl/sleep/esp32s2.rs index 52e88542d..3e9159ab9 100644 --- a/esp-hal/src/rtc_cntl/sleep/esp32s2.rs +++ b/esp-hal/src/rtc_cntl/sleep/esp32s2.rs @@ -9,7 +9,7 @@ use super::{ use crate::{ gpio::{RtcFunction, RtcPin}, peripherals::{EXTMEM, LPWR, RTC_IO, SENS, SPI0, SPI1, SYSTEM}, - rtc_cntl::{sleep::RtcioWakeupSource, Clock, Rtc, RtcClock}, + rtc_cntl::{Clock, Rtc, RtcClock, sleep::RtcioWakeupSource}, soc::regi2c, }; diff --git a/esp-hal/src/rtc_cntl/sleep/esp32s3.rs b/esp-hal/src/rtc_cntl/sleep/esp32s3.rs index 9eb8a32c9..294078027 100644 --- a/esp-hal/src/rtc_cntl/sleep/esp32s3.rs +++ b/esp-hal/src/rtc_cntl/sleep/esp32s3.rs @@ -9,7 +9,7 @@ use super::{ use crate::{ gpio::{RtcFunction, RtcPin}, peripherals::{APB_CTRL, EXTMEM, LPWR, RTC_IO, SPI0, SPI1, SYSTEM}, - rtc_cntl::{sleep::RtcioWakeupSource, Clock, Rtc, RtcClock}, + rtc_cntl::{Clock, Rtc, RtcClock, sleep::RtcioWakeupSource}, soc::regi2c, }; diff --git a/esp-hal/src/soc/esp32/cpu_control.rs b/esp-hal/src/soc/esp32/cpu_control.rs index 15d2a23e5..3d5d54253 100644 --- a/esp-hal/src/soc/esp32/cpu_control.rs +++ b/esp-hal/src/soc/esp32/cpu_control.rs @@ -159,18 +159,18 @@ unsafe fn internal_park_core(core: Cpu, park: bool) { Cpu::ProCpu => { LPWR::regs() .sw_cpu_stall() - .modify(|_, w| w.sw_stall_procpu_c1().bits(c1_value)); + .modify(|_, w| unsafe { w.sw_stall_procpu_c1().bits(c1_value) }); LPWR::regs() .options0() - .modify(|_, w| w.sw_stall_procpu_c0().bits(c0_value)); + .modify(|_, w| unsafe { w.sw_stall_procpu_c0().bits(c0_value) }); } Cpu::AppCpu => { LPWR::regs() .sw_cpu_stall() - .modify(|_, w| w.sw_stall_appcpu_c1().bits(c1_value)); + .modify(|_, w| unsafe { w.sw_stall_appcpu_c1().bits(c1_value) }); LPWR::regs() .options0() - .modify(|_, w| w.sw_stall_appcpu_c0().bits(c0_value)); + .modify(|_, w| unsafe { w.sw_stall_appcpu_c0().bits(c0_value) }); } } } @@ -192,7 +192,9 @@ impl<'d> CpuControl<'d> { /// currently executing their code. #[instability::unstable] pub unsafe fn park_core(&mut self, core: Cpu) { - internal_park_core(core, true); + unsafe { + internal_park_core(core, true); + } } /// Unpark the given core @@ -273,31 +275,33 @@ impl<'d> CpuControl<'d> { F: FnOnce(), { // disables interrupts - xtensa_lx::interrupt::set_mask(0); + unsafe { + xtensa_lx::interrupt::set_mask(0); + } // reset cycle compare registers xtensa_lx::timer::set_ccompare0(0); xtensa_lx::timer::set_ccompare1(0); xtensa_lx::timer::set_ccompare2(0); - extern "C" { + unsafe extern "C" { static mut _init_start: u32; } - unsafe { - // move vec table - let base = core::ptr::addr_of!(_init_start); - core::arch::asm!("wsr.vecbase {0}", in(reg) base, options(nostack)); - } + // move vec table + let base = core::ptr::addr_of!(_init_start); - // switch to new stack - xtensa_lx::set_stack_pointer(unwrap!(APP_CORE_STACK_TOP)); + unsafe { + core::arch::asm!("wsr.vecbase {0}", in(reg) base, options(nostack)); + // switch to new stack + xtensa_lx::set_stack_pointer(unwrap!(APP_CORE_STACK_TOP)); + } // Trampoline to run from the new stack. // start_core1_run should _NEVER_ be inlined // as we rely on the function call to use // the new stack. - Self::start_core1_run::() + unsafe { Self::start_core1_run::() } } /// Run the core1 closure. @@ -307,14 +311,14 @@ impl<'d> CpuControl<'d> { F: FnOnce(), { #[allow(static_mut_refs)] // FIXME - match START_CORE1_FUNCTION.take() { - Some(entry) => { - let entry = unsafe { ManuallyDrop::take(&mut *entry.cast::>()) }; + match unsafe { START_CORE1_FUNCTION.take() } { + Some(entry) => unsafe { + let entry = ManuallyDrop::take(&mut *entry.cast::>()); entry(); loop { - unsafe { internal_park_core(Cpu::current(), true) }; + internal_park_core(Cpu::current(), true); } - } + }, None => panic!("No start function set"), } } diff --git a/esp-hal/src/soc/esp32/mod.rs b/esp-hal/src/soc/esp32/mod.rs index d844d51d3..d99cccda4 100644 --- a/esp-hal/src/soc/esp32/mod.rs +++ b/esp-hal/src/soc/esp32/mod.rs @@ -59,10 +59,10 @@ pub(crate) mod constants { /// *Note: the pre_init function is called in the original reset handler /// after the initializations done in this function* #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn ESP32Reset() -> ! { // These symbols come from `memory.x` - extern "C" { + unsafe extern "C" { static mut _rtc_fast_bss_start: u32; static mut _rtc_fast_bss_end: u32; static mut _rtc_fast_persistent_start: u32; @@ -79,38 +79,44 @@ pub unsafe extern "C" fn ESP32Reset() -> ! { } // set stack pointer to end of memory: no need to retain stack up to this point - xtensa_lx::set_stack_pointer(addr_of_mut!(_stack_start_cpu0)); + unsafe { + xtensa_lx::set_stack_pointer(addr_of_mut!(_stack_start_cpu0)); + } // copying data from flash to various data segments is done by the bootloader // initialization to zero needs to be done by the application // Initialize RTC RAM - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_fast_bss_start), - addr_of_mut!(_rtc_fast_bss_end), - ); - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_slow_bss_start), - addr_of_mut!(_rtc_slow_bss_end), - ); + unsafe { + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_fast_bss_start), + addr_of_mut!(_rtc_fast_bss_end), + ); + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_slow_bss_start), + addr_of_mut!(_rtc_slow_bss_end), + ); + } if matches!( crate::system::reset_reason(), None | Some(SocResetReason::ChipPowerOn) ) { - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_fast_persistent_start), - addr_of_mut!(_rtc_fast_persistent_end), - ); - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_slow_persistent_start), - addr_of_mut!(_rtc_slow_persistent_end), - ); + unsafe { + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_fast_persistent_start), + addr_of_mut!(_rtc_fast_persistent_end), + ); + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_slow_persistent_start), + addr_of_mut!(_rtc_slow_persistent_end), + ); + } } + let stack_chk_guard = core::ptr::addr_of_mut!(__stack_chk_guard); + // we _should_ use a random value but we don't have a good source for random + // numbers here unsafe { - let stack_chk_guard = core::ptr::addr_of_mut!(__stack_chk_guard); - // we _should_ use a random value but we don't have a good source for random - // numbers here stack_chk_guard.write_volatile(esp_config::esp_config_int!( u32, "ESP_HAL_CONFIG_STACK_GUARD_VALUE" @@ -120,13 +126,13 @@ pub unsafe extern "C" fn ESP32Reset() -> ! { crate::interrupt::setup_interrupts(); // continue with default reset handler - xtensa_lx_rt::Reset() + unsafe { xtensa_lx_rt::Reset() } } /// The ESP32 has a first stage bootloader that handles loading program data /// into the right place therefore we skip loading it again. #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[rustfmt::skip] pub extern "Rust" fn __init_data() -> bool { false diff --git a/esp-hal/src/soc/esp32/psram.rs b/esp-hal/src/soc/esp32/psram.rs index 358706204..5608dcac0 100644 --- a/esp-hal/src/soc/esp32/psram.rs +++ b/esp-hal/src/soc/esp32/psram.rs @@ -311,7 +311,7 @@ pub(crate) mod utils { pub status_mask: u32, } - extern "C" { + unsafe extern "C" { fn esp_rom_efuse_get_flash_gpio_info() -> u32; fn esp_rom_gpio_connect_out_signal( @@ -616,7 +616,7 @@ pub(crate) mod utils { if clk_mode == PsramClkMode::PsramClkModeDclk { spi.sram_drd_cmd() .modify(|_, w| w.cache_sram_usr_rd_cmd_bitlen().bits(15)); // read command length, 2 bytes(1byte for delay),sending in qio mode in - // cache + // cache spi.sram_drd_cmd().modify(|_, w| { w.cache_sram_usr_rd_cmd_value() .bits((PSRAM_FAST_READ_QUAD << 8) as u16) diff --git a/esp-hal/src/soc/esp32/regi2c.rs b/esp-hal/src/soc/esp32/regi2c.rs index 3f3d25fde..bed60e465 100644 --- a/esp-hal/src/soc/esp32/regi2c.rs +++ b/esp-hal/src/soc/esp32/regi2c.rs @@ -1,4 +1,4 @@ -use crate::rom::regi2c::{define_regi2c, RegI2cMaster, RegI2cRegister}; +use crate::rom::regi2c::{RegI2cMaster, RegI2cRegister, define_regi2c}; define_regi2c! { master: REGI2C_BBPLL(0x66, 4) { @@ -16,14 +16,14 @@ define_regi2c! { } pub(crate) fn regi2c_read(block: u8, host_id: u8, reg_add: u8) -> u8 { - extern "C" { + unsafe extern "C" { pub(crate) fn esp_rom_regi2c_read(block: u8, block_hostid: u8, reg_add: u8) -> u8; } unsafe { esp_rom_regi2c_read(block, host_id, reg_add) } } pub(crate) fn regi2c_write(block: u8, host_id: u8, reg_add: u8, data: u8) { - extern "C" { + unsafe extern "C" { pub(crate) fn rom_i2c_writeReg(block: u8, block_hostid: u8, reg_add: u8, indata: u8); } unsafe { rom_i2c_writeReg(block, host_id, reg_add, data) }; diff --git a/esp-hal/src/soc/esp32c2/efuse/mod.rs b/esp-hal/src/soc/esp32c2/efuse/mod.rs index face0238b..e9b3f1e27 100644 --- a/esp-hal/src/soc/esp32c2/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c2/efuse/mod.rs @@ -81,11 +81,7 @@ impl Efuse { /// see pub fn rtc_calib_version() -> u8 { let (major, _minor) = Self::block_version(); - if major == 0 { - 1 - } else { - 0 - } + if major == 0 { 1 } else { 0 } } /// Get ADC initial code for specified attenuation from efuse diff --git a/esp-hal/src/soc/esp32c2/gpio.rs b/esp-hal/src/soc/esp32c2/gpio.rs index 6ed50352b..faacfcac7 100644 --- a/esp-hal/src/soc/esp32c2/gpio.rs +++ b/esp-hal/src/soc/esp32c2/gpio.rs @@ -180,9 +180,11 @@ macro_rules! rtc_pins { impl $crate::gpio::RtcPin for paste::paste!($crate::peripherals::[]<'_>) { unsafe fn apply_wakeup(&self, wakeup: bool, level: u8) { let gpio_wakeup = $crate::peripherals::LPWR::regs().cntl_gpio_wakeup(); - paste::paste! { - gpio_wakeup.modify(|_, w| w.[< gpio_pin $pin_num _wakeup_enable >]().bit(wakeup)); - gpio_wakeup.modify(|_, w| w.[< gpio_pin $pin_num _int_type >]().bits(level)); + unsafe { + paste::paste! { + gpio_wakeup.modify(|_, w| w.[< gpio_pin $pin_num _wakeup_enable >]().bit(wakeup)); + gpio_wakeup.modify(|_, w| w.[< gpio_pin $pin_num _int_type >]().bits(level)); + } } } diff --git a/esp-hal/src/soc/esp32c2/regi2c.rs b/esp-hal/src/soc/esp32c2/regi2c.rs index 4acccc665..9dd3f28f9 100644 --- a/esp-hal/src/soc/esp32c2/regi2c.rs +++ b/esp-hal/src/soc/esp32c2/regi2c.rs @@ -1,4 +1,4 @@ -use crate::rom::regi2c::{define_regi2c, RawRegI2cField, RegI2cMaster, RegI2cRegister}; +use crate::rom::regi2c::{RawRegI2cField, RegI2cMaster, RegI2cRegister, define_regi2c}; define_regi2c! { master: REGI2C_BBPLL(0x66, 0) { @@ -144,14 +144,14 @@ define_regi2c! { } pub(crate) fn regi2c_read(block: u8, host_id: u8, reg_add: u8) -> u8 { - extern "C" { + unsafe extern "C" { pub(crate) fn esp_rom_regi2c_read(block: u8, block_hostid: u8, reg_add: u8) -> u8; } unsafe { esp_rom_regi2c_read(block, host_id, reg_add) } } pub(crate) fn regi2c_write(block: u8, host_id: u8, reg_add: u8, data: u8) { - extern "C" { + unsafe extern "C" { pub(crate) fn rom_i2c_writeReg(block: u8, block_hostid: u8, reg_add: u8, indata: u8); } unsafe { rom_i2c_writeReg(block, host_id, reg_add, data) }; diff --git a/esp-hal/src/soc/esp32c3/efuse/mod.rs b/esp-hal/src/soc/esp32c3/efuse/mod.rs index 0e0a65e78..674762576 100644 --- a/esp-hal/src/soc/esp32c3/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c3/efuse/mod.rs @@ -83,11 +83,7 @@ impl Efuse { /// see pub fn rtc_calib_version() -> u8 { let (major, _minor) = Self::block_version(); - if major == 1 { - 1 - } else { - 0 - } + if major == 1 { 1 } else { 0 } } /// Get ADC initial code for specified attenuation from efuse diff --git a/esp-hal/src/soc/esp32c3/gpio.rs b/esp-hal/src/soc/esp32c3/gpio.rs index c8305de0b..28ffd7d9c 100644 --- a/esp-hal/src/soc/esp32c3/gpio.rs +++ b/esp-hal/src/soc/esp32c3/gpio.rs @@ -211,8 +211,10 @@ macro_rules! rtc_pins { let rtc_cntl = $crate::peripherals::LPWR::regs(); let gpio_wakeup = rtc_cntl.gpio_wakeup(); - gpio_wakeup.modify(|_, w| w.[< gpio_pin $pin_num _wakeup_enable >]().bit(wakeup)); - gpio_wakeup.modify(|_, w| w.[< gpio_pin $pin_num _int_type >]().bits(level)); + unsafe { + gpio_wakeup.modify(|_, w| w.[< gpio_pin $pin_num _wakeup_enable >]().bit(wakeup)); + gpio_wakeup.modify(|_, w| w.[< gpio_pin $pin_num _int_type >]().bits(level)); + } } fn rtcio_pad_hold(&self, enable: bool) { diff --git a/esp-hal/src/soc/esp32c3/regi2c.rs b/esp-hal/src/soc/esp32c3/regi2c.rs index 4acccc665..9dd3f28f9 100644 --- a/esp-hal/src/soc/esp32c3/regi2c.rs +++ b/esp-hal/src/soc/esp32c3/regi2c.rs @@ -1,4 +1,4 @@ -use crate::rom::regi2c::{define_regi2c, RawRegI2cField, RegI2cMaster, RegI2cRegister}; +use crate::rom::regi2c::{RawRegI2cField, RegI2cMaster, RegI2cRegister, define_regi2c}; define_regi2c! { master: REGI2C_BBPLL(0x66, 0) { @@ -144,14 +144,14 @@ define_regi2c! { } pub(crate) fn regi2c_read(block: u8, host_id: u8, reg_add: u8) -> u8 { - extern "C" { + unsafe extern "C" { pub(crate) fn esp_rom_regi2c_read(block: u8, block_hostid: u8, reg_add: u8) -> u8; } unsafe { esp_rom_regi2c_read(block, host_id, reg_add) } } pub(crate) fn regi2c_write(block: u8, host_id: u8, reg_add: u8, data: u8) { - extern "C" { + unsafe extern "C" { pub(crate) fn rom_i2c_writeReg(block: u8, block_hostid: u8, reg_add: u8, indata: u8); } unsafe { rom_i2c_writeReg(block, host_id, reg_add, data) }; diff --git a/esp-hal/src/soc/esp32c6/efuse/mod.rs b/esp-hal/src/soc/esp32c6/efuse/mod.rs index 5daca9730..33818eba6 100644 --- a/esp-hal/src/soc/esp32c6/efuse/mod.rs +++ b/esp-hal/src/soc/esp32c6/efuse/mod.rs @@ -82,11 +82,7 @@ impl Efuse { /// see pub fn rtc_calib_version() -> u8 { let (_major, minor) = Self::block_version(); - if minor >= 1 { - 1 - } else { - 0 - } + if minor >= 1 { 1 } else { 0 } } /// Get ADC initial code for specified attenuation from efuse diff --git a/esp-hal/src/soc/esp32c6/lp_core.rs b/esp-hal/src/soc/esp32c6/lp_core.rs index db323c58e..5a73a3a89 100644 --- a/esp-hal/src/soc/esp32c6/lp_core.rs +++ b/esp-hal/src/soc/esp32c6/lp_core.rs @@ -19,7 +19,7 @@ //! //! [the repository with corresponding example]: https://github.com/esp-rs/esp-hal/blob/main/examples/src/bin/lp_core_basic.rs -use crate::peripherals::{LPWR, LP_AON, LP_CORE, LP_PERI, PMU}; +use crate::peripherals::{LP_AON, LP_CORE, LP_PERI, LPWR, PMU}; /// Represents the possible wakeup sources for the LP (Low Power) core. #[derive(Debug, Clone, Copy)] diff --git a/esp-hal/src/soc/esp32c6/regi2c.rs b/esp-hal/src/soc/esp32c6/regi2c.rs index bbc07e28d..7cfd036c6 100644 --- a/esp-hal/src/soc/esp32c6/regi2c.rs +++ b/esp-hal/src/soc/esp32c6/regi2c.rs @@ -1,6 +1,6 @@ use crate::{ peripherals::{I2C_ANA_MST, MODEM_LPCON}, - rom::regi2c::{define_regi2c, RawRegI2cField, RegI2cMaster, RegI2cRegister}, + rom::regi2c::{RawRegI2cField, RegI2cMaster, RegI2cRegister, define_regi2c}, }; define_regi2c! { @@ -174,11 +174,7 @@ fn regi2c_enable_block(block: u8) -> usize { } }); - if i2c_sel { - 0 - } else { - 1 - } + if i2c_sel { 0 } else { 1 } } pub(crate) fn regi2c_read(block: u8, _host_id: u8, reg_add: u8) -> u8 { diff --git a/esp-hal/src/soc/esp32h2/regi2c.rs b/esp-hal/src/soc/esp32h2/regi2c.rs index ff146b372..bcddc36f4 100644 --- a/esp-hal/src/soc/esp32h2/regi2c.rs +++ b/esp-hal/src/soc/esp32h2/regi2c.rs @@ -1,6 +1,6 @@ use crate::{ peripherals::{I2C_ANA_MST, MODEM_LPCON}, - rom::regi2c::{define_regi2c, RawRegI2cField, RegI2cMaster, RegI2cRegister}, + rom::regi2c::{RawRegI2cField, RegI2cMaster, RegI2cRegister, define_regi2c}, }; define_regi2c! { @@ -110,11 +110,7 @@ fn regi2c_enable_block(block: u8) -> usize { } }); - if i2c_sel { - 0 - } else { - 1 - } + if i2c_sel { 0 } else { 1 } } pub(crate) fn regi2c_read(block: u8, _host_id: u8, reg_add: u8) -> u8 { diff --git a/esp-hal/src/soc/esp32s2/mod.rs b/esp-hal/src/soc/esp32s2/mod.rs index e4c5d80b5..a71dad0bc 100644 --- a/esp-hal/src/soc/esp32s2/mod.rs +++ b/esp-hal/src/soc/esp32s2/mod.rs @@ -63,10 +63,10 @@ pub(crate) mod constants { /// *Note: the pre_init function is called in the original reset handler /// after the initializations done in this function* #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn ESP32Reset() -> ! { // These symbols come from `memory.x` - extern "C" { + unsafe extern "C" { static mut _rtc_fast_bss_start: u32; static mut _rtc_fast_bss_end: u32; static mut _rtc_fast_persistent_start: u32; @@ -83,38 +83,44 @@ pub unsafe extern "C" fn ESP32Reset() -> ! { } // set stack pointer to end of memory: no need to retain stack up to this point - xtensa_lx::set_stack_pointer(addr_of_mut!(_stack_start_cpu0)); + unsafe { + xtensa_lx::set_stack_pointer(addr_of_mut!(_stack_start_cpu0)); + } // copying data from flash to various data segments is done by the bootloader // initialization to zero needs to be done by the application // Initialize RTC RAM - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_fast_bss_start), - addr_of_mut!(_rtc_fast_bss_end), - ); - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_slow_bss_start), - addr_of_mut!(_rtc_slow_bss_end), - ); + unsafe { + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_fast_bss_start), + addr_of_mut!(_rtc_fast_bss_end), + ); + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_slow_bss_start), + addr_of_mut!(_rtc_slow_bss_end), + ); + } if matches!( crate::system::reset_reason(), None | Some(SocResetReason::ChipPowerOn) ) { - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_fast_persistent_start), - addr_of_mut!(_rtc_fast_persistent_end), - ); - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_slow_persistent_start), - addr_of_mut!(_rtc_slow_persistent_end), - ); + unsafe { + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_fast_persistent_start), + addr_of_mut!(_rtc_fast_persistent_end), + ); + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_slow_persistent_start), + addr_of_mut!(_rtc_slow_persistent_end), + ); + } } + let stack_chk_guard = core::ptr::addr_of_mut!(__stack_chk_guard); + // we _should_ use a random value but we don't have a good source for random + // numbers here unsafe { - let stack_chk_guard = core::ptr::addr_of_mut!(__stack_chk_guard); - // we _should_ use a random value but we don't have a good source for random - // numbers here stack_chk_guard.write_volatile(esp_config::esp_config_int!( u32, "ESP_HAL_CONFIG_STACK_GUARD_VALUE" @@ -124,13 +130,13 @@ pub unsafe extern "C" fn ESP32Reset() -> ! { crate::interrupt::setup_interrupts(); // continue with default reset handler - xtensa_lx_rt::Reset() + unsafe { xtensa_lx_rt::Reset() } } /// The ESP32 has a first stage bootloader that handles loading program data /// into the right place therefore we skip loading it again. #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[rustfmt::skip] pub extern "Rust" fn __init_data() -> bool { false @@ -138,32 +144,36 @@ pub extern "Rust" fn __init_data() -> bool { /// Write back a specific range of data in the cache. #[doc(hidden)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub unsafe fn cache_writeback_addr(addr: u32, size: u32) { - extern "C" { + unsafe extern "C" { fn Cache_WriteBack_Addr(addr: u32, size: u32); } - Cache_WriteBack_Addr(addr, size); + unsafe { + Cache_WriteBack_Addr(addr, size); + } } /// Invalidate a specific range of addresses in the cache. #[doc(hidden)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub unsafe fn cache_invalidate_addr(addr: u32, size: u32) { - extern "C" { + unsafe extern "C" { fn Cache_Invalidate_Addr(addr: u32, size: u32); } - Cache_Invalidate_Addr(addr, size); + unsafe { + Cache_Invalidate_Addr(addr, size); + } } /// Get the size of a cache line in the DCache. #[doc(hidden)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub unsafe fn cache_get_dcache_line_size() -> u32 { - extern "C" { + unsafe extern "C" { fn Cache_Get_DCache_Line_Size() -> u32; } - Cache_Get_DCache_Line_Size() + unsafe { Cache_Get_DCache_Line_Size() } } pub(crate) fn pre_init() {} diff --git a/esp-hal/src/soc/esp32s2/psram.rs b/esp-hal/src/soc/esp32s2/psram.rs index 2b28a3eb1..26a583624 100644 --- a/esp-hal/src/soc/esp32s2/psram.rs +++ b/esp-hal/src/soc/esp32s2/psram.rs @@ -102,7 +102,7 @@ pub(crate) fn init_psram(config: PsramConfig) { const CACHE_4WAYS_ASSOC: u32 = 0; const CACHE_LINE_SIZE_16B: u32 = 0; - extern "C" { + unsafe extern "C" { /// Allocate memory to used by ICache and DCache. /// /// [`sram0_layout`]: u32 the usage of first 8KB internal memory block, @@ -338,7 +338,7 @@ pub(crate) mod utils { cs_mask: u8, is_write_erase_operation: bool, ) { - extern "C" { + unsafe extern "C" { /// Start a spi user command sequence /// [`spi_num`] spi port /// [`rx_buf`] buffer pointer to receive data @@ -415,7 +415,7 @@ pub(crate) mod utils { dummy_bit_len: u32, } - extern "C" { + unsafe extern "C" { /// Config the spi user command /// [`spi_num`] spi port /// [`pcmd`] pointer to accept the spi command struct @@ -440,7 +440,7 @@ pub(crate) mod utils { } fn psram_set_op_mode(mode: CommandMode) { - extern "C" { + unsafe extern "C" { fn esp_rom_spi_set_op_mode(spi: u32, mode: u32); } @@ -473,7 +473,7 @@ pub(crate) mod utils { } fn psram_gpio_config() { - extern "C" { + unsafe extern "C" { fn esp_rom_efuse_get_flash_gpio_info() -> u32; /// Enable Quad I/O pin functions @@ -515,7 +515,9 @@ pub(crate) mod utils { // rom. } else { // this case is currently not yet supported - panic!("Unsupported for now! The case 'FLASH pins are all configured via GPIO matrix in ROM.' is not yet supported."); + panic!( + "Unsupported for now! The case 'FLASH pins are all configured via GPIO matrix in ROM.' is not yet supported." + ); // FLASH pins are all configured via GPIO matrix in ROM. // psram_io.flash_clk_io = diff --git a/esp-hal/src/soc/esp32s2/regi2c.rs b/esp-hal/src/soc/esp32s2/regi2c.rs index 0f38a56b9..596cbca11 100644 --- a/esp-hal/src/soc/esp32s2/regi2c.rs +++ b/esp-hal/src/soc/esp32s2/regi2c.rs @@ -1,6 +1,6 @@ use crate::{ peripherals::{I2C_ANA_MST, SYSCON}, - rom::regi2c::{define_regi2c, RawRegI2cField, RegI2cMaster, RegI2cRegister}, + rom::regi2c::{RawRegI2cField, RegI2cMaster, RegI2cRegister, define_regi2c}, }; define_regi2c! { diff --git a/esp-hal/src/soc/esp32s3/cpu_control.rs b/esp-hal/src/soc/esp32s3/cpu_control.rs index 0a1b1096a..2be814ff3 100644 --- a/esp-hal/src/soc/esp32s3/cpu_control.rs +++ b/esp-hal/src/soc/esp32s3/cpu_control.rs @@ -160,18 +160,18 @@ unsafe fn internal_park_core(core: Cpu, park: bool) { Cpu::ProCpu => { LPWR::regs() .sw_cpu_stall() - .modify(|_, w| w.sw_stall_procpu_c1().bits(c1_value)); + .modify(|_, w| unsafe { w.sw_stall_procpu_c1().bits(c1_value) }); LPWR::regs() .options0() - .modify(|_, w| w.sw_stall_procpu_c0().bits(c0_value)); + .modify(|_, w| unsafe { w.sw_stall_procpu_c0().bits(c0_value) }); } Cpu::AppCpu => { LPWR::regs() .sw_cpu_stall() - .modify(|_, w| w.sw_stall_appcpu_c1().bits(c1_value)); + .modify(|_, w| unsafe { w.sw_stall_appcpu_c1().bits(c1_value) }); LPWR::regs() .options0() - .modify(|_, w| w.sw_stall_appcpu_c0().bits(c0_value)); + .modify(|_, w| unsafe { w.sw_stall_appcpu_c0().bits(c0_value) }); } } } @@ -193,7 +193,9 @@ impl<'d> CpuControl<'d> { /// currently executing their code. #[instability::unstable] pub unsafe fn park_core(&mut self, core: Cpu) { - internal_park_core(core, true); + unsafe { + internal_park_core(core, true); + } } /// Unpark the given core @@ -212,31 +214,32 @@ impl<'d> CpuControl<'d> { F: FnOnce(), { // disables interrupts - xtensa_lx::interrupt::set_mask(0); + unsafe { + xtensa_lx::interrupt::set_mask(0); + } // reset cycle compare registers xtensa_lx::timer::set_ccompare0(0); xtensa_lx::timer::set_ccompare1(0); xtensa_lx::timer::set_ccompare2(0); - extern "C" { + unsafe extern "C" { static mut _init_start: u32; } + // move vec table + let base = core::ptr::addr_of!(_init_start); unsafe { - // move vec table - let base = core::ptr::addr_of!(_init_start); core::arch::asm!("wsr.vecbase {0}", in(reg) base, options(nostack)); + // switch to new stack + xtensa_lx::set_stack_pointer(unwrap!(APP_CORE_STACK_TOP)); } - // switch to new stack - xtensa_lx::set_stack_pointer(unwrap!(APP_CORE_STACK_TOP)); - // Trampoline to run from the new stack. // start_core1_run should _NEVER_ be inlined // as we rely on the function call to use // the new stack. - Self::start_core1_run::() + unsafe { Self::start_core1_run::() } } /// Run the core1 closure. @@ -246,14 +249,14 @@ impl<'d> CpuControl<'d> { F: FnOnce(), { #[allow(static_mut_refs)] // FIXME - match START_CORE1_FUNCTION.take() { - Some(entry) => { - let entry = unsafe { ManuallyDrop::take(&mut *entry.cast::>()) }; + match unsafe { START_CORE1_FUNCTION.take() } { + Some(entry) => unsafe { + let entry = ManuallyDrop::take(&mut *entry.cast::>()); entry(); loop { - unsafe { internal_park_core(Cpu::current(), true) }; + internal_park_core(Cpu::current(), true); } - } + }, None => panic!("No start function set"), } } diff --git a/esp-hal/src/soc/esp32s3/efuse/mod.rs b/esp-hal/src/soc/esp32s3/efuse/mod.rs index f9ab3004c..6dce639f1 100644 --- a/esp-hal/src/soc/esp32s3/efuse/mod.rs +++ b/esp-hal/src/soc/esp32s3/efuse/mod.rs @@ -83,11 +83,7 @@ impl Efuse { pub fn rtc_calib_version() -> u8 { let (major, _minor) = Self::block_version(); - if major == 1 { - 1 - } else { - 0 - } + if major == 1 { 1 } else { 0 } } /// Get ADC initial code for specified attenuation from efuse diff --git a/esp-hal/src/soc/esp32s3/gpio.rs b/esp-hal/src/soc/esp32s3/gpio.rs index 93f79b1ef..fc1a0e861 100644 --- a/esp-hal/src/soc/esp32s3/gpio.rs +++ b/esp-hal/src/soc/esp32s3/gpio.rs @@ -233,7 +233,7 @@ pub enum InputSignal { #[derive(Debug, PartialEq, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[doc(hidden)] // TODO connection operations are now public on these, we might want to publish - // them +// them pub enum OutputSignal { SPIQ = 0, SPID = 1, diff --git a/esp-hal/src/soc/esp32s3/mod.rs b/esp-hal/src/soc/esp32s3/mod.rs index cb6b00d4d..b8549bc45 100644 --- a/esp-hal/src/soc/esp32s3/mod.rs +++ b/esp-hal/src/soc/esp32s3/mod.rs @@ -64,13 +64,13 @@ pub(crate) mod constants { } #[doc(hidden)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub unsafe fn configure_cpu_caches() { // this is just the bare minimum we need to run code from flash // consider implementing more advanced configurations // see https://github.com/apache/incubator-nuttx/blob/master/arch/xtensa/src/esp32s3/esp32s3_start.c - extern "C" { + unsafe extern "C" { fn rom_config_instruction_cache_mode( cfg_cache_size: u32, cfg_cache_ways: u8, @@ -84,11 +84,13 @@ pub unsafe fn configure_cpu_caches() { const CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE: u8 = 32; // ESP32S3_INSTRUCTION_CACHE_LINE_32B // Configure the mode of instruction cache: cache size, cache line size. - rom_config_instruction_cache_mode( - CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE, - CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS, - CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE, - ); + unsafe { + rom_config_instruction_cache_mode( + CONFIG_ESP32S3_INSTRUCTION_CACHE_SIZE, + CONFIG_ESP32S3_ICACHE_ASSOCIATED_WAYS, + CONFIG_ESP32S3_INSTRUCTION_CACHE_LINE_SIZE, + ); + } } /// Function initializes ESP32S3 specific memories (RTC slow and fast) and @@ -98,13 +100,15 @@ pub unsafe fn configure_cpu_caches() { /// *Note: the pre_init function is called in the original reset handler /// after the initializations done in this function* #[doc(hidden)] -#[no_mangle] -#[link_section = ".rwtext"] +#[unsafe(no_mangle)] +#[unsafe(link_section = ".rwtext")] pub unsafe extern "C" fn ESP32Reset() -> ! { - configure_cpu_caches(); + unsafe { + configure_cpu_caches(); + } // These symbols come from `memory.x` - extern "C" { + unsafe extern "C" { static mut _rtc_fast_bss_start: u32; static mut _rtc_fast_bss_end: u32; static mut _rtc_fast_persistent_start: u32; @@ -121,38 +125,44 @@ pub unsafe extern "C" fn ESP32Reset() -> ! { } // set stack pointer to end of memory: no need to retain stack up to this point - xtensa_lx::set_stack_pointer(addr_of_mut!(_stack_start_cpu0)); + unsafe { + xtensa_lx::set_stack_pointer(addr_of_mut!(_stack_start_cpu0)); + } // copying data from flash to various data segments is done by the bootloader // initialization to zero needs to be done by the application // Initialize RTC RAM - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_fast_bss_start), - addr_of_mut!(_rtc_fast_bss_end), - ); - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_slow_bss_start), - addr_of_mut!(_rtc_slow_bss_end), - ); + unsafe { + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_fast_bss_start), + addr_of_mut!(_rtc_fast_bss_end), + ); + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_slow_bss_start), + addr_of_mut!(_rtc_slow_bss_end), + ); + } if matches!( crate::system::reset_reason(), None | Some(SocResetReason::ChipPowerOn) ) { - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_fast_persistent_start), - addr_of_mut!(_rtc_fast_persistent_end), - ); - xtensa_lx_rt::zero_bss( - addr_of_mut!(_rtc_slow_persistent_start), - addr_of_mut!(_rtc_slow_persistent_end), - ); + unsafe { + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_fast_persistent_start), + addr_of_mut!(_rtc_fast_persistent_end), + ); + xtensa_lx_rt::zero_bss( + addr_of_mut!(_rtc_slow_persistent_start), + addr_of_mut!(_rtc_slow_persistent_end), + ); + } } + let stack_chk_guard = core::ptr::addr_of_mut!(__stack_chk_guard); + // we _should_ use a random value but we don't have a good source for random + // numbers here unsafe { - let stack_chk_guard = core::ptr::addr_of_mut!(__stack_chk_guard); - // we _should_ use a random value but we don't have a good source for random - // numbers here stack_chk_guard.write_volatile(esp_config::esp_config_int!( u32, "ESP_HAL_CONFIG_STACK_GUARD_VALUE" @@ -162,13 +172,13 @@ pub unsafe extern "C" fn ESP32Reset() -> ! { crate::interrupt::setup_interrupts(); // continue with default reset handler - xtensa_lx_rt::Reset() + unsafe { xtensa_lx_rt::Reset() } } /// The ESP32 has a first stage bootloader that handles loading program data /// into the right place therefore we skip loading it again. #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[rustfmt::skip] pub extern "Rust" fn __init_data() -> bool { false @@ -176,37 +186,41 @@ pub extern "Rust" fn __init_data() -> bool { /// Write back a specific range of data in the cache. #[doc(hidden)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub unsafe fn cache_writeback_addr(addr: u32, size: u32) { - extern "C" { + unsafe extern "C" { fn rom_Cache_WriteBack_Addr(addr: u32, size: u32); fn Cache_Suspend_DCache_Autoload() -> u32; fn Cache_Resume_DCache_Autoload(value: u32); } // suspend autoload, avoid load cachelines being written back - let autoload = Cache_Suspend_DCache_Autoload(); - rom_Cache_WriteBack_Addr(addr, size); - Cache_Resume_DCache_Autoload(autoload); + unsafe { + let autoload = Cache_Suspend_DCache_Autoload(); + rom_Cache_WriteBack_Addr(addr, size); + Cache_Resume_DCache_Autoload(autoload); + } } /// Invalidate a specific range of addresses in the cache. #[doc(hidden)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub unsafe fn cache_invalidate_addr(addr: u32, size: u32) { - extern "C" { + unsafe extern "C" { fn Cache_Invalidate_Addr(addr: u32, size: u32); } - Cache_Invalidate_Addr(addr, size); + unsafe { + Cache_Invalidate_Addr(addr, size); + } } /// Get the size of a cache line in the DCache. #[doc(hidden)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub unsafe fn cache_get_dcache_line_size() -> u32 { - extern "C" { + unsafe extern "C" { fn Cache_Get_DCache_Line_Size() -> u32; } - Cache_Get_DCache_Line_Size() + unsafe { Cache_Get_DCache_Line_Size() } } pub(crate) fn pre_init() {} diff --git a/esp-hal/src/soc/esp32s3/psram.rs b/esp-hal/src/soc/esp32s3/psram.rs index 727fe2d82..f70a1d607 100644 --- a/esp-hal/src/soc/esp32s3/psram.rs +++ b/esp-hal/src/soc/esp32s3/psram.rs @@ -128,7 +128,7 @@ pub(crate) fn init_psram(config: PsramConfig) { const MMU_ACCESS_SPIRAM: u32 = 1 << 15; const START_PAGE: u32 = 0; - extern "C" { + unsafe extern "C" { fn rom_config_instruction_cache_mode( cfg_cache_size: u32, cfg_cache_ways: u8, @@ -325,7 +325,7 @@ pub(crate) mod utils { const SPI_MEM_CLKCNT_L_S: u32 = 0; const SPI_MEM_SCLKCNT_L_S: u32 = 0; - extern "C" { + unsafe extern "C" { fn esp_rom_efuse_get_flash_gpio_info() -> u32; fn esp_rom_efuse_get_flash_wp_gpio() -> u8; @@ -587,7 +587,7 @@ pub(crate) mod utils { cs_mask: u8, is_write_erase_operation: bool, ) { - extern "C" { + unsafe extern "C" { /// Start a spi user command sequence /// [`spi_num`] spi port /// [`rx_buf`] buffer pointer to receive data @@ -663,7 +663,7 @@ pub(crate) mod utils { dummy_bit_len: u32, } - extern "C" { + unsafe extern "C" { /// Config the spi user command /// [`spi_num`] spi port /// [`pcmd`] pointer to accept the spi command struct @@ -689,7 +689,7 @@ pub(crate) mod utils { #[ram] fn psram_set_op_mode(mode: CommandMode) { - extern "C" { + unsafe extern "C" { fn esp_rom_spi_set_op_mode(spi: u32, mode: u32); } @@ -828,7 +828,7 @@ pub(crate) mod utils { const SPI_MEM_SCLKCNT_L_S: u32 = 0; const ESP_ROM_SPIFLASH_OPI_DTR_MODE: u8 = 7; - extern "C" { + unsafe extern "C" { // @brief To execute a flash operation command // @param spi_num spi port // @param mode Flash Read Mode @@ -1114,7 +1114,10 @@ pub(crate) mod utils { print_psram_info(&mode_reg); if mode_reg.vendor_id() != OCT_PSRAM_VENDOR_ID { - warn!("PSRAM ID read error: {:x}, PSRAM chip not found or not supported, or wrong PSRAM line mode", mode_reg.vendor_id()); + warn!( + "PSRAM ID read error: {:x}, PSRAM chip not found or not supported, or wrong PSRAM line mode", + mode_reg.vendor_id() + ); return; } @@ -1296,7 +1299,7 @@ pub(crate) mod utils { // Set SPI01 core clock spi0_timing_config_set_core_clock(core_clock); // SPI0 and SPI1 share the register for core clock. So we only set SPI0 here. - // Set FLASH module clock + // Set FLASH module clock spi0_timing_config_set_flash_clock(flash_div); if control_spi1 { spi1_timing_config_set_flash_clock(flash_div); diff --git a/esp-hal/src/soc/esp32s3/regi2c.rs b/esp-hal/src/soc/esp32s3/regi2c.rs index 6992b12dc..c630ddfd8 100644 --- a/esp-hal/src/soc/esp32s3/regi2c.rs +++ b/esp-hal/src/soc/esp32s3/regi2c.rs @@ -1,4 +1,4 @@ -use crate::rom::regi2c::{define_regi2c, RawRegI2cField, RegI2cMaster, RegI2cRegister}; +use crate::rom::regi2c::{RawRegI2cField, RegI2cMaster, RegI2cRegister, define_regi2c}; define_regi2c! { master: REGI2C_SAR_I2C(0x69, 1) { @@ -55,14 +55,14 @@ define_regi2c! { } pub(crate) fn regi2c_read(block: u8, host_id: u8, reg_add: u8) -> u8 { - extern "C" { + unsafe extern "C" { pub(crate) fn esp_rom_regi2c_read(block: u8, block_hostid: u8, reg_add: u8) -> u8; } unsafe { esp_rom_regi2c_read(block, host_id, reg_add) } } pub(crate) fn regi2c_write(block: u8, host_id: u8, reg_add: u8, data: u8) { - extern "C" { + unsafe extern "C" { pub(crate) fn rom_i2c_writeReg(block: u8, block_hostid: u8, reg_add: u8, indata: u8); } unsafe { rom_i2c_writeReg(block, host_id, reg_add, data) }; diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index b6983675d..e444cb397 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -46,15 +46,18 @@ use procmacros::ram; use super::{BitOrder, DataMode, DmaError, Error, Mode}; use crate::{ + Async, + Blocking, + DriverMode, asynch::AtomicWaker, clock::Clocks, dma::{DmaChannelFor, DmaEligible, DmaRxBuffer, DmaTxBuffer}, gpio::{ - interconnect::{PeripheralInput, PeripheralOutput}, InputSignal, NoPin, OutputSignal, PinGuard, + interconnect::{PeripheralInput, PeripheralOutput}, }, interrupt::InterruptHandler, pac::spi2::RegisterBlock, @@ -62,9 +65,6 @@ use crate::{ spi::AnySpi, system::{Cpu, PeripheralGuard}, time::Rate, - Async, - Blocking, - DriverMode, }; /// Enumeration of possible SPI interrupt events. @@ -1198,12 +1198,12 @@ mod dma { use core::{ cmp::min, mem::ManuallyDrop, - sync::atomic::{fence, Ordering}, + sync::atomic::{Ordering, fence}, }; use super::*; use crate::{ - dma::{asynch::DmaRxFuture, Channel, DmaRxBuf, DmaTxBuf, EmptyBuf, PeripheralDmaChannel}, + dma::{Channel, DmaRxBuf, DmaTxBuf, EmptyBuf, PeripheralDmaChannel, asynch::DmaRxFuture}, spi::master::dma::asynch::DropGuard, }; @@ -1730,7 +1730,7 @@ mod dma { bytes_to_write: usize, buffer: &mut impl DmaTxBuffer, ) -> Result<(), Error> { - self.start_dma_transfer(0, bytes_to_write, &mut EmptyBuf, buffer) + unsafe { self.start_dma_transfer(0, bytes_to_write, &mut EmptyBuf, buffer) } } /// Configures the DMA buffers for the SPI instance. @@ -1776,7 +1776,7 @@ mod dma { bytes_to_read: usize, buffer: &mut impl DmaRxBuffer, ) -> Result<(), Error> { - self.start_dma_transfer(bytes_to_read, 0, buffer, &mut EmptyBuf) + unsafe { self.start_dma_transfer(bytes_to_read, 0, buffer, &mut EmptyBuf) } } /// Perform a DMA read. @@ -1814,7 +1814,9 @@ mod dma { rx_buffer: &mut impl DmaRxBuffer, tx_buffer: &mut impl DmaTxBuffer, ) -> Result<(), Error> { - self.start_transfer_dma(true, bytes_to_read, bytes_to_write, rx_buffer, tx_buffer) + unsafe { + self.start_transfer_dma(true, bytes_to_read, bytes_to_write, rx_buffer, tx_buffer) + } } /// Perform a DMA transfer @@ -1873,7 +1875,7 @@ mod dma { data_mode, )?; - self.start_transfer_dma(false, bytes_to_read, 0, buffer, &mut EmptyBuf) + unsafe { self.start_transfer_dma(false, bytes_to_read, 0, buffer, &mut EmptyBuf) } } /// Perform a half-duplex read operation using DMA. @@ -1939,7 +1941,7 @@ mod dma { data_mode, )?; - self.start_transfer_dma(false, 0, bytes_to_write, &mut EmptyBuf, buffer) + unsafe { self.start_transfer_dma(false, 0, bytes_to_write, &mut EmptyBuf, buffer) } } /// Perform a half-duplex write operation using DMA. @@ -2791,8 +2793,8 @@ impl DmaDriver { #[cfg(esp32s2)] { // without this a transfer after a write will fail - self.regs().dma_out_link().write(|w| w.bits(0)); - self.regs().dma_in_link().write(|w| w.bits(0)); + self.regs().dma_out_link().write(|w| unsafe { w.bits(0) }); + self.regs().dma_in_link().write(|w| unsafe { w.bits(0) }); } self.driver.configure_datalen(rx_len, tx_len); @@ -2805,10 +2807,12 @@ impl DmaDriver { self.enable_dma(); if rx_len > 0 { - channel - .rx - .prepare_transfer(self.dma_peripheral, rx_buffer) - .and_then(|_| channel.rx.start_transfer())?; + unsafe { + channel + .rx + .prepare_transfer(self.dma_peripheral, rx_buffer) + .and_then(|_| channel.rx.start_transfer())?; + } } else { #[cfg(esp32)] { @@ -2825,10 +2829,12 @@ impl DmaDriver { } } if tx_len > 0 { - channel - .tx - .prepare_transfer(self.dma_peripheral, tx_buffer) - .and_then(|_| channel.tx.start_transfer())?; + unsafe { + channel + .tx + .prepare_transfer(self.dma_peripheral, tx_buffer) + .and_then(|_| channel.tx.start_transfer())?; + } } #[cfg(gdma)] diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs index 3616a360d..1c3078199 100644 --- a/esp-hal/src/spi/slave.rs +++ b/esp-hal/src/spi/slave.rs @@ -69,18 +69,18 @@ use core::marker::PhantomData; use super::{Error, Mode}; use crate::{ + Blocking, + DriverMode, dma::DmaEligible, gpio::{ - interconnect::{PeripheralInput, PeripheralOutput}, InputSignal, NoPin, OutputSignal, + interconnect::{PeripheralInput, PeripheralOutput}, }, pac::spi2::RegisterBlock, spi::AnySpi, system::PeripheralGuard, - Blocking, - DriverMode, }; const MAX_DMA_SIZE: usize = 32768 - 32; @@ -164,6 +164,7 @@ pub mod dma { use super::*; use crate::{ + DriverMode, dma::{ Channel, DmaChannelFor, @@ -173,7 +174,6 @@ pub mod dma { EmptyBuf, PeripheralDmaChannel, }, - DriverMode, }; impl<'d> Spi<'d, Blocking> { @@ -470,15 +470,19 @@ pub mod dma { self.info.reset_spi(); if read_buffer_len > 0 { - channel - .rx - .prepare_transfer(self.dma_peripheral, rx_buffer)?; + unsafe { + channel + .rx + .prepare_transfer(self.dma_peripheral, rx_buffer)?; + } } if write_buffer_len > 0 { - channel - .tx - .prepare_transfer(self.dma_peripheral, tx_buffer)?; + unsafe { + channel + .tx + .prepare_transfer(self.dma_peripheral, tx_buffer)?; + } } #[cfg(esp32)] diff --git a/esp-hal/src/sync.rs b/esp-hal/src/sync.rs index f04563960..97663a9c2 100644 --- a/esp-hal/src/sync.rs +++ b/esp-hal/src/sync.rs @@ -50,7 +50,7 @@ impl TryFrom for Priority { } mod single_core { - use core::sync::atomic::{compiler_fence, Ordering}; + use core::sync::atomic::{Ordering, compiler_fence}; use super::RestoreState; use crate::interrupt::Priority; @@ -72,7 +72,7 @@ mod single_core { /// Prevents interrupts above `level` from firing and returns the /// current run level. unsafe fn change_current_level(level: Priority) -> Priority { - crate::interrupt::change_current_runlevel(level) + unsafe { crate::interrupt::change_current_runlevel(level) } } } @@ -80,7 +80,7 @@ mod single_core { unsafe fn enter(&self) -> RestoreState { #[cfg(riscv)] if self.0 == Priority::max() { - return InterruptLock.enter(); + return unsafe { InterruptLock.enter() }; } let prev_interrupt_priority = unsafe { Self::change_current_level(self.0) }; @@ -96,7 +96,7 @@ mod single_core { unsafe fn exit(&self, token: RestoreState) { #[cfg(riscv)] if self.0 == Priority::max() { - return InterruptLock.exit(token); + return unsafe { InterruptLock.exit(token) }; } assert!(Self::current_priority() <= self.0); // Ensure no preceeding memory accesses are reordered to after interrupts are @@ -104,7 +104,9 @@ mod single_core { compiler_fence(Ordering::SeqCst); let priority = unwrap!(Priority::try_from(token)); - unsafe { Self::change_current_level(priority) }; + unsafe { + Self::change_current_level(priority); + } } } @@ -116,11 +118,11 @@ mod single_core { cfg_if::cfg_if! { if #[cfg(riscv)] { let mut mstatus = 0u32; - core::arch::asm!("csrrci {0}, mstatus, 8", inout(reg) mstatus); + unsafe {core::arch::asm!("csrrci {0}, mstatus, 8", inout(reg) mstatus);} let token = mstatus & 0b1000; } else if #[cfg(xtensa)] { let token: u32; - core::arch::asm!("rsil {0}, 5", out(reg) token); + unsafe {core::arch::asm!("rsil {0}, 5", out(reg) token);} } else { compile_error!("Unsupported architecture") } @@ -143,15 +145,19 @@ mod single_core { cfg_if::cfg_if! { if #[cfg(riscv)] { if token != 0 { - esp_riscv_rt::riscv::interrupt::enable(); + unsafe { + esp_riscv_rt::riscv::interrupt::enable(); + } } } else if #[cfg(xtensa)] { // Reserved bits in the PS register, these must be written as 0. const RESERVED_MASK: u32 = 0b1111_1111_1111_1000_1111_0000_0000_0000; debug_assert!(token & RESERVED_MASK == 0); - core::arch::asm!( - "wsr.ps {0}", - "rsync", in(reg) token) + unsafe { + core::arch::asm!( + "wsr.ps {0}", + "rsync", in(reg) token) + } } else { compile_error!("Unsupported architecture") } @@ -301,14 +307,16 @@ impl GenericRawMutex { /// were acquired. /// - Each release call must be paired with an acquire call. unsafe fn release(&self, token: RestoreState) { - if !token.is_reentry() { - #[cfg(multi_core)] - self.inner.unlock(); + unsafe { + if !token.is_reentry() { + #[cfg(multi_core)] + self.inner.unlock(); - #[cfg(single_core)] - self.is_locked.set(false); + #[cfg(single_core)] + self.is_locked.set(false); - self.lock.exit(token) + self.lock.exit(token) + } } } @@ -357,7 +365,7 @@ impl RawMutex { /// - The caller must ensure to release the locks in the reverse order they /// were acquired. pub unsafe fn acquire(&self) -> RestoreState { - self.inner.acquire() + unsafe { self.inner.acquire() } } /// Releases the lock. @@ -370,7 +378,9 @@ impl RawMutex { /// were acquired. /// - Each release call must be paired with an acquire call. pub unsafe fn release(&self, token: RestoreState) { - self.inner.release(token); + unsafe { + self.inner.release(token); + } } /// Runs the callback with this lock locked. @@ -504,11 +514,13 @@ mod critical_section { unsafe impl critical_section::Impl for CriticalSection { unsafe fn acquire() -> critical_section::RawRestoreState { - CRITICAL_SECTION.acquire().0 + unsafe { CRITICAL_SECTION.acquire().0 } } unsafe fn release(token: critical_section::RawRestoreState) { - CRITICAL_SECTION.release(super::RestoreState(token)); + unsafe { + CRITICAL_SECTION.release(super::RestoreState(token)); + } } } } diff --git a/esp-hal/src/timer/mod.rs b/esp-hal/src/timer/mod.rs index 8af54042f..531fc0be9 100644 --- a/esp-hal/src/timer/mod.rs +++ b/esp-hal/src/timer/mod.rs @@ -48,14 +48,14 @@ use core::{ }; use crate::{ + Async, + Blocking, + DriverMode, asynch::AtomicWaker, interrupt::{InterruptConfigurable, InterruptHandler}, peripherals::Interrupt, system::Cpu, time::{Duration, Instant}, - Async, - Blocking, - DriverMode, }; #[cfg(systimer)] diff --git a/esp-hal/src/timer/systimer.rs b/esp-hal/src/timer/systimer.rs index 087db733d..4eeb97cc9 100644 --- a/esp-hal/src/timer/systimer.rs +++ b/esp-hal/src/timer/systimer.rs @@ -24,7 +24,7 @@ use crate::{ asynch::AtomicWaker, interrupt::{self, InterruptHandler}, peripherals::{Interrupt, SYSTIMER}, - sync::{lock, RawMutex}, + sync::{RawMutex, lock}, system::{Cpu, Peripheral as PeripheralEnable, PeripheralClockControl}, time::{Duration, Instant}, }; diff --git a/esp-hal/src/touch.rs b/esp-hal/src/touch.rs index 927b6f27d..cf3566e74 100644 --- a/esp-hal/src/touch.rs +++ b/esp-hal/src/touch.rs @@ -29,13 +29,13 @@ use core::marker::PhantomData; use crate::{ + Async, + Blocking, + DriverMode, gpio::TouchPin, peripherals::{LPWR, SENS, TOUCH}, private::{Internal, Sealed}, rtc_cntl::Rtc, - Async, - Blocking, - DriverMode, }; /// A marker trait describing the mode the touch pad is set to. @@ -517,7 +517,7 @@ mod asynch { }; use super::*; - use crate::{asynch::AtomicWaker, handler, ram, Async}; + use crate::{Async, asynch::AtomicWaker, handler, ram}; const NUM_TOUCH_PINS: usize = 10; diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs index 6d445f0d3..61f71572e 100644 --- a/esp-hal/src/twai/mod.rs +++ b/esp-hal/src/twai/mod.rs @@ -122,19 +122,19 @@ use core::marker::PhantomData; use self::filter::{Filter, FilterType}; use crate::{ + Async, + Blocking, + DriverMode, gpio::{ - interconnect::{PeripheralInput, PeripheralOutput}, InputSignal, OutputSignal, Pull, + interconnect::{PeripheralInput, PeripheralOutput}, }, interrupt::InterruptHandler, pac::twai0::RegisterBlock, system::{Cpu, PeripheralGuard}, twai::filter::SingleStandardFilter, - Async, - Blocking, - DriverMode, }; pub mod filter; @@ -479,7 +479,9 @@ impl EspTwaiFrame { let mut data: [u8; 8] = [0; 8]; // Copy the data from the memory mapped peripheral into actual memory. - copy_from_data_register(&mut data[..dlc], registers); + unsafe { + copy_from_data_register(&mut data[..dlc], registers); + } Self { id: id.into(), @@ -1238,7 +1240,9 @@ impl embedded_can::Error for EspTwaiError { unsafe fn copy_from_data_register(dest: &mut [u8], src: *const u32) { for (i, dest) in dest.iter_mut().enumerate() { // Perform a volatile read to avoid compiler optimizations. - *dest = src.add(i).read_volatile() as u8; + unsafe { + *dest = src.add(i).read_volatile() as u8; + } } } @@ -1254,7 +1258,9 @@ unsafe fn copy_from_data_register(dest: &mut [u8], src: *const u32) { unsafe fn copy_to_data_register(dest: *mut u32, src: &[u8]) { for (i, src) in src.iter().enumerate() { // Perform a volatile write to avoid compiler optimizations. - dest.add(i).write_volatile(*src as u32); + unsafe { + dest.add(i).write_volatile(*src as u32); + } } } diff --git a/esp-hal/src/uart.rs b/esp-hal/src/uart.rs index d6ce321fe..d86df530d 100644 --- a/esp-hal/src/uart.rs +++ b/esp-hal/src/uart.rs @@ -49,23 +49,23 @@ use enumset::{EnumSet, EnumSetType}; use portable_atomic::AtomicBool; use crate::{ + Async, + Blocking, + DriverMode, asynch::AtomicWaker, clock::Clocks, gpio::{ - interconnect::{PeripheralInput, PeripheralOutput}, InputSignal, OutputSignal, PinGuard, Pull, + interconnect::{PeripheralInput, PeripheralOutput}, }, interrupt::InterruptHandler, pac::uart0::RegisterBlock, peripherals::Interrupt, private::OnDrop, system::{PeripheralClockControl, PeripheralGuard}, - Async, - Blocking, - DriverMode, }; /// UART RX Error @@ -2145,7 +2145,7 @@ pub(super) fn intr_handler(uart: &Info, state: &State) { pub mod lp_uart { use crate::{ gpio::lp_io::{LowPowerInput, LowPowerOutput}, - peripherals::{LPWR, LP_AON, LP_IO, LP_UART}, + peripherals::{LP_AON, LP_IO, LP_UART, LPWR}, uart::{Config, DataBits, Parity, StopBits}, }; /// LP-UART driver diff --git a/esp-hal/src/usb_serial_jtag.rs b/esp-hal/src/usb_serial_jtag.rs index ad175ccfc..8b8827c73 100644 --- a/esp-hal/src/usb_serial_jtag.rs +++ b/esp-hal/src/usb_serial_jtag.rs @@ -128,13 +128,13 @@ use core::{convert::Infallible, marker::PhantomData}; use procmacros::handler; use crate::{ + Async, + Blocking, + DriverMode, asynch::AtomicWaker, pac::usb_device::RegisterBlock, peripherals::{Interrupt, USB_DEVICE}, system::{Cpu, PeripheralClockControl}, - Async, - Blocking, - DriverMode, }; /// Custom USB serial error type diff --git a/esp-ieee802154/CHANGELOG.md b/esp-ieee802154/CHANGELOG.md index 796a1e611..ffe9e8e72 100644 --- a/esp-ieee802154/CHANGELOG.md +++ b/esp-ieee802154/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed - Fixed compatibility with `defmt` (#3374) diff --git a/esp-ieee802154/Cargo.toml b/esp-ieee802154/Cargo.toml index b45ccae8d..f5e3a8767 100644 --- a/esp-ieee802154/Cargo.toml +++ b/esp-ieee802154/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-ieee802154" version = "0.6.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Low-level IEEE 802.15.4 driver for the ESP32-C6 and ESP32-H2" documentation = "https://docs.espressif.com/projects/rust/esp-ieee802154/latest/" keywords = ["embedded", "esp32", "espressif", "ieee802154", "wpan"] diff --git a/esp-ieee802154/build.rs b/esp-ieee802154/build.rs index 585857bfd..d8db8ad45 100644 --- a/esp-ieee802154/build.rs +++ b/esp-ieee802154/build.rs @@ -1,6 +1,6 @@ use std::{env, path::PathBuf}; -use esp_config::{generate_config, ConfigOption, Stability, Validator, Value}; +use esp_config::{ConfigOption, Stability, Validator, Value, generate_config}; fn main() { let out = PathBuf::from(env::var_os("OUT_DIR").unwrap()); diff --git a/esp-ieee802154/src/raw.rs b/esp-ieee802154/src/raw.rs index 038212b08..d150b5e7d 100644 --- a/esp-ieee802154/src/raw.rs +++ b/esp-ieee802154/src/raw.rs @@ -15,11 +15,11 @@ use heapless::spsc::Queue; use crate::{ frame::{ - frame_get_version, - frame_is_ack_required, FRAME_SIZE, FRAME_VERSION_1, FRAME_VERSION_2, + frame_get_version, + frame_is_ack_required, }, hal::*, pib::*, @@ -32,7 +32,7 @@ static RX_QUEUE: Mutex> = Mutex::new(RefCell::new(Ieee802154State::Idle)); -extern "C" { +unsafe extern "C" { fn bt_bb_v2_init_cmplx(print_version: u32); // from libbtbb.a fn bt_bb_set_zb_tx_on_delay(time: u16); // from libbtbb.a @@ -108,7 +108,7 @@ fn esp_btbb_enable() { fn ieee802154_mac_init() { #[cfg(feature = "esp32c6")] unsafe { - extern "C" { + unsafe extern "C" { static mut coex_pti_tab_ptr: u32; static coex_pti_tab: u8; } diff --git a/esp-lp-hal/CHANGELOG.md b/esp-lp-hal/CHANGELOG.md index 19a444a22..2a7ed316c 100644 --- a/esp-lp-hal/CHANGELOG.md +++ b/esp-lp-hal/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump MSRV to 1.84 (#2951) - Fix gpio `input_state` and `output_state` for the ESP32-S3 and ESP32-S2 (#3191) +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) ### Fixed diff --git a/esp-lp-hal/Cargo.toml b/esp-lp-hal/Cargo.toml index bd41b3e83..898b5dd1a 100644 --- a/esp-lp-hal/Cargo.toml +++ b/esp-lp-hal/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-lp-hal" version = "0.1.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "HAL for low-power RISC-V coprocessors found in ESP32 devices" documentation = "https://docs.espressif.com/projects/rust/esp-lp-hal/latest/" keywords = ["embedded", "embedded-hal", "esp32", "espressif", "hal"] diff --git a/esp-lp-hal/src/i2c.rs b/esp-lp-hal/src/i2c.rs index 85b1c2720..726eeb621 100644 --- a/esp-lp-hal/src/i2c.rs +++ b/esp-lp-hal/src/i2c.rs @@ -2,7 +2,7 @@ #![allow(unused)] // TODO: Remove me when `embedded_hal::i2c::I2c` is implemented -use crate::pac::{lp_i2c0::COMD, LP_I2C0}; +use crate::pac::{LP_I2C0, lp_i2c0::COMD}; const LP_I2C_TRANS_COMPLETE_INT_ST_S: u32 = 7; const LP_I2C_END_DETECT_INT_ST_S: u32 = 3; @@ -16,8 +16,10 @@ const LP_I2C_FIFO_LEN: u32 = 16; #[doc(hidden)] pub unsafe fn conjure() -> LpI2c { - LpI2c { - i2c: LP_I2C0::steal(), + unsafe { + LpI2c { + i2c: LP_I2C0::steal(), + } } } diff --git a/esp-lp-hal/src/lib.rs b/esp-lp-hal/src/lib.rs index 4632179f9..235ca56f7 100644 --- a/esp-lp-hal/src/lib.rs +++ b/esp-lp-hal/src/lib.rs @@ -125,29 +125,31 @@ loop: "# ); -#[link_section = ".init.rust"] -#[export_name = "rust_main"] +#[unsafe(link_section = ".init.rust")] +#[unsafe(export_name = "rust_main")] unsafe extern "C" fn lp_core_startup() -> ! { - extern "Rust" { - fn main() -> !; - } + unsafe { + unsafe extern "Rust" { + fn main() -> !; + } - #[cfg(feature = "esp32c6")] - if (*pac::LP_CLKRST::PTR) - .lp_clk_conf() - .read() - .fast_clk_sel() - .bit_is_set() - { - CPU_CLOCK = XTAL_D2_CLK_HZ; - } + #[cfg(feature = "esp32c6")] + if (*pac::LP_CLKRST::PTR) + .lp_clk_conf() + .read() + .fast_clk_sel() + .bit_is_set() + { + CPU_CLOCK = XTAL_D2_CLK_HZ; + } - main(); + main(); + } } #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] -#[link_section = ".init.rust"] -#[no_mangle] +#[unsafe(link_section = ".init.rust")] +#[unsafe(no_mangle)] unsafe extern "C" fn ulp_riscv_rescue_from_monitor() { // Rescue RISC-V core from monitor state. unsafe { &*pac::RTC_CNTL::PTR } @@ -156,8 +158,8 @@ unsafe extern "C" fn ulp_riscv_rescue_from_monitor() { } #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] -#[link_section = ".init.rust"] -#[no_mangle] +#[unsafe(link_section = ".init.rust")] +#[unsafe(no_mangle)] unsafe extern "C" fn ulp_riscv_halt() { unsafe { &*pac::RTC_CNTL::PTR } .cocpu_ctrl() diff --git a/esp-lp-hal/src/uart.rs b/esp-lp-hal/src/uart.rs index db09f0be2..a0eceb9d5 100644 --- a/esp-lp-hal/src/uart.rs +++ b/esp-lp-hal/src/uart.rs @@ -40,8 +40,10 @@ const UART_FIFO_SIZE: u16 = 128; #[doc(hidden)] pub unsafe fn conjure() -> LpUart { - LpUart { - uart: LP_UART::steal(), + unsafe { + LpUart { + uart: LP_UART::steal(), + } } } diff --git a/esp-metadata/CHANGELOG.md b/esp-metadata/CHANGELOG.md index ceb694a77..79a411521 100644 --- a/esp-metadata/CHANGELOG.md +++ b/esp-metadata/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed ### Removed diff --git a/esp-metadata/Cargo.toml b/esp-metadata/Cargo.toml index c6423e750..1ac63abd2 100644 --- a/esp-metadata/Cargo.toml +++ b/esp-metadata/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-metadata" version = "0.6.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Metadata for Espressif devices" documentation = "https://docs.espressif.com/projects/rust/esp-metadata/latest/" repository = "https://github.com/esp-rs/esp-hal" diff --git a/esp-metadata/src/generate_cfg.rs b/esp-metadata/src/generate_cfg.rs index f2927fa63..d52d0c9de 100644 --- a/esp-metadata/src/generate_cfg.rs +++ b/esp-metadata/src/generate_cfg.rs @@ -1,6 +1,6 @@ use std::sync::OnceLock; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use strum::IntoEnumIterator; macro_rules! include_toml { diff --git a/esp-println/CHANGELOG.md b/esp-println/CHANGELOG.md index d2cd06d0c..e4cfe0950 100644 --- a/esp-println/CHANGELOG.md +++ b/esp-println/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed - Manually setting a log level now correctly ignores `ESP_LOG`. (#3240) diff --git a/esp-println/Cargo.toml b/esp-println/Cargo.toml index 31e712289..1de16d2fc 100644 --- a/esp-println/Cargo.toml +++ b/esp-println/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-println" version = "0.13.1" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Provides `print!` and `println!` implementations various Espressif devices" documentation = "https://docs.espressif.com/projects/rust/esp-println/latest/" keywords = ["defmt", "embedded", "esp32", "espressif", "logging"] @@ -16,6 +16,10 @@ cargo-args = ["-Z", "build-std=core"] default-target = "riscv32imc-unknown-none-elf" features = ["esp32c3"] +[lib] +bench = false +test = false + [dependencies] critical-section = { version = "1.2.0", optional = true } defmt = { version = "0.3.10", optional = true } diff --git a/esp-println/build.rs b/esp-println/build.rs index 9836c7b83..e301c9761 100644 --- a/esp-println/build.rs +++ b/esp-println/build.rs @@ -33,7 +33,9 @@ fn main() { } if std::env::var("ESP_LOGLEVEL").is_ok() || std::env::var("ESP_LOGFILTER").is_ok() { - panic!("`ESP_LOGLEVEL` and `ESP_LOGFILTER` is not supported anymore. Please use `ESP_LOG` instead."); + panic!( + "`ESP_LOGLEVEL` and `ESP_LOGFILTER` is not supported anymore. Please use `ESP_LOG` instead." + ); } generate_filter_snippet(); diff --git a/esp-println/src/defmt.rs b/esp-println/src/defmt.rs index 509eacb7e..896abaa11 100644 --- a/esp-println/src/defmt.rs +++ b/esp-println/src/defmt.rs @@ -48,28 +48,30 @@ unsafe impl defmt::Logger for Logger { } unsafe fn release() { - // safety: accessing the `static mut` is OK because we have acquired a critical - // section. - ENCODER.end_frame(do_write); - - Self::flush(); - - #[cfg(feature = "critical-section")] - { - // We don't need to write a custom end-of-frame sequence because: - // - using `defmt`, the rzcobs encoding already includes a terminating zero - // - using `defmt-raw`, we don't add any additional framing data - + unsafe { // safety: accessing the `static mut` is OK because we have acquired a critical // section. - TAKEN = false; + ENCODER.end_frame(do_write); - // safety: accessing the `static mut` is OK because we have acquired a critical - // section. - let restore = CS_RESTORE; + Self::flush(); - // safety: Must be paired with corresponding call to acquire(), see above - critical_section::release(restore); + #[cfg(feature = "critical-section")] + { + // We don't need to write a custom end-of-frame sequence because: + // - using `defmt`, the rzcobs encoding already includes a terminating zero + // - using `defmt-raw`, we don't add any additional framing data + + // safety: accessing the `static mut` is OK because we have acquired a critical + // section. + TAKEN = false; + + // safety: accessing the `static mut` is OK because we have acquired a critical + // section. + let restore = CS_RESTORE; + + // safety: Must be paired with corresponding call to acquire(), see above + critical_section::release(restore); + } } } @@ -83,9 +85,11 @@ unsafe impl defmt::Logger for Logger { } unsafe fn write(bytes: &[u8]) { - // safety: accessing the `static mut` is OK because we have acquired a critical - // section. - ENCODER.write(bytes, do_write); + unsafe { + // safety: accessing the `static mut` is OK because we have acquired a critical + // section. + ENCODER.write(bytes, do_write); + } } } diff --git a/esp-println/src/lib.rs b/esp-println/src/lib.rs index 3e7099e51..32586522f 100644 --- a/esp-println/src/lib.rs +++ b/esp-println/src/lib.rs @@ -10,9 +10,9 @@ pub mod logger; macro_rules! log_format { ($value:expr) => { - #[link_section = concat!(".espressif.metadata")] + #[unsafe(link_section = concat!(".espressif.metadata"))] #[used] - #[export_name = concat!("espflash.LOG_FORMAT")] + #[unsafe(export_name = concat!("espflash.LOG_FORMAT"))] static LOG_FORMAT: [u8; $value.len()] = const { let val_bytes = $value.as_bytes(); let mut val_bytes_array = [0; $value.len()]; @@ -139,9 +139,9 @@ type PrinterImpl = auto_printer::Printer; ))] mod auto_printer { use crate::{ + LockToken, serial_jtag_printer::Printer as PrinterSerialJtag, uart_printer::Printer as PrinterUart, - LockToken, }; pub struct Printer; @@ -508,12 +508,14 @@ struct LockToken<'a>(LockInner<'a>); impl LockToken<'_> { #[allow(unused)] unsafe fn conjure() -> Self { - #[cfg(feature = "critical-section")] - let inner = critical_section::CriticalSection::new(); - #[cfg(not(feature = "critical-section"))] - let inner = PhantomData; + unsafe { + #[cfg(feature = "critical-section")] + let inner = critical_section::CriticalSection::new(); + #[cfg(not(feature = "critical-section"))] + let inner = PhantomData; - LockToken(inner) + LockToken(inner) + } } } diff --git a/esp-riscv-rt/CHANGELOG.md b/esp-riscv-rt/CHANGELOG.md index 0c3a3e98c..277cc8e3b 100644 --- a/esp-riscv-rt/CHANGELOG.md +++ b/esp-riscv-rt/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed ### Removed diff --git a/esp-riscv-rt/Cargo.toml b/esp-riscv-rt/Cargo.toml index 7adfda09e..f99632d3d 100644 --- a/esp-riscv-rt/Cargo.toml +++ b/esp-riscv-rt/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-riscv-rt" version = "0.10.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Minimal runtime / startup for RISC-V CPUs from Espressif" documentation = "https://docs.espressif.com/projects/rust/esp-riscv-rt/latest/" keywords = ["esp32", "espressif", "riscv", "runtime", "startup"] @@ -10,6 +10,10 @@ categories = ["embedded", "hardware-support", "no-std"] repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" +[lib] +bench = false +test = false + [dependencies] document-features = "0.2.11" riscv = "0.12.1" diff --git a/esp-riscv-rt/src/lib.rs b/esp-riscv-rt/src/lib.rs index 5c35b53cc..743f13f43 100644 --- a/esp-riscv-rt/src/lib.rs +++ b/esp-riscv-rt/src/lib.rs @@ -25,11 +25,11 @@ pub use riscv_rt_macros::{entry, pre_init}; pub use self::Interrupt as interrupt; -#[export_name = "error: esp-riscv-rt appears more than once in the dependency graph"] +#[unsafe(export_name = "error: esp-riscv-rt appears more than once in the dependency graph")] #[doc(hidden)] pub static __ONCE__: () = (); -extern "C" { +unsafe extern "C" { // Boundaries of the .bss section static mut _bss_end: u32; static mut _bss_start: u32; @@ -51,23 +51,25 @@ extern "C" { /// /// This function should not be called directly by the user, and should instead /// be invoked by the runtime implicitly. -#[link_section = ".init.rust"] -#[export_name = "_start_rust"] +#[unsafe(link_section = ".init.rust")] +#[unsafe(export_name = "_start_rust")] pub unsafe extern "C" fn start_rust(a0: usize, a1: usize, a2: usize) -> ! { - extern "Rust" { - fn hal_main(a0: usize, a1: usize, a2: usize) -> !; + unsafe { + unsafe extern "Rust" { + fn hal_main(a0: usize, a1: usize, a2: usize) -> !; - fn __post_init(); + fn __post_init(); - fn _setup_interrupts(); + fn _setup_interrupts(); + } + + __post_init(); + + _setup_interrupts(); + + hal_main(a0, a1, a2); } - - __post_init(); - - _setup_interrupts(); - - hal_main(a0, a1, a2); } /// Registers saved in trap handler @@ -170,10 +172,10 @@ pub struct TrapFrame { /// /// This function should not be called directly by the user, and should instead /// be invoked by the runtime implicitly. -#[link_section = ".trap.rust"] -#[export_name = "_start_trap_rust"] +#[unsafe(link_section = ".trap.rust")] +#[unsafe(export_name = "_start_trap_rust")] pub unsafe extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) { - extern "C" { + unsafe extern "C" { fn ExceptionHandler(trap_frame: &TrapFrame); fn DefaultHandler(); } @@ -197,7 +199,7 @@ pub unsafe extern "C" fn start_trap_rust(trap_frame: *const TrapFrame) { } #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[allow(unused_variables, non_snake_case)] pub fn DefaultExceptionHandler(trap_frame: &TrapFrame) -> ! { loop { @@ -208,7 +210,7 @@ pub fn DefaultExceptionHandler(trap_frame: &TrapFrame) -> ! { } #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[allow(unused_variables, non_snake_case)] pub fn DefaultInterruptHandler() { loop { @@ -232,7 +234,7 @@ pub enum Interrupt { MachineExternal, } -extern "C" { +unsafe extern "C" { fn UserSoft(); fn SupervisorSoft(); fn MachineSoft(); @@ -251,7 +253,7 @@ pub union Vector { } #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub static __INTERRUPTS: [Vector; 12] = [ Vector { handler: UserSoft }, Vector { @@ -282,22 +284,22 @@ pub static __INTERRUPTS: [Vector; 12] = [ ]; #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[rustfmt::skip] pub unsafe extern "Rust" fn default_post_init() {} /// Default implementation of `_setup_interrupts` that sets `mtvec`/`stvec` to a /// trap handler address. #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[rustfmt::skip] -pub unsafe extern "Rust" fn default_setup_interrupts() { - extern "C" { +pub unsafe extern "Rust" fn default_setup_interrupts() { unsafe { + unsafe extern "C" { fn _start_trap(); } mtvec::write(_start_trap as usize, TrapMode::Direct); -} +}} /// Parse cfg attributes inside a global_asm call. macro_rules! cfg_global_asm { diff --git a/esp-storage/CHANGELOG.md b/esp-storage/CHANGELOG.md index 7ac1c2c82..bb56779d3 100644 --- a/esp-storage/CHANGELOG.md +++ b/esp-storage/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed ### Removed diff --git a/esp-storage/Cargo.toml b/esp-storage/Cargo.toml index c5dff1491..e038fa7f7 100644 --- a/esp-storage/Cargo.toml +++ b/esp-storage/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-storage" version = "0.5.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Implementation of embedded-storage traits to access unencrypted ESP32 flash" documentation = "https://docs.espressif.com/projects/rust/esp-storage/latest/" keywords = ["embedded-storage", "esp32", "espressif", "no-std"] @@ -14,6 +14,10 @@ license = "MIT OR Apache-2.0" default-target = "riscv32imac-unknown-none-elf" features = ["esp32c6"] +[lib] +bench = false +test = false + [dependencies] embedded-storage = "0.3.1" critical-section = { version = "1.2.0", optional = true } diff --git a/esp-storage/build.rs b/esp-storage/build.rs index 83a0d56af..c7c4a4fbb 100644 --- a/esp-storage/build.rs +++ b/esp-storage/build.rs @@ -8,7 +8,10 @@ fn main() -> Result<(), String> { match std::env::var("OPT_LEVEL") { Ok(level) if std::env::var("CI").is_err() => { if level != "2" && level != "3" { - Err(format!("Building esp-storage for ESP32 needs optimization level 2 or 3 - yours is {}. See https://github.com/esp-rs/esp-storage", level)) + Err(format!( + "Building esp-storage for ESP32 needs optimization level 2 or 3 - yours is {}. See https://github.com/esp-rs/esp-storage", + level + )) } else { Ok(()) } diff --git a/esp-storage/src/common.rs b/esp-storage/src/common.rs index 74feffd6e..999288e88 100644 --- a/esp-storage/src/common.rs +++ b/esp-storage/src/common.rs @@ -112,7 +112,7 @@ impl FlashStorage { #[allow(clippy::all)] #[inline(never)] - #[link_section = ".rwtext"] + #[unsafe(link_section = ".rwtext")] pub(crate) fn internal_read( &mut self, offset: u32, @@ -137,7 +137,7 @@ impl FlashStorage { } #[inline(never)] - #[link_section = ".rwtext"] + #[unsafe(link_section = ".rwtext")] pub(crate) fn internal_erase(&mut self, sector: u32) -> Result<(), FlashStorageError> { self.unlock_once()?; @@ -145,7 +145,7 @@ impl FlashStorage { } #[inline(never)] - #[link_section = ".rwtext"] + #[unsafe(link_section = ".rwtext")] pub(crate) fn internal_write( &mut self, offset: u32, diff --git a/esp-storage/src/esp32.rs b/esp-storage/src/esp32.rs index d17c737cc..e2fb7612f 100644 --- a/esp-storage/src/esp32.rs +++ b/esp-storage/src/esp32.rs @@ -39,7 +39,7 @@ crate::rom_fn! { } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spi_read_status_high( flash_chip: *const EspRomSpiflashChipT, status: &mut u32, @@ -48,26 +48,26 @@ pub(crate) fn spi_read_status_high( } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spi_read_status(flash_chip: *const EspRomSpiflashChipT, status: &mut u32) -> i32 { esp_rom_spi_read_status(flash_chip, status as *mut u32) } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spi_write_status(flash_chip: *const EspRomSpiflashChipT, status_value: u32) -> i32 { esp_rom_spi_write_status(flash_chip, status_value) } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] fn begin() { // on some chips disabling cache access caused issues - we don't really need // it } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] fn end() { esp_rom_cache_flush(0); esp_rom_cache_flush(1); @@ -87,7 +87,7 @@ pub struct EspRomSpiflashChipT { } #[inline(never)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spiflash_read(src_addr: u32, data: *const u32, len: u32) -> i32 { maybe_with_critical_section(|| { spiflash_wait_for_ready(); @@ -96,7 +96,7 @@ pub(crate) fn spiflash_read(src_addr: u32, data: *const u32, len: u32) -> i32 { } #[inline(never)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spiflash_erase_sector(sector_number: u32) -> i32 { maybe_with_critical_section(|| { let res = esp_rom_spiflash_erase_sector(sector_number); @@ -106,7 +106,7 @@ pub(crate) fn spiflash_erase_sector(sector_number: u32) -> i32 { } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] fn spi_write_enable() { spiflash_wait_for_ready(); @@ -116,7 +116,7 @@ fn spi_write_enable() { } #[inline(never)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spiflash_write(dest_addr: u32, data: *const u32, len: u32) -> i32 { maybe_with_critical_section(|| { begin(); @@ -175,13 +175,13 @@ pub(crate) fn spiflash_write(dest_addr: u32, data: *const u32, len: u32) -> i32 } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub fn read_register(address: u32) -> u32 { unsafe { (address as *const u32).read_volatile() } } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub fn write_register(address: u32, value: u32) { unsafe { (address as *mut u32).write_volatile(value); @@ -189,7 +189,7 @@ pub fn write_register(address: u32, value: u32) { } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] fn wait_for_ready() { while (read_register(SPI_EXT2_REG) & SPI_ST) != 0 {} // ESP32_OR_LATER ... we don't support anything earlier @@ -197,7 +197,7 @@ fn wait_for_ready() { } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] fn spiflash_wait_for_ready() { let flashchip = FLASH_CHIP_ADDR as *const EspRomSpiflashChipT; @@ -212,7 +212,7 @@ fn spiflash_wait_for_ready() { } #[inline(never)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spiflash_unlock() -> i32 { let flashchip = FLASH_CHIP_ADDR as *const EspRomSpiflashChipT; if (unsafe { (*flashchip).device_id } >> 16) & 0xff == 0x9D { diff --git a/esp-storage/src/esp32s3.rs b/esp-storage/src/esp32s3.rs index 3dcb777c4..24f96b7a8 100644 --- a/esp-storage/src/esp32s3.rs +++ b/esp-storage/src/esp32s3.rs @@ -8,25 +8,25 @@ crate::rom_fn! { } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spiflash_read(src_addr: u32, data: *const u32, len: u32) -> i32 { maybe_with_critical_section(|| esp_rom_spiflash_read(src_addr, data, len)) } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spiflash_unlock() -> i32 { maybe_with_critical_section(esp_rom_spiflash_unlock) } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spiflash_erase_sector(sector_number: u32) -> i32 { maybe_with_critical_section(|| esp_rom_spiflash_erase_sector(sector_number)) } #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] pub(crate) fn spiflash_write(dest_addr: u32, data: *const u32, len: u32) -> i32 { maybe_with_critical_section(|| esp_rom_spiflash_write(dest_addr, data, len)) } diff --git a/esp-storage/src/lib.rs b/esp-storage/src/lib.rs index 1a18ed1f2..e699979a9 100644 --- a/esp-storage/src/lib.rs +++ b/esp-storage/src/lib.rs @@ -45,7 +45,7 @@ pub mod ll; #[cfg(not(feature = "emulation"))] #[inline(always)] -#[link_section = ".rwtext"] +#[unsafe(link_section = ".rwtext")] fn maybe_with_critical_section(f: impl FnOnce() -> R) -> R { #[cfg(feature = "critical-section")] return critical_section::with(|_| f()); @@ -66,7 +66,7 @@ macro_rules! rom_fn { $(#[$attrs])* #[allow(unused)] #[inline(always)] - #[link_section = ".rwtext"] + #[unsafe(link_section = ".rwtext")] fn $name($($arg:$ty),*) $(-> $retval)? { unsafe { let rom_fn: unsafe extern "C" fn($($arg: $ty),*) $(-> $retval)? = diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index 00e808cc8..c3e00bf62 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove the `heapless` dependency (including from the public API) (#3317) +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed - Update bt-hci version to fix serialization/deserialization of byte slices (#3340) diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 9522458b4..d34e6a86c 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "esp-wifi" version = "0.13.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "A WiFi, Bluetooth and ESP-NOW driver for use with Espressif chips and bare-metal Rust" documentation = "https://docs.espressif.com/projects/rust/esp-wifi/latest/" keywords = ["wifi", "bluetooth", "esp-now", "esp32", "no-std"] @@ -10,6 +10,10 @@ categories = ["embedded", "hardware-support", "no-std"] repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" +[lib] +bench = false +test = false + [dependencies] allocator-api2 = { version = "0.2.0", default-features = false, features = ["alloc"] } defmt = { version = "0.3.10", optional = true } diff --git a/esp-wifi/build.rs b/esp-wifi/build.rs index e375293a0..ae3a14e33 100644 --- a/esp-wifi/build.rs +++ b/esp-wifi/build.rs @@ -1,7 +1,7 @@ use std::{error::Error, str::FromStr}; use esp_build::assert_unique_used_features; -use esp_config::{generate_config, ConfigOption, Stability, Validator, Value}; +use esp_config::{ConfigOption, Stability, Validator, Value, generate_config}; use esp_metadata::{Chip, Config}; fn main() -> Result<(), Box> { diff --git a/esp-wifi/src/ble/btdm.rs b/esp-wifi/src/ble/btdm.rs index 3bcf5b803..ac347dddb 100644 --- a/esp-wifi/src/ble/btdm.rs +++ b/esp-wifi/src/ble/btdm.rs @@ -8,11 +8,11 @@ use super::ReceivedPacket; use crate::{ binary::include::*, ble::{ - btdm::ble_os_adapter_chip_specific::{osi_funcs_s, G_OSI_FUNCS}, - HciOutCollector, HCI_OUT_COLLECTOR, + HciOutCollector, + btdm::ble_os_adapter_chip_specific::{G_OSI_FUNCS, osi_funcs_s}, }, - compat::common::{self, str_from_c, ConcurrentQueue}, + compat::common::{self, ConcurrentQueue, str_from_c}, hal::ram, }; @@ -34,7 +34,7 @@ struct VhciHostCallbacks { notify_host_recv: extern "C" fn(*mut u8, u16) -> i32, } -extern "C" { +unsafe extern "C" { fn btdm_osi_funcs_register(osi_funcs: *const osi_funcs_s) -> i32; fn btdm_controller_get_compile_version() -> *const c_char; @@ -94,24 +94,28 @@ static mut INTERRUPT_DISABLE_CNT: usize = 0; #[ram] unsafe extern "C" fn interrupt_enable() { - INTERRUPT_DISABLE_CNT -= 1; - let flags = G_INTER_FLAGS[INTERRUPT_DISABLE_CNT]; - trace!("interrupt_enable {}", flags); - critical_section::release(core::mem::transmute::< - InterruptsFlagType, - critical_section::RestoreState, - >(flags)); + unsafe { + INTERRUPT_DISABLE_CNT -= 1; + let flags = G_INTER_FLAGS[INTERRUPT_DISABLE_CNT]; + trace!("interrupt_enable {}", flags); + critical_section::release(core::mem::transmute::< + InterruptsFlagType, + critical_section::RestoreState, + >(flags)); + } } #[ram] unsafe extern "C" fn interrupt_disable() { trace!("interrupt_disable"); - let flags = core::mem::transmute::( - critical_section::acquire(), - ); - G_INTER_FLAGS[INTERRUPT_DISABLE_CNT] = flags; - INTERRUPT_DISABLE_CNT += 1; - trace!("interrupt_disable {}", flags); + unsafe { + let flags = core::mem::transmute::( + critical_section::acquire(), + ); + G_INTER_FLAGS[INTERRUPT_DISABLE_CNT] = flags; + INTERRUPT_DISABLE_CNT += 1; + trace!("interrupt_disable {}", flags); + } } #[ram] @@ -124,19 +128,26 @@ unsafe extern "C" fn task_yield_from_isr() { } unsafe extern "C" fn semphr_create(max: u32, init: u32) -> *const () { - crate::common_adapter::semphr_create(max, init) as *const () + unsafe { crate::common_adapter::semphr_create(max, init) as *const () } } unsafe extern "C" fn semphr_delete(sem: *const ()) { - crate::common_adapter::semphr_delete(sem as *mut crate::binary::c_types::c_void); + unsafe { + crate::common_adapter::semphr_delete(sem as *mut crate::binary::c_types::c_void); + } } unsafe extern "C" fn semphr_take(sem: *const (), block_time_ms: u32) -> i32 { - crate::common_adapter::semphr_take(sem as *mut crate::binary::c_types::c_void, block_time_ms) + unsafe { + crate::common_adapter::semphr_take( + sem as *mut crate::binary::c_types::c_void, + block_time_ms, + ) + } } unsafe extern "C" fn semphr_give(sem: *const ()) -> i32 { - crate::common_adapter::semphr_give(sem as *mut crate::binary::c_types::c_void) + unsafe { crate::common_adapter::semphr_give(sem as *mut crate::binary::c_types::c_void) } } unsafe extern "C" fn mutex_create() -> *const () { @@ -181,8 +192,10 @@ unsafe extern "C" fn queue_send_from_isr( ) -> i32 { trace!("queue_send_from_isr {:?} {:?} {:?}", _queue, _item, _hptw); // Force to set the value to be false - *(_hptw as *mut bool) = false; - queue_send(_queue, _item, 0) + unsafe { + *(_hptw as *mut bool) = false; + } + unsafe { queue_send(_queue, _item, 0) } } unsafe extern "C" fn queue_recv(queue: *const (), item: *const (), block_time_ms: u32) -> i32 { @@ -211,26 +224,23 @@ unsafe extern "C" fn task_create( handle: *mut crate::binary::c_types::c_void, core_id: u32, ) -> i32 { - let n = str_from_c(name); - trace!( - "task_create {:?} {:?} {} {} {:?} {} {:?} {}", - func, - name, - n, - stack_depth, - param, - prio, - handle, - core_id - ); + unsafe { + let n = str_from_c(name); + trace!( + "task_create {:?} {:?} {} {} {:?} {} {:?} {}", + func, name, n, stack_depth, param, prio, handle, core_id + ); + } - let task_func = core::mem::transmute::< - *mut crate::binary::c_types::c_void, - extern "C" fn(*mut esp_wifi_sys::c_types::c_void), - >(func); + unsafe { + let task_func = core::mem::transmute::< + *mut crate::binary::c_types::c_void, + extern "C" fn(*mut esp_wifi_sys::c_types::c_void), + >(func); - let task = crate::preempt::task_create(task_func, param, stack_depth as usize); - *(handle as *mut usize) = task as usize; + let task = crate::preempt::task_create(task_func, param, stack_depth as usize); + *(handle as *mut usize) = task as usize; + } 1 } @@ -260,7 +270,7 @@ unsafe extern "C" fn cause_sw_intr_to_core(_core: i32, _intr_no: i32) -> i32 { { trace!("cause_sw_intr_to_core {} {}", _core, _intr_no); let intr = 1 << _intr_no; - core::arch::asm!("wsr.intset {0}", in(reg) intr, options(nostack)); + unsafe { core::arch::asm!("wsr.intset {0}", in(reg) intr, options(nostack)) }; 0 } } @@ -275,7 +285,7 @@ unsafe extern "C" fn srand(seed: u32) { #[ram] unsafe extern "C" fn rand() -> i32 { trace!("rand"); - crate::common_adapter::random() as i32 + unsafe { crate::common_adapter::random() as i32 } } #[ram] @@ -324,23 +334,27 @@ unsafe extern "C" fn btdm_sleep_exit_phase3() { unsafe extern "C" fn coex_schm_status_bit_set(_typ: i32, status: i32) { trace!("coex_schm_status_bit_set {} {}", _typ, status); #[cfg(coex)] - crate::binary::include::coex_schm_status_bit_set(_typ as u32, status as u32); + unsafe { + crate::binary::include::coex_schm_status_bit_set(_typ as u32, status as u32) + }; } unsafe extern "C" fn coex_schm_status_bit_clear(_typ: i32, status: i32) { trace!("coex_schm_status_bit_clear {} {}", _typ, status); #[cfg(coex)] - crate::binary::include::coex_schm_status_bit_clear(_typ as u32, status as u32); + unsafe { + crate::binary::include::coex_schm_status_bit_clear(_typ as u32, status as u32) + }; } #[ram] unsafe extern "C" fn read_efuse_mac(mac: *const ()) -> i32 { - crate::common_adapter::read_mac(mac as *mut _, 2) + unsafe { crate::common_adapter::read_mac(mac as *mut _, 2) } } #[cfg(esp32)] unsafe extern "C" fn set_isr13(n: i32, handler: unsafe extern "C" fn(), arg: *const ()) -> i32 { - ble_os_adapter_chip_specific::set_isr(n, handler, arg) + unsafe { ble_os_adapter_chip_specific::set_isr(n, handler, arg) } } #[cfg(esp32)] @@ -424,7 +438,7 @@ pub(crate) fn ble_init() { #[cfg(esp32)] { - extern "C" { + unsafe extern "C" { fn btdm_rf_bb_init_phase2(); } @@ -443,7 +457,7 @@ pub(crate) fn ble_init() { } pub(crate) fn ble_deinit() { - extern "C" { + unsafe extern "C" { fn btdm_controller_deinit(); } diff --git a/esp-wifi/src/ble/controller/mod.rs b/esp-wifi/src/ble/controller/mod.rs index 832711bc6..a957a2710 100644 --- a/esp-wifi/src/ble/controller/mod.rs +++ b/esp-wifi/src/ble/controller/mod.rs @@ -79,11 +79,11 @@ pub(crate) mod asynch { use core::task::Poll; use bt_hci::{ - transport::{Transport, WithIndicator}, ControllerToHostPacket, FromHciBytes, HostToControllerPacket, WriteHci, + transport::{Transport, WithIndicator}, }; use esp_hal::asynch::AtomicWaker; @@ -156,7 +156,7 @@ pub(crate) mod asynch { Ok(p) => Ok(Some(p)), Err(e) => { if e == bt_hci::FromHciBytesError::InvalidSize { - use bt_hci::{event::EventPacketHeader, PacketKind}; + use bt_hci::{PacketKind, event::EventPacketHeader}; // Some controllers emit a suprious command complete event at startup. let (kind, data) = diff --git a/esp-wifi/src/ble/mod.rs b/esp-wifi/src/ble/mod.rs index 1c6584f3c..5caa60ad2 100644 --- a/esp-wifi/src/ble/mod.rs +++ b/esp-wifi/src/ble/mod.rs @@ -20,16 +20,16 @@ use self::npl as ble; pub mod controller; pub(crate) unsafe extern "C" fn malloc(size: u32) -> *mut crate::binary::c_types::c_void { - crate::compat::malloc::malloc(size as usize).cast() + unsafe { crate::compat::malloc::malloc(size as usize).cast() } } #[cfg(any(esp32, esp32c3, esp32s3))] pub(crate) unsafe extern "C" fn malloc_internal(size: u32) -> *mut crate::binary::c_types::c_void { - crate::compat::malloc::malloc(size as usize).cast() + unsafe { crate::compat::malloc::malloc(size as usize).cast() } } pub(crate) unsafe extern "C" fn free(ptr: *mut crate::binary::c_types::c_void) { - crate::compat::malloc::free(ptr.cast()) + unsafe { crate::compat::malloc::free(ptr.cast()) } } // Stores received packets until the the BLE stack dequeues them diff --git a/esp-wifi/src/ble/npl.rs b/esp-wifi/src/ble/npl.rs index 90451575b..0079bd857 100644 --- a/esp-wifi/src/ble/npl.rs +++ b/esp-wifi/src/ble/npl.rs @@ -13,7 +13,7 @@ use crate::{ }, compat::{ self, - common::{str_from_c, ConcurrentQueue}, + common::{ConcurrentQueue, str_from_c}, }, preempt::yield_task, }; @@ -171,7 +171,7 @@ pub(crate) static mut OS_MSYS_INIT_2_MBUF_POOL: OsMbufPool = OsMbufPool::zeroed( #[cfg(esp32c2)] pub(crate) static mut OS_MSYS_INIT_2_MEMPOOL: OsMempool = OsMempool::zeroed(); -extern "C" { +unsafe extern "C" { // Sends ACL data from host to controller. // // om The ACL data packet to send. @@ -372,7 +372,7 @@ unsafe extern "C" fn ecc_gen_key_pair(_: *const u8, _: *const u8) -> i32 { unsafe extern "C" fn os_random() -> u32 { trace!("os_random"); - (crate::common_adapter::random() & u32::MAX) as u32 + unsafe { (crate::common_adapter::random() & u32::MAX) as u32 } } unsafe extern "C" fn task_create( @@ -384,27 +384,28 @@ unsafe extern "C" fn task_create( task_handle: *const c_void, core_id: u32, ) -> i32 { - let name_str = str_from_c(name); - trace!( - "task_create {:?} {} {} {:?} {} {:?} {}", - task_func, - name_str, - stack_depth, - param, - prio, - task_handle, - core_id, - ); + unsafe { + let name_str = str_from_c(name); - *(task_handle as *mut usize) = 0; // we will run it in task 0 + trace!( + "task_create {:?} {} {} {:?} {} {:?} {}", + task_func, name_str, stack_depth, param, prio, task_handle, core_id, + ); + }; - let task_func = core::mem::transmute::< - *mut crate::binary::c_types::c_void, - extern "C" fn(*mut esp_wifi_sys::c_types::c_void), - >(task_func); + unsafe { + *(task_handle as *mut usize) = 0; + } // we will run it in task 0 - let task = crate::preempt::task_create(task_func, param, stack_depth as usize); - *(task_handle as *mut usize) = task as usize; + unsafe { + let task_func = core::mem::transmute::< + *mut crate::binary::c_types::c_void, + extern "C" fn(*mut esp_wifi_sys::c_types::c_void), + >(task_func); + + let task = crate::preempt::task_create(task_func, param, stack_depth as usize); + *(task_handle as *mut usize) = task as usize; + } 1 } @@ -421,8 +422,10 @@ unsafe extern "C" fn task_delete(task: *const c_void) { } unsafe extern "C" fn osi_assert(ln: u32, fn_name: *const c_void, param1: u32, param2: u32) { - let name_str = str_from_c(fn_name as _); - panic!("ASSERT {}:{} {} {}", name_str, ln, param1, param2); + unsafe { + let name_str = str_from_c(fn_name as _); + panic!("ASSERT {}:{} {} {}", name_str, ln, param1, param2); + } } unsafe extern "C" fn esp_intr_free(_ret_handle: *mut *mut c_void) -> i32 { @@ -617,14 +620,18 @@ unsafe extern "C" fn ble_npl_get_time_forever() -> u32 { unsafe extern "C" fn ble_npl_hw_exit_critical(mask: u32) { trace!("ble_npl_hw_exit_critical {}", mask); - critical_section::release(core::mem::transmute::( - mask, - )); + unsafe { + critical_section::release(core::mem::transmute::( + mask, + )); + } } unsafe extern "C" fn ble_npl_hw_enter_critical() -> u32 { trace!("ble_npl_hw_enter_critical"); - core::mem::transmute::(critical_section::acquire()) + unsafe { + core::mem::transmute::(critical_section::acquire()) + } } unsafe extern "C" fn ble_npl_hw_set_isr(_no: i32, _mask: u32) { @@ -689,25 +696,28 @@ unsafe extern "C" fn ble_npl_callout_is_active(_callout: *const ble_npl_callout) unsafe extern "C" fn ble_npl_callout_mem_reset(callout: *const ble_npl_callout) { trace!("ble_npl_callout_mem_reset"); - - ble_npl_callout_stop(callout); + unsafe { + ble_npl_callout_stop(callout); + } } unsafe extern "C" fn ble_npl_callout_deinit(callout: *const ble_npl_callout) { trace!("ble_npl_callout_deinit"); - - ble_npl_callout_stop(callout); + unsafe { + ble_npl_callout_stop(callout); + } } unsafe extern "C" fn ble_npl_callout_stop(callout: *const ble_npl_callout) { trace!("ble_npl_callout_stop {:?}", callout); - assert!((*callout).dummy != 0); + assert!(unsafe { (*callout).dummy != 0 }); - let co = (*callout).dummy as *mut Callout; - - // stop timer - compat::timer_compat::compat_timer_disarm(addr_of_mut!((*co).timer_handle)); + unsafe { + let co = (*callout).dummy as *mut Callout; + // stop timer + compat::timer_compat::compat_timer_disarm(addr_of_mut!((*co).timer_handle)); + } } unsafe extern "C" fn ble_npl_callout_reset( @@ -716,11 +726,11 @@ unsafe extern "C" fn ble_npl_callout_reset( ) -> ble_npl_error_t { trace!("ble_npl_callout_reset {:?} {}", callout, time); - let co = (*callout).dummy as *mut Callout; - - // start timer - compat::timer_compat::compat_timer_arm(addr_of_mut!((*co).timer_handle), time, false); - + let co = unsafe { (*callout).dummy } as *mut Callout; + unsafe { + // start timer + compat::timer_compat::compat_timer_arm(addr_of_mut!((*co).timer_handle), time, false); + } 0 } @@ -765,52 +775,61 @@ unsafe extern "C" fn ble_npl_mutex_deinit(_mutex: *const ble_npl_mutex) -> ble_n unsafe extern "C" fn ble_npl_event_set_arg(event: *const ble_npl_event, arg: *const c_void) { trace!("ble_npl_event_set_arg {:?} {:?}", event, arg); - let evt = (*event).dummy as *mut Event; + let evt = unsafe { (*event).dummy } as *mut Event; assert!(!evt.is_null()); - (*evt).ev_arg_ptr = arg; + unsafe { + (*evt).ev_arg_ptr = arg; + } } unsafe extern "C" fn ble_npl_event_get_arg(event: *const ble_npl_event) -> *const c_void { trace!("ble_npl_event_get_arg {:?}", event); - let evt = (*event).dummy as *mut Event; - assert!(!evt.is_null()); + unsafe { + let evt = (*event).dummy as *mut Event; + assert!(!evt.is_null()); - let arg_ptr = (*evt).ev_arg_ptr; + let arg_ptr = (*evt).ev_arg_ptr; - trace!("returning arg {:x}", arg_ptr as usize); + trace!("returning arg {:x}", arg_ptr as usize); - arg_ptr + arg_ptr + } } unsafe extern "C" fn ble_npl_event_is_queued(event: *const ble_npl_event) -> bool { trace!("ble_npl_event_is_queued {:?}", event); - let evt = (*event).dummy as *mut Event; + let evt = unsafe { (*event).dummy } as *mut Event; assert!(!evt.is_null()); - (*evt).queued + unsafe { (*evt).queued } } unsafe extern "C" fn ble_npl_event_reset(event: *const ble_npl_event) { trace!("ble_npl_event_reset {:?}", event); - let evt = (*event).dummy as *mut Event; + let evt = unsafe { (*event).dummy } as *mut Event; assert!(!evt.is_null()); - (*evt).queued = false + unsafe { (*evt).queued = false } } unsafe extern "C" fn ble_npl_event_deinit(event: *const ble_npl_event) { trace!("ble_npl_event_deinit {:?}", event); let event = event as *mut ble_npl_event; - let evt = (*event).dummy as *mut Event; + let evt = unsafe { (*event).dummy } as *mut Event; assert!(!evt.is_null()); - crate::compat::malloc::free(evt.cast()); - (*event).dummy = 0; + unsafe { + crate::compat::malloc::free(evt.cast()); + } + + unsafe { + (*event).dummy = 0; + } } unsafe extern "C" fn ble_npl_event_init( @@ -820,35 +839,43 @@ unsafe extern "C" fn ble_npl_event_init( ) { trace!("ble_npl_event_init {:?} {:?} {:?}", event, func, arg); - if (*event).dummy == 0 { - let evt = crate::compat::malloc::calloc(1, core::mem::size_of::()) as *mut Event; + if unsafe { (*event).dummy } == 0 { + unsafe { + let evt = crate::compat::malloc::calloc(1, core::mem::size_of::()) as *mut Event; - (*evt).event_fn_ptr = func; - (*evt).ev_arg_ptr = arg; - (*evt).queued = false; + (*evt).event_fn_ptr = func; + (*evt).ev_arg_ptr = arg; + (*evt).queued = false; - let event = event.cast_mut(); - (*event).dummy = evt as i32; + let event = event.cast_mut(); + (*event).dummy = evt as i32; + } } } unsafe extern "C" fn ble_npl_eventq_is_empty(queue: *const ble_npl_eventq) -> bool { trace!("ble_npl_eventq_is_empty {:?}", queue); - let queue = (*queue).dummy as *mut ConcurrentQueue; + let queue = unsafe { (*queue).dummy } as *mut ConcurrentQueue; assert!(!queue.is_null()); - (*queue).count() == 0 + unsafe { (*queue).count() == 0 } } unsafe extern "C" fn ble_npl_event_run(event: *const ble_npl_event) { trace!("ble_npl_event_run {:?}", event); - let evt = (*event).dummy as *mut Event; + let evt = unsafe { (*event).dummy } as *mut Event; assert!(!evt.is_null()); - trace!("info {:?} with arg {:x}", (*evt).event_fn_ptr, event as u32); - let func: unsafe extern "C" fn(u32) = core::mem::transmute((*evt).event_fn_ptr); - func(event as u32); + trace!( + "info {:?} with arg {:x}", + unsafe { (*evt).event_fn_ptr }, + event as u32 + ); + unsafe { + let func: unsafe extern "C" fn(u32) = core::mem::transmute((*evt).event_fn_ptr); + func(event as u32); + } trace!("ble_npl_event_run done"); } @@ -858,34 +885,38 @@ unsafe extern "C" fn ble_npl_eventq_remove( event: *const ble_npl_event, ) { trace!("ble_npl_eventq_remove {:?} {:?}", queue, event); + unsafe { + assert!((*queue).dummy != 0); + let evt = (*event).dummy as *mut Event; + assert!(!evt.is_null()); - assert!((*queue).dummy != 0); - let evt = (*event).dummy as *mut Event; - assert!(!evt.is_null()); + if !(*evt).queued { + return; + } - if !(*evt).queued { - return; + let queue = (*queue).dummy as *mut ConcurrentQueue; + (*queue).remove(addr_of!(event) as *mut _); + (*evt).queued = false; } - - let queue = (*queue).dummy as *mut ConcurrentQueue; - (*queue).remove(addr_of!(event) as *mut _); - - (*evt).queued = false; } unsafe extern "C" fn ble_npl_eventq_put(queue: *const ble_npl_eventq, event: *const ble_npl_event) { trace!("ble_npl_eventq_put {:?} {:?}", queue, event); - assert!((*queue).dummy != 0); + assert!(unsafe { (*queue).dummy } != 0); - let evt = (*event).dummy as *mut Event; + let evt = unsafe { (*event).dummy } as *mut Event; assert!(!evt.is_null()); - (*evt).queued = true; + unsafe { + (*evt).queued = true; + } - let queue = (*queue).dummy as *mut ConcurrentQueue; + let queue = unsafe { (*queue).dummy } as *mut ConcurrentQueue; let mut event = event as usize; - (*queue).enqueue(addr_of_mut!(event).cast()); + unsafe { + (*queue).enqueue(addr_of_mut!(event).cast()); + } } unsafe extern "C" fn ble_npl_eventq_get( @@ -894,17 +925,19 @@ unsafe extern "C" fn ble_npl_eventq_get( ) -> *const ble_npl_event { trace!("ble_npl_eventq_get {:?} {}", queue, time); - let queue = (*queue).dummy as *mut ConcurrentQueue; + let queue = unsafe { (*queue).dummy } as *mut ConcurrentQueue; let mut event: usize = 0; if time == TIME_FOREVER { loop { - if (*queue).try_dequeue(addr_of_mut!(event).cast()) { + if unsafe { (*queue).try_dequeue(addr_of_mut!(event).cast()) } { let event = event as *mut ble_npl_event; - let evt = (*event).dummy as *mut Event; - if (*evt).queued { + let evt = unsafe { (*event).dummy } as *mut Event; + if unsafe { (*evt).queued } { trace!("got {:x}", evt as usize); - (*evt).queued = false; + unsafe { + (*evt).queued = false; + } return event as *const ble_npl_event; } } @@ -920,13 +953,15 @@ unsafe extern "C" fn ble_npl_eventq_deinit(queue: *const ble_npl_eventq) { trace!("ble_npl_eventq_deinit {:?}", queue); let queue = queue.cast_mut(); - assert!((*queue).dummy != 0); + assert!(unsafe { (*queue).dummy } != 0); - let real_queue = (*queue).dummy as *mut ConcurrentQueue; + let real_queue = unsafe { (*queue).dummy } as *mut ConcurrentQueue; unsafe { core::ptr::drop_in_place(real_queue); } - (*queue).dummy = 0; + unsafe { + (*queue).dummy = 0; + } } unsafe extern "C" fn ble_npl_callout_init( @@ -937,25 +972,24 @@ unsafe extern "C" fn ble_npl_callout_init( ) -> i32 { trace!( "ble_npl_callout_init {:?} {:?} {:?} {:?}", - callout, - eventq, - func, - args + callout, eventq, func, args ); - if (*callout).dummy == 0 { + if unsafe { (*callout).dummy } == 0 { let callout = callout.cast_mut(); - let new_callout = - crate::compat::malloc::calloc(1, core::mem::size_of::()) as *mut Callout; - ble_npl_event_init(addr_of_mut!((*new_callout).events), func, args); - (*callout).dummy = new_callout as i32; + unsafe { + let new_callout = + crate::compat::malloc::calloc(1, core::mem::size_of::()) as *mut Callout; + ble_npl_event_init(addr_of_mut!((*new_callout).events), func, args); + (*callout).dummy = new_callout as i32; - crate::compat::timer_compat::compat_timer_setfn( - addr_of_mut!((*new_callout).timer_handle), - callout_timer_callback_wrapper, - callout as *mut c_void, - ); + crate::compat::timer_compat::compat_timer_setfn( + addr_of_mut!((*new_callout).timer_handle), + callout_timer_callback_wrapper, + callout as *mut c_void, + ); + } } 0 @@ -963,12 +997,14 @@ unsafe extern "C" fn ble_npl_callout_init( unsafe extern "C" fn callout_timer_callback_wrapper(arg: *mut c_void) { trace!("callout_timer_callback_wrapper {:?}", arg); - let co = (*(arg as *mut ble_npl_callout)).dummy as *mut Callout; + let co = unsafe { (*(arg as *mut ble_npl_callout)).dummy } as *mut Callout; - if !(*co).eventq.is_null() { - ble_npl_eventq_put(addr_of!((*co).eventq).cast(), addr_of!((*co).events)); - } else { - ble_npl_event_run(addr_of!((*co).events)); + unsafe { + if !(*co).eventq.is_null() { + ble_npl_eventq_put(addr_of!((*co).eventq).cast(), addr_of!((*co).events)); + } else { + ble_npl_event_run(addr_of!((*co).events)); + } } } @@ -979,12 +1015,14 @@ unsafe extern "C" fn ble_npl_eventq_init(queue: *const ble_npl_eventq) { let raw_queue = ConcurrentQueue::new(EVENT_QUEUE_SIZE, 4); let ptr = - unsafe { crate::compat::malloc::malloc(size_of_val(&raw_queue)) as *mut ConcurrentQueue }; + unsafe { crate::compat::malloc::malloc(size_of_val(&raw_queue)) } as *mut ConcurrentQueue; unsafe { ptr.write(raw_queue); } - (*queue).dummy = ptr as i32; + unsafe { + (*queue).dummy = ptr as i32; + } } unsafe extern "C" fn ble_npl_mutex_init(_mutex: *const ble_npl_mutex) -> u32 { @@ -1036,7 +1074,7 @@ pub(crate) fn ble_init() { #[cfg(esp32c2)] { debug!("Init esp_ble_rom_func_ptr_init_all"); - extern "C" { + unsafe extern "C" { fn esp_ble_rom_func_ptr_init_all() -> i32; } let res = esp_ble_rom_func_ptr_init_all(); @@ -1110,7 +1148,7 @@ pub(crate) fn ble_init() { #[cfg(not(esp32c2))] { - extern "C" { + unsafe extern "C" { fn esp_ble_register_bb_funcs() -> i32; } let res = esp_ble_register_bb_funcs(); @@ -1129,7 +1167,7 @@ pub(crate) fn ble_init() { } #[cfg(not(esp32c2))] { - extern "C" { + unsafe extern "C" { fn r_esp_ble_msys_init( msys_size1: u16, msys_size2: u16, @@ -1157,7 +1195,7 @@ pub(crate) fn ble_init() { #[cfg(not(esp32c2))] r_esp_ble_ll_set_public_addr(&mac as *const u8); - extern "C" { + unsafe extern "C" { fn r_ble_hci_trans_init(m: u8); } r_ble_hci_trans_init(0); @@ -1275,12 +1313,12 @@ fn os_msys_init() { unsafe extern "C" fn ble_hs_hci_rx_evt(cmd: *const u8, arg: *const c_void) -> i32 { trace!("ble_hs_hci_rx_evt {:?} {:?}", cmd, arg); - trace!("$ cmd = {:x}", *cmd); - trace!("$ len = {:x}", *(cmd.offset(1))); + trace!("$ cmd = {:x}", unsafe { *cmd }); + trace!("$ len = {:x}", unsafe { *(cmd.offset(1)) }); - let event = *cmd; - let len = *(cmd.offset(1)) as usize; - let payload = core::slice::from_raw_parts(cmd.offset(2), len); + let event = unsafe { *cmd }; + let len = unsafe { *(cmd.offset(1)) } as usize; + let payload = unsafe { core::slice::from_raw_parts(cmd.offset(2), len) }; trace!("$ pld = {:?}", payload); critical_section::with(|cs| { @@ -1299,7 +1337,9 @@ unsafe extern "C" fn ble_hs_hci_rx_evt(cmd: *const u8, arg: *const c_void) -> i3 dump_packet_info(&data[..(len + 3)]); }); - r_ble_hci_trans_buf_free(cmd); + unsafe { + r_ble_hci_trans_buf_free(cmd); + } crate::ble::controller::asynch::hci_read_data_available(); @@ -1309,9 +1349,9 @@ unsafe extern "C" fn ble_hs_hci_rx_evt(cmd: *const u8, arg: *const c_void) -> i3 unsafe extern "C" fn ble_hs_rx_data(om: *const OsMbuf, arg: *const c_void) -> i32 { trace!("ble_hs_rx_data {:?} {:?}", om, arg); - let data_ptr = (*om).om_data; - let len = (*om).om_len; - let data_slice = core::slice::from_raw_parts(data_ptr, len as usize); + let data_ptr = unsafe { (*om).om_data }; + let len = unsafe { (*om).om_len }; + let data_slice = unsafe { core::slice::from_raw_parts(data_ptr, len as usize) }; critical_section::with(|cs| { let mut queue = super::BT_RECEIVE_QUEUE.borrow_ref_mut(cs); @@ -1327,7 +1367,9 @@ unsafe extern "C" fn ble_hs_rx_data(om: *const OsMbuf, arg: *const c_void) -> i3 super::dump_packet_info(&data[..(len + 1) as usize]); }); - r_os_mbuf_free_chain(om as *mut _); + unsafe { + r_os_mbuf_free_chain(om as *mut _); + } crate::ble::controller::asynch::hci_read_data_available(); diff --git a/esp-wifi/src/ble/os_adapter_esp32.rs b/esp-wifi/src/ble/os_adapter_esp32.rs index a8adc7e0b..cef02e4c4 100644 --- a/esp-wifi/src/ble/os_adapter_esp32.rs +++ b/esp-wifi/src/ble/os_adapter_esp32.rs @@ -189,7 +189,7 @@ pub(super) static G_OSI_FUNCS: osi_funcs_s = osi_funcs_s { extern "C" fn patch_apply() { trace!("patch apply"); - extern "C" { + unsafe extern "C" { fn config_ble_funcs_reset(); fn config_btdm_funcs_reset(); } @@ -202,11 +202,11 @@ extern "C" fn patch_apply() { extern "C" fn coex_version_get_wrapper(major: *mut u32, minor: *mut u32, patch: *mut u32) -> i32 { unsafe { - let coex_version = unwrap!(core::ffi::CStr::from_ptr( - crate::binary::include::coex_version_get() - ) - .to_str() - .ok()); + let coex_version = unwrap!( + core::ffi::CStr::from_ptr(crate::binary::include::coex_version_get()) + .to_str() + .ok() + ); info!("COEX Version {}", coex_version); // we should parse it ... for now just hardcoded major.write_volatile(1); @@ -239,7 +239,7 @@ const SOC_MEM_BT_MISC_START: u32 = 0x3ffbdb28; const SOC_MEM_BT_MISC_END: u32 = 0x3ffbdb5c; const SOC_MEM_BT_EM_BREDR_REAL_END: u32 = 0x3ffb6388; // (SOC_MEM_BT_EM_BREDR_NO_SYNC_END + CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF - // * SOC_MEM_BT_EM_PER_SYNC_SIZE); +// * SOC_MEM_BT_EM_PER_SYNC_SIZE); static BTDM_DRAM_AVAILABLE_REGION: [btdm_dram_available_region_t; 7] = [ // following is .data @@ -313,7 +313,7 @@ pub(crate) fn create_ble_config() -> esp_bt_controller_config_t { } pub(crate) fn btdm_controller_mem_init() { - extern "C" { + unsafe extern "C" { static mut _data_start_btdm: u32; static mut _data_end_btdm: u32; static _data_start_btdm_rom: u32; @@ -367,7 +367,7 @@ pub(crate) fn bt_periph_module_enable() { } pub(crate) fn disable_sleep_mode() { - extern "C" { + unsafe extern "C" { fn btdm_controller_set_sleep_mode(mode: u8); } @@ -397,13 +397,13 @@ pub(crate) unsafe extern "C" fn coex_bt_wakeup_request_end() { #[allow(unused_variables)] pub(crate) unsafe extern "C" fn coex_bt_request(event: u32, latency: u32, duration: u32) -> i32 { trace!("coex_bt_request"); - extern "C" { + unsafe extern "C" { #[cfg(coex)] fn coex_bt_request(event: u32, latency: u32, duration: u32) -> i32; } #[cfg(coex)] - return coex_bt_request(event, latency, duration); + return unsafe { coex_bt_request(event, latency, duration) }; #[cfg(not(coex))] 0 @@ -412,13 +412,13 @@ pub(crate) unsafe extern "C" fn coex_bt_request(event: u32, latency: u32, durati #[allow(unused_variables)] pub(crate) unsafe extern "C" fn coex_bt_release(event: u32) -> i32 { trace!("coex_bt_release"); - extern "C" { + unsafe extern "C" { #[cfg(coex)] fn coex_bt_release(event: u32) -> i32; } #[cfg(coex)] - return coex_bt_release(event); + return unsafe { coex_bt_release(event) }; #[cfg(not(coex))] 0 @@ -428,13 +428,13 @@ pub(crate) unsafe extern "C" fn coex_register_bt_cb_wrapper( callback: unsafe extern "C" fn(), ) -> i32 { warn!("coex_register_bt_cb {:?}", callback); - extern "C" { + unsafe extern "C" { #[cfg(coex)] fn coex_register_bt_cb(callback: unsafe extern "C" fn()) -> i32; } #[cfg(coex)] - return coex_register_bt_cb(callback); + return unsafe { coex_register_bt_cb(callback) }; #[cfg(not(coex))] 0 @@ -442,13 +442,13 @@ pub(crate) unsafe extern "C" fn coex_register_bt_cb_wrapper( pub(crate) unsafe extern "C" fn coex_bb_reset_lock() -> u32 { trace!("coex_bb_reset_lock"); - extern "C" { + unsafe extern "C" { #[cfg(coex)] fn coex_bb_reset_lock() -> u32; } #[cfg(coex)] - return coex_bb_reset_lock(); + return unsafe { coex_bb_reset_lock() }; #[cfg(not(coex))] 0 @@ -457,26 +457,28 @@ pub(crate) unsafe extern "C" fn coex_bb_reset_lock() -> u32 { #[allow(unused_variables)] pub(crate) unsafe extern "C" fn coex_bb_reset_unlock(event: u32) { trace!("coex_bb_reset_unlock"); - extern "C" { + unsafe extern "C" { #[cfg(coex)] fn coex_bb_reset_unlock(event: u32); } #[cfg(coex)] - coex_bb_reset_unlock(event); + unsafe { + coex_bb_reset_unlock(event) + }; } pub(crate) unsafe extern "C" fn coex_schm_register_btdm_callback_wrapper( callback: unsafe extern "C" fn(), ) -> i32 { warn!("coex_schm_register_btdm_callback {:?}", callback); - extern "C" { + unsafe extern "C" { #[cfg(coex)] fn coex_schm_register_callback(kind: u32, callback: unsafe extern "C" fn()) -> i32; } #[cfg(coex)] - return coex_schm_register_callback(1, callback); // COEX_SCHM_CALLBACK_TYPE_BT = 1 + return unsafe { coex_schm_register_callback(1, callback) }; // COEX_SCHM_CALLBACK_TYPE_BT = 1 #[cfg(not(coex))] 0 @@ -486,7 +488,7 @@ pub(crate) unsafe extern "C" fn coex_schm_interval_get() -> u32 { trace!("coex_schm_interval_get"); #[cfg(coex)] - return crate::binary::include::coex_schm_interval_get(); + return unsafe { crate::binary::include::coex_schm_interval_get() }; #[cfg(not(coex))] 0 @@ -496,7 +498,7 @@ pub(crate) unsafe extern "C" fn coex_schm_curr_period_get() -> u8 { trace!("coex_schm_curr_period_get"); #[cfg(coex)] - return crate::binary::include::coex_schm_curr_period_get(); + return unsafe { crate::binary::include::coex_schm_curr_period_get() }; #[cfg(not(coex))] 0 @@ -506,7 +508,7 @@ pub(crate) unsafe extern "C" fn coex_schm_curr_phase_get() -> *const () { trace!("coex_schm_curr_phase_get"); #[cfg(coex)] - return crate::binary::include::coex_schm_curr_phase_get() as *const (); + return unsafe { crate::binary::include::coex_schm_curr_phase_get() } as *const (); #[cfg(not(coex))] return core::ptr::null::<()>(); @@ -515,13 +517,13 @@ pub(crate) unsafe extern "C" fn coex_schm_curr_phase_get() -> *const () { #[allow(unused_variables)] pub(crate) unsafe extern "C" fn coex_wifi_channel_get(primary: *mut u8, secondary: *mut u8) -> i32 { warn!("coex_wifi_channel_get"); - extern "C" { + unsafe extern "C" { #[cfg(coex)] fn coex_wifi_channel_get(primary: *mut u8, secondary: *mut u8) -> i32; } #[cfg(coex)] - return coex_wifi_channel_get(primary, secondary); + return unsafe { coex_wifi_channel_get(primary, secondary) }; #[cfg(not(coex))] -1 @@ -532,13 +534,13 @@ pub(crate) unsafe extern "C" fn coex_register_wifi_channel_change_callback( callback: unsafe extern "C" fn(), ) -> i32 { warn!("coex_register_wifi_channel_change_callback"); - extern "C" { + unsafe extern "C" { #[cfg(coex)] fn coex_register_wifi_channel_change_callback(callback: unsafe extern "C" fn()) -> i32; } #[cfg(coex)] - return coex_register_wifi_channel_change_callback(callback); + return unsafe { coex_register_wifi_channel_change_callback(callback) }; #[cfg(not(coex))] 0 @@ -549,17 +551,21 @@ pub(crate) unsafe extern "C" fn set_isr(n: i32, f: unsafe extern "C" fn(), arg: match n { 5 => { - ISR_INTERRUPT_5 = (f as *mut c_types::c_void, arg as *mut c_types::c_void); + unsafe { + ISR_INTERRUPT_5 = (f as *mut c_types::c_void, arg as *mut c_types::c_void); + } unwrap!(interrupt::enable( Interrupt::RWBT, interrupt::Priority::Priority1 )); } - 7 => { + 7 => unsafe { ISR_INTERRUPT_7 = (f as *mut c_types::c_void, arg as *mut c_types::c_void); - } + }, 8 => { - ISR_INTERRUPT_8 = (f as *mut c_types::c_void, arg as *mut c_types::c_void); + unsafe { + ISR_INTERRUPT_8 = (f as *mut c_types::c_void, arg as *mut c_types::c_void); + } unwrap!(interrupt::enable( Interrupt::BT_BB, interrupt::Priority::Priority1, @@ -573,7 +579,9 @@ pub(crate) unsafe extern "C" fn set_isr(n: i32, f: unsafe extern "C" fn(), arg: pub(crate) unsafe extern "C" fn ints_on(mask: u32) { trace!("chip_ints_on esp32 {:b}", mask); - crate::hal::xtensa_lx::interrupt::enable_mask(mask); + unsafe { + crate::hal::xtensa_lx::interrupt::enable_mask(mask); + } } #[cfg(coex)] @@ -607,7 +615,7 @@ fn async_wakeup_request(event: i32) -> bool { _ => return false, }; - extern "C" { + unsafe extern "C" { fn btdm_power_state_active() -> bool; fn btdm_wakeup_request(request_lock: bool); } @@ -641,7 +649,7 @@ fn async_wakeup_request_end(event: i32) { _ => return, }; - extern "C" { + unsafe extern "C" { // this isn't found anywhere ... not a ROM function // not in any of the libs - but the code will never call this anyway diff --git a/esp-wifi/src/ble/os_adapter_esp32c2.rs b/esp-wifi/src/ble/os_adapter_esp32c2.rs index 7821f6ec2..de31718f0 100644 --- a/esp-wifi/src/ble/os_adapter_esp32c2.rs +++ b/esp-wifi/src/ble/os_adapter_esp32c2.rs @@ -89,29 +89,27 @@ pub(super) unsafe extern "C" fn esp_intr_alloc( ) -> i32 { trace!( "esp_intr_alloc {} {} {:?} {:?} {:?}", - source, - flags, - handler, - arg, - ret_handle + source, flags, handler, arg, ret_handle ); - match source { - 4 => { - ISR_INTERRUPT_4 = (handler, arg); - unwrap!(interrupt::enable( - Interrupt::BT_MAC, - interrupt::Priority::Priority1 - )); + unsafe { + match source { + 4 => { + ISR_INTERRUPT_4 = (handler, arg); + unwrap!(interrupt::enable( + Interrupt::BT_MAC, + interrupt::Priority::Priority1 + )); + } + 7 => { + ISR_INTERRUPT_7 = (handler, arg); + unwrap!(interrupt::enable( + Interrupt::LP_TIMER, + interrupt::Priority::Priority1 + )); + } + _ => panic!("Unexpected interrupt source {}", source), } - 7 => { - ISR_INTERRUPT_7 = (handler, arg); - unwrap!(interrupt::enable( - Interrupt::LP_TIMER, - interrupt::Priority::Priority1 - )); - } - _ => panic!("Unexpected interrupt source {}", source), } 0 diff --git a/esp-wifi/src/ble/os_adapter_esp32c3.rs b/esp-wifi/src/ble/os_adapter_esp32c3.rs index bffb911a2..42db50d91 100644 --- a/esp-wifi/src/ble/os_adapter_esp32c3.rs +++ b/esp-wifi/src/ble/os_adapter_esp32c3.rs @@ -207,7 +207,7 @@ extern "C" fn coex_schm_curr_phase_get() -> *const () { extern "C" fn coex_bt_wakeup_request() { trace!("coex_bt_wakeup_request"); - extern "C" { + unsafe extern "C" { fn btdm_wakeup_request(); } @@ -219,7 +219,7 @@ extern "C" fn coex_bt_wakeup_request() { extern "C" fn coex_bt_wakeup_request_end() { trace!("coex_bt_wakeup_request_end"); - extern "C" { + unsafe extern "C" { fn btdm_in_wakeup_requesting_set(set: bool); } @@ -229,7 +229,7 @@ extern "C" fn coex_bt_wakeup_request_end() { } extern "C" fn ets_delay_us_wrapper(us: u32) { - extern "C" { + unsafe extern "C" { fn ets_delay_us(us: u32); } @@ -246,7 +246,7 @@ extern "C" fn btdm_rom_table_ready_wrapper() { // #endif } -extern "C" { +unsafe extern "C" { fn btdm_controller_rom_data_init() -> i32; } @@ -329,14 +329,12 @@ pub(crate) unsafe extern "C" fn interrupt_set( ) -> i32 { trace!( "interrupt_set {} {} {} {} {}", - cpu_no, - intr_source, - handler as usize, - arg as u32, - ret_handle as usize, + cpu_no, intr_source, handler as usize, arg as u32, ret_handle as usize, ); - interrupt_handler_set(intr_source, handler, arg); + unsafe { + interrupt_handler_set(intr_source, handler, arg); + } 0 } @@ -352,36 +350,36 @@ pub(crate) unsafe extern "C" fn interrupt_handler_set( ) { trace!( "interrupt_handler_set {} {:?} {:?}", - interrupt_no, - func, - arg + interrupt_no, func, arg ); - match interrupt_no { - 5 => { - BT_INTERRUPT_FUNCTION5 = ( - func as *mut crate::binary::c_types::c_void, - arg as *mut crate::binary::c_types::c_void, - ); - unwrap!(interrupt::enable( - Interrupt::RWBT, - interrupt::Priority::Priority1 - )); - unwrap!(interrupt::enable( - Interrupt::BT_BB, - interrupt::Priority::Priority1 - )); + unsafe { + match interrupt_no { + 5 => { + BT_INTERRUPT_FUNCTION5 = ( + func as *mut crate::binary::c_types::c_void, + arg as *mut crate::binary::c_types::c_void, + ); + unwrap!(interrupt::enable( + Interrupt::RWBT, + interrupt::Priority::Priority1 + )); + unwrap!(interrupt::enable( + Interrupt::BT_BB, + interrupt::Priority::Priority1 + )); + } + 8 => { + BT_INTERRUPT_FUNCTION8 = ( + func as *mut crate::binary::c_types::c_void, + arg as *mut crate::binary::c_types::c_void, + ); + unwrap!(interrupt::enable( + Interrupt::RWBLE, + interrupt::Priority::Priority1 + )); + } + _ => panic!("Unsupported interrupt number {}", interrupt_no), } - 8 => { - BT_INTERRUPT_FUNCTION8 = ( - func as *mut crate::binary::c_types::c_void, - arg as *mut crate::binary::c_types::c_void, - ); - unwrap!(interrupt::enable( - Interrupt::RWBLE, - interrupt::Priority::Priority1 - )); - } - _ => panic!("Unsupported interrupt number {}", interrupt_no), } } @@ -397,13 +395,13 @@ pub(crate) unsafe extern "C" fn coex_core_ble_conn_dyn_prio_get( low: *mut i32, high: *mut i32, ) -> i32 { - extern "C" { + unsafe extern "C" { fn coex_core_ble_conn_dyn_prio_get(low: *mut i32, high: *mut i32) -> i32; } trace!("coex_core_ble_conn_dyn_prio_get"); #[cfg(coex)] - return coex_core_ble_conn_dyn_prio_get(low, high); + return unsafe { coex_core_ble_conn_dyn_prio_get(low, high) }; #[cfg(not(coex))] 0 diff --git a/esp-wifi/src/ble/os_adapter_esp32c6.rs b/esp-wifi/src/ble/os_adapter_esp32c6.rs index 6c3efe776..bf344d1a6 100644 --- a/esp-wifi/src/ble/os_adapter_esp32c6.rs +++ b/esp-wifi/src/ble/os_adapter_esp32c6.rs @@ -88,29 +88,27 @@ pub(super) unsafe extern "C" fn esp_intr_alloc( ) -> i32 { trace!( "esp_intr_alloc {} {} {:?} {:?} {:?}", - source, - flags, - handler, - arg, - ret_handle + source, flags, handler, arg, ret_handle ); - match source { - 4 => { - ISR_INTERRUPT_4 = (handler, arg); - unwrap!(interrupt::enable( - Interrupt::BT_MAC, - interrupt::Priority::Priority1 - )); + unsafe { + match source { + 4 => { + ISR_INTERRUPT_4 = (handler, arg); + unwrap!(interrupt::enable( + Interrupt::BT_MAC, + interrupt::Priority::Priority1 + )); + } + 7 => { + ISR_INTERRUPT_7 = (handler, arg); + unwrap!(interrupt::enable( + Interrupt::LP_TIMER, + interrupt::Priority::Priority1 + )); + } + _ => panic!("Unexpected interrupt source {}", source), } - 7 => { - ISR_INTERRUPT_7 = (handler, arg); - unwrap!(interrupt::enable( - Interrupt::LP_TIMER, - interrupt::Priority::Priority1 - )); - } - _ => panic!("Unexpected interrupt source {}", source), } 0 @@ -132,7 +130,7 @@ pub(super) unsafe extern "C" fn esp_reset_rpa_moudle() { } #[allow(improper_ctypes_definitions)] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn jrand48( _xsubi: [crate::binary::c_types::c_ushort; 3], ) -> crate::binary::c_types::c_long { diff --git a/esp-wifi/src/ble/os_adapter_esp32h2.rs b/esp-wifi/src/ble/os_adapter_esp32h2.rs index 35d966774..2059b2c1c 100644 --- a/esp-wifi/src/ble/os_adapter_esp32h2.rs +++ b/esp-wifi/src/ble/os_adapter_esp32h2.rs @@ -88,29 +88,27 @@ pub(super) unsafe extern "C" fn esp_intr_alloc( ) -> i32 { trace!( "esp_intr_alloc {} {} {:?} {:?} {:?}", - source, - flags, - handler, - arg, - ret_handle + source, flags, handler, arg, ret_handle ); - match source { - 3 => { - ISR_INTERRUPT_3 = (handler, arg); - unwrap!(interrupt::enable( - Interrupt::LP_BLE_TIMER, - interrupt::Priority::Priority1 - )); + unsafe { + match source { + 3 => { + ISR_INTERRUPT_3 = (handler, arg); + unwrap!(interrupt::enable( + Interrupt::LP_BLE_TIMER, + interrupt::Priority::Priority1 + )); + } + 15 => { + ISR_INTERRUPT_15 = (handler, arg); + unwrap!(interrupt::enable( + Interrupt::BT_MAC, + interrupt::Priority::Priority1 + )); + } + _ => panic!("Unexpected interrupt source {}", source), } - 15 => { - ISR_INTERRUPT_15 = (handler, arg); - unwrap!(interrupt::enable( - Interrupt::BT_MAC, - interrupt::Priority::Priority1 - )); - } - _ => panic!("Unexpected interrupt source {}", source), } 0 @@ -132,7 +130,7 @@ pub(super) unsafe extern "C" fn esp_reset_rpa_moudle() { } #[allow(improper_ctypes_definitions)] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn jrand48( _xsubi: [crate::binary::c_types::c_ushort; 3], ) -> crate::binary::c_types::c_long { diff --git a/esp-wifi/src/ble/os_adapter_esp32s3.rs b/esp-wifi/src/ble/os_adapter_esp32s3.rs index 880165bb3..1402ca4fc 100644 --- a/esp-wifi/src/ble/os_adapter_esp32s3.rs +++ b/esp-wifi/src/ble/os_adapter_esp32s3.rs @@ -207,7 +207,7 @@ extern "C" fn coex_schm_curr_phase_get() -> *const () { extern "C" fn coex_bt_wakeup_request() { trace!("coex_bt_wakeup_request"); - extern "C" { + unsafe extern "C" { fn btdm_wakeup_request(); } @@ -219,7 +219,7 @@ extern "C" fn coex_bt_wakeup_request() { extern "C" fn coex_bt_wakeup_request_end() { trace!("coex_bt_wakeup_request_end"); - extern "C" { + unsafe extern "C" { fn btdm_in_wakeup_requesting_set(set: bool); } @@ -229,7 +229,7 @@ extern "C" fn coex_bt_wakeup_request_end() { } extern "C" fn ets_delay_us_wrapper(us: u32) { - extern "C" { + unsafe extern "C" { fn ets_delay_us(us: u32); } @@ -246,7 +246,7 @@ extern "C" fn btdm_rom_table_ready_wrapper() { // #endif } -extern "C" { +unsafe extern "C" { fn btdm_controller_rom_data_init() -> i32; } @@ -338,14 +338,12 @@ pub(crate) unsafe extern "C" fn interrupt_set( ) -> i32 { trace!( "interrupt_set {} {} {} {} {}", - cpu_no, - intr_source, - handler as usize, - arg as u32, - ret_handle as usize, + cpu_no, intr_source, handler as usize, arg as u32, ret_handle as usize, ); - interrupt_handler_set(intr_source, handler, arg); + unsafe { + interrupt_handler_set(intr_source, handler, arg); + } 0 } @@ -361,32 +359,32 @@ pub(crate) unsafe extern "C" fn interrupt_handler_set( ) { trace!( "interrupt_handler_set {} {:?} {:?}", - interrupt_no, - func, - arg + interrupt_no, func, arg ); - match interrupt_no { - 5 => { - ISR_INTERRUPT_5 = ( - func as *mut crate::binary::c_types::c_void, - arg as *mut crate::binary::c_types::c_void, - ); - unwrap!(interrupt::enable( - Interrupt::BT_BB, - interrupt::Priority::Priority1, - )); + unsafe { + match interrupt_no { + 5 => { + ISR_INTERRUPT_5 = ( + func as *mut crate::binary::c_types::c_void, + arg as *mut crate::binary::c_types::c_void, + ); + unwrap!(interrupt::enable( + Interrupt::BT_BB, + interrupt::Priority::Priority1, + )); + } + 8 => { + ISR_INTERRUPT_8 = ( + func as *mut crate::binary::c_types::c_void, + arg as *mut crate::binary::c_types::c_void, + ); + unwrap!(interrupt::enable( + Interrupt::RWBLE, + interrupt::Priority::Priority1, + )); + } + _ => panic!("Unsupported interrupt number {}", interrupt_no), } - 8 => { - ISR_INTERRUPT_8 = ( - func as *mut crate::binary::c_types::c_void, - arg as *mut crate::binary::c_types::c_void, - ); - unwrap!(interrupt::enable( - Interrupt::RWBLE, - interrupt::Priority::Priority1, - )); - } - _ => panic!("Unsupported interrupt number {}", interrupt_no), } } @@ -402,13 +400,13 @@ pub(crate) unsafe extern "C" fn coex_core_ble_conn_dyn_prio_get( low: *mut i32, high: *mut i32, ) -> i32 { - extern "C" { + unsafe extern "C" { fn coex_core_ble_conn_dyn_prio_get(low: *mut i32, high: *mut i32) -> i32; } trace!("coex_core_ble_conn_dyn_prio_get"); #[cfg(coex)] - return coex_core_ble_conn_dyn_prio_get(low, high); + return unsafe { coex_core_ble_conn_dyn_prio_get(low, high) }; #[cfg(not(coex))] 0 diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32.rs b/esp-wifi/src/common_adapter/common_adapter_esp32.rs index 826e672a6..62914bc77 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32.rs @@ -41,29 +41,37 @@ pub(crate) unsafe fn phy_enable() { // phy_update_wifi_mac_time(false, s_phy_rf_en_ts); // #endif - super::phy_enable_clock(); + unsafe { + super::phy_enable_clock(); + } - if !G_IS_PHY_CALIBRATED { + if !unsafe { G_IS_PHY_CALIBRATED } { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; let init_data = &PHY_INIT_DATA_DEFAULT; - register_chipv7_phy( - init_data, - &mut cal_data as *mut _ - as *mut crate::binary::include::esp_phy_calibration_data_t, - esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, - ); + unsafe { + register_chipv7_phy( + init_data, + &mut cal_data as *mut _ + as *mut crate::binary::include::esp_phy_calibration_data_t, + esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, + ); - G_IS_PHY_CALIBRATED = true; + G_IS_PHY_CALIBRATED = true; + } } else { - phy_wakeup_init(); + unsafe { + phy_wakeup_init(); + } phy_digital_regs_load(); } #[cfg(coex)] - coex_bt_high_prio(); + unsafe { + coex_bt_high_prio(); + } trace!("PHY ENABLE"); }); @@ -76,17 +84,19 @@ pub(crate) unsafe fn phy_disable() { if count == 1 { critical_section::with(|_| { phy_digital_regs_store(); - // Disable PHY and RF. - phy_close_rf(); + unsafe { + // Disable PHY and RF. + phy_close_rf(); - // #if CONFIG_IDF_TARGET_ESP32 - // // Update WiFi MAC time before disalbe WiFi/BT common peripheral - // clock phy_update_wifi_mac_time(true, - // esp_timer_get_time()); #endif + // #if CONFIG_IDF_TARGET_ESP32 + // // Update WiFi MAC time before disalbe WiFi/BT common peripheral + // clock phy_update_wifi_mac_time(true, + // esp_timer_get_time()); #endif - // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware - // RNG - super::phy_disable_clock(); + // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware + // RNG + super::phy_disable_clock(); + } trace!("PHY DISABLE"); }); } @@ -123,10 +133,12 @@ fn phy_digital_regs_store() { /// /// ************************************************************************* #[ram] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn esp_dport_access_reg_read(reg: u32) -> u32 { - // trace!("esp_dport_access_reg_read {:x} => {:x}", reg, res); - (reg as *mut u32).read_volatile() + unsafe { + // trace!("esp_dport_access_reg_read {:x} => {:x}", reg, res); + (reg as *mut u32).read_volatile() + } } /// ************************************************************************** @@ -143,11 +155,11 @@ unsafe extern "C" fn esp_dport_access_reg_read(reg: u32) -> u32 { /// /// ************************************************************************* #[ram] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn phy_enter_critical() -> u32 { trace!("phy_enter_critical"); - core::mem::transmute(critical_section::acquire()) + unsafe { core::mem::transmute(critical_section::acquire()) } } /// ************************************************************************** @@ -164,17 +176,19 @@ unsafe extern "C" fn phy_enter_critical() -> u32 { /// /// ************************************************************************* #[ram] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn phy_exit_critical(level: u32) { trace!("phy_exit_critical {}", level); - critical_section::release(core::mem::transmute::( - level, - )); + unsafe { + critical_section::release(core::mem::transmute::( + level, + )); + } } #[ram] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn rtc_get_xtal() -> u32 { use esp_hal::clock::Clock; @@ -182,27 +196,27 @@ unsafe extern "C" fn rtc_get_xtal() -> u32 { xtal.mhz() } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_deinit() { trace!("misc_nvs_deinit") } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_init() -> i32 { trace!("misc_nvs_init"); 0 } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_restore() -> i32 { todo!("misc_nvs_restore") } -#[no_mangle] +#[unsafe(no_mangle)] static mut g_log_mod: i32 = 0; -#[no_mangle] +#[unsafe(no_mangle)] static mut g_log_level: i32 = 0; -#[no_mangle] +#[unsafe(no_mangle)] pub static mut g_misc_nvs: u32 = 0; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs index 548ee2d43..e53615522 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c2.rs @@ -26,38 +26,46 @@ pub(crate) unsafe fn phy_enable() { let count = PHY_ACCESS_REF.fetch_add(1, Ordering::SeqCst); if count == 0 { critical_section::with(|_| { - super::phy_enable_clock(); + unsafe { + super::phy_enable_clock(); + } - if !G_IS_PHY_CALIBRATED { + if !unsafe { G_IS_PHY_CALIBRATED } { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; - let phy_version = get_phy_version_str(); - trace!("phy_version {}", str_from_c(phy_version)); + let phy_version = unsafe { get_phy_version_str() }; + trace!("phy_version {}", unsafe { str_from_c(phy_version) }); let init_data = &PHY_INIT_DATA_DEFAULT; // DON'T CALL `phy_bbpll_en_usb` on ESP32-C2 - register_chipv7_phy( - init_data, - &mut cal_data as *mut _ - as *mut crate::binary::include::esp_phy_calibration_data_t, - esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, - ); + unsafe { + register_chipv7_phy( + init_data, + &mut cal_data as *mut _ + as *mut crate::binary::include::esp_phy_calibration_data_t, + esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, + ); - G_IS_PHY_CALIBRATED = true; + G_IS_PHY_CALIBRATED = true; + } } else { - phy_wakeup_init(); + unsafe { + phy_wakeup_init(); + } phy_digital_regs_load(); } #[cfg(feature = "ble")] { - extern "C" { + unsafe extern "C" { fn coex_pti_v2(); } - coex_pti_v2(); + unsafe { + coex_pti_v2(); + } } trace!("PHY ENABLE"); @@ -71,20 +79,22 @@ pub(crate) unsafe fn phy_disable() { if count == 1 { critical_section::with(|_| { phy_digital_regs_store(); - // Disable PHY and RF. - phy_close_rf(); + unsafe { + // Disable PHY and RF. + phy_close_rf(); - // Disable PHY temperature sensor - phy_xpd_tsens(); + // Disable PHY temperature sensor + phy_xpd_tsens(); - // #if CONFIG_IDF_TARGET_ESP32 - // // Update WiFi MAC time before disalbe WiFi/BT common peripheral - // clock phy_update_wifi_mac_time(true, - // esp_timer_get_time()); #endif + // #if CONFIG_IDF_TARGET_ESP32 + // // Update WiFi MAC time before disalbe WiFi/BT common peripheral + // clock phy_update_wifi_mac_time(true, + // esp_timer_get_time()); #endif - // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware - // RNG - super::phy_disable_clock(); + // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware + // RNG + super::phy_disable_clock(); + } trace!("PHY DISABLE"); }); } diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs index 90d94ad3f..cd284e189 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs @@ -61,45 +61,55 @@ pub(crate) unsafe fn phy_enable() { let count = PHY_ACCESS_REF.fetch_add(1, Ordering::SeqCst); if count == 0 { critical_section::with(|_| { - super::phy_enable_clock(); + unsafe { + super::phy_enable_clock(); + } - if !G_IS_PHY_CALIBRATED { + if !unsafe { G_IS_PHY_CALIBRATED } { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; - let phy_version = get_phy_version_str(); - trace!("phy_version {}", str_from_c(phy_version)); + let phy_version = unsafe { get_phy_version_str() }; + trace!("phy_version {}", unsafe { str_from_c(phy_version) }); let init_data = &PHY_INIT_DATA_DEFAULT; #[cfg(phy_enable_usb)] { - extern "C" { + unsafe extern "C" { fn phy_bbpll_en_usb(param: bool); } - phy_bbpll_en_usb(true); + unsafe { + phy_bbpll_en_usb(true); + } } - register_chipv7_phy( - init_data, - &mut cal_data as *mut _ - as *mut crate::binary::include::esp_phy_calibration_data_t, - esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, - ); + unsafe { + register_chipv7_phy( + init_data, + &mut cal_data as *mut _ + as *mut crate::binary::include::esp_phy_calibration_data_t, + esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, + ); - G_IS_PHY_CALIBRATED = true; + G_IS_PHY_CALIBRATED = true; + } } else { - phy_wakeup_init(); + unsafe { + phy_wakeup_init(); + } phy_digital_regs_load(); } #[cfg(feature = "ble")] { - extern "C" { + unsafe extern "C" { fn coex_pti_v2(); } - coex_pti_v2(); + unsafe { + coex_pti_v2(); + } } trace!("PHY ENABLE"); @@ -113,20 +123,22 @@ pub(crate) unsafe fn phy_disable() { if count == 1 { critical_section::with(|_| { phy_digital_regs_store(); - // Disable PHY and RF. - phy_close_rf(); + unsafe { + // Disable PHY and RF. + phy_close_rf(); - // Disable PHY temperature sensor - phy_xpd_tsens(); + // Disable PHY temperature sensor + phy_xpd_tsens(); - // #if CONFIG_IDF_TARGET_ESP32 - // // Update WiFi MAC time before disalbe WiFi/BT common peripheral - // clock phy_update_wifi_mac_time(true, - // esp_timer_get_time()); #endif + // #if CONFIG_IDF_TARGET_ESP32 + // // Update WiFi MAC time before disalbe WiFi/BT common peripheral + // clock phy_update_wifi_mac_time(true, + // esp_timer_get_time()); #endif - // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware - // RNG - super::phy_disable_clock(); + // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware + // RNG + super::phy_disable_clock(); + } trace!("PHY DISABLE"); }); } diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs index 28d8e7fcf..4937f6548 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs @@ -26,44 +26,54 @@ pub(crate) unsafe fn phy_enable() { let count = PHY_ACCESS_REF.fetch_add(1, Ordering::SeqCst); if count == 0 { critical_section::with(|_| { - super::phy_enable_clock(); + unsafe { + super::phy_enable_clock(); + } - if !G_IS_PHY_CALIBRATED { + if !unsafe { G_IS_PHY_CALIBRATED } { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; - let phy_version = get_phy_version_str(); - trace!("phy_version {}", str_from_c(phy_version)); + let phy_version = unsafe { get_phy_version_str() }; + trace!("phy_version {}", unsafe { str_from_c(phy_version) }); let init_data = &PHY_INIT_DATA_DEFAULT; #[cfg(phy_enable_usb)] { - extern "C" { + unsafe extern "C" { fn phy_bbpll_en_usb(param: bool); } - phy_bbpll_en_usb(true); + unsafe { + phy_bbpll_en_usb(true); + } } - register_chipv7_phy( - init_data, - &mut cal_data as *mut _ - as *mut crate::binary::include::esp_phy_calibration_data_t, - esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, - ); + unsafe { + register_chipv7_phy( + init_data, + &mut cal_data as *mut _ + as *mut crate::binary::include::esp_phy_calibration_data_t, + esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, + ); - G_IS_PHY_CALIBRATED = true; + G_IS_PHY_CALIBRATED = true; + } } else { - phy_wakeup_init(); + unsafe { + phy_wakeup_init(); + } phy_digital_regs_load(); } #[cfg(feature = "ble")] { - extern "C" { + unsafe extern "C" { fn coex_pti_v2(); } - coex_pti_v2(); + unsafe { + coex_pti_v2(); + } } trace!("PHY ENABLE"); @@ -77,20 +87,22 @@ pub(crate) unsafe fn phy_disable() { if count == 1 { critical_section::with(|_| { phy_digital_regs_store(); - // Disable PHY and RF. - phy_close_rf(); + unsafe { + // Disable PHY and RF. + phy_close_rf(); - // Disable PHY temperature sensor - phy_xpd_tsens(); + // Disable PHY temperature sensor + phy_xpd_tsens(); - // #if CONFIG_IDF_TARGET_ESP32 - // // Update WiFi MAC time before disable WiFi/BT common peripheral - // clock phy_update_wifi_mac_time(true, - // esp_timer_get_time()); #endif + // #if CONFIG_IDF_TARGET_ESP32 + // // Update WiFi MAC time before disable WiFi/BT common peripheral + // clock phy_update_wifi_mac_time(true, + // esp_timer_get_time()); #endif - // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware - // RNG - super::phy_disable_clock(); + // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware + // RNG + super::phy_disable_clock(); + } trace!("PHY DISABLE"); }); } diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs index 51350ed72..c2e8a0162 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs @@ -27,14 +27,16 @@ pub(crate) unsafe fn phy_enable() { let count = PHY_ACCESS_REF.fetch_add(1, Ordering::SeqCst); if count == 0 { critical_section::with(|_| { - super::phy_enable_clock(); + unsafe { + super::phy_enable_clock(); + } - if !G_IS_PHY_CALIBRATED { + if !unsafe { G_IS_PHY_CALIBRATED } { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; - let phy_version = get_phy_version_str(); - trace!("phy_version {}", str_from_c(phy_version)); + let phy_version = unsafe { get_phy_version_str() }; + trace!("phy_version {}", unsafe { str_from_c(phy_version) }); let init_data = &PHY_INIT_DATA_DEFAULT; @@ -48,25 +50,31 @@ pub(crate) unsafe fn phy_enable() { // phy_bbpll_en_usb(true); // } - register_chipv7_phy( - init_data, - &mut cal_data as *mut _ - as *mut crate::binary::include::esp_phy_calibration_data_t, - esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, - ); + unsafe { + register_chipv7_phy( + init_data, + &mut cal_data as *mut _ + as *mut crate::binary::include::esp_phy_calibration_data_t, + esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, + ); - G_IS_PHY_CALIBRATED = true; + G_IS_PHY_CALIBRATED = true; + } } else { - phy_wakeup_init(); + unsafe { + phy_wakeup_init(); + } phy_digital_regs_load(); } #[cfg(feature = "ble")] { - extern "C" { + unsafe extern "C" { fn coex_pti_v2(); } - coex_pti_v2(); + unsafe { + coex_pti_v2(); + } } trace!("PHY ENABLE"); @@ -80,20 +88,22 @@ pub(crate) unsafe fn phy_disable() { if count == 1 { critical_section::with(|_| { phy_digital_regs_store(); - // Disable PHY and RF. - phy_close_rf(); + unsafe { + // Disable PHY and RF. + phy_close_rf(); - // Disable PHY temperature sensor - phy_xpd_tsens(); + // Disable PHY temperature sensor + phy_xpd_tsens(); - // #if CONFIG_IDF_TARGET_ESP32 - // // Update WiFi MAC time before disalbe WiFi/BT common peripheral - // clock phy_update_wifi_mac_time(true, - // esp_timer_get_time()); #endif + // #if CONFIG_IDF_TARGET_ESP32 + // // Update WiFi MAC time before disalbe WiFi/BT common peripheral + // clock phy_update_wifi_mac_time(true, + // esp_timer_get_time()); #endif - // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware - // RNG - super::phy_disable_clock(); + // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware + // RNG + super::phy_disable_clock(); + } trace!("PHY DISABLE"); }); } diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs index 16c6b476b..07f6f7411 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32s2.rs @@ -59,24 +59,30 @@ pub(crate) unsafe fn phy_enable() { let count = PHY_ACCESS_REF.fetch_add(1, Ordering::SeqCst); if count == 0 { critical_section::with(|_| { - super::phy_enable_clock(); + unsafe { + super::phy_enable_clock(); + } - if !G_IS_PHY_CALIBRATED { + if !unsafe { G_IS_PHY_CALIBRATED } { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; let init_data = &PHY_INIT_DATA_DEFAULT; - register_chipv7_phy( - init_data, - &mut cal_data as *mut _ - as *mut crate::binary::include::esp_phy_calibration_data_t, - esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, - ); + unsafe { + register_chipv7_phy( + init_data, + &mut cal_data as *mut _ + as *mut crate::binary::include::esp_phy_calibration_data_t, + esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, + ); - G_IS_PHY_CALIBRATED = true; + G_IS_PHY_CALIBRATED = true; + } } else { - phy_wakeup_init(); + unsafe { + phy_wakeup_init(); + } phy_digital_regs_load(); } @@ -85,7 +91,9 @@ pub(crate) unsafe fn phy_enable() { extern "C" { fn coex_pti_v2(); } - coex_pti_v2(); + unsafe { + coex_pti_v2(); + } } }); } @@ -97,15 +105,17 @@ pub(crate) unsafe fn phy_disable() { if count == 1 { critical_section::with(|_| { phy_digital_regs_store(); - // Disable PHY and RF. - phy_close_rf(); + unsafe { + // Disable PHY and RF. + phy_close_rf(); - // Disable PHY temperature sensor - phy_xpd_tsens(); + // Disable PHY temperature sensor + phy_xpd_tsens(); - // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware - // RNG - super::phy_disable_clock(); + // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware + // RNG + super::phy_disable_clock(); + } }); } } @@ -141,11 +151,11 @@ fn phy_digital_regs_store() { /// /// ************************************************************************* #[ram] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn phy_enter_critical() -> u32 { trace!("phy_enter_critical"); - core::mem::transmute(critical_section::acquire()) + unsafe { core::mem::transmute(critical_section::acquire()) } } /// ************************************************************************** @@ -162,43 +172,45 @@ unsafe extern "C" fn phy_enter_critical() -> u32 { /// /// ************************************************************************* #[ram] -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn phy_exit_critical(level: u32) { trace!("phy_exit_critical {}", level); - critical_section::release(core::mem::transmute::( - level, - )); + unsafe { + critical_section::release(core::mem::transmute::( + level, + )); + } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn abort() { trace!("misc_nvs_deinit") } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_deinit() { trace!("misc_nvs_deinit") } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_init() -> i32 { trace!("misc_nvs_init"); 0 } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_restore() -> i32 { todo!("misc_nvs_restore") } -#[no_mangle] +#[unsafe(no_mangle)] static mut g_log_mod: i32 = 0; -#[no_mangle] +#[unsafe(no_mangle)] static mut g_log_level: i32 = 0; -#[no_mangle] +#[unsafe(no_mangle)] pub static mut g_misc_nvs: &u32 = unsafe { &*core::ptr::addr_of!(NVS) }; pub static mut NVS: u32 = 0; diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs b/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs index 24f2f2fe8..9771c81a2 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs @@ -61,9 +61,11 @@ pub(crate) unsafe fn phy_enable() { let count = PHY_ACCESS_REF.fetch_add(1, Ordering::SeqCst); if count == 0 { critical_section::with(|_| { - super::phy_enable_clock(); + unsafe { + super::phy_enable_clock(); + } - if !G_IS_PHY_CALIBRATED { + if !unsafe { G_IS_PHY_CALIBRATED } { let mut cal_data: [u8; core::mem::size_of::()] = [0u8; core::mem::size_of::()]; @@ -71,32 +73,40 @@ pub(crate) unsafe fn phy_enable() { #[cfg(phy_enable_usb)] { - extern "C" { + unsafe extern "C" { fn phy_bbpll_en_usb(param: bool); } - phy_bbpll_en_usb(true); + unsafe { + phy_bbpll_en_usb(true); + } } - register_chipv7_phy( - init_data, - &mut cal_data as *mut _ - as *mut crate::binary::include::esp_phy_calibration_data_t, - esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, - ); + unsafe { + register_chipv7_phy( + init_data, + &mut cal_data as *mut _ + as *mut crate::binary::include::esp_phy_calibration_data_t, + esp_phy_calibration_mode_t_PHY_RF_CAL_FULL, + ); - G_IS_PHY_CALIBRATED = true; + G_IS_PHY_CALIBRATED = true; + } } else { - phy_wakeup_init(); + unsafe { + phy_wakeup_init(); + } phy_digital_regs_load(); } #[cfg(feature = "ble")] { - extern "C" { + unsafe extern "C" { fn coex_pti_v2(); } - coex_pti_v2(); + unsafe { + coex_pti_v2(); + } } trace!("PHY ENABLE"); @@ -110,15 +120,17 @@ pub(crate) unsafe fn phy_disable() { if count == 1 { critical_section::with(|_| { phy_digital_regs_store(); - // Disable PHY and RF. - phy_close_rf(); + unsafe { + // Disable PHY and RF. + phy_close_rf(); - // Disable PHY temperature sensor - phy_xpd_tsens(); + // Disable PHY temperature sensor + phy_xpd_tsens(); - // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware - // RNG - super::phy_disable_clock(); + // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware + // RNG + super::phy_disable_clock(); + } trace!("PHY DISABLE"); }); @@ -142,32 +154,32 @@ fn phy_digital_regs_store() { } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn abort() { trace!("misc_nvs_deinit") } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_deinit() { trace!("misc_nvs_deinit") } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_init() -> i32 { trace!("misc_nvs_init"); 0 } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn misc_nvs_restore() -> i32 { todo!("misc_nvs_restore") } -#[no_mangle] +#[unsafe(no_mangle)] static mut g_log_mod: i32 = 0; -#[no_mangle] +#[unsafe(no_mangle)] static mut g_log_level: i32 = 0; -#[no_mangle] +#[unsafe(no_mangle)] pub static mut g_misc_nvs: u32 = 0; diff --git a/esp-wifi/src/common_adapter/mod.rs b/esp-wifi/src/common_adapter/mod.rs index 66cbf1c53..9e69bd7a0 100644 --- a/esp-wifi/src/common_adapter/mod.rs +++ b/esp-wifi/src/common_adapter/mod.rs @@ -109,7 +109,7 @@ pub unsafe extern "C" fn semphr_give(semphr: *mut crate::binary::c_types::c_void /// ************************************************************************* #[allow(unused)] #[ram] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn random() -> crate::binary::c_types::c_ulong { trace!("random"); @@ -138,38 +138,42 @@ pub unsafe extern "C" fn read_mac(mac: *mut u8, type_: u32) -> crate::binary::c_ let base_mac = hal::efuse::Efuse::mac_address(); for (i, &byte) in base_mac.iter().enumerate() { - mac.add(i).write_volatile(byte); - } - - // ESP_MAC_WIFI_SOFTAP - if type_ == 1 { - let tmp = mac.offset(0).read_volatile(); - for i in 0..64 { - mac.offset(0).write_volatile(tmp | 0x02); - mac.offset(0) - .write_volatile(mac.offset(0).read_volatile() ^ (i << 2)); - - if mac.offset(0).read_volatile() != tmp { - break; - } + unsafe { + mac.add(i).write_volatile(byte); } } - // ESP_MAC_BT - if type_ == 2 { - let tmp = mac.offset(0).read_volatile(); - for i in 0..64 { - mac.offset(0).write_volatile(tmp | 0x02); - mac.offset(0) - .write_volatile(mac.offset(0).read_volatile() ^ (i << 2)); + unsafe { + // ESP_MAC_WIFI_SOFTAP + if type_ == 1 { + let tmp = mac.offset(0).read_volatile(); + for i in 0..64 { + mac.offset(0).write_volatile(tmp | 0x02); + mac.offset(0) + .write_volatile(mac.offset(0).read_volatile() ^ (i << 2)); - if mac.offset(0).read_volatile() != tmp { - break; + if mac.offset(0).read_volatile() != tmp { + break; + } } } - mac.offset(5) - .write_volatile(mac.offset(5).read_volatile() + 1); + // ESP_MAC_BT + if type_ == 2 { + let tmp = mac.offset(0).read_volatile(); + for i in 0..64 { + mac.offset(0).write_volatile(tmp | 0x02); + mac.offset(0) + .write_volatile(mac.offset(0).read_volatile() ^ (i << 2)); + + if mac.offset(0).read_volatile() != tmp { + break; + } + } + + mac.offset(5) + .write_volatile(mac.offset(5).read_volatile() + 1); + } } 0 @@ -179,78 +183,88 @@ pub unsafe extern "C" fn read_mac(mac: *mut u8, type_: u32) -> crate::binary::c_ #[ram] pub(crate) unsafe extern "C" fn semphr_take_from_isr(sem: *const (), hptw: *const ()) -> i32 { trace!("sem take from isr"); - (hptw as *mut u32).write_volatile(0); - crate::common_adapter::semphr_take(sem as *mut crate::binary::c_types::c_void, 0) + unsafe { + (hptw as *mut u32).write_volatile(0); + crate::common_adapter::semphr_take(sem as *mut crate::binary::c_types::c_void, 0) + } } #[allow(unused)] #[ram] pub(crate) unsafe extern "C" fn semphr_give_from_isr(sem: *const (), hptw: *const ()) -> i32 { trace!("sem give from isr"); - (hptw as *mut u32).write_volatile(0); - crate::common_adapter::semphr_give(sem as *mut crate::binary::c_types::c_void) + unsafe { + (hptw as *mut u32).write_volatile(0); + crate::common_adapter::semphr_give(sem as *mut crate::binary::c_types::c_void) + } } // other functions -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn puts(s: *const c_char) { - let cstr = str_from_c(s); - info!("{}", cstr); + unsafe { + let cstr = str_from_c(s); + info!("{}", cstr); + } } // #define ESP_EVENT_DEFINE_BASE(id) esp_event_base_t id = #id -#[no_mangle] +#[unsafe(no_mangle)] static mut WIFI_EVENT: esp_event_base_t = c"WIFI_EVENT".as_ptr(); // stuff needed by wpa-supplicant -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn __assert_func( file: *const c_char, line: u32, func: *const c_char, failed_expr: *const c_char, ) { - let file = str_from_c(file); - let (func_pre, func) = if func.is_null() { - ("", "") - } else { - (", function: ", str_from_c(func)) - }; - let expr = str_from_c(failed_expr); + unsafe { + let file = str_from_c(file); + let (func_pre, func) = if func.is_null() { + ("", "") + } else { + (", function: ", str_from_c(func)) + }; + let expr = str_from_c(failed_expr); - panic!( - "assertion \"{}\" failed: file \"{}\", line {}{}{}", - expr, file, line, func_pre, func - ); + panic!( + "assertion \"{}\" failed: file \"{}\", line {}{}{}", + expr, file, line, func_pre, func + ); + } } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn ets_timer_disarm(timer: *mut crate::binary::c_types::c_void) { compat_timer_disarm(timer.cast()); } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn ets_timer_done(timer: *mut crate::binary::c_types::c_void) { compat_timer_done(timer.cast()); } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn ets_timer_setfn( ptimer: *mut crate::binary::c_types::c_void, pfunction: *mut crate::binary::c_types::c_void, parg: *mut crate::binary::c_types::c_void, ) { - compat_timer_setfn( - ptimer.cast(), - core::mem::transmute::< - *mut crate::binary::c_types::c_void, - unsafe extern "C" fn(*mut crate::binary::c_types::c_void), - >(pfunction), - parg, - ); + unsafe { + compat_timer_setfn( + ptimer.cast(), + core::mem::transmute::< + *mut crate::binary::c_types::c_void, + unsafe extern "C" fn(*mut crate::binary::c_types::c_void), + >(pfunction), + parg, + ); + } } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn ets_timer_arm( timer: *mut crate::binary::c_types::c_void, tmout: u32, @@ -259,7 +273,7 @@ pub unsafe extern "C" fn ets_timer_arm( compat_timer_arm(timer.cast(), tmout, repeat); } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn ets_timer_arm_us( timer: *mut crate::binary::c_types::c_void, tmout: u32, @@ -268,7 +282,7 @@ pub unsafe extern "C" fn ets_timer_arm_us( compat_timer_arm_us(timer.cast(), tmout, repeat); } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn gettimeofday(tv: *mut timeval, _tz: *mut ()) -> i32 { if !tv.is_null() { unsafe { @@ -281,20 +295,22 @@ pub unsafe extern "C" fn gettimeofday(tv: *mut timeval, _tz: *mut ()) -> i32 { 0 } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn esp_fill_random(dst: *mut u8, len: u32) { trace!("esp_fill_random"); - let dst = core::slice::from_raw_parts_mut(dst, len as usize); + unsafe { + let dst = core::slice::from_raw_parts_mut(dst, len as usize); - // stealing RNG is safe since we own it (passed into `init`) - let mut rng = esp_hal::rng::Rng::new(unsafe { esp_hal::peripherals::RNG::steal() }); - for chunk in dst.chunks_mut(4) { - let bytes = rng.random().to_le_bytes(); - chunk.copy_from_slice(&bytes[..chunk.len()]); + // stealing RNG is safe since we own it (passed into `init`) + let mut rng = esp_hal::rng::Rng::new(esp_hal::peripherals::RNG::steal()); + for chunk in dst.chunks_mut(4) { + let bytes = rng.random().to_le_bytes(); + chunk.copy_from_slice(&bytes[..chunk.len()]); + } } } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn strrchr(_s: *const (), _c: u32) -> *const u8 { todo!("strrchr"); } diff --git a/esp-wifi/src/compat/common.rs b/esp-wifi/src/compat/common.rs index 9a92610e7..c1e3bd024 100644 --- a/esp-wifi/src/compat/common.rs +++ b/esp-wifi/src/compat/common.rs @@ -134,7 +134,7 @@ impl RawQueue { // do what the ESP-IDF implementations does ... // just remove all elements and add them back except the one we need to remove - // good enough for now - let item_slice = core::slice::from_raw_parts(item as *const u8, self.item_size); + let item_slice = unsafe { core::slice::from_raw_parts(item as *const u8, self.item_size) }; let count = self.count(); if count == 0 { @@ -146,11 +146,11 @@ impl RawQueue { tmp_item.resize(self.item_size, 0); for _ in 0..count { - if !self.try_dequeue(tmp_item.as_mut_ptr().cast()) { + if !unsafe { self.try_dequeue(tmp_item.as_mut_ptr().cast()) } { break; } if &tmp_item[..] != item_slice { - self.enqueue(tmp_item.as_mut_ptr().cast()); + unsafe { self.enqueue(tmp_item.as_mut_ptr().cast()) }; } } } @@ -165,18 +165,22 @@ impl RawQueue { } pub unsafe fn str_from_c<'a>(s: *const c_char) -> &'a str { - let c_str = core::ffi::CStr::from_ptr(s.cast()); - core::str::from_utf8_unchecked(c_str.to_bytes()) + unsafe { + let c_str = core::ffi::CStr::from_ptr(s.cast()); + core::str::from_utf8_unchecked(c_str.to_bytes()) + } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn strnlen(chars: *const c_char, maxlen: usize) -> usize { let mut len = 0; loop { - if chars.offset(len).read_volatile() == 0 { - break; + unsafe { + if chars.offset(len).read_volatile() == 0 { + break; + } + len += 1; } - len += 1; } len as usize @@ -352,9 +356,7 @@ pub(crate) fn send_queued( ) -> i32 { trace!( "queue_send queue {:?} item {:x} block_time_tick {}", - queue, - item as usize, - block_time_tick + queue, item as usize, block_time_tick ); let queue: *mut ConcurrentQueue = queue.cast(); @@ -368,9 +370,7 @@ pub(crate) fn receive_queued( ) -> i32 { trace!( "queue_recv {:?} item {:?} block_time_tick {}", - queue, - item, - block_time_tick + queue, item, block_time_tick ); let forever = block_time_tick == OSI_FUNCS_TIME_BLOCKING; @@ -401,29 +401,34 @@ pub(crate) fn number_of_messages_in_queue(queue: *const ConcurrentQueue) -> u32 /// Implementation of sleep() from newlib in esp-idf. /// components/newlib/time.c -#[no_mangle] +#[unsafe(no_mangle)] pub(crate) unsafe extern "C" fn sleep( seconds: crate::binary::c_types::c_uint, ) -> crate::binary::c_types::c_uint { trace!("sleep"); - usleep(seconds * 1_000); + unsafe { + usleep(seconds * 1_000); + } 0 } /// Implementation of usleep() from newlib in esp-idf. /// components/newlib/time.c -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn usleep(us: u32) -> crate::binary::c_types::c_int { trace!("usleep"); - extern "C" { + unsafe extern "C" { fn esp_rom_delay_us(us: u32); } - esp_rom_delay_us(us); + + unsafe { + esp_rom_delay_us(us); + } 0 } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn putchar(c: i32) -> crate::binary::c_types::c_int { trace!("putchar {}", c as u8 as char); c diff --git a/esp-wifi/src/compat/malloc.rs b/esp-wifi/src/compat/malloc.rs index 11be3304e..970b136ff 100644 --- a/esp-wifi/src/compat/malloc.rs +++ b/esp-wifi/src/compat/malloc.rs @@ -1,8 +1,8 @@ -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 { trace!("alloc {}", size); - extern "C" { + unsafe extern "C" { fn esp_wifi_allocate_from_internal_ram(size: usize) -> *mut u8; } @@ -15,7 +15,7 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 { ptr } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn free(ptr: *mut u8) { trace!("free {:?}", ptr); @@ -24,34 +24,38 @@ pub unsafe extern "C" fn free(ptr: *mut u8) { return; } - extern "C" { + unsafe extern "C" { fn esp_wifi_deallocate_internal_ram(ptr: *mut u8); } - esp_wifi_deallocate_internal_ram(ptr); + unsafe { + esp_wifi_deallocate_internal_ram(ptr); + } } -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn calloc(number: u32, size: usize) -> *mut u8 { trace!("calloc {} {}", number, size); let total_size = number as usize * size; - let ptr = malloc(total_size); + unsafe { + let ptr = malloc(total_size); - if !ptr.is_null() { - for i in 0..total_size as isize { - ptr.offset(i).write_volatile(0); + if !ptr.is_null() { + for i in 0..total_size as isize { + ptr.offset(i).write_volatile(0); + } } - } - ptr + ptr + } } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn realloc(ptr: *mut u8, new_size: usize) -> *mut u8 { trace!("realloc {:?} {}", ptr, new_size); - extern "C" { + unsafe extern "C" { fn memcpy(d: *mut u8, s: *const u8, l: usize); } @@ -71,14 +75,14 @@ unsafe extern "C" fn realloc(ptr: *mut u8, new_size: usize) -> *mut u8 { #[cfg(feature = "esp-alloc")] #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn esp_wifi_free_internal_heap() -> usize { esp_alloc::HEAP.free_caps(esp_alloc::MemoryCapability::Internal.into()) } #[cfg(feature = "esp-alloc")] #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn esp_wifi_allocate_from_internal_ram(size: usize) -> *mut u8 { let total_size = size + 4; unsafe { @@ -98,7 +102,7 @@ pub extern "C" fn esp_wifi_allocate_from_internal_ram(size: usize) -> *mut u8 { #[cfg(feature = "esp-alloc")] #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub extern "C" fn esp_wifi_deallocate_internal_ram(ptr: *mut u8) { use core::alloc::GlobalAlloc; @@ -125,7 +129,7 @@ mod esp_alloc { unsafe impl Allocator for InternalMemory { fn allocate(&self, layout: Layout) -> Result, AllocError> { - extern "C" { + unsafe extern "C" { fn esp_wifi_allocate_from_internal_ram(size: usize) -> *mut u8; } let raw_ptr = unsafe { esp_wifi_allocate_from_internal_ram(layout.size()) }; @@ -134,10 +138,12 @@ mod esp_alloc { } unsafe fn deallocate(&self, ptr: NonNull, _layout: Layout) { - extern "C" { + unsafe extern "C" { fn esp_wifi_deallocate_internal_ram(ptr: *mut u8); } - esp_wifi_deallocate_internal_ram(ptr.as_ptr()); + unsafe { + esp_wifi_deallocate_internal_ram(ptr.as_ptr()); + } } } } diff --git a/esp-wifi/src/compat/misc.rs b/esp-wifi/src/compat/misc.rs index 9f645f2d2..2bea70854 100644 --- a/esp-wifi/src/compat/misc.rs +++ b/esp-wifi/src/compat/misc.rs @@ -1,28 +1,28 @@ use crate::compat::malloc::malloc; // these are not called but needed for linking -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn fwrite(ptr: *const (), size: usize, count: usize, stream: *const ()) -> usize { todo!("fwrite {:?} {} {} {:?}", ptr, size, count, stream) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn fopen(filename: *const u8, mode: *const u8) -> *const () { todo!("fopen {:?} {:?}", filename, mode) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn fgets(str: *const u8, count: u32, file: *const ()) -> *const u8 { todo!("fgets {:?} {} {:?}", str, count, file) } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn fclose(stream: *const ()) -> i32 { todo!("fclose {:?}", stream); } // We cannot just use the ROM function since it needs to allocate memory -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn strdup(str: *const core::ffi::c_char) -> *const core::ffi::c_char { trace!("strdup {:?}", str); @@ -42,7 +42,7 @@ unsafe extern "C" fn strdup(str: *const core::ffi::c_char) -> *const core::ffi:: // From docs: The __getreent() function returns a per-task pointer to struct // _reent in newlib libc. This structure is allocated on the TCB of each task. // i.e. it assumes a FreeRTOS task calling it. -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn atoi(str: *const i8) -> i32 { trace!("atoi {:?}", str); @@ -51,12 +51,12 @@ unsafe extern "C" fn atoi(str: *const i8) -> i32 { let mut idx = 0; // skip leading spaces - while str.add(idx).read() as u8 == b' ' { + while unsafe { str.add(idx).read() } as u8 == b' ' { idx += 1; } // check sign - let c = str.add(idx).read() as u8; + let c = unsafe { str.add(idx).read() } as u8; if c == b'-' || c == b'+' { if c == b'-' { sign = -1; @@ -66,7 +66,7 @@ unsafe extern "C" fn atoi(str: *const i8) -> i32 { // parse number digit by digit loop { - let c = str.add(idx).read() as u8; + let c = unsafe { str.add(idx).read() } as u8; if !c.is_ascii_digit() { break; @@ -97,10 +97,10 @@ struct Tm { tm_isdst: u32, // daylight savings time flag } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn mktime(time: *const Tm) -> i64 { trace!("mktime {:?}", time); - let time = *time; + let time = unsafe { *time }; // Simplified implementation, ignoring time zones, leap seconds, and other // complexities diff --git a/esp-wifi/src/compat/mod.rs b/esp-wifi/src/compat/mod.rs index dc68d68e1..7c18a6054 100644 --- a/esp-wifi/src/compat/mod.rs +++ b/esp-wifi/src/compat/mod.rs @@ -3,23 +3,25 @@ pub mod malloc; pub mod misc; pub mod timer_compat; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn _putchar(c: u8) { static mut BUFFER: [u8; 256] = [0u8; 256]; static mut IDX: usize = 0; - let buffer = core::ptr::addr_of_mut!(BUFFER); - if c == 0 || c == b'\n' || IDX == (*buffer).len() - 1 { - if c != 0 { - BUFFER[IDX] = c; - } else { - IDX = IDX.saturating_sub(1); - } + unsafe { + let buffer = core::ptr::addr_of_mut!(BUFFER); + if c == 0 || c == b'\n' || IDX == (*buffer).len() - 1 { + if c != 0 { + BUFFER[IDX] = c; + } else { + IDX = IDX.saturating_sub(1); + } - info!("{}", core::str::from_utf8_unchecked(&BUFFER[..IDX])); - IDX = 0; - } else { - BUFFER[IDX] = c; - IDX += 1; + info!("{}", core::str::from_utf8_unchecked(&BUFFER[..IDX])); + IDX = 0; + } else { + BUFFER[IDX] = c; + IDX += 1; + } } } diff --git a/esp-wifi/src/compat/timer_compat.rs b/esp-wifi/src/compat/timer_compat.rs index 5900d5c4c..b74ae6a2b 100644 --- a/esp-wifi/src/compat/timer_compat.rs +++ b/esp-wifi/src/compat/timer_compat.rs @@ -154,10 +154,7 @@ pub(crate) fn compat_timer_arm_us(ets_timer: *mut ets_timer, us: u32, repeat: bo trace!( "timer_arm_us {:x} current: {} ticks: {} repeat: {}", - ets_timer as usize, - systick, - ticks, - repeat + ets_timer as usize, systick, ticks, repeat ); TIMERS.with(|timers| { @@ -210,9 +207,7 @@ pub(crate) fn compat_timer_setfn( ) { trace!( "timer_setfn {:x} {:?} {:?}", - ets_timer as usize, - pfunction, - parg + ets_timer as usize, pfunction, parg ); let set = TIMERS.with(|timers| unsafe { if let Some(timer) = timers.find(ets_timer) { diff --git a/esp-wifi/src/esp_now/mod.rs b/esp-wifi/src/esp_now/mod.rs index ebe23fbc7..90769bfb5 100644 --- a/esp-wifi/src/esp_now/mod.rs +++ b/esp-wifi/src/esp_now/mod.rs @@ -746,33 +746,37 @@ unsafe extern "C" fn rcv_cb( data: *const u8, data_len: i32, ) { - let src = [ - (*esp_now_info).src_addr.offset(0).read(), - (*esp_now_info).src_addr.offset(1).read(), - (*esp_now_info).src_addr.offset(2).read(), - (*esp_now_info).src_addr.offset(3).read(), - (*esp_now_info).src_addr.offset(4).read(), - (*esp_now_info).src_addr.offset(5).read(), - ]; + let src = unsafe { + [ + (*esp_now_info).src_addr.offset(0).read(), + (*esp_now_info).src_addr.offset(1).read(), + (*esp_now_info).src_addr.offset(2).read(), + (*esp_now_info).src_addr.offset(3).read(), + (*esp_now_info).src_addr.offset(4).read(), + (*esp_now_info).src_addr.offset(5).read(), + ] + }; - let dst = [ - (*esp_now_info).des_addr.offset(0).read(), - (*esp_now_info).des_addr.offset(1).read(), - (*esp_now_info).des_addr.offset(2).read(), - (*esp_now_info).des_addr.offset(3).read(), - (*esp_now_info).des_addr.offset(4).read(), - (*esp_now_info).des_addr.offset(5).read(), - ]; + let dst = unsafe { + [ + (*esp_now_info).des_addr.offset(0).read(), + (*esp_now_info).des_addr.offset(1).read(), + (*esp_now_info).des_addr.offset(2).read(), + (*esp_now_info).des_addr.offset(3).read(), + (*esp_now_info).des_addr.offset(4).read(), + (*esp_now_info).des_addr.offset(5).read(), + ] + }; - let rx_cntl = (*esp_now_info).rx_ctrl; - let rx_control = RxControlInfo::from_raw(rx_cntl); + let rx_cntl = unsafe { (*esp_now_info).rx_ctrl }; + let rx_control = unsafe { RxControlInfo::from_raw(rx_cntl) }; let info = ReceiveInfo { src_address: src, dst_address: dst, rx_control, }; - let slice = core::slice::from_raw_parts(data, data_len as usize); + let slice = unsafe { core::slice::from_raw_parts(data, data_len as usize) }; critical_section::with(|cs| { let mut queue = RECEIVE_QUEUE.borrow_ref_mut(cs); let data = Box::from(slice); diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index ecd64862b..6b8dbedfa 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -118,11 +118,11 @@ use esp_config::*; use esp_hal::timer::systimer::Alarm; use esp_hal::{self as hal, clock::RadioClockController, peripherals::RADIO_CLK}; use hal::{ + Blocking, clock::Clocks, rng::{Rng, Trng}, time::Rate, - timer::{timg::Timer as TimgTimer, AnyTimer, PeriodicTimer}, - Blocking, + timer::{AnyTimer, PeriodicTimer, timg::Timer as TimgTimer}, }; use portable_atomic::Ordering; @@ -244,7 +244,10 @@ const _: () = { CONFIG.rx_ba_win < CONFIG.dynamic_rx_buf_num, "WiFi configuration check: rx_ba_win should not be larger than dynamic_rx_buf_num!" ); - core::assert!(CONFIG.rx_ba_win < (CONFIG.static_rx_buf_num * 2), "WiFi configuration check: rx_ba_win should not be larger than double of the static_rx_buf_num!"); + core::assert!( + CONFIG.rx_ba_win < (CONFIG.static_rx_buf_num * 2), + "WiFi configuration check: rx_ba_win should not be larger than double of the static_rx_buf_num!" + ); }; type TimeBase = PeriodicTimer<'static, Blocking>; diff --git a/esp-wifi/src/preempt.rs b/esp-wifi/src/preempt.rs index 94418665f..9e6c39298 100644 --- a/esp-wifi/src/preempt.rs +++ b/esp-wifi/src/preempt.rs @@ -56,7 +56,7 @@ pub trait Scheduler: Send + Sync + 'static { fn current_task_thread_semaphore(&self) -> *mut c_void; } -extern "Rust" { +unsafe extern "Rust" { fn esp_wifi_preempt_enable(); fn esp_wifi_preempt_disable(); fn esp_wifi_preempt_yield_task(); @@ -110,23 +110,23 @@ macro_rules! scheduler_impl { (static $name:ident: $t: ty = $val:expr) => { static $name: $t = $val; - #[no_mangle] + #[unsafe(no_mangle)] fn esp_wifi_preempt_enable() { <$t as $crate::preempt::Scheduler>::enable(&$name) } - #[no_mangle] + #[unsafe(no_mangle)] fn esp_wifi_preempt_disable() { <$t as $crate::preempt::Scheduler>::disable(&$name) } - #[no_mangle] + #[unsafe(no_mangle)] fn esp_wifi_preempt_yield_task() { <$t as $crate::preempt::Scheduler>::yield_task(&$name) } - #[no_mangle] + #[unsafe(no_mangle)] fn esp_wifi_preempt_current_task() -> *mut c_void { <$t as $crate::preempt::Scheduler>::current_task(&$name) } - #[no_mangle] + #[unsafe(no_mangle)] fn esp_wifi_preempt_task_create( task: extern "C" fn(*mut c_void), param: *mut c_void, @@ -134,11 +134,11 @@ macro_rules! scheduler_impl { ) -> *mut c_void { <$t as $crate::preempt::Scheduler>::task_create(&$name, task, param, task_stack_size) } - #[no_mangle] + #[unsafe(no_mangle)] fn esp_wifi_preempt_schedule_task_deletion(task_handle: *mut c_void) { <$t as $crate::preempt::Scheduler>::schedule_task_deletion(&$name, task_handle) } - #[no_mangle] + #[unsafe(no_mangle)] fn esp_wifi_preempt_current_task_thread_semaphore() -> *mut c_void { <$t as $crate::preempt::Scheduler>::current_task_thread_semaphore(&$name) } diff --git a/esp-wifi/src/preempt_builtin/timer/riscv.rs b/esp-wifi/src/preempt_builtin/timer/riscv.rs index 7db256d40..fc792e557 100644 --- a/esp-wifi/src/preempt_builtin/timer/riscv.rs +++ b/esp-wifi/src/preempt_builtin/timer/riscv.rs @@ -5,6 +5,7 @@ use peripherals::INTPRI as SystemPeripheral; use peripherals::SYSTEM as SystemPeripheral; use crate::{ + TimeBase, hal::{ interrupt::{self, TrapFrame}, peripherals::{self, Interrupt}, @@ -12,7 +13,6 @@ use crate::{ time::Rate, }, preempt_builtin::task_switch, - TimeBase, }; /// The timer responsible for time slicing. @@ -65,7 +65,7 @@ extern "C" fn handler(trap_frame: &mut TrapFrame) { task_switch(trap_frame); } -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn FROM_CPU_INTR3(trap_frame: &mut TrapFrame) { // clear FROM_CPU_INTR3 SystemPeripheral::regs() diff --git a/esp-wifi/src/preempt_builtin/timer/xtensa.rs b/esp-wifi/src/preempt_builtin/timer/xtensa.rs index 530a850cd..29f308086 100644 --- a/esp-wifi/src/preempt_builtin/timer/xtensa.rs +++ b/esp-wifi/src/preempt_builtin/timer/xtensa.rs @@ -1,9 +1,9 @@ use esp_hal::interrupt::InterruptHandler; use crate::{ + TimeBase, hal::{interrupt, time::Rate, trapframe::TrapFrame, xtensa_lx, xtensa_lx_rt}, preempt_builtin::task_switch, - TimeBase, }; /// The timer responsible for time slicing. @@ -75,8 +75,8 @@ extern "C" fn timer_tick_handler(_context: &mut TrapFrame) { } #[allow(non_snake_case)] -#[cfg_attr(not(esp32), export_name = "Software0")] -#[cfg_attr(esp32, export_name = "Software1")] +#[cfg_attr(not(esp32), unsafe(export_name = "Software0"))] +#[cfg_attr(esp32, unsafe(export_name = "Software1"))] fn task_switch_interrupt(context: &mut TrapFrame) { let intr = SW_INTERRUPT; unsafe { core::arch::asm!("wsr.intclear {0}", in(reg) intr, options(nostack)) }; diff --git a/esp-wifi/src/radio/radio_esp32.rs b/esp-wifi/src/radio/radio_esp32.rs index e86af1387..a5c98f9ff 100644 --- a/esp-wifi/src/radio/radio_esp32.rs +++ b/esp-wifi/src/radio/radio_esp32.rs @@ -34,7 +34,7 @@ pub(crate) fn shutdown_radio_isr() { #[cfg(feature = "ble")] #[allow(non_snake_case)] -#[no_mangle] +#[unsafe(no_mangle)] fn Software0() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_7; @@ -48,7 +48,7 @@ fn Software0() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -62,7 +62,7 @@ extern "C" fn WIFI_MAC() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn RWBT() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_5; @@ -76,7 +76,7 @@ extern "C" fn RWBT() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn RWBLE() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_5; @@ -90,7 +90,7 @@ extern "C" fn RWBLE() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn BT_BB() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_8; diff --git a/esp-wifi/src/radio/radio_esp32c2.rs b/esp-wifi/src/radio/radio_esp32c2.rs index ddd302df6..284c3aa31 100644 --- a/esp-wifi/src/radio/radio_esp32c2.rs +++ b/esp-wifi/src/radio/radio_esp32c2.rs @@ -18,7 +18,7 @@ pub(crate) fn shutdown_radio_isr() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -35,7 +35,7 @@ extern "C" fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -52,7 +52,7 @@ extern "C" fn WIFI_PWR() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn LP_TIMER() { unsafe { trace!("LP_TIMER interrupt"); @@ -74,7 +74,7 @@ extern "C" fn LP_TIMER() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn BT_MAC() { unsafe { trace!("BT_MAC interrupt"); diff --git a/esp-wifi/src/radio/radio_esp32c3.rs b/esp-wifi/src/radio/radio_esp32c3.rs index 11b6e2695..8eefbbe2a 100644 --- a/esp-wifi/src/radio/radio_esp32c3.rs +++ b/esp-wifi/src/radio/radio_esp32c3.rs @@ -19,7 +19,7 @@ pub(crate) fn shutdown_radio_isr() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -36,7 +36,7 @@ extern "C" fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -53,7 +53,7 @@ extern "C" fn WIFI_PWR() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn RWBT() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION5; @@ -70,7 +70,7 @@ extern "C" fn RWBT() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn RWBLE() { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION8; @@ -87,7 +87,7 @@ extern "C" fn RWBLE() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn BT_BB(_trap_frame: &mut crate::hal::interrupt::TrapFrame) { unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::BT_INTERRUPT_FUNCTION5; diff --git a/esp-wifi/src/radio/radio_esp32c6.rs b/esp-wifi/src/radio/radio_esp32c6.rs index 5a6f9e8fe..eb523480a 100644 --- a/esp-wifi/src/radio/radio_esp32c6.rs +++ b/esp-wifi/src/radio/radio_esp32c6.rs @@ -27,7 +27,7 @@ pub(crate) fn shutdown_radio_isr() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -44,7 +44,7 @@ extern "C" fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -61,7 +61,7 @@ extern "C" fn WIFI_PWR() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn LP_TIMER() { unsafe { trace!("LP_TIMER interrupt"); @@ -83,7 +83,7 @@ extern "C" fn LP_TIMER() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn BT_MAC() { unsafe { trace!("BT_MAC interrupt"); diff --git a/esp-wifi/src/radio/radio_esp32h2.rs b/esp-wifi/src/radio/radio_esp32h2.rs index b75f805e7..46d58f78f 100644 --- a/esp-wifi/src/radio/radio_esp32h2.rs +++ b/esp-wifi/src/radio/radio_esp32h2.rs @@ -17,7 +17,7 @@ pub(crate) fn shutdown_radio_isr() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn LP_BLE_TIMER() { unsafe { trace!("LP_TIMER interrupt"); @@ -39,7 +39,7 @@ extern "C" fn LP_BLE_TIMER() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn BT_MAC() { unsafe { trace!("BT_MAC interrupt"); diff --git a/esp-wifi/src/radio/radio_esp32s2.rs b/esp-wifi/src/radio/radio_esp32s2.rs index bd0c7e7b0..c5c9f878b 100644 --- a/esp-wifi/src/radio/radio_esp32s2.rs +++ b/esp-wifi/src/radio/radio_esp32s2.rs @@ -12,7 +12,7 @@ pub(crate) fn shutdown_radio_isr() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -26,7 +26,7 @@ extern "C" fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; diff --git a/esp-wifi/src/radio/radio_esp32s3.rs b/esp-wifi/src/radio/radio_esp32s3.rs index 5b903e9ab..a638d9d63 100644 --- a/esp-wifi/src/radio/radio_esp32s3.rs +++ b/esp-wifi/src/radio/radio_esp32s3.rs @@ -15,7 +15,7 @@ pub(crate) fn shutdown_radio_isr() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_MAC() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -29,7 +29,7 @@ extern "C" fn WIFI_MAC() { } #[cfg(feature = "wifi")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn WIFI_PWR() { unsafe { let (fnc, arg) = crate::wifi::os_adapter::ISR_INTERRUPT_1; @@ -45,7 +45,7 @@ extern "C" fn WIFI_PWR() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn RWBLE() { critical_section::with(|_| unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_8; @@ -58,7 +58,7 @@ extern "C" fn RWBLE() { } #[cfg(feature = "ble")] -#[no_mangle] +#[unsafe(no_mangle)] extern "C" fn BT_BB() { critical_section::with(|_| unsafe { let (fnc, arg) = crate::ble::btdm::ble_os_adapter_chip_specific::ISR_INTERRUPT_5; diff --git a/esp-wifi/src/wifi/event.rs b/esp-wifi/src/wifi/event.rs index ac9976746..5b6cafe3a 100644 --- a/esp-wifi/src/wifi/event.rs +++ b/esp-wifi/src/wifi/event.rs @@ -186,7 +186,8 @@ pub(crate) unsafe fn handle_raw( "wrong size event data" ); - handle::(unsafe { &Event::from_raw_event_data(event_data) }) + let event = unsafe { Event::from_raw_event_data(event_data) }; + handle::(&event) } /// Handle event regardless of its type. @@ -197,7 +198,7 @@ pub(crate) unsafe fn dispatch_event_handler( event: WifiEvent, event_data: *mut crate::binary::c_types::c_void, event_data_size: usize, -) -> bool { +) -> bool { unsafe { match event { WifiEvent::WifiReady => { handle_raw::(event_data, event_data_size) @@ -335,4 +336,4 @@ pub(crate) unsafe fn dispatch_event_handler( handle_raw::(event_data, event_data_size) } } -} +}} diff --git a/esp-wifi/src/wifi/internal.rs b/esp-wifi/src/wifi/internal.rs index 1936b8058..639d81039 100644 --- a/esp-wifi/src/wifi/internal.rs +++ b/esp-wifi/src/wifi/internal.rs @@ -1,10 +1,10 @@ use esp_wifi_sys::include::{ - wifi_init_config_t, - wifi_osi_funcs_t, - wpa_crypto_funcs_t, ESP_WIFI_OS_ADAPTER_MAGIC, ESP_WIFI_OS_ADAPTER_VERSION, WIFI_INIT_CONFIG_MAGIC, + wifi_init_config_t, + wifi_osi_funcs_t, + wpa_crypto_funcs_t, }; use super::os_adapter::*; @@ -50,7 +50,7 @@ unsafe extern "C" fn semphr_take_from_isr_wrapper( semphr: *mut crate::binary::c_types::c_void, hptw: *mut crate::binary::c_types::c_void, ) -> i32 { - crate::common_adapter::semphr_take_from_isr(semphr as *const (), hptw as *const ()) + unsafe { crate::common_adapter::semphr_take_from_isr(semphr as *const (), hptw as *const ()) } } #[cfg(coex)] @@ -58,7 +58,7 @@ unsafe extern "C" fn semphr_give_from_isr_wrapper( semphr: *mut crate::binary::c_types::c_void, hptw: *mut crate::binary::c_types::c_void, ) -> i32 { - crate::common_adapter::semphr_give_from_isr(semphr as *const (), hptw as *const ()) + unsafe { crate::common_adapter::semphr_give_from_isr(semphr as *const (), hptw as *const ()) } } #[cfg(coex)] @@ -67,7 +67,7 @@ unsafe extern "C" fn is_in_isr_wrapper() -> i32 { 0 } -#[no_mangle] +#[unsafe(no_mangle)] static g_wifi_osi_funcs: wifi_osi_funcs_t = wifi_osi_funcs_t { _version: ESP_WIFI_OS_ADAPTER_VERSION as i32, _env_is_chip: Some(env_is_chip), @@ -222,7 +222,7 @@ const WIFI_ENABLE_ENTERPRISE: u64 = 1 << 7; const WIFI_FEATURE_CAPS: u64 = WIFI_ENABLE_WPA3_SAE | WIFI_ENABLE_ENTERPRISE; -#[no_mangle] +#[unsafe(no_mangle)] pub(super) static mut g_wifi_feature_caps: u64 = WIFI_FEATURE_CAPS; pub(super) static mut G_CONFIG: wifi_init_config_t = wifi_init_config_t { diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index 41bd8f32f..f0a4f9ab0 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -17,6 +17,11 @@ use core::{ use enumset::{EnumSet, EnumSetType}; use esp_hal::{asynch::AtomicWaker, sync::Locked}; use esp_wifi_sys::include::{ + WIFI_PROTOCOL_11AX, + WIFI_PROTOCOL_11B, + WIFI_PROTOCOL_11G, + WIFI_PROTOCOL_11N, + WIFI_PROTOCOL_LR, esp_eap_client_clear_ca_cert, esp_eap_client_clear_certificate_and_key, esp_eap_client_clear_identity, @@ -37,11 +42,6 @@ use esp_wifi_sys::include::{ esp_wifi_sta_enterprise_enable, wifi_pkt_rx_ctrl_t, wifi_scan_channel_bitmap_t, - WIFI_PROTOCOL_11AX, - WIFI_PROTOCOL_11B, - WIFI_PROTOCOL_11G, - WIFI_PROTOCOL_11N, - WIFI_PROTOCOL_LR, }; #[cfg(feature = "sniffer")] use esp_wifi_sys::include::{ @@ -62,12 +62,12 @@ use smoltcp::phy::{Device, DeviceCapabilities, RxToken, TxToken}; pub use state::*; use crate::{ + EspWifiController, common_adapter::*, config::PowerSaveMode, esp_wifi_result, hal::ram, wifi::private::EspWifiPacketBuffer, - EspWifiController, }; const MTU: usize = crate::CONFIG.mtu; @@ -766,7 +766,7 @@ impl Configuration { &mut self, ) -> (&mut ClientConfiguration, &mut AccessPointConfiguration) { match self { - Self::Mixed(client_conf, ref mut ap_conf) => (client_conf, ap_conf), + Self::Mixed(client_conf, ap_conf) => (client_conf, ap_conf), Self::AccessPoint(_) => { let prev = mem::replace(self, Self::None); match prev { @@ -923,8 +923,10 @@ unsafe extern "C" fn csi_rx_cb( ctx: *mut crate::wifi::c_types::c_void, data: *mut crate::binary::include::wifi_csi_info_t, ) { - let csi_callback = unsafe { &mut *(ctx as *mut C) }; - csi_callback(*data); + unsafe { + let csi_callback = &mut *(ctx as *mut C); + csi_callback(*data); + } } #[derive(Clone, PartialEq, Eq)] @@ -1388,7 +1390,7 @@ pub(crate) unsafe extern "C" fn coex_init() -> i32 { { debug!("coex-init"); #[allow(clippy::needless_return)] - return crate::binary::include::coex_init(); + return unsafe { crate::binary::include::coex_init() }; } #[cfg(not(coex))] @@ -1414,7 +1416,7 @@ unsafe extern "C" fn recv_cb_sta( // which will try to lock an internal mutex. If the mutex is already taken, // the function will try to trigger a context switch, which will fail if we // are in an interrupt-free context. - if let Ok(()) = DATA_QUEUE_RX_STA.with(|queue| { + match DATA_QUEUE_RX_STA.with(|queue| { if queue.len() < RX_QUEUE_SIZE { queue.push_back(packet); Ok(()) @@ -1422,11 +1424,14 @@ unsafe extern "C" fn recv_cb_sta( Err(packet) } }) { - embassy::STA_RECEIVE_WAKER.wake(); - include::ESP_OK as esp_err_t - } else { - debug!("RX QUEUE FULL"); - include::ESP_ERR_NO_MEM as esp_err_t + Ok(()) => { + embassy::STA_RECEIVE_WAKER.wake(); + include::ESP_OK as esp_err_t + } + _ => { + debug!("RX QUEUE FULL"); + include::ESP_ERR_NO_MEM as esp_err_t + } } } @@ -1442,7 +1447,7 @@ unsafe extern "C" fn recv_cb_ap( // which will try to lock an internal mutex. If the mutex is already taken, // the function will try to trigger a context switch, which will fail if we // are in an interrupt-free context. - if let Ok(()) = DATA_QUEUE_RX_AP.with(|queue| { + match DATA_QUEUE_RX_AP.with(|queue| { if queue.len() < RX_QUEUE_SIZE { queue.push_back(packet); Ok(()) @@ -1450,11 +1455,14 @@ unsafe extern "C" fn recv_cb_ap( Err(packet) } }) { - embassy::AP_RECEIVE_WAKER.wake(); - include::ESP_OK as esp_err_t - } else { - debug!("RX QUEUE FULL"); - include::ESP_ERR_NO_MEM as esp_err_t + Ok(()) => { + embassy::AP_RECEIVE_WAKER.wake(); + include::ESP_OK as esp_err_t + } + _ => { + debug!("RX QUEUE FULL"); + include::ESP_ERR_NO_MEM as esp_err_t + } } } @@ -1556,7 +1564,9 @@ impl Default for ScanTypeConfig { impl ScanTypeConfig { fn validate(&self) { if matches!(self, Self::Passive(dur) if *dur > Duration::from_millis(1500)) { - warn!("Passive scan duration longer than 1500ms may cause a station to disconnect from the AP"); + warn!( + "Passive scan duration longer than 1500ms may cause a station to disconnect from the AP" + ); } } } @@ -1957,48 +1967,52 @@ impl RxControlInfo { /// instance of [wifi_pkt_rx_ctrl_t]. pub unsafe fn from_raw(rx_cntl: *const wifi_pkt_rx_ctrl_t) -> Self { #[cfg(not(esp32c6))] - let rx_control_info = RxControlInfo { - rssi: (*rx_cntl).rssi(), - rate: (*rx_cntl).rate(), - sig_mode: (*rx_cntl).sig_mode(), - mcs: (*rx_cntl).mcs(), - cwb: (*rx_cntl).cwb(), - smoothing: (*rx_cntl).smoothing(), - not_sounding: (*rx_cntl).not_sounding(), - aggregation: (*rx_cntl).aggregation(), - stbc: (*rx_cntl).stbc(), - fec_coding: (*rx_cntl).fec_coding(), - sgi: (*rx_cntl).sgi(), - ampdu_cnt: (*rx_cntl).ampdu_cnt(), - channel: (*rx_cntl).channel(), - secondary_channel: (*rx_cntl).secondary_channel(), - timestamp: (*rx_cntl).timestamp(), - noise_floor: (*rx_cntl).noise_floor(), - ant: (*rx_cntl).ant(), - sig_len: (*rx_cntl).sig_len(), - rx_state: (*rx_cntl).rx_state(), + let rx_control_info = unsafe { + RxControlInfo { + rssi: (*rx_cntl).rssi(), + rate: (*rx_cntl).rate(), + sig_mode: (*rx_cntl).sig_mode(), + mcs: (*rx_cntl).mcs(), + cwb: (*rx_cntl).cwb(), + smoothing: (*rx_cntl).smoothing(), + not_sounding: (*rx_cntl).not_sounding(), + aggregation: (*rx_cntl).aggregation(), + stbc: (*rx_cntl).stbc(), + fec_coding: (*rx_cntl).fec_coding(), + sgi: (*rx_cntl).sgi(), + ampdu_cnt: (*rx_cntl).ampdu_cnt(), + channel: (*rx_cntl).channel(), + secondary_channel: (*rx_cntl).secondary_channel(), + timestamp: (*rx_cntl).timestamp(), + noise_floor: (*rx_cntl).noise_floor(), + ant: (*rx_cntl).ant(), + sig_len: (*rx_cntl).sig_len(), + rx_state: (*rx_cntl).rx_state(), + } }; #[cfg(esp32c6)] - let rx_control_info = RxControlInfo { - rssi: (*rx_cntl).rssi(), - rate: (*rx_cntl).rate(), - sig_len: (*rx_cntl).sig_len(), - rx_state: (*rx_cntl).rx_state(), - dump_len: (*rx_cntl).dump_len(), - he_sigb_len: (*rx_cntl).he_sigb_len(), - cur_single_mpdu: (*rx_cntl).cur_single_mpdu(), - cur_bb_format: (*rx_cntl).cur_bb_format(), - rx_channel_estimate_info_vld: (*rx_cntl).rx_channel_estimate_info_vld(), - rx_channel_estimate_len: (*rx_cntl).rx_channel_estimate_len(), - second: (*rx_cntl).second(), - channel: (*rx_cntl).channel(), - noise_floor: (*rx_cntl).noise_floor(), - is_group: (*rx_cntl).is_group(), - rxend_state: (*rx_cntl).rxend_state(), - rxmatch3: (*rx_cntl).rxmatch3(), - rxmatch2: (*rx_cntl).rxmatch2(), - rxmatch1: (*rx_cntl).rxmatch1(), - rxmatch0: (*rx_cntl).rxmatch0(), + let rx_control_info = unsafe { + RxControlInfo { + rssi: (*rx_cntl).rssi(), + rate: (*rx_cntl).rate(), + sig_len: (*rx_cntl).sig_len(), + rx_state: (*rx_cntl).rx_state(), + dump_len: (*rx_cntl).dump_len(), + he_sigb_len: (*rx_cntl).he_sigb_len(), + cur_single_mpdu: (*rx_cntl).cur_single_mpdu(), + cur_bb_format: (*rx_cntl).cur_bb_format(), + rx_channel_estimate_info_vld: (*rx_cntl).rx_channel_estimate_info_vld(), + rx_channel_estimate_len: (*rx_cntl).rx_channel_estimate_len(), + second: (*rx_cntl).second(), + channel: (*rx_cntl).channel(), + noise_floor: (*rx_cntl).noise_floor(), + is_group: (*rx_cntl).is_group(), + rxend_state: (*rx_cntl).rxend_state(), + rxmatch3: (*rx_cntl).rxmatch3(), + rxmatch2: (*rx_cntl).rxmatch2(), + rxmatch1: (*rx_cntl).rxmatch1(), + rxmatch0: (*rx_cntl).rxmatch0(), + } }; rx_control_info } @@ -2024,16 +2038,18 @@ impl PromiscuousPkt<'_> { buf: *const wifi_promiscuous_pkt_t, frame_type: wifi_promiscuous_pkt_type_t, ) -> Self { - let rx_cntl = RxControlInfo::from_raw(&(*buf).rx_ctrl); + let rx_cntl = unsafe { RxControlInfo::from_raw(&(*buf).rx_ctrl) }; let len = rx_cntl.sig_len as usize; PromiscuousPkt { rx_cntl, frame_type, len, - data: core::slice::from_raw_parts( - (buf as *const u8).add(core::mem::size_of::()), - len, - ), + data: unsafe { + core::slice::from_raw_parts( + (buf as *const u8).add(core::mem::size_of::()), + len, + ) + }, } } } @@ -2043,9 +2059,11 @@ static SNIFFER_CB: Locked)>> = Locked::new(None); #[cfg(feature = "sniffer")] unsafe extern "C" fn promiscuous_rx_cb(buf: *mut core::ffi::c_void, frame_type: u32) { - if let Some(sniffer_callback) = SNIFFER_CB.with(|callback| *callback) { - let promiscuous_pkt = PromiscuousPkt::from_raw(buf as *const _, frame_type); - sniffer_callback(promiscuous_pkt); + unsafe { + if let Some(sniffer_callback) = SNIFFER_CB.with(|callback| *callback) { + let promiscuous_pkt = PromiscuousPkt::from_raw(buf as *const _, frame_type); + sniffer_callback(promiscuous_pkt); + } } } diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index 8c556d88c..c7abda80e 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -15,6 +15,7 @@ use super::WifiEvent; use crate::{ compat::{ common::{ + ConcurrentQueue, create_queue, create_recursive_mutex, delete_queue, @@ -25,7 +26,6 @@ use crate::{ str_from_c, thread_sem_get, unlock_mutex, - ConcurrentQueue, }, malloc::calloc, }, @@ -80,17 +80,16 @@ pub unsafe extern "C" fn env_is_chip() -> bool { pub unsafe extern "C" fn set_intr(cpu_no: i32, intr_source: u32, intr_num: u32, intr_prio: i32) { trace!( "set_intr {} {} {} {}", - cpu_no, - intr_source, - intr_num, - intr_prio - ); - crate::wifi::os_adapter::os_adapter_chip_specific::set_intr( - cpu_no, - intr_source, - intr_num, - intr_prio, + cpu_no, intr_source, intr_num, intr_prio ); + unsafe { + crate::wifi::os_adapter::os_adapter_chip_specific::set_intr( + cpu_no, + intr_source, + intr_num, + intr_prio, + ); + } } /// ************************************************************************** @@ -464,8 +463,10 @@ pub unsafe extern "C" fn queue_send_from_isr( _hptw: *mut crate::binary::c_types::c_void, ) -> i32 { trace!("queue_send_from_isr"); - *(_hptw as *mut u32) = 1; - queue_send(queue, item, 1000) + unsafe { + *(_hptw as *mut u32) = 1; + queue_send(queue, item, 1000) + } } /// ************************************************************************** @@ -651,9 +652,10 @@ pub unsafe extern "C" fn task_create_pinned_to_core( task_handle: *mut crate::binary::c_types::c_void, core_id: u32, ) -> i32 { - trace!("task_create_pinned_to_core task_func {:?} name {} stack_depth {} param {:?} prio {}, task_handle {:?} core_id {}", + trace!( + "task_create_pinned_to_core task_func {:?} name {} stack_depth {} param {:?} prio {}, task_handle {:?} core_id {}", task_func, - str_from_c(name as _), + unsafe { str_from_c(name as _) }, stack_depth, param, prio, @@ -661,15 +663,17 @@ pub unsafe extern "C" fn task_create_pinned_to_core( core_id ); - let task_func = core::mem::transmute::< - *mut crate::binary::c_types::c_void, - extern "C" fn(*mut esp_wifi_sys::c_types::c_void), - >(task_func); + unsafe { + let task_func = core::mem::transmute::< + *mut crate::binary::c_types::c_void, + extern "C" fn(*mut esp_wifi_sys::c_types::c_void), + >(task_func); - let task = crate::preempt::task_create(task_func, param, stack_depth as usize); - *(task_handle as *mut usize) = task as usize; + let task = crate::preempt::task_create(task_func, param, stack_depth as usize); + *(task_handle as *mut usize) = task as usize; - 1 + 1 + } } /// ************************************************************************** @@ -699,7 +703,7 @@ pub unsafe extern "C" fn task_create( prio: u32, task_handle: *mut crate::binary::c_types::c_void, ) -> i32 { - task_create_pinned_to_core(task_func, name, stack_depth, param, prio, task_handle, 0) + unsafe { task_create_pinned_to_core(task_func, name, stack_depth, param, prio, task_handle, 0) } } /// ************************************************************************** @@ -818,7 +822,7 @@ pub unsafe extern "C" fn task_get_max_priority() -> i32 { /// /// ************************************************************************* pub unsafe extern "C" fn malloc(size: usize) -> *mut crate::binary::c_types::c_void { - crate::compat::malloc::malloc(size).cast() + unsafe { crate::compat::malloc::malloc(size).cast() } } /// ************************************************************************** @@ -835,7 +839,9 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut crate::binary::c_types::c_v /// /// ************************************************************************* pub unsafe extern "C" fn free(p: *mut crate::binary::c_types::c_void) { - crate::compat::malloc::free(p.cast()); + unsafe { + crate::compat::malloc::free(p.cast()); + } } /// ************************************************************************** @@ -864,11 +870,7 @@ pub unsafe extern "C" fn event_post( ) -> i32 { trace!( "event_post {:?} {} {:?} {} {:?}", - event_base, - event_id, - event_data, - event_data_size, - ticks_to_wait + event_base, event_id, event_data, event_data_size, ticks_to_wait ); use num_traits::FromPrimitive; @@ -876,7 +878,8 @@ pub unsafe extern "C" fn event_post( trace!("EVENT: {:?}", event); WIFI_EVENTS.with(|events| events.borrow_mut().insert(event)); - let handled = super::event::dispatch_event_handler(event, event_data, event_data_size); + let handled = + unsafe { super::event::dispatch_event_handler(event, event_data, event_data_size) }; super::state::update_state(event, handled); @@ -913,11 +916,11 @@ pub unsafe extern "C" fn event_post( /// /// ************************************************************************* pub unsafe extern "C" fn get_free_heap_size() -> u32 { - extern "C" { + unsafe extern "C" { fn esp_wifi_free_internal_heap() -> usize; } - esp_wifi_free_internal_heap() as u32 + unsafe { esp_wifi_free_internal_heap() as u32 } } /// ************************************************************************** @@ -934,7 +937,7 @@ pub unsafe extern "C" fn get_free_heap_size() -> u32 { /// /// ************************************************************************* pub unsafe extern "C" fn rand() -> u32 { - crate::common_adapter::random() + unsafe { crate::common_adapter::random() } } /// ************************************************************************** @@ -995,7 +998,9 @@ pub unsafe extern "C" fn wifi_apb80m_release() { pub unsafe extern "C" fn phy_disable() { trace!("phy_disable"); - crate::common_adapter::chip_specific::phy_disable(); + unsafe { + crate::common_adapter::chip_specific::phy_disable(); + } } /// ************************************************************************** @@ -1015,7 +1020,9 @@ pub unsafe extern "C" fn phy_enable() { // quite some code needed here trace!("phy_enable"); - crate::common_adapter::chip_specific::phy_enable(); + unsafe { + crate::common_adapter::chip_specific::phy_enable(); + } } /// ************************************************************************** @@ -1029,9 +1036,11 @@ pub unsafe extern "C" fn phy_enable() { pub unsafe extern "C" fn phy_update_country_info( country: *const crate::binary::c_types::c_char, ) -> crate::binary::c_types::c_int { - // not implemented in original code - trace!("phy_update_country_info {}", str_from_c(country.cast())); - -1 + unsafe { + // not implemented in original code + trace!("phy_update_country_info {}", str_from_c(country.cast())); + -1 + } } /// ************************************************************************** @@ -1129,7 +1138,7 @@ pub unsafe extern "C" fn wifi_rtc_disable_iso() { /// System time in micros /// /// ************************************************************************* -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn esp_timer_get_time() -> i64 { trace!("esp_timer_get_time"); crate::time::ticks_to_micros(crate::time::systimer_count()) as i64 @@ -1412,7 +1421,9 @@ pub unsafe extern "C" fn nvs_erase_key( /// ************************************************************************* pub unsafe extern "C" fn get_random(buf: *mut u8, len: usize) -> crate::binary::c_types::c_int { trace!("get_random"); - crate::common_adapter::esp_fill_random(buf, len as u32); + unsafe { + crate::common_adapter::esp_fill_random(buf, len as u32); + } 0 } @@ -1524,7 +1535,7 @@ pub unsafe extern "C" fn log_timestamp() -> u32 { /// /// ************************************************************************* pub unsafe extern "C" fn malloc_internal(size: usize) -> *mut crate::binary::c_types::c_void { - crate::compat::malloc::malloc(size).cast() + unsafe { crate::compat::malloc::malloc(size).cast() } } /// ************************************************************************** @@ -1566,7 +1577,7 @@ pub unsafe extern "C" fn calloc_internal( n: usize, size: usize, ) -> *mut crate::binary::c_types::c_void { - calloc(n as u32, size) as *mut crate::binary::c_types::c_void + unsafe { calloc(n as u32, size) as *mut crate::binary::c_types::c_void } } /// ************************************************************************** @@ -1583,7 +1594,7 @@ pub unsafe extern "C" fn calloc_internal( /// /// ************************************************************************* pub unsafe extern "C" fn zalloc_internal(size: usize) -> *mut crate::binary::c_types::c_void { - calloc(size as u32, 1usize) as *mut crate::binary::c_types::c_void + unsafe { calloc(size as u32, 1usize) as *mut crate::binary::c_types::c_void } } /// ************************************************************************** @@ -1600,7 +1611,7 @@ pub unsafe extern "C" fn zalloc_internal(size: usize) -> *mut crate::binary::c_t /// /// ************************************************************************* pub unsafe extern "C" fn wifi_malloc(size: usize) -> *mut crate::binary::c_types::c_void { - malloc(size) + unsafe { malloc(size) } } /// ************************************************************************** @@ -1640,7 +1651,7 @@ pub unsafe extern "C" fn wifi_realloc( /// ************************************************************************* pub unsafe extern "C" fn wifi_calloc(n: usize, size: usize) -> *mut crate::binary::c_types::c_void { trace!("wifi_calloc {} {}", n, size); - calloc(n as u32, size) as *mut crate::binary::c_types::c_void + unsafe { calloc(n as u32, size) as *mut crate::binary::c_types::c_void } } /// ************************************************************************** @@ -1657,7 +1668,7 @@ pub unsafe extern "C" fn wifi_calloc(n: usize, size: usize) -> *mut crate::binar /// /// ************************************************************************* pub unsafe extern "C" fn wifi_zalloc(size: usize) -> *mut crate::binary::c_types::c_void { - wifi_calloc(size, 1) + unsafe { wifi_calloc(size, 1) } } /// ************************************************************************** @@ -1678,10 +1689,12 @@ pub unsafe extern "C" fn wifi_create_queue( queue_len: crate::binary::c_types::c_int, item_size: crate::binary::c_types::c_int, ) -> *mut crate::binary::c_types::c_void { - let queue = create_queue(queue_len, item_size); - QUEUE_HANDLE = queue; + unsafe { + let queue = create_queue(queue_len, item_size); + QUEUE_HANDLE = queue; - addr_of_mut!(QUEUE_HANDLE).cast() + addr_of_mut!(QUEUE_HANDLE).cast() + } } /// ************************************************************************** @@ -1699,10 +1712,12 @@ pub unsafe extern "C" fn wifi_create_queue( /// ************************************************************************* pub unsafe extern "C" fn wifi_delete_queue(queue: *mut crate::binary::c_types::c_void) { trace!("wifi_delete_queue {:?}", queue); - if core::ptr::eq(queue, addr_of_mut!(QUEUE_HANDLE).cast()) { - delete_queue(QUEUE_HANDLE); - } else { - warn!("unknown queue when trying to delete WIFI queue"); + unsafe { + if core::ptr::eq(queue, addr_of_mut!(QUEUE_HANDLE).cast()) { + delete_queue(QUEUE_HANDLE); + } else { + warn!("unknown queue when trying to delete WIFI queue"); + } } } @@ -1717,7 +1732,9 @@ pub unsafe extern "C" fn coex_deinit() { trace!("coex_deinit"); #[cfg(coex)] - crate::binary::include::coex_deinit(); + unsafe { + crate::binary::include::coex_deinit() + }; } /// ************************************************************************** @@ -1731,7 +1748,7 @@ pub unsafe extern "C" fn coex_enable() -> crate::binary::c_types::c_int { trace!("coex_enable"); #[cfg(coex)] - return crate::binary::include::coex_enable(); + return unsafe { crate::binary::include::coex_enable() }; #[cfg(not(coex))] 0 @@ -1748,7 +1765,9 @@ pub unsafe extern "C" fn coex_disable() { trace!("coex_disable"); #[cfg(coex)] - crate::binary::include::coex_disable(); + unsafe { + crate::binary::include::coex_disable() + }; } /// ************************************************************************** @@ -1762,7 +1781,7 @@ pub unsafe extern "C" fn coex_status_get() -> u32 { trace!("coex_status_get"); #[cfg(coex)] - return crate::binary::include::coex_status_get(); + return unsafe { crate::binary::include::coex_status_get() }; #[cfg(not(coex))] 0 @@ -1784,7 +1803,7 @@ pub unsafe extern "C" fn coex_wifi_request( trace!("coex_wifi_request"); #[cfg(coex)] - return crate::binary::include::coex_wifi_request(event, latency, duration); + return unsafe { crate::binary::include::coex_wifi_request(event, latency, duration) }; #[cfg(not(coex))] 0 @@ -1802,7 +1821,7 @@ pub unsafe extern "C" fn coex_wifi_release(event: u32) -> crate::binary::c_types trace!("coex_wifi_release"); #[cfg(coex)] - return crate::binary::include::coex_wifi_release(event); + return unsafe { crate::binary::include::coex_wifi_release(event) }; #[cfg(not(coex))] 0 @@ -1823,7 +1842,7 @@ pub unsafe extern "C" fn coex_wifi_channel_set( trace!("coex_wifi_channel_set"); #[cfg(coex)] - return crate::binary::include::coex_wifi_channel_set(primary, secondary); + return unsafe { crate::binary::include::coex_wifi_channel_set(primary, secondary) }; #[cfg(not(coex))] 0 @@ -1844,7 +1863,7 @@ pub unsafe extern "C" fn coex_event_duration_get( trace!("coex_event_duration_get"); #[cfg(coex)] - return crate::binary::include::coex_event_duration_get(event, duration); + return unsafe { crate::binary::include::coex_event_duration_get(event, duration) }; #[cfg(not(coex))] 0 @@ -1863,7 +1882,7 @@ pub unsafe extern "C" fn coex_pti_get(event: u32, pti: *mut u8) -> crate::binary trace!("coex_pti_get"); #[cfg(coex)] - return crate::binary::include::coex_pti_get(event, pti); + return unsafe { crate::binary::include::coex_pti_get(event, pti) }; #[cfg(not(coex))] 0 @@ -1887,7 +1906,9 @@ pub unsafe extern "C" fn coex_schm_status_bit_clear(type_: u32, status: u32) { trace!("coex_schm_status_bit_clear"); #[cfg(coex)] - crate::binary::include::coex_schm_status_bit_clear(type_, status); + unsafe { + crate::binary::include::coex_schm_status_bit_clear(type_, status) + }; } /// ************************************************************************** @@ -1902,7 +1923,9 @@ pub unsafe extern "C" fn coex_schm_status_bit_set(type_: u32, status: u32) { trace!("coex_schm_status_bit_set"); #[cfg(coex)] - crate::binary::include::coex_schm_status_bit_set(type_, status); + unsafe { + crate::binary::include::coex_schm_status_bit_set(type_, status) + }; } /// ************************************************************************** @@ -1917,7 +1940,7 @@ pub unsafe extern "C" fn coex_schm_interval_set(interval: u32) -> crate::binary: trace!("coex_schm_interval_set"); #[cfg(coex)] - return crate::binary::include::coex_schm_interval_set(interval); + return unsafe { crate::binary::include::coex_schm_interval_set(interval) }; #[cfg(not(coex))] 0 @@ -1935,7 +1958,7 @@ pub unsafe extern "C" fn coex_schm_interval_get() -> u32 { trace!("coex_schm_interval_get"); #[cfg(coex)] - return crate::binary::include::coex_schm_interval_get(); + return unsafe { crate::binary::include::coex_schm_interval_get() }; #[cfg(not(coex))] 0 @@ -1953,7 +1976,7 @@ pub unsafe extern "C" fn coex_schm_curr_period_get() -> u8 { trace!("coex_schm_curr_period_get"); #[cfg(coex)] - return crate::binary::include::coex_schm_curr_period_get(); + return unsafe { crate::binary::include::coex_schm_curr_period_get() }; #[cfg(not(coex))] 0 @@ -1971,7 +1994,7 @@ pub unsafe extern "C" fn coex_schm_curr_phase_get() -> *mut crate::binary::c_typ trace!("coex_schm_curr_phase_get"); #[cfg(coex)] - return crate::binary::include::coex_schm_curr_phase_get(); + return unsafe { crate::binary::include::coex_schm_curr_phase_get() }; #[cfg(not(coex))] return core::ptr::null_mut(); @@ -1984,7 +2007,9 @@ pub unsafe extern "C" fn coex_schm_process_restart_wrapper() -> esp_wifi_sys::c_ return 0; #[cfg(coex)] - crate::binary::include::coex_schm_process_restart() + unsafe { + crate::binary::include::coex_schm_process_restart() + } } #[allow(unused_variables)] @@ -2000,10 +2025,13 @@ pub unsafe extern "C" fn coex_schm_register_cb_wrapper( return 0; #[cfg(coex)] - crate::binary::include::coex_schm_register_callback( - arg1 as u32, - unwrap!(cb) as *const esp_wifi_sys::c_types::c_void as *mut esp_wifi_sys::c_types::c_void, - ) + unsafe { + crate::binary::include::coex_schm_register_callback( + arg1 as u32, + unwrap!(cb) as *const esp_wifi_sys::c_types::c_void + as *mut esp_wifi_sys::c_types::c_void, + ) + } } pub unsafe extern "C" fn coex_schm_flexible_period_set(period: u8) -> i32 { @@ -2011,7 +2039,7 @@ pub unsafe extern "C" fn coex_schm_flexible_period_set(period: u8) -> i32 { #[cfg(coex)] unsafe { - extern "C" { + unsafe extern "C" { fn coex_schm_flexible_period_set(period: u8) -> i32; } @@ -2027,7 +2055,7 @@ pub unsafe extern "C" fn coex_schm_flexible_period_get() -> u8 { #[cfg(coex)] unsafe { - extern "C" { + unsafe extern "C" { fn coex_schm_flexible_period_get() -> u8; } @@ -2042,7 +2070,7 @@ pub unsafe extern "C" fn coex_register_start_cb( _cb: Option esp_wifi_sys::c_types::c_int>, ) -> esp_wifi_sys::c_types::c_int { #[cfg(coex)] - return esp_wifi_sys::include::coex_register_start_cb(_cb); + return unsafe { esp_wifi_sys::include::coex_register_start_cb(_cb) }; #[cfg(not(coex))] 0 diff --git a/esp-wifi/src/wifi/os_adapter_esp32.rs b/esp-wifi/src/wifi/os_adapter_esp32.rs index 08ec47fc3..fe7d3a8c4 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32.rs @@ -9,11 +9,15 @@ pub(crate) fn chip_ints_off(mask: u32) { } pub(crate) unsafe extern "C" fn phy_common_clock_disable() { - crate::common_adapter::phy_disable_clock(); + unsafe { + crate::common_adapter::phy_disable_clock(); + } } pub(crate) unsafe extern "C" fn phy_common_clock_enable() { - crate::common_adapter::phy_enable_clock(); + unsafe { + crate::common_adapter::phy_enable_clock(); + } } pub(crate) unsafe extern "C" fn set_intr( @@ -22,11 +26,13 @@ pub(crate) unsafe extern "C" fn set_intr( intr_num: u32, _intr_prio: i32, ) { - extern "C" { + unsafe extern "C" { fn intr_matrix_set(cpu_no: u32, model_num: u32, intr_num: u32); } - // Force to bind WiFi interrupt to CPU0 - intr_matrix_set(0, intr_source, intr_num); + unsafe { + // Force to bind WiFi interrupt to CPU0 + intr_matrix_set(0, intr_source, intr_num); + } } /// ************************************************************************** @@ -50,14 +56,13 @@ pub unsafe extern "C" fn set_isr( arg: *mut crate::binary::c_types::c_void, ) { trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); - match n { - 0 => { + 0 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } - 1 => { + }, + 1 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } + }, _ => panic!("set_isr - unsupported interrupt number {}", n), } #[cfg(feature = "wifi")] diff --git a/esp-wifi/src/wifi/os_adapter_esp32c2.rs b/esp-wifi/src/wifi/os_adapter_esp32c2.rs index 65b89b947..be30b9ac9 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c2.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c2.rs @@ -52,14 +52,13 @@ pub unsafe extern "C" fn set_isr( arg: *mut crate::binary::c_types::c_void, ) { trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); - match n { - 0 => { + 0 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } - 1 => { + }, + 1 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } + }, _ => panic!("set_isr - unsupported interrupt number {}", n), } #[cfg(feature = "wifi")] diff --git a/esp-wifi/src/wifi/os_adapter_esp32c3.rs b/esp-wifi/src/wifi/os_adapter_esp32c3.rs index 68a2bf2c6..cd9eb9ef7 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c3.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c3.rs @@ -52,14 +52,13 @@ pub unsafe extern "C" fn set_isr( arg: *mut crate::binary::c_types::c_void, ) { trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); - match n { - 0 => { + 0 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } - 1 => { + }, + 1 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } + }, _ => panic!("set_isr - unsupported interrupt number {}", n), } diff --git a/esp-wifi/src/wifi/os_adapter_esp32c6.rs b/esp-wifi/src/wifi/os_adapter_esp32c6.rs index f73118c16..b42b6517f 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32c6.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32c6.rs @@ -68,12 +68,12 @@ pub unsafe extern "C" fn set_isr( trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); match n { - 0 => { + 0 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } - 1 => { + }, + 1 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } + }, _ => panic!("set_isr - unsupported interrupt number {}", n), } #[cfg(feature = "wifi")] diff --git a/esp-wifi/src/wifi/os_adapter_esp32h2.rs b/esp-wifi/src/wifi/os_adapter_esp32h2.rs index 3fc920b7a..f74b559bc 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32h2.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32h2.rs @@ -83,12 +83,12 @@ pub unsafe extern "C" fn set_isr( trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); match n { - 0 => { + 0 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } - 1 => { + }, + 1 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } + }, _ => panic!("set_isr - unsupported interrupt number {}", n), } } diff --git a/esp-wifi/src/wifi/os_adapter_esp32s2.rs b/esp-wifi/src/wifi/os_adapter_esp32s2.rs index 5c0d01a3f..3dd2b28e3 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32s2.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32s2.rs @@ -14,19 +14,25 @@ pub(crate) unsafe extern "C" fn set_intr( intr_num: u32, _intr_prio: i32, ) { - extern "C" { + unsafe extern "C" { fn intr_matrix_set(cpu_no: u32, model_num: u32, intr_num: u32); } - // Force to bind WiFi interrupt to CPU0 - intr_matrix_set(0, intr_source, intr_num); + unsafe { + // Force to bind WiFi interrupt to CPU0 + intr_matrix_set(0, intr_source, intr_num); + } } pub(crate) unsafe extern "C" fn phy_common_clock_disable() { - crate::common_adapter::phy_disable_clock(); + unsafe { + crate::common_adapter::phy_disable_clock(); + } } pub(crate) unsafe extern "C" fn phy_common_clock_enable() { - crate::common_adapter::phy_enable_clock(); + unsafe { + crate::common_adapter::phy_enable_clock(); + } } /// ************************************************************************** @@ -52,12 +58,12 @@ pub unsafe extern "C" fn set_isr( trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); match n { - 0 => { + 0 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } - 1 => { + }, + 1 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } + }, _ => panic!("set_isr - unsupported interrupt number {}", n), } diff --git a/esp-wifi/src/wifi/os_adapter_esp32s3.rs b/esp-wifi/src/wifi/os_adapter_esp32s3.rs index 94240b9b4..165b306d3 100644 --- a/esp-wifi/src/wifi/os_adapter_esp32s3.rs +++ b/esp-wifi/src/wifi/os_adapter_esp32s3.rs @@ -14,11 +14,13 @@ pub(crate) unsafe extern "C" fn set_intr( intr_num: u32, _intr_prio: i32, ) { - extern "C" { + unsafe extern "C" { fn intr_matrix_set(cpu_no: u32, model_num: u32, intr_num: u32); } - // Force to bind WiFi interrupt to CPU0 - intr_matrix_set(0, intr_source, intr_num); + unsafe { + // Force to bind WiFi interrupt to CPU0 + intr_matrix_set(0, intr_source, intr_num); + } } /// ************************************************************************** @@ -44,12 +46,12 @@ pub unsafe extern "C" fn set_isr( trace!("set_isr - interrupt {} function {:?} arg {:?}", n, f, arg); match n { - 0 => { + 0 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } - 1 => { + }, + 1 => unsafe { crate::wifi::ISR_INTERRUPT_1 = (f, arg); - } + }, _ => panic!("set_isr - unsupported interrupt number {}", n), } #[cfg(feature = "wifi")] diff --git a/examples/Cargo.toml b/examples/Cargo.toml index d7fee1d7b..619346675 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "examples" version = "0.0.0" -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" publish = false diff --git a/examples/src/bin/debug_assist.rs b/examples/src/bin/debug_assist.rs index ad306862d..45ea3a5e3 100644 --- a/examples/src/bin/debug_assist.rs +++ b/examples/src/bin/debug_assist.rs @@ -28,7 +28,7 @@ fn main() -> ! { if #[cfg(not(feature = "esp32s3"))] { use core::ptr::addr_of_mut; - extern "C" { + unsafe extern "C" { // top of stack static mut _stack_start: u32; // bottom of stack diff --git a/examples/src/bin/dma_extmem2mem.rs b/examples/src/bin/dma_extmem2mem.rs index 0f8031c72..ceab43e30 100644 --- a/examples/src/bin/dma_extmem2mem.rs +++ b/examples/src/bin/dma_extmem2mem.rs @@ -8,7 +8,7 @@ #![no_std] #![no_main] -use aligned::{Aligned, A64}; +use aligned::{A64, Aligned}; use esp_alloc as _; use esp_backtrace as _; use esp_hal::{ @@ -66,8 +66,8 @@ fn main() -> ! { let delay = Delay::new(); - let mut extram_buffer: &mut [u8] = dma_alloc_buffer!(DATA_SIZE, 64); - let mut intram_buffer = dma_buffer_aligned!(DATA_SIZE, A64); + let extram_buffer: &mut [u8] = dma_alloc_buffer!(DATA_SIZE, 64); + let intram_buffer = dma_buffer_aligned!(DATA_SIZE, A64); let (rx_descriptors, tx_descriptors) = dma_descriptors_chunk_size!(DATA_SIZE, CHUNK_SIZE); let dma_peripheral = peripherals.SPI2; diff --git a/examples/src/bin/embassy_multicore.rs b/examples/src/bin/embassy_multicore.rs index 188829a95..6a1e168c6 100644 --- a/examples/src/bin/embassy_multicore.rs +++ b/examples/src/bin/embassy_multicore.rs @@ -21,7 +21,7 @@ use esp_backtrace as _; use esp_hal::{ gpio::{Level, Output, OutputConfig}, system::{Cpu, CpuControl, Stack}, - timer::{timg::TimerGroup, AnyTimer}, + timer::{AnyTimer, timg::TimerGroup}, }; use esp_hal_embassy::Executor; use esp_println::println; diff --git a/examples/src/bin/embassy_multicore_interrupt.rs b/examples/src/bin/embassy_multicore_interrupt.rs index 7f02ed053..297b1f6be 100644 --- a/examples/src/bin/embassy_multicore_interrupt.rs +++ b/examples/src/bin/embassy_multicore_interrupt.rs @@ -19,10 +19,10 @@ use embassy_time::{Duration, Ticker}; use esp_backtrace as _; use esp_hal::{ gpio::{Level, Output, OutputConfig}, - interrupt::{software::SoftwareInterruptControl, Priority}, + interrupt::{Priority, software::SoftwareInterruptControl}, main, system::{Cpu, CpuControl, Stack}, - timer::{timg::TimerGroup, AnyTimer}, + timer::{AnyTimer, timg::TimerGroup}, }; use esp_hal_embassy::InterruptExecutor; use esp_println::println; diff --git a/examples/src/bin/embassy_multiprio.rs b/examples/src/bin/embassy_multiprio.rs index f72f1f6fe..e3693b34e 100644 --- a/examples/src/bin/embassy_multiprio.rs +++ b/examples/src/bin/embassy_multiprio.rs @@ -24,8 +24,8 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Instant, Ticker, Timer}; use esp_backtrace as _; use esp_hal::{ - interrupt::{software::SoftwareInterruptControl, Priority}, - timer::{timg::TimerGroup, AnyTimer}, + interrupt::{Priority, software::SoftwareInterruptControl}, + timer::{AnyTimer, timg::TimerGroup}, }; use esp_hal_embassy::InterruptExecutor; use esp_println::println; @@ -58,7 +58,9 @@ async fn low_prio_blocking() { /// A well-behaved, but starved async task. #[embassy_executor::task] async fn low_prio_async() { - println!("Starting low-priority task that will not be able to run while the blocking task is running"); + println!( + "Starting low-priority task that will not be able to run while the blocking task is running" + ); let mut ticker = Ticker::every(Duration::from_secs(1)); loop { println!("Low priority ticks"); diff --git a/examples/src/bin/embassy_serial.rs b/examples/src/bin/embassy_serial.rs index 6cf5279a0..3df1ae516 100644 --- a/examples/src/bin/embassy_serial.rs +++ b/examples/src/bin/embassy_serial.rs @@ -13,9 +13,9 @@ use embassy_executor::Spawner; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; use esp_backtrace as _; use esp_hal::{ + Async, timer::timg::TimerGroup, uart::{AtCmdConfig, Config, RxConfig, Uart, UartRx, UartTx}, - Async, }; use static_cell::StaticCell; diff --git a/examples/src/bin/embassy_spi.rs b/examples/src/bin/embassy_spi.rs index 77dfcabd7..744d9b6ce 100644 --- a/examples/src/bin/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -25,8 +25,8 @@ use esp_hal::{ dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, spi::{ - master::{Config, Spi}, Mode, + master::{Config, Spi}, }, time::Rate, timer::timg::TimerGroup, diff --git a/examples/src/bin/embassy_usb_serial.rs b/examples/src/bin/embassy_usb_serial.rs index fbcf4961f..660f9c518 100644 --- a/examples/src/bin/embassy_usb_serial.rs +++ b/examples/src/bin/embassy_usb_serial.rs @@ -15,15 +15,15 @@ use embassy_executor::Spawner; use embassy_futures::join::join; use embassy_usb::{ + Builder, class::cdc_acm::{CdcAcmClass, State}, driver::EndpointError, - Builder, }; use esp_backtrace as _; use esp_hal::{ otg_fs::{ - asynch::{Config, Driver}, Usb, + asynch::{Config, Driver}, }, timer::timg::TimerGroup, }; diff --git a/examples/src/bin/embassy_usb_serial_jtag.rs b/examples/src/bin/embassy_usb_serial_jtag.rs index c7b5a7179..2a6c0154f 100644 --- a/examples/src/bin/embassy_usb_serial_jtag.rs +++ b/examples/src/bin/embassy_usb_serial_jtag.rs @@ -12,9 +12,9 @@ use embassy_executor::Spawner; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; use esp_backtrace as _; use esp_hal::{ + Async, timer::timg::TimerGroup, usb_serial_jtag::{UsbSerialJtag, UsbSerialJtagRx, UsbSerialJtagTx}, - Async, }; use static_cell::StaticCell; diff --git a/examples/src/bin/etm_timer.rs b/examples/src/bin/etm_timer.rs index 184d8756f..e29ec943e 100644 --- a/examples/src/bin/etm_timer.rs +++ b/examples/src/bin/etm_timer.rs @@ -13,17 +13,17 @@ use esp_backtrace as _; use esp_hal::{ etm::Etm, gpio::{ - etm::{Channels, OutputConfig as EtmOutputConfig}, Level, Output, OutputConfig, Pull, + etm::{Channels, OutputConfig as EtmOutputConfig}, }, main, time::Duration, timer::{ - systimer::{etm::Event, SystemTimer}, PeriodicTimer, + systimer::{SystemTimer, etm::Event}, }, }; diff --git a/examples/src/bin/hmac.rs b/examples/src/bin/hmac.rs index f7eefef48..a7c6f3571 100644 --- a/examples/src/bin/hmac.rs +++ b/examples/src/bin/hmac.rs @@ -110,7 +110,13 @@ fn main() -> ! { for (a, b) in output.iter().zip(soft_result) { assert_eq!(*a, b); } - println!("Testing for length: {:>4} | HW: {:>6} cycles, SW: {:>7} cycles (HW HMAC is {:>2}x faster)", i, hw_time, soft_time, soft_time / hw_time); + println!( + "Testing for length: {:>4} | HW: {:>6} cycles, SW: {:>7} cycles (HW HMAC is {:>2}x faster)", + i, + hw_time, + soft_time, + soft_time / hw_time + ); } println!("Finished stress tests!"); diff --git a/examples/src/bin/spi_loopback.rs b/examples/src/bin/spi_loopback.rs index f8540bbc1..98774dd88 100644 --- a/examples/src/bin/spi_loopback.rs +++ b/examples/src/bin/spi_loopback.rs @@ -21,8 +21,8 @@ use esp_hal::{ delay::Delay, main, spi::{ - master::{Config, Spi}, Mode, + master::{Config, Spi}, }, time::Rate, }; diff --git a/examples/src/bin/spi_loopback_dma_psram.rs b/examples/src/bin/spi_loopback_dma_psram.rs index 993b08398..5167f6684 100644 --- a/examples/src/bin/spi_loopback_dma_psram.rs +++ b/examples/src/bin/spi_loopback_dma_psram.rs @@ -27,8 +27,8 @@ use esp_hal::{ dma::{DmaRxBuf, DmaTxBuf, ExternalBurstConfig}, main, spi::{ - master::{Config, Spi}, Mode, + master::{Config, Spi}, }, time::Rate, }; diff --git a/examples/src/bin/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs index e65ebc8ef..aeb2270ab 100644 --- a/examples/src/bin/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -37,7 +37,7 @@ use esp_hal::{ dma_buffers, gpio::{Input, InputConfig, Level, Output, OutputConfig, Pull}, main, - spi::{slave::Spi, Mode}, + spi::{Mode, slave::Spi}, }; use esp_println::println; diff --git a/examples/src/bin/touch.rs b/examples/src/bin/touch.rs index 48d847eac..f8a58df24 100644 --- a/examples/src/bin/touch.rs +++ b/examples/src/bin/touch.rs @@ -17,6 +17,7 @@ use core::cell::RefCell; use critical_section::Mutex; use esp_backtrace as _; use esp_hal::{ + Blocking, delay::Delay, handler, main, @@ -24,7 +25,6 @@ use esp_hal::{ ram, rtc_cntl::Rtc, touch::{Continuous, Touch, TouchConfig, TouchPad}, - Blocking, }; use esp_println::println; diff --git a/examples/src/bin/twai.rs b/examples/src/bin/twai.rs index 72382ebae..dfec3818d 100644 --- a/examples/src/bin/twai.rs +++ b/examples/src/bin/twai.rs @@ -31,7 +31,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, main, - twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode}, + twai::{self, EspTwaiFrame, StandardId, TwaiMode, filter::SingleStandardFilter}, }; use esp_println::println; use nb::block; diff --git a/examples/src/bin/wifi_80211_tx.rs b/examples/src/bin/wifi_80211_tx.rs index 9f5532b67..669aff34a 100644 --- a/examples/src/bin/wifi_80211_tx.rs +++ b/examples/src/bin/wifi_80211_tx.rs @@ -27,7 +27,7 @@ use ieee80211::{ common::{CapabilitiesInformation, FCFFlags}, element_chain, elements::{DSSSParameterSetElement, RawIEEE80211Element, SSIDElement}, - mgmt_frame::{body::BeaconBody, header::ManagementFrameHeader, BeaconFrame}, + mgmt_frame::{BeaconFrame, body::BeaconBody, header::ManagementFrameHeader}, scroll::Pwrite, supported_rates, }; diff --git a/examples/src/bin/wifi_access_point.rs b/examples/src/bin/wifi_access_point.rs index 393be498c..ec3b0b90e 100644 --- a/examples/src/bin/wifi_access_point.rs +++ b/examples/src/bin/wifi_access_point.rs @@ -29,9 +29,9 @@ use esp_println::{print, println}; use esp_wifi::{ init, wifi::{ - event::{self, EventExt}, AccessPointConfiguration, Configuration, + event::{self, EventExt}, }, }; use smoltcp::iface::{SocketSet, SocketStorage}; @@ -110,7 +110,9 @@ fn main() -> ! { )) .unwrap(); - println!("Start busy loop on main. Connect to the AP `esp-wifi` and point your browser to http://192.168.2.1:8080/"); + println!( + "Start busy loop on main. Connect to the AP `esp-wifi` and point your browser to http://192.168.2.1:8080/" + ); println!("Use a static IP in the range 192.168.2.2 .. 192.168.2.255, use gateway 192.168.2.1"); let mut rx_buffer = [0u8; 1536]; diff --git a/examples/src/bin/wifi_access_point_with_sta.rs b/examples/src/bin/wifi_access_point_with_sta.rs index 1663dc96c..58abb4228 100644 --- a/examples/src/bin/wifi_access_point_with_sta.rs +++ b/examples/src/bin/wifi_access_point_with_sta.rs @@ -124,7 +124,9 @@ fn main() -> ! { } } - println!("Start busy loop on main. Connect to the AP `esp-wifi` and point your browser to http://192.168.2.1:8080/"); + println!( + "Start busy loop on main. Connect to the AP `esp-wifi` and point your browser to http://192.168.2.1:8080/" + ); println!("Use a static IP in the range 192.168.2.2 .. 192.168.2.255, use gateway 192.168.2.1"); let mut rx_buffer = [0u8; 1536]; diff --git a/examples/src/bin/wifi_ble.rs b/examples/src/bin/wifi_ble.rs index ed54fefd5..64292c88d 100644 --- a/examples/src/bin/wifi_ble.rs +++ b/examples/src/bin/wifi_ble.rs @@ -11,16 +11,16 @@ #![no_main] use bleps::{ + Ble, + HciConnector, ad_structure::{ - create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE, + create_advertising_data, }, attribute_server::{AttributeServer, NotificationData, WorkResult}, gatt, - Ble, - HciConnector, }; use esp_alloc as _; use esp_backtrace as _; diff --git a/examples/src/bin/wifi_coex.rs b/examples/src/bin/wifi_coex.rs index c59a77b72..9f5566935 100644 --- a/examples/src/bin/wifi_coex.rs +++ b/examples/src/bin/wifi_coex.rs @@ -17,15 +17,15 @@ use core::net::Ipv4Addr; use bleps::{ + Ble, + HciConnector, ad_structure::{ - create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE, + create_advertising_data, }, att::Uuid, - Ble, - HciConnector, }; use blocking_network_stack::Stack; use embedded_io::*; @@ -60,7 +60,7 @@ fn main() -> ! { esp_alloc::heap_allocator!(size: 72 * 1024); // COEX needs more RAM - add some more - esp_alloc::heap_allocator!(#[link_section = ".dram2_uninit"] size: 64 * 1024); + esp_alloc::heap_allocator!(#[unsafe(link_section = ".dram2_uninit")] size: 64 * 1024); let timg0 = TimerGroup::new(peripherals.TIMG0); diff --git a/examples/src/bin/wifi_embassy_access_point.rs b/examples/src/bin/wifi_embassy_access_point.rs index 7d0d019fd..25f9a75a9 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -16,13 +16,13 @@ use core::{net::Ipv4Addr, str::FromStr}; use embassy_executor::Spawner; use embassy_net::{ - tcp::TcpSocket, IpListenEndpoint, Ipv4Cidr, Runner, Stack, StackResources, StaticConfigV4, + tcp::TcpSocket, }; use embassy_time::{Duration, Timer}; use esp_alloc as _; @@ -30,6 +30,7 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ + EspWifiController, init, wifi::{ AccessPointConfiguration, @@ -39,7 +40,6 @@ use esp_wifi::{ WifiEvent, WifiState, }, - EspWifiController, }; // When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html diff --git a/examples/src/bin/wifi_embassy_access_point_with_sta.rs b/examples/src/bin/wifi_embassy_access_point_with_sta.rs index 9e2d93986..be680275c 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -25,12 +25,12 @@ use core::net::Ipv4Addr; use embassy_executor::Spawner; use embassy_futures::select::Either; use embassy_net::{ - tcp::TcpSocket, IpListenEndpoint, Ipv4Cidr, Runner, StackResources, StaticConfigV4, + tcp::TcpSocket, }; use embassy_time::{Duration, Timer}; use esp_alloc as _; @@ -38,6 +38,7 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_wifi::{ + EspWifiController, init, wifi::{ AccessPointConfiguration, @@ -48,7 +49,6 @@ use esp_wifi::{ WifiEvent, WifiState, }, - EspWifiController, }; const SSID: &str = env!("SSID"); diff --git a/examples/src/bin/wifi_embassy_bench.rs b/examples/src/bin/wifi_embassy_bench.rs index c4d3fc729..a14569cb6 100644 --- a/examples/src/bin/wifi_embassy_bench.rs +++ b/examples/src/bin/wifi_embassy_bench.rs @@ -21,16 +21,16 @@ use core::net::Ipv4Addr; use embassy_executor::Spawner; use embassy_futures::join::join; -use embassy_net::{tcp::TcpSocket, Runner, StackResources}; -use embassy_time::{with_timeout, Duration, Timer}; +use embassy_net::{Runner, StackResources, tcp::TcpSocket}; +use embassy_time::{Duration, Timer, with_timeout}; use esp_alloc as _; use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ + EspWifiController, init, wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState}, - EspWifiController, }; // When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html @@ -67,7 +67,7 @@ async fn main(spawner: Spawner) -> ! { esp_alloc::heap_allocator!(size: 32 * 1024); // add some more RAM - esp_alloc::heap_allocator!(#[link_section = ".dram2_uninit"] size: 64 * 1024); + esp_alloc::heap_allocator!(#[unsafe(link_section = ".dram2_uninit")] size: 64 * 1024); let server_address: Ipv4Addr = HOST_IP.parse().expect("Invalid HOST_IP address"); diff --git a/examples/src/bin/wifi_embassy_ble.rs b/examples/src/bin/wifi_embassy_ble.rs index 6fa82b0f8..a1f11acc0 100644 --- a/examples/src/bin/wifi_embassy_ble.rs +++ b/examples/src/bin/wifi_embassy_ble.rs @@ -14,10 +14,10 @@ use core::cell::RefCell; use bleps::{ ad_structure::{ - create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE, + create_advertising_data, }, async_attribute_server::AttributeServer, asynch::Ble, @@ -35,7 +35,7 @@ use esp_hal::{ timer::timg::TimerGroup, }; use esp_println::println; -use esp_wifi::{ble::controller::BleConnector, init, EspWifiController}; +use esp_wifi::{EspWifiController, ble::controller::BleConnector, init}; // When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html macro_rules! mk_static { diff --git a/examples/src/bin/wifi_embassy_dhcp.rs b/examples/src/bin/wifi_embassy_dhcp.rs index 231a4b240..9030e02d4 100644 --- a/examples/src/bin/wifi_embassy_dhcp.rs +++ b/examples/src/bin/wifi_embassy_dhcp.rs @@ -16,16 +16,16 @@ use core::net::Ipv4Addr; use embassy_executor::Spawner; -use embassy_net::{tcp::TcpSocket, Runner, StackResources}; +use embassy_net::{Runner, StackResources, tcp::TcpSocket}; use embassy_time::{Duration, Timer}; use esp_alloc as _; use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ + EspWifiController, init, wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState}, - EspWifiController, }; // When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html diff --git a/examples/src/bin/wifi_embassy_esp_now.rs b/examples/src/bin/wifi_embassy_esp_now.rs index f11049bc4..8f1b02cd1 100644 --- a/examples/src/bin/wifi_embassy_esp_now.rs +++ b/examples/src/bin/wifi_embassy_esp_now.rs @@ -11,16 +11,16 @@ #![no_main] use embassy_executor::Spawner; -use embassy_futures::select::{select, Either}; +use embassy_futures::select::{Either, select}; use embassy_time::{Duration, Ticker}; use esp_alloc as _; use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ - esp_now::{PeerInfo, BROADCAST_ADDRESS}, - init, EspWifiController, + esp_now::{BROADCAST_ADDRESS, PeerInfo}, + init, }; // When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html diff --git a/examples/src/bin/wifi_embassy_esp_now_duplex.rs b/examples/src/bin/wifi_embassy_esp_now_duplex.rs index 436b85d8f..a4a7a84de 100644 --- a/examples/src/bin/wifi_embassy_esp_now_duplex.rs +++ b/examples/src/bin/wifi_embassy_esp_now_duplex.rs @@ -18,9 +18,9 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_wifi::{ - esp_now::{EspNowManager, EspNowReceiver, EspNowSender, PeerInfo, BROADCAST_ADDRESS}, - init, EspWifiController, + esp_now::{BROADCAST_ADDRESS, EspNowManager, EspNowReceiver, EspNowSender, PeerInfo}, + init, }; // When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html diff --git a/examples/src/bin/wifi_esp_now.rs b/examples/src/bin/wifi_esp_now.rs index a0f9d999e..5f657f7d1 100644 --- a/examples/src/bin/wifi_esp_now.rs +++ b/examples/src/bin/wifi_esp_now.rs @@ -19,7 +19,7 @@ use esp_hal::{ }; use esp_println::println; use esp_wifi::{ - esp_now::{PeerInfo, BROADCAST_ADDRESS}, + esp_now::{BROADCAST_ADDRESS, PeerInfo}, init, }; diff --git a/hil-test/Cargo.toml b/hil-test/Cargo.toml index 905aa3248..78110df82 100644 --- a/hil-test/Cargo.toml +++ b/hil-test/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "hil-test" version = "0.0.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/hil-test/src/lib.rs b/hil-test/src/lib.rs index 1ce1a1b44..b9484b660 100644 --- a/hil-test/src/lib.rs +++ b/hil-test/src/lib.rs @@ -89,9 +89,9 @@ macro_rules! unconnected_pin { mod executor { use core::marker::PhantomData; - use embassy_executor::{raw, Spawner}; + use embassy_executor::{Spawner, raw}; - #[export_name = "__pender"] + #[unsafe(export_name = "__pender")] fn __pender(_: *mut ()) {} pub struct Executor { diff --git a/hil-test/tests/aes_dma.rs b/hil-test/tests/aes_dma.rs index a5418fb51..93c719754 100644 --- a/hil-test/tests/aes_dma.rs +++ b/hil-test/tests/aes_dma.rs @@ -7,7 +7,7 @@ #![no_main] use esp_hal::{ - aes::{dma::CipherMode, Aes, Mode}, + aes::{Aes, Mode, dma::CipherMode}, dma_buffers, peripherals::Peripherals, }; diff --git a/hil-test/tests/critical_section.rs b/hil-test/tests/critical_section.rs index d1d32c83f..ee764df10 100644 --- a/hil-test/tests/critical_section.rs +++ b/hil-test/tests/critical_section.rs @@ -11,9 +11,9 @@ use esp_hal::{ delay::Delay, interrupt::{ - software::{SoftwareInterrupt, SoftwareInterruptControl}, InterruptHandler, Priority, + software::{SoftwareInterrupt, SoftwareInterruptControl}, }, peripherals::Peripherals, sync::{Locked, RawPriorityLimitedMutex}, diff --git a/hil-test/tests/delay_async.rs b/hil-test/tests/delay_async.rs index 56c19ddcb..d8395ca1c 100644 --- a/hil-test/tests/delay_async.rs +++ b/hil-test/tests/delay_async.rs @@ -17,7 +17,7 @@ use embedded_hal_async::delay::DelayNs; use esp_hal::timer::systimer::SystemTimer; use esp_hal::{ peripherals::Peripherals, - timer::{timg::TimerGroup, OneShotTimer}, + timer::{OneShotTimer, timg::TimerGroup}, }; use hil_test as _; diff --git a/hil-test/tests/dma_mem2mem.rs b/hil-test/tests/dma_mem2mem.rs index 7396f214a..956f45a27 100644 --- a/hil-test/tests/dma_mem2mem.rs +++ b/hil-test/tests/dma_mem2mem.rs @@ -7,10 +7,10 @@ #![no_main] use esp_hal::{ + Blocking, dma::{DmaError, Mem2Mem}, dma_buffers, dma_descriptors, - Blocking, }; use hil_test as _; diff --git a/hil-test/tests/ecc.rs b/hil-test/tests/ecc.rs index d290fbd7a..f9e185766 100644 --- a/hil-test/tests/ecc.rs +++ b/hil-test/tests/ecc.rs @@ -9,19 +9,19 @@ use core::ops::Mul; use crypto_bigint::{ - modular::runtime_mod::{DynResidue, DynResidueParams}, Encoding, U192, U256, + modular::runtime_mod::{DynResidue, DynResidueParams}, }; use elliptic_curve::sec1::ToEncodedPoint; #[cfg(feature = "esp32h2")] use esp_hal::ecc::WorkMode; use esp_hal::{ + Blocking, clock::CpuClock, ecc::{Ecc, EllipticCurve, Error}, rng::Rng, - Blocking, }; use hex_literal::hex; use hil_test as _; @@ -290,12 +290,15 @@ mod tests { .ecc .affine_point_verification_multiplication(curve, k, px, py, qx, qy, qz); match result { - Err(Error::SizeMismatchCurve) => assert!(false, "Inputs data doesn't match the key length selected."), + Err(Error::SizeMismatchCurve) => { + assert!(false, "Inputs data doesn't match the key length selected.") + } Err(Error::PointNotOnSelectedCurve) => assert!( - false, "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", + false, + "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", px, py, ), - _ => {}, + _ => {} } let t2 = &mut [0_u8; 64]; @@ -604,13 +607,19 @@ mod tests { _ => unimplemented!(), }; - match ctx.ecc.affine_point_verification_jacobian_multiplication(curve, k, x, y) { - Err(Error::SizeMismatchCurve) => assert!(false, "Inputs data doesn't match the key length selected."), + match ctx + .ecc + .affine_point_verification_jacobian_multiplication(curve, k, x, y) + { + Err(Error::SizeMismatchCurve) => { + assert!(false, "Inputs data doesn't match the key length selected.") + } Err(Error::PointNotOnSelectedCurve) => assert!( - false, "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", + false, + "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", x, y, ), - _ => {}, + _ => {} } match prime_field.len() { diff --git a/hil-test/tests/embassy_interrupt_executor.rs b/hil-test/tests/embassy_interrupt_executor.rs index 07016f65f..1355e1b52 100644 --- a/hil-test/tests/embassy_interrupt_executor.rs +++ b/hil-test/tests/embassy_interrupt_executor.rs @@ -18,8 +18,8 @@ use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal} use esp_hal::system::{CpuControl, Stack}; use esp_hal::{ interrupt::{ - software::{SoftwareInterrupt, SoftwareInterruptControl}, Priority, + software::{SoftwareInterrupt, SoftwareInterruptControl}, }, timer::AnyTimer, }; diff --git a/hil-test/tests/embassy_interrupt_spi_dma.rs b/hil-test/tests/embassy_interrupt_spi_dma.rs index 3b3e34426..a0780a74d 100644 --- a/hil-test/tests/embassy_interrupt_spi_dma.rs +++ b/hil-test/tests/embassy_interrupt_spi_dma.rs @@ -12,16 +12,16 @@ use embassy_time::{Duration, Instant, Timer}; use esp_hal::{ + Blocking, dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, - interrupt::{software::SoftwareInterruptControl, Priority}, + interrupt::{Priority, software::SoftwareInterruptControl}, spi::{ - master::{Config, Spi}, Mode, + master::{Config, Spi}, }, time::Rate, timer::AnyTimer, - Blocking, }; use esp_hal_embassy::InterruptExecutor; use hil_test as _; diff --git a/hil-test/tests/embassy_timers_executors.rs b/hil-test/tests/embassy_timers_executors.rs index 4f8de9de6..e4ba95376 100644 --- a/hil-test/tests/embassy_timers_executors.rs +++ b/hil-test/tests/embassy_timers_executors.rs @@ -9,14 +9,14 @@ use embassy_time::{Duration, Ticker, Timer}; #[cfg(not(feature = "esp32"))] use esp_hal::{ - interrupt::software::SoftwareInterruptControl, interrupt::Priority, + interrupt::software::SoftwareInterruptControl, timer::systimer::SystemTimer, }; use esp_hal::{ peripherals::Peripherals, time, - timer::{timg::TimerGroup, AnyTimer, OneShotTimer, PeriodicTimer}, + timer::{AnyTimer, OneShotTimer, PeriodicTimer, timg::TimerGroup}, }; #[cfg(not(feature = "esp32"))] use esp_hal_embassy::InterruptExecutor; diff --git a/hil-test/tests/gpio.rs b/hil-test/tests/gpio.rs index 2f2f42290..1e5e3c547 100644 --- a/hil-test/tests/gpio.rs +++ b/hil-test/tests/gpio.rs @@ -411,7 +411,7 @@ mod tests { #[test] #[cfg(feature = "unstable")] fn interrupt_executor_is_not_frozen(ctx: Context) { - use esp_hal::interrupt::{software::SoftwareInterrupt, Priority}; + use esp_hal::interrupt::{Priority, software::SoftwareInterrupt}; use esp_hal_embassy::InterruptExecutor; use static_cell::StaticCell; diff --git a/hil-test/tests/gpio_custom_handler.rs b/hil-test/tests/gpio_custom_handler.rs index c0406e39b..6fd9bb8a2 100644 --- a/hil-test/tests/gpio_custom_handler.rs +++ b/hil-test/tests/gpio_custom_handler.rs @@ -20,11 +20,11 @@ use esp_hal::{ use hil_test as _; use portable_atomic::{AtomicUsize, Ordering}; -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn GPIO() { // Prevents binding the default handler, but we need to clear the GPIO // interrupts by hand. - let peripherals = esp_hal::peripherals::Peripherals::steal(); + let peripherals = unsafe { esp_hal::peripherals::Peripherals::steal() }; let (gpio1, _) = hil_test::common_test_pins!(peripherals); diff --git a/hil-test/tests/i2c.rs b/hil-test/tests/i2c.rs index c6fc32fa7..349b04c12 100644 --- a/hil-test/tests/i2c.rs +++ b/hil-test/tests/i2c.rs @@ -7,9 +7,9 @@ #![no_main] use esp_hal::{ - i2c::master::{AcknowledgeCheckFailedReason, Config, Error, I2c, I2cAddress, Operation}, Async, Blocking, + i2c::master::{AcknowledgeCheckFailedReason, Config, Error, I2c, I2cAddress, Operation}, }; use hil_test as _; diff --git a/hil-test/tests/i2s.rs b/hil-test/tests/i2s.rs index 28562b624..4bcda5f3d 100644 --- a/hil-test/tests/i2s.rs +++ b/hil-test/tests/i2s.rs @@ -11,13 +11,13 @@ #![no_main] use esp_hal::{ + Async, delay::Delay, dma_buffers, gpio::{AnyPin, NoPin, Pin}, i2s::master::{DataFormat, I2s, I2sTx, Standard}, peripherals::I2S0, time::Rate, - Async, }; use hil_test as _; diff --git a/hil-test/tests/init.rs b/hil-test/tests/init.rs index 88aec70f7..3c8856eca 100644 --- a/hil-test/tests/init.rs +++ b/hil-test/tests/init.rs @@ -7,13 +7,13 @@ #![no_main] use esp_hal::{ + Config, clock::CpuClock, config::{WatchdogConfig, WatchdogStatus}, delay::Delay, rtc_cntl::Rtc, time::Duration, timer::timg::TimerGroup, - Config, }; use hil_test as _; diff --git a/hil-test/tests/interrupt.rs b/hil-test/tests/interrupt.rs index bee4e190e..48f5e5593 100644 --- a/hil-test/tests/interrupt.rs +++ b/hil-test/tests/interrupt.rs @@ -15,9 +15,9 @@ use esp_hal::{ clock::CpuClock, interrupt::{ self, - software::{SoftwareInterrupt, SoftwareInterruptControl}, CpuInterrupt, Priority, + software::{SoftwareInterrupt, SoftwareInterruptControl}, }, peripherals::Interrupt, }; @@ -30,7 +30,7 @@ struct Context { sw0_trigger_addr: u32, } -#[no_mangle] +#[unsafe(no_mangle)] fn interrupt20() { unsafe { asm!("csrrwi x0, 0x7e1, 0 #disable timer") } critical_section::with(|cs| { diff --git a/hil-test/tests/lcd_cam.rs b/hil-test/tests/lcd_cam.rs index 8e76534eb..7284b58a9 100644 --- a/hil-test/tests/lcd_cam.rs +++ b/hil-test/tests/lcd_cam.rs @@ -11,15 +11,15 @@ use esp_hal::{ dma_buffers, gpio::Level, lcd_cam::{ + LcdCam, cam::{self, Camera, VhdeMode}, lcd::{ - dpi, - dpi::{Dpi, Format, FrameTiming}, ClockMode, Phase, Polarity, + dpi, + dpi::{Dpi, Format, FrameTiming}, }, - LcdCam, }, peripherals::Peripherals, time::Rate, diff --git a/hil-test/tests/lcd_cam_i8080.rs b/hil-test/tests/lcd_cam_i8080.rs index 070222cd1..809e4b8e8 100644 --- a/hil-test/tests/lcd_cam_i8080.rs +++ b/hil-test/tests/lcd_cam_i8080.rs @@ -7,21 +7,21 @@ #![no_main] use esp_hal::{ + Blocking, dma::DmaTxBuf, dma_buffers, gpio::NoPin, lcd_cam::{ - lcd::i8080::{Command, Config, TxEightBits, TxSixteenBits, I8080}, BitOrder, LcdCam, + lcd::i8080::{Command, Config, I8080, TxEightBits, TxSixteenBits}, }, pcnt::{ - channel::{CtrlMode, EdgeMode}, Pcnt, + channel::{CtrlMode, EdgeMode}, }, peripherals::DMA_CH0, time::Rate, - Blocking, }; use hil_test as _; diff --git a/hil-test/tests/lcd_cam_i8080_async.rs b/hil-test/tests/lcd_cam_i8080_async.rs index 3af3ef846..22ff19267 100644 --- a/hil-test/tests/lcd_cam_i8080_async.rs +++ b/hil-test/tests/lcd_cam_i8080_async.rs @@ -7,16 +7,16 @@ #![no_main] use esp_hal::{ + Async, dma::DmaTxBuf, dma_buffers, gpio::NoPin, lcd_cam::{ - lcd::i8080::{Command, Config, TxEightBits, I8080}, LcdCam, + lcd::i8080::{Command, Config, I8080, TxEightBits}, }, peripherals::DMA_CH0, time::Rate, - Async, }; use hil_test as _; diff --git a/hil-test/tests/parl_io.rs b/hil-test/tests/parl_io.rs index 48730d8c1..c9f94fb48 100644 --- a/hil-test/tests/parl_io.rs +++ b/hil-test/tests/parl_io.rs @@ -230,8 +230,13 @@ mod tests { let (clock_rx, clock_tx) = ctx.clock_pin.split(); let (valid_rx, valid_tx) = ctx.valid_pin.split(); - let [(d0_rx, d0_tx), (d1_rx, d1_tx), (d2_rx, d2_tx), (d3_rx, d3_tx), ..] = - ctx.data_pins.map(|pin| pin.split()); + let [ + (d0_rx, d0_tx), + (d1_rx, d1_tx), + (d2_rx, d2_tx), + (d3_rx, d3_tx), + .., + ] = ctx.data_pins.map(|pin| pin.split()); let tx_pins = TxFourBits::new(d0_tx, d1_tx, d2_tx, d3_tx); let rx_pins = RxFourBits::new(d0_rx, d1_rx, d2_rx, d3_rx); @@ -299,8 +304,16 @@ mod tests { let (clock_rx, clock_tx) = ctx.clock_pin.split(); let (valid_rx, valid_tx) = ctx.valid_pin.split(); - let [(d0_rx, d0_tx), (d1_rx, d1_tx), (d2_rx, d2_tx), (d3_rx, d3_tx), (d4_rx, d4_tx), (d5_rx, d5_tx), (d6_rx, d6_tx), (d7_rx, d7_tx)] = - ctx.data_pins.map(|pin| pin.split()); + let [ + (d0_rx, d0_tx), + (d1_rx, d1_tx), + (d2_rx, d2_tx), + (d3_rx, d3_tx), + (d4_rx, d4_tx), + (d5_rx, d5_tx), + (d6_rx, d6_tx), + (d7_rx, d7_tx), + ] = ctx.data_pins.map(|pin| pin.split()); let tx_pins = TxEightBits::new(d0_tx, d1_tx, d2_tx, d3_tx, d4_tx, d5_tx, d6_tx, d7_tx); let rx_pins = RxEightBits::new(d0_rx, d1_rx, d2_rx, d3_rx, d4_rx, d5_rx, d6_rx, d7_rx); diff --git a/hil-test/tests/parl_io_tx.rs b/hil-test/tests/parl_io_tx.rs index 6a5a45f3a..c6673ace7 100644 --- a/hil-test/tests/parl_io_tx.rs +++ b/hil-test/tests/parl_io_tx.rs @@ -12,8 +12,8 @@ use esp_hal::{ dma::DmaTxBuf, dma_tx_buffer, gpio::{ - interconnect::{InputSignal, OutputSignal}, NoPin, + interconnect::{InputSignal, OutputSignal}, }, parl_io::{ BitPackOrder, @@ -25,9 +25,9 @@ use esp_hal::{ TxPinConfigIncludingValidPin, }, pcnt::{ + Pcnt, channel::{CtrlMode, EdgeMode}, unit::Unit, - Pcnt, }, peripherals::{DMA_CH0, PARL_IO}, time::Rate, diff --git a/hil-test/tests/parl_io_tx_async.rs b/hil-test/tests/parl_io_tx_async.rs index 304cad9d0..ed52e097f 100644 --- a/hil-test/tests/parl_io_tx_async.rs +++ b/hil-test/tests/parl_io_tx_async.rs @@ -12,8 +12,8 @@ use esp_hal::{ dma::DmaTxBuf, dma_tx_buffer, gpio::{ - interconnect::{InputSignal, OutputSignal}, NoPin, + interconnect::{InputSignal, OutputSignal}, }, parl_io::{ BitPackOrder, @@ -25,9 +25,9 @@ use esp_hal::{ TxPinConfigIncludingValidPin, }, pcnt::{ + Pcnt, channel::{CtrlMode, EdgeMode}, unit::Unit, - Pcnt, }, peripherals::{DMA_CH0, PARL_IO}, time::Rate, diff --git a/hil-test/tests/pcnt.rs b/hil-test/tests/pcnt.rs index b7e075f02..9cbf6b64e 100644 --- a/hil-test/tests/pcnt.rs +++ b/hil-test/tests/pcnt.rs @@ -9,7 +9,7 @@ use esp_hal::{ delay::Delay, gpio::{AnyPin, Input, InputConfig, Level, Output, OutputConfig, Pin, Pull}, - pcnt::{channel::EdgeMode, Pcnt}, + pcnt::{Pcnt, channel::EdgeMode}, }; use hil_test as _; diff --git a/hil-test/tests/qspi.rs b/hil-test/tests/qspi.rs index 673e03082..2dd89658f 100644 --- a/hil-test/tests/qspi.rs +++ b/hil-test/tests/qspi.rs @@ -7,18 +7,18 @@ #![no_main] #[cfg(pcnt)] -use esp_hal::pcnt::{channel::EdgeMode, unit::Unit, Pcnt}; +use esp_hal::pcnt::{Pcnt, channel::EdgeMode, unit::Unit}; use esp_hal::{ + Blocking, dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{AnyPin, Input, InputConfig, Level, Output, OutputConfig, Pull}, spi::{ - master::{Address, Command, Config, Spi, SpiDma}, DataMode, Mode, + master::{Address, Command, Config, Spi, SpiDma}, }, time::Rate, - Blocking, }; use hil_test as _; diff --git a/hil-test/tests/rsa.rs b/hil-test/tests/rsa.rs index 48bb86e6f..0e9d040e9 100644 --- a/hil-test/tests/rsa.rs +++ b/hil-test/tests/rsa.rs @@ -6,16 +6,16 @@ #![no_std] #![no_main] -use crypto_bigint::{Uint, U1024, U512}; +use crypto_bigint::{U512, U1024, Uint}; use esp_hal::{ + Blocking, rsa::{ - operand_sizes::*, Rsa, RsaModularExponentiation, RsaModularMultiplication, RsaMultiplication, + operand_sizes::*, }, - Blocking, }; use hil_test as _; diff --git a/hil-test/tests/rsa_async.rs b/hil-test/tests/rsa_async.rs index c9b1a132a..4ee6e0fcd 100644 --- a/hil-test/tests/rsa_async.rs +++ b/hil-test/tests/rsa_async.rs @@ -6,16 +6,16 @@ #![no_std] #![no_main] -use crypto_bigint::{Uint, U1024, U512}; +use crypto_bigint::{U512, U1024, Uint}; use esp_hal::{ + Async, rsa::{ - operand_sizes::*, Rsa, RsaModularExponentiation, RsaModularMultiplication, RsaMultiplication, + operand_sizes::*, }, - Async, }; use hil_test as _; diff --git a/hil-test/tests/spi_full_duplex.rs b/hil-test/tests/spi_full_duplex.rs index 582da1c91..8fb8ddb45 100644 --- a/hil-test/tests/spi_full_duplex.rs +++ b/hil-test/tests/spi_full_duplex.rs @@ -14,10 +14,10 @@ use embedded_hal_async::spi::SpiBus as SpiBusAsync; #[cfg(feature = "unstable")] use esp_hal::peripherals::SPI2; use esp_hal::{ + Blocking, gpio::Input, spi::master::{Config, Spi}, time::Rate, - Blocking, }; use hil_test as _; diff --git a/hil-test/tests/spi_half_duplex_read.rs b/hil-test/tests/spi_half_duplex_read.rs index e6e85e898..419ae6537 100644 --- a/hil-test/tests/spi_half_duplex_read.rs +++ b/hil-test/tests/spi_half_duplex_read.rs @@ -7,16 +7,16 @@ #![no_main] use esp_hal::{ + Blocking, dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{Level, Output, OutputConfig}, spi::{ - master::{Address, Command, Config, Spi, SpiDma}, DataMode, Mode, + master::{Address, Command, Config, Spi, SpiDma}, }, time::Rate, - Blocking, }; use hil_test as _; diff --git a/hil-test/tests/spi_half_duplex_write.rs b/hil-test/tests/spi_half_duplex_write.rs index c525b5901..ad6827a6b 100644 --- a/hil-test/tests/spi_half_duplex_write.rs +++ b/hil-test/tests/spi_half_duplex_write.rs @@ -7,17 +7,17 @@ #![no_main] use esp_hal::{ + Blocking, dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::interconnect::InputSignal, - pcnt::{channel::EdgeMode, unit::Unit, Pcnt}, + pcnt::{Pcnt, channel::EdgeMode, unit::Unit}, spi::{ - master::{Address, Command, Config, Spi, SpiDma}, DataMode, Mode, + master::{Address, Command, Config, Spi, SpiDma}, }, time::Rate, - Blocking, }; use hil_test as _; diff --git a/hil-test/tests/spi_half_duplex_write_psram.rs b/hil-test/tests/spi_half_duplex_write_psram.rs index e4e8de860..b80a9e310 100644 --- a/hil-test/tests/spi_half_duplex_write_psram.rs +++ b/hil-test/tests/spi_half_duplex_write_psram.rs @@ -10,18 +10,18 @@ use defmt::error; use esp_alloc as _; use esp_hal::{ + Blocking, dma::{DmaRxBuf, DmaTxBuf, ExternalBurstConfig}, dma_buffers, dma_descriptors_chunk_size, gpio::interconnect::InputSignal, - pcnt::{channel::EdgeMode, unit::Unit, Pcnt}, + pcnt::{Pcnt, channel::EdgeMode, unit::Unit}, spi::{ - master::{Address, Command, Config, Spi, SpiDma}, DataMode, Mode, + master::{Address, Command, Config, Spi, SpiDma}, }, time::Rate, - Blocking, }; use hil_test as _; extern crate alloc; diff --git a/hil-test/tests/spi_slave.rs b/hil-test/tests/spi_slave.rs index 1c6fc4b89..01a90a4f0 100644 --- a/hil-test/tests/spi_slave.rs +++ b/hil-test/tests/spi_slave.rs @@ -10,11 +10,11 @@ #![no_main] use esp_hal::{ + Blocking, dma::{DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{Input, InputConfig, Level, Output, OutputConfig, Pull}, - spi::{slave::Spi, Mode}, - Blocking, + spi::{Mode, slave::Spi}, }; use hil_test as _; diff --git a/hil-test/tests/storage_read_app_desc.rs b/hil-test/tests/storage_read_app_desc.rs index 4a258328f..f39dafba9 100644 --- a/hil-test/tests/storage_read_app_desc.rs +++ b/hil-test/tests/storage_read_app_desc.rs @@ -51,9 +51,9 @@ const fn str_to_cstr_array(s: &str) -> [::core::ffi::c_char; C] ret } -#[no_mangle] +#[unsafe(no_mangle)] #[used] -#[link_section = ".rodata_desc"] +#[unsafe(link_section = ".rodata_desc")] #[allow(non_upper_case_globals)] pub static esp_app_desc: EspAppDesc = EspAppDesc { magic_word: ESP_APP_DESC_MAGIC_WORD, diff --git a/hil-test/tests/systimer.rs b/hil-test/tests/systimer.rs index 62967af75..9a2e8b657 100644 --- a/hil-test/tests/systimer.rs +++ b/hil-test/tests/systimer.rs @@ -12,15 +12,15 @@ use core::cell::RefCell; use critical_section::Mutex; use embedded_hal::delay::DelayNs; use esp_hal::{ + Blocking, delay::Delay, handler, time::Duration, timer::{ - systimer::{Alarm, SystemTimer}, OneShotTimer, PeriodicTimer, + systimer::{Alarm, SystemTimer}, }, - Blocking, }; use hil_test as _; use portable_atomic::{AtomicUsize, Ordering}; diff --git a/hil-test/tests/twai.rs b/hil-test/tests/twai.rs index 61d276436..0e4ed33b1 100644 --- a/hil-test/tests/twai.rs +++ b/hil-test/tests/twai.rs @@ -8,8 +8,8 @@ use embedded_can::Frame; use esp_hal::{ - twai::{self, filter::SingleStandardFilter, EspTwaiFrame, StandardId, TwaiMode}, Blocking, + twai::{self, EspTwaiFrame, StandardId, TwaiMode, filter::SingleStandardFilter}, }; use hil_test as _; use nb::block; diff --git a/hil-test/tests/uart.rs b/hil-test/tests/uart.rs index 48d900760..70ee53ba7 100644 --- a/hil-test/tests/uart.rs +++ b/hil-test/tests/uart.rs @@ -7,12 +7,12 @@ #![no_main] use esp_hal::{ + Blocking, gpio::{ - interconnect::{InputSignal, OutputSignal}, AnyPin, + interconnect::{InputSignal, OutputSignal}, }, uart::{self, ClockSource, Uart}, - Blocking, }; use hil_test as _; diff --git a/hil-test/tests/uart_async.rs b/hil-test/tests/uart_async.rs index 5c33c731f..abe90505f 100644 --- a/hil-test/tests/uart_async.rs +++ b/hil-test/tests/uart_async.rs @@ -7,8 +7,8 @@ #![no_main] use esp_hal::{ - uart::{self, Uart}, Async, + uart::{self, Uart}, }; use hil_test as _; diff --git a/hil-test/tests/uart_tx_rx_async.rs b/hil-test/tests/uart_tx_rx_async.rs index c919942db..ec1b9e806 100644 --- a/hil-test/tests/uart_tx_rx_async.rs +++ b/hil-test/tests/uart_tx_rx_async.rs @@ -7,8 +7,8 @@ #![no_main] use esp_hal::{ - uart::{self, UartRx, UartTx}, Async, + uart::{self, UartRx, UartTx}, }; use hil_test as _; @@ -22,7 +22,7 @@ struct Context { mod tests { use embassy_futures::{ join::join, - select::{select, Either}, + select::{Either, select}, }; use embassy_time::{Duration, Timer}; use embedded_io_async::Write; diff --git a/qa-test/Cargo.toml b/qa-test/Cargo.toml index 26feac8d1..482348960 100644 --- a/qa-test/Cargo.toml +++ b/qa-test/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "qa-test" version = "0.0.0" -edition = "2021" +edition = "2024" license = "MIT OR Apache-2.0" publish = false diff --git a/qa-test/src/bin/embassy_executor_benchmark.rs b/qa-test/src/bin/embassy_executor_benchmark.rs index 8fddfa64d..2240cfc1c 100644 --- a/qa-test/src/bin/embassy_executor_benchmark.rs +++ b/qa-test/src/bin/embassy_executor_benchmark.rs @@ -11,13 +11,13 @@ use core::{ task::{Context, Poll}, }; -use embassy_executor::{raw::TaskStorage, Spawner}; +use embassy_executor::{Spawner, raw::TaskStorage}; use esp_backtrace as _; use esp_hal::{ clock::{Clock, CpuClock}, handler, time::Duration, - timer::{systimer::SystemTimer, OneShotTimer}, + timer::{OneShotTimer, systimer::SystemTimer}, }; use esp_println::println; diff --git a/qa-test/src/bin/i2c_display.rs b/qa-test/src/bin/i2c_display.rs index d0768e9ac..11570e56c 100644 --- a/qa-test/src/bin/i2c_display.rs +++ b/qa-test/src/bin/i2c_display.rs @@ -14,8 +14,8 @@ use embedded_graphics::{ mono_font::{ - ascii::{FONT_6X10, FONT_9X18_BOLD}, MonoTextStyleBuilder, + ascii::{FONT_6X10, FONT_9X18_BOLD}, }, pixelcolor::BinaryColor, prelude::*, @@ -28,7 +28,7 @@ use esp_hal::{ main, time::Duration, }; -use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; +use ssd1306::{I2CDisplayInterface, Ssd1306, prelude::*}; #[main] fn main() -> ! { diff --git a/qa-test/src/bin/lcd_cam_ov2640.rs b/qa-test/src/bin/lcd_cam_ov2640.rs index aaa5e7e09..87b5d0dc0 100644 --- a/qa-test/src/bin/lcd_cam_ov2640.rs +++ b/qa-test/src/bin/lcd_cam_ov2640.rs @@ -27,6 +27,7 @@ use esp_backtrace as _; use esp_hal::{ + Blocking, delay::Delay, dma_rx_stream_buffer, i2c::{ @@ -34,12 +35,11 @@ use esp_hal::{ master::{Config, I2c}, }, lcd_cam::{ - cam::{self, Camera}, LcdCam, + cam::{self, Camera}, }, main, time::Rate, - Blocking, }; use esp_println::{print, println}; diff --git a/qa-test/src/bin/lcd_dpi.rs b/qa-test/src/bin/lcd_dpi.rs index 3380c2d33..f92323f97 100644 --- a/qa-test/src/bin/lcd_dpi.rs +++ b/qa-test/src/bin/lcd_dpi.rs @@ -33,23 +33,23 @@ use core::iter::{empty, once}; use esp_backtrace as _; use esp_hal::{ + Blocking, delay::Delay, dma_loop_buffer, gpio::{Level, Output, OutputConfig}, i2c::{self, master::I2c}, lcd_cam::{ + LcdCam, lcd::{ - dpi::{Config, Dpi, Format, FrameTiming}, ClockMode, Phase, Polarity, + dpi::{Config, Dpi, Format, FrameTiming}, }, - LcdCam, }, main, peripherals::Peripherals, time::Rate, - Blocking, }; use esp_println::println; diff --git a/qa-test/src/bin/lcd_i8080.rs b/qa-test/src/bin/lcd_i8080.rs index aa654cdf8..60480f29f 100644 --- a/qa-test/src/bin/lcd_i8080.rs +++ b/qa-test/src/bin/lcd_i8080.rs @@ -24,17 +24,17 @@ use esp_backtrace as _; use esp_hal::{ + Blocking, delay::Delay, dma::DmaTxBuf, dma_tx_buffer, gpio::{Input, InputConfig, Level, Output, OutputConfig, Pull}, lcd_cam::{ - lcd::i8080::{Config, TxEightBits, I8080}, LcdCam, + lcd::i8080::{Config, I8080, TxEightBits}, }, main, time::Rate, - Blocking, }; use esp_println::println; @@ -161,9 +161,9 @@ fn main() -> ! { ], ); bus.send(CMD_PWCTR2, &[0x06]); // Power control2 //VAP(GVDD)=3.85+( vcom+vcom offset), VAN(GVCL)=-3.85+( - // vcom+vcom offset) + // vcom+vcom offset) bus.send(CMD_PWCTR3, &[0xA7]); // Power control 3 //Source driving current level=low, Gamma driving current - // level=High + // level=High bus.send(CMD_VMCTR, &[0x18]); // VCOM Control //VCOM=0.9 delay.delay_micros(120_000); bus.send( @@ -181,7 +181,7 @@ fn main() -> ! { delay.delay_micros(120_000); bus.send(CMD_CSCON, &[0x3C]); // Command Set control // Disable extension command 2 partI bus.send(CMD_CSCON, &[0x69]); // Command Set control // Disable - // extension command 2 partII + // extension command 2 partII bus.send(0x11, &[]); // ExitSleepMode delay.delay_micros(130_000); diff --git a/qa-test/src/bin/qspi_flash.rs b/qa-test/src/bin/qspi_flash.rs index a19611db5..107243cd4 100644 --- a/qa-test/src/bin/qspi_flash.rs +++ b/qa-test/src/bin/qspi_flash.rs @@ -35,9 +35,9 @@ use esp_hal::{ dma_buffers, main, spi::{ - master::{Address, Command, Config, Spi}, DataMode, Mode, + master::{Address, Command, Config, Spi}, }, time::Rate, }; diff --git a/qa-test/src/bin/sleep_timer.rs b/qa-test/src/bin/sleep_timer.rs index 559208877..4719d956c 100644 --- a/qa-test/src/bin/sleep_timer.rs +++ b/qa-test/src/bin/sleep_timer.rs @@ -11,7 +11,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, main, - rtc_cntl::{reset_reason, sleep::TimerWakeupSource, wakeup_cause, Rtc, SocResetReason}, + rtc_cntl::{Rtc, SocResetReason, reset_reason, sleep::TimerWakeupSource, wakeup_cause}, system::Cpu, }; use esp_println::println; diff --git a/qa-test/src/bin/sleep_timer_ext0.rs b/qa-test/src/bin/sleep_timer_ext0.rs index 1966ef9fb..534056c53 100644 --- a/qa-test/src/bin/sleep_timer_ext0.rs +++ b/qa-test/src/bin/sleep_timer_ext0.rs @@ -16,11 +16,11 @@ use esp_hal::{ gpio::{Input, InputConfig, Pull}, main, rtc_cntl::{ + Rtc, + SocResetReason, reset_reason, sleep::{Ext0WakeupSource, TimerWakeupSource, WakeupLevel}, wakeup_cause, - Rtc, - SocResetReason, }, system::Cpu, }; diff --git a/qa-test/src/bin/sleep_timer_ext1.rs b/qa-test/src/bin/sleep_timer_ext1.rs index 4a6fa4594..3623efb5a 100644 --- a/qa-test/src/bin/sleep_timer_ext1.rs +++ b/qa-test/src/bin/sleep_timer_ext1.rs @@ -16,11 +16,11 @@ use esp_hal::{ gpio::{Input, InputConfig, Pull, RtcPin}, main, rtc_cntl::{ + Rtc, + SocResetReason, reset_reason, sleep::{Ext1WakeupSource, TimerWakeupSource, WakeupLevel}, wakeup_cause, - Rtc, - SocResetReason, }, system::Cpu, }; diff --git a/qa-test/src/bin/sleep_timer_lpio.rs b/qa-test/src/bin/sleep_timer_lpio.rs index 9545f0862..4aa619a04 100644 --- a/qa-test/src/bin/sleep_timer_lpio.rs +++ b/qa-test/src/bin/sleep_timer_lpio.rs @@ -17,11 +17,11 @@ use esp_hal::{ gpio::{Input, InputConfig, Pull, RtcPinWithResistors}, main, rtc_cntl::{ + Rtc, + SocResetReason, reset_reason, sleep::{Ext1WakeupSource, TimerWakeupSource, WakeupLevel}, wakeup_cause, - Rtc, - SocResetReason, }, system::Cpu, }; diff --git a/qa-test/src/bin/sleep_timer_rtcio.rs b/qa-test/src/bin/sleep_timer_rtcio.rs index 3101881ff..b556564a5 100644 --- a/qa-test/src/bin/sleep_timer_rtcio.rs +++ b/qa-test/src/bin/sleep_timer_rtcio.rs @@ -22,11 +22,11 @@ use esp_hal::{ gpio::{Input, InputConfig, Pull}, main, rtc_cntl::{ + Rtc, + SocResetReason, reset_reason, sleep::{RtcioWakeupSource, TimerWakeupSource, WakeupLevel}, wakeup_cause, - Rtc, - SocResetReason, }, system::Cpu, }; diff --git a/qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs b/qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs index e654f1ab9..278421285 100644 --- a/qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs +++ b/qa-test/src/bin/spi_halfduplex_read_manufacturer_id.rs @@ -33,9 +33,9 @@ use esp_hal::{ delay::Delay, main, spi::{ - master::{Address, Command, Config, Spi}, DataMode, Mode, + master::{Address, Command, Config, Spi}, }, time::Rate, }; diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index a2b4fef66..a951d7cda 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xtask" version = "0.0.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 2d157a536..d87a7e373 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -151,6 +151,7 @@ impl Package { if config.contains("lp_core") { features.push("embedded-io".to_owned()); } + features.push("embedded-hal".to_owned()); } Package::EspPrintln => { features.push("auto".to_owned()); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 0fb724220..b8baea108 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -648,7 +648,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> { let feature_sets = [ vec![package.feature_rules(device)], // initially test all features - package.lint_feature_rules(device), // add separate test cases + package.lint_feature_rules(device), // add separate test cases ] .concat(); diff --git a/xtensa-lx-rt-proc-macros/Cargo.toml b/xtensa-lx-rt-proc-macros/Cargo.toml index 26e9f2fc4..d4c98c8de 100644 --- a/xtensa-lx-rt-proc-macros/Cargo.toml +++ b/xtensa-lx-rt-proc-macros/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "xtensa-lx-rt-proc-macros" version = "0.2.2" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Attributes re-exported in `xtensa-lx-rt`" documentation = "https://docs.espressif.com/projects/rust/xtensa-lx-rt-proc-macros/latest/" repository = "https://github.com/esp-rs/esp-hal" diff --git a/xtensa-lx-rt-proc-macros/src/lib.rs b/xtensa-lx-rt-proc-macros/src/lib.rs index ee26f29cc..e38289130 100644 --- a/xtensa-lx-rt-proc-macros/src/lib.rs +++ b/xtensa-lx-rt-proc-macros/src/lib.rs @@ -13,9 +13,6 @@ use proc_macro::TokenStream; use proc_macro2::Span; use quote::quote; use syn::{ - parse, - parse_macro_input, - spanned::Spanned, AttrStyle, Attribute, FnArg, @@ -28,6 +25,9 @@ use syn::{ Stmt, Type, Visibility, + parse, + parse_macro_input, + spanned::Spanned, }; /// Marks a function as the main function to be called on program start @@ -118,7 +118,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { #(#cfgs)* #(#attrs)* #[doc(hidden)] - #[export_name = "main"] + #[unsafe(export_name = "main")] pub unsafe extern "C" fn #tramp_ident() { #ident( #(#resource_args),* @@ -239,7 +239,7 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { "This attribute accepts an integer attribute", ) .to_compile_error() - .into() + .into(); } }, _ => { @@ -248,7 +248,7 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { "This attribute accepts an integer attribute", ) .to_compile_error() - .into() + .into(); } } } diff --git a/xtensa-lx-rt/CHANGELOG.md b/xtensa-lx-rt/CHANGELOG.md index 10f714bdb..b56034614 100644 --- a/xtensa-lx-rt/CHANGELOG.md +++ b/xtensa-lx-rt/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed ### Removed diff --git a/xtensa-lx-rt/Cargo.toml b/xtensa-lx-rt/Cargo.toml index 29b63e717..b02a09d1a 100644 --- a/xtensa-lx-rt/Cargo.toml +++ b/xtensa-lx-rt/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "xtensa-lx-rt" version = "0.18.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Minimal startup/runtime for Xtensa LX CPUs" documentation = "https://docs.espressif.com/projects/rust/xtensa-lx-rt/latest/" repository = "https://github.com/esp-rs/esp-hal" @@ -13,6 +13,10 @@ categories = ["embedded", "hardware-support", "no-std"] [package.metadata.docs.rs] features = ["esp32"] +[lib] +bench = false +test = false + [dependencies] document-features = "0.2.10" macros = { version = "0.2.2", package = "xtensa-lx-rt-proc-macros", path = "../xtensa-lx-rt-proc-macros" } diff --git a/xtensa-lx-rt/build.rs b/xtensa-lx-rt/build.rs index 20748844c..008538079 100644 --- a/xtensa-lx-rt/build.rs +++ b/xtensa-lx-rt/build.rs @@ -8,7 +8,7 @@ use std::{ use anyhow::Result; use enum_as_inner::EnumAsInner; -use minijinja::{context, Environment}; +use minijinja::{Environment, context}; use serde::Deserialize; use strum::{Display, EnumIter, EnumString}; diff --git a/xtensa-lx-rt/src/exception/context.rs b/xtensa-lx-rt/src/exception/context.rs index 2a7ed1b55..8ac32c750 100644 --- a/xtensa-lx-rt/src/exception/context.rs +++ b/xtensa-lx-rt/src/exception/context.rs @@ -103,7 +103,7 @@ impl Context { } } -extern "Rust" { +unsafe extern "Rust" { /// The exception assembly jumps here once registers have been spilled fn __exception(cause: ExceptionCause, save_frame: &mut Context); /// This symbol will be provided by the user via `#[exception]` @@ -128,14 +128,14 @@ extern "Rust" { fn __level_7_interrupt(save_frame: &mut Context); } -#[no_mangle] -#[link_section = ".rwtext"] +#[unsafe(no_mangle)] +#[unsafe(link_section = ".rwtext")] unsafe extern "C" fn __default_exception(cause: ExceptionCause, save_frame: &mut Context) { - __user_exception(cause, save_frame) + unsafe { __user_exception(cause, save_frame) } } -#[no_mangle] -#[link_section = ".rwtext"] +#[unsafe(no_mangle)] +#[unsafe(link_section = ".rwtext")] extern "C" fn __default_user_exception(cause: ExceptionCause, save_frame: &Context) { #[cfg(any(feature = "esp32", feature = "esp32s3"))] if cause == ExceptionCause::Cp0Disabled { @@ -148,14 +148,14 @@ extern "C" fn __default_user_exception(cause: ExceptionCause, save_frame: &Conte panic!("Exception: {:?}, {:08x?}", cause, save_frame) } -#[no_mangle] -#[link_section = ".rwtext"] +#[unsafe(no_mangle)] +#[unsafe(link_section = ".rwtext")] extern "C" fn __default_interrupt(level: u32, save_frame: &Context) { panic!("Interrupt: {:?}, {:08x?}", level, save_frame) } -#[no_mangle] -#[link_section = ".rwtext"] +#[unsafe(no_mangle)] +#[unsafe(link_section = ".rwtext")] extern "C" fn __default_double_exception(cause: ExceptionCause, save_frame: &Context) { panic!("Double Exception: {:?}, {:08x?}", cause, save_frame) } diff --git a/xtensa-lx-rt/src/lib.rs b/xtensa-lx-rt/src/lib.rs index 8b444dd2c..d0607c842 100644 --- a/xtensa-lx-rt/src/lib.rs +++ b/xtensa-lx-rt/src/lib.rs @@ -25,65 +25,67 @@ pub mod exception; pub mod interrupt; #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn DefaultPreInit() {} #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] pub unsafe extern "C" fn Reset() -> ! { - // These symbols come from `link.x` - extern "C" { - static mut _bss_start: u32; - static mut _bss_end: u32; + unsafe { + // These symbols come from `link.x` + unsafe extern "C" { + static mut _bss_start: u32; + static mut _bss_end: u32; - static mut _data_start: u32; - static mut _data_end: u32; - static _sidata: u32; + static mut _data_start: u32; + static mut _data_end: u32; + static _sidata: u32; - static mut _init_start: u32; + static mut _init_start: u32; + } + + unsafe extern "Rust" { + // This symbol will be provided by the user via `#[entry]` + fn main() -> !; + + // This symbol will be provided by the user via `#[pre_init]` + fn __pre_init(); + + fn __post_init(); + + fn __zero_bss() -> bool; + + fn __init_data() -> bool; + } + + __pre_init(); + + if __zero_bss() { + r0::zero_bss(addr_of_mut!(_bss_start), addr_of_mut!(_bss_end)); + } + + if __init_data() { + r0::init_data(addr_of_mut!(_data_start), addr_of_mut!(_data_end), &_sidata); + } + + // Copy of data segment is done by bootloader + + // According to 4.4.6.2 of the xtensa isa, ccount and compare are undefined on + // reset, set all values to zero to disable + reset_internal_timers(); + + // move vec table + set_vecbase(addr_of!(_init_start)); + + __post_init(); + + main(); } - - extern "Rust" { - // This symbol will be provided by the user via `#[entry]` - fn main() -> !; - - // This symbol will be provided by the user via `#[pre_init]` - fn __pre_init(); - - fn __post_init(); - - fn __zero_bss() -> bool; - - fn __init_data() -> bool; - } - - __pre_init(); - - if __zero_bss() { - r0::zero_bss(addr_of_mut!(_bss_start), addr_of_mut!(_bss_end)); - } - - if __init_data() { - r0::init_data(addr_of_mut!(_data_start), addr_of_mut!(_data_end), &_sidata); - } - - // Copy of data segment is done by bootloader - - // According to 4.4.6.2 of the xtensa isa, ccount and compare are undefined on - // reset, set all values to zero to disable - reset_internal_timers(); - - // move vec table - set_vecbase(addr_of!(_init_start)); - - __post_init(); - - main(); } #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[rustfmt::skip] pub unsafe extern "Rust" fn default_post_init() {} @@ -92,15 +94,16 @@ pub unsafe extern "Rust" fn default_post_init() {} #[doc(hidden)] #[inline] unsafe fn reset_internal_timers() { - #[cfg(any( - XCHAL_HAVE_TIMER0, - XCHAL_HAVE_TIMER1, - XCHAL_HAVE_TIMER2, - XCHAL_HAVE_TIMER3 - ))] - { - let value = 0; - cfg_asm!( + unsafe { + #[cfg(any( + XCHAL_HAVE_TIMER0, + XCHAL_HAVE_TIMER1, + XCHAL_HAVE_TIMER2, + XCHAL_HAVE_TIMER3 + ))] + { + let value = 0; + cfg_asm!( { #[cfg(XCHAL_HAVE_TIMER0)] "wsr.ccompare0 {0}", @@ -112,11 +115,12 @@ unsafe fn reset_internal_timers() { "wsr.ccompare3 {0}", "isync", }, in(reg) value, options(nostack)); + } } } // CPU Interrupts -extern "C" { +unsafe extern "C" { #[cfg(XCHAL_HAVE_TIMER0)] pub fn Timer0(save_frame: &mut crate::exception::Context); #[cfg(XCHAL_HAVE_TIMER1)] @@ -141,11 +145,13 @@ extern "C" { #[doc(hidden)] #[inline] unsafe fn set_vecbase(base: *const u32) { - asm!("wsr.vecbase {0}", in(reg) base, options(nostack)); + unsafe { + asm!("wsr.vecbase {0}", in(reg) base, options(nostack)); + } } #[doc(hidden)] -#[no_mangle] +#[unsafe(no_mangle)] #[rustfmt::skip] pub extern "Rust" fn default_mem_hook() -> bool { true // default to zeroing bss & initializing data diff --git a/xtensa-lx/CHANGELOG.md b/xtensa-lx/CHANGELOG.md index 92bf6f10c..2b3cdd9a9 100644 --- a/xtensa-lx/CHANGELOG.md +++ b/xtensa-lx/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Bump Rust edition to 2024, bump MSRV to 1.85. (#3391) + ### Fixed ### Removed diff --git a/xtensa-lx/Cargo.toml b/xtensa-lx/Cargo.toml index b5201e212..a1bcb80cb 100644 --- a/xtensa-lx/Cargo.toml +++ b/xtensa-lx/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "xtensa-lx" version = "0.10.0" -edition = "2021" -rust-version = "1.84.0" +edition = "2024" +rust-version = "1.85.0" description = "Low-level access to Xtensa LX processors and peripherals" documentation = "https://docs.espressif.com/projects/rust/xtensa-lx/latest/" repository = "https://github.com/esp-rs/esp-hal" @@ -11,6 +11,10 @@ categories = ["embedded", "hardware-support", "no-std"] keywords = ["lx", "peripheral", "register", "xtensa"] links = "xtensa-lx" +[lib] +bench = false +test = false + [dependencies] critical-section = "1.2.0" document-features = "0.2.10" diff --git a/xtensa-lx/src/interrupt.rs b/xtensa-lx/src/interrupt.rs index 14583d7b5..801dd9b4a 100644 --- a/xtensa-lx/src/interrupt.rs +++ b/xtensa-lx/src/interrupt.rs @@ -15,7 +15,7 @@ pub fn disable() -> u32 { /// - Do not call this function inside an `interrupt::free` critical section #[inline] pub unsafe fn enable() -> u32 { - set_mask(!0) + unsafe { set_mask(!0) } } /// Enables specific interrupts and returns the previous setting @@ -25,13 +25,15 @@ pub unsafe fn enable() -> u32 { /// - Do not call this function inside an `interrupt::free` critical section #[inline] pub unsafe fn set_mask(mut mask: u32) -> u32 { - asm!(" + unsafe { + asm!(" xsr {0}, intenable rsync ", - inout(reg) mask, options(nostack) - ); - mask + inout(reg) mask, options(nostack) + ); + mask + } } /// Disables specific interrupts and returns the previous settings @@ -59,16 +61,18 @@ pub fn disable_mask(mask: u32) -> u32 { /// - Do not call this function inside an `interrupt::free` critical section #[inline] pub unsafe fn enable_mask(mask: u32) -> u32 { - let mut prev: u32 = 0; - let _dummy: u32; - asm!(" + unsafe { + let mut prev: u32 = 0; + let _dummy: u32; + asm!(" xsr.intenable {0} // get mask and temporarily disable interrupts or {1}, {1}, {0} rsync wsr.intenable {1} rsync ", inout(reg) prev, inout(reg) mask => _dummy, options(nostack)); - prev + prev + } } /// Get current interrupt mask @@ -96,12 +100,14 @@ pub fn get() -> u32 { /// Only valid for software interrupts #[inline] pub unsafe fn set(mask: u32) { - asm!(" + unsafe { + asm!(" wsr.intset {0} rsync ", - in(reg) mask, options(nostack) - ); + in(reg) mask, options(nostack) + ); + } } /// Clear interrupt @@ -111,12 +117,14 @@ pub unsafe fn set(mask: u32) { /// Only valid for software and edge-triggered interrupts #[inline] pub unsafe fn clear(mask: u32) { - asm!(" + unsafe { + asm!(" wsr.intclear {0} rsync ", - in(reg) mask, options(nostack) - ); + in(reg) mask, options(nostack) + ); + } } /// Get current interrupt level diff --git a/xtensa-lx/src/lib.rs b/xtensa-lx/src/lib.rs index cc8eb0768..40449d3ed 100644 --- a/xtensa-lx/src/lib.rs +++ b/xtensa-lx/src/lib.rs @@ -31,7 +31,9 @@ const XDM_OCD_DCR_SET: u32 = 0x10200C; /// It should be used with care, `base` MUST be a valid pointer #[inline(always)] pub unsafe fn set_vecbase(base: *const u32) { - asm!("wsr.vecbase {0}", in(reg) base, options(nostack)); + unsafe { + asm!("wsr.vecbase {0}", in(reg) base, options(nostack)); + } } /// Get the core stack pointer @@ -54,22 +56,24 @@ pub fn get_stack_pointer() -> *const u32 { /// scheduler #[inline(always)] pub unsafe fn set_stack_pointer(stack: *mut u32) { - // FIXME: this function relies on it getting inlined - if it doesn't inline it - // will try and return from this function using the adress in `a0` which has - // just been trashed... According to https://nnethercote.github.io/perf-book/inlining.html: - // "Inline attributes do not guarantee that a function is inlined or not - // inlined, but in practice, #[inline(always)] will cause inlining in all but - // the most exceptional cases." Is this good enough? Should we rewrite these - // as a macro to guarentee inlining? + unsafe { + // FIXME: this function relies on it getting inlined - if it doesn't inline it + // will try and return from this function using the adress in `a0` which has + // just been trashed... According to https://nnethercote.github.io/perf-book/inlining.html: + // "Inline attributes do not guarantee that a function is inlined or not + // inlined, but in practice, #[inline(always)] will cause inlining in all but + // the most exceptional cases." Is this good enough? Should we rewrite these + // as a macro to guarentee inlining? - // NOTE: modification of the `sp` & `a0` is not typically allowed inside inline - // asm!, but because we *need* to modify it we can do so by ommiting it from - // the clobber - asm!( - "movi a0, 0", // trash return register - "mov sp, {0}", // move stack pointer - in(reg) stack, options(nostack) - ); + // NOTE: modification of the `sp` & `a0` is not typically allowed inside inline + // asm!, but because we *need* to modify it we can do so by ommiting it from + // the clobber + asm!( + "movi a0, 0", // trash return register + "mov sp, {0}", // move stack pointer + in(reg) stack, options(nostack) + ); + } } /// Get the core current program counter