Interface changes and added example

This commit is contained in:
Magnus Nordlander 2025-08-05 09:53:16 +02:00
parent 6d38e8b306
commit 8965a13da4
2 changed files with 51 additions and 5 deletions

View File

@ -11,10 +11,9 @@
#![cfg(feature = "_rp235x")]
use critical_section::{acquire, release, CriticalSection, RestoreState};
use embassy_hal_internal::Peri;
use crate::qmi_cs1::QmiCs1;
use crate::{pac, peripherals};
use crate::pac;
/// PSRAM errors.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -215,11 +214,9 @@ impl<'d> Psram<'d> {
///
/// This will detect the PSRAM device and configure it for memory-mapped access.
pub fn new(
qmi_cs1_peripheral: Peri<'d, peripherals::QMI_CS1>,
cs1: Peri<'d, impl crate::qmi_cs1::QmiCs1Pin>,
qmi_cs1: QmiCs1<'d>,
config: Config,
) -> Result<Self, Error> {
let qmi_cs1 = QmiCs1::new(qmi_cs1_peripheral, cs1);
let qmi = pac::QMI;
let xip = pac::XIP_CTRL;

View File

@ -0,0 +1,49 @@
//! This example tests an APS6404L PSRAM chip connected to the RP235x
//! It fills the PSRAM with alternating patterns and reads back a value
//!
//! In this example, the PSRAM CS is connected to Pin 0.
#![no_std]
#![no_main]
use defmt::*;
use embassy_executor::Spawner;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
use core::slice;
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let config = embassy_rp::config::Config::default();
let p = embassy_rp::init(config);
let psram_config = embassy_rp::psram::Config::aps6404l();
let psram = embassy_rp::psram::Psram::new(embassy_rp::qmi_cs1::QmiCs1::new(p.QMI_CS1, p.PIN_0), psram_config);
let Ok(psram) = psram else {
error!("PSRAM not found");
loop {
Timer::after_secs(1).await;
};
};
let psram_slice = unsafe {
let psram_ptr = psram.base_address();
let slice: &'static mut [u8] =
slice::from_raw_parts_mut(psram_ptr, psram.size() as usize);
slice
};
loop {
psram_slice.fill(0x55);
info!("PSRAM filled with 0x55");
let at_addr = psram_slice[0x100];
info!("Read from PSRAM at address 0x100: 0x{:02x}", at_addr);
Timer::after_secs(1).await;
psram_slice.fill(0xAA);
info!("PSRAM filled with 0xAA");
let at_addr = psram_slice[0x100];
info!("Read from PSRAM at address 0x100: 0x{:02x}", at_addr);
Timer::after_secs(1).await;
}
}