Use the ram macro instead of assuming the .rwtext section (#4005)

This commit is contained in:
Björn Quentin 2025-08-28 17:26:22 +02:00 committed by GitHub
parent 1ecb6f5f76
commit 63d48b3c04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 9 deletions

View File

@ -19,6 +19,7 @@ bench = false
[dependencies]
embedded-storage = "0.3.1"
procmacros = { version = "0.19.0", package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }
# Optional dependencies
critical-section = { version = "1.2.0", optional = true }

View File

@ -1,28 +1,25 @@
use esp_rom_sys as _;
use esp_rom_sys::rom::spiflash::*;
use procmacros::ram;
use crate::maybe_with_critical_section;
#[inline(never)]
#[unsafe(link_section = ".rwtext")]
#[ram]
pub(crate) fn spiflash_read(src_addr: u32, data: *const u32, len: u32) -> i32 {
maybe_with_critical_section(|| unsafe { esp_rom_spiflash_read(src_addr, data, len) })
}
#[inline(never)]
#[unsafe(link_section = ".rwtext")]
#[ram]
pub(crate) fn spiflash_unlock() -> i32 {
maybe_with_critical_section(|| unsafe { esp_rom_spiflash_unlock() })
}
#[inline(never)]
#[unsafe(link_section = ".rwtext")]
#[ram]
pub(crate) fn spiflash_erase_sector(sector_number: u32) -> i32 {
maybe_with_critical_section(|| unsafe { esp_rom_spiflash_erase_sector(sector_number) })
}
#[inline(never)]
#[unsafe(link_section = ".rwtext")]
#[ram]
pub(crate) fn spiflash_write(dest_addr: u32, data: *const u32, len: u32) -> i32 {
maybe_with_critical_section(|| unsafe { esp_rom_spiflash_write(dest_addr, data, len) })
}

View File

@ -17,7 +17,6 @@ mod storage;
#[cfg(not(feature = "emulation"))]
#[inline(always)]
#[cfg_attr(not(target_os = "macos"), unsafe(link_section = ".rwtext"))]
fn maybe_with_critical_section<R>(f: impl FnOnce() -> R) -> R {
#[cfg(feature = "critical-section")]
return critical_section::with(|_| f());