Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove most PSRAM features #2178

Merged
merged 8 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions esp-alloc/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ macro_rules! heap_allocator {
macro_rules! psram_allocator {
($peripheral:expr,$psram_module:path) => {{
use $psram_module as _psram;
_psram::init_psram($peripheral);
let (start, size) = _psram::init_psram($peripheral, _psram::PsramConfig::default());
unsafe {
$crate::HEAP.add_region($crate::HeapRegion::new(
_psram::psram_vaddr_start() as *mut u8,
_psram::PSRAM_BYTES,
start,
size,
$crate::MemoryCapability::External.into(),
));
}
Expand Down
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The `NO_PIN` constant has been removed. (#2133)
- MSRV bump to 1.79 (#2156)
- Allow handling interrupts while trying to lock critical section on multi-core chips. (#2197)
- Removed the PS-RAM related features, replaced by `quad-psram`/`octal-psram`, `init_psram` takes a configuration parameter, it's now possible to auto-detect PS-RAM size (#2178)

### Fixed

Expand Down
23 changes: 5 additions & 18 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,11 @@ defmt = [
]

#! ### PSRAM Feature Flags
## Use externally connected PSRAM (2MB).
psram-2m = []
## Use externally connected PSRAM (4MB).
psram-4m = []
## Use externally connected PSRAM (8MB).
psram-8m = []
## PSRAM 80Mhz frequency support
psram-80mhz = []

#! ### Octal RAM Feature Flags
## Use externally connected Octal RAM (2MB).
opsram-2m = []
## Use externally connected Octal RAM (4MB).
opsram-4m = []
## Use externally connected Octal RAM (8MB).
opsram-8m = []
## Use externally connected Octal RAM (16MB).
opsram-16m = []
## Use externally connected Quad PSRAM
quad-psram = []

## Use externally connected Octal RAM
octal-psram = []

# This feature is intended for testing; you probably don't want to enable it:
ci = ["defmt", "bluetooth"]
Expand Down
46 changes: 46 additions & 0 deletions esp-hal/MIGRATING-0.20.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,49 @@ We've replaced some usage of features with [esp-config](https://docs.rs/esp-conf
# key in .cargo/config.toml [env] section
+ ESP_HAL_PLACE_SPI_DRIVER_IN_RAM=true
```

## PS-RAM

Initializing PS-RAM now takes a chip specific config and returns start of the mapped memory and the size.

Example
```rust
let (start, size) = psram::init_psram(peripherals.PSRAM, psram::PsramConfig::default());
```

If you don't specify the size of PS-RAM via `PsramConfig::size` the size of PS-RAM is derived from the RAM-chip id (or via probing in case of ESP32).

`psram::psram_vaddr_start()` and `psram::PSRAM_BYTES` are removed.

The features `psram-Xm` and `opsram-Xm` are removed and replaced by `quad-psram`/`octal-psram`.
The feature `psram-80mhz` is removed and replaced by `PsramConfig`

Diff of the `psram_quad.rs` example
```diff
-//% FEATURES: psram-2m
+//% FEATURES: esp-hal/quad-psram

...

-fn init_psram_heap() {
+fn init_psram_heap(start: *mut u8, size: usize) {
unsafe {
esp_alloc::HEAP.add_region(esp_alloc::HeapRegion::new(
- psram::psram_vaddr_start() as *mut u8,
- psram::PSRAM_BYTES,
+ start,
+ size,
esp_alloc::MemoryCapability::External.into(),
));
}

...

- psram::init_psram(peripherals.PSRAM);
- init_psram_heap();
+ let (start, size) = psram::init_psram(peripherals.PSRAM, psram::PsramConfig::default());
+ init_psram_heap(start, size);

...

```
14 changes: 6 additions & 8 deletions esp-hal/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ fn main() -> Result<(), Box<dyn Error>> {
let config = Config::for_chip(&chip);

// Check PSRAM features are only given if the target supports PSRAM:
if !config.contains(&String::from("psram"))
&& (cfg!(feature = "psram-2m") || cfg!(feature = "psram-4m") || cfg!(feature = "psram-8m"))
{
if !config.contains(&String::from("psram")) && cfg!(feature = "quad-psram") {
panic!("The target does not support PSRAM");
}

if !config.contains(&String::from("octal_psram")) && cfg!(feature = "octal-psram") {
panic!("The target does not support Octal PSRAM");
}

// Define all necessary configuration symbols for the configured device:
config.define_symbols();

Expand Down Expand Up @@ -226,11 +228,7 @@ fn generate_memory_extras() -> Vec<u8> {

#[cfg(feature = "esp32s2")]
fn generate_memory_extras() -> Vec<u8> {
let reserved_cache = if cfg!(any(
feature = "psram-2m",
feature = "psram-4m",
feature = "psram-8m"
)) {
let reserved_cache = if cfg!(feature = "quad-psram") {
"0x4000"
} else {
"0x2000"
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub use self::soc::efuse;
#[cfg(lp_core)]
pub use self::soc::lp_core;
pub use self::soc::peripherals;
#[cfg(psram)]
#[cfg(any(feature = "quad-psram", feature = "octal-psram"))]
pub use self::soc::psram;
#[cfg(ulp_riscv_core)]
pub use self::soc::ulp_core;
Expand Down
27 changes: 27 additions & 0 deletions esp-hal/src/lock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::cell::UnsafeCell;

mod single_core {
pub unsafe fn disable_interrupts() -> critical_section::RawRestoreState {
cfg_if::cfg_if! {
Expand Down Expand Up @@ -210,6 +212,31 @@ pub(crate) fn lock<T>(lock: &Lock, f: impl FnOnce() -> T) -> T {
f()
}

/// Data protected by a [Lock]
#[allow(unused)]
pub(crate) struct Locked<T> {
lock_state: Lock,
data: UnsafeCell<T>,
}

#[allow(unused)]
impl<T> Locked<T> {
/// Create a new instance
pub(crate) const fn new(data: T) -> Self {
Self {
lock_state: Lock::new(),
data: UnsafeCell::new(data),
}
}

/// Provide exclusive access to the protected data to the given closure
pub(crate) fn with<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
lock(&self.lock_state, || f(unsafe { &mut *self.data.get() }))
}
}

unsafe impl<T> Sync for Locked<T> {}

struct CriticalSection;

critical_section::set_impl!(CriticalSection);
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/soc/esp32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod cpu_control;
pub mod efuse;
pub mod gpio;
pub mod peripherals;
#[cfg(psram)]
#[cfg(feature = "quad-psram")]
pub mod psram;
pub mod radio_clocks;
pub mod trng;
Expand Down
Loading
Loading