From 460d213788d4a1d5f13d03d0c183c0a2de950236 Mon Sep 17 00:00:00 2001 From: ElouanPetereau Date: Thu, 5 Oct 2023 19:51:42 +0200 Subject: [PATCH] Rename QUADSPI change_bank and check for business --- src/xspi/qspi.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/xspi/qspi.rs b/src/xspi/qspi.rs index 5912de0e..9934cbc3 100644 --- a/src/xspi/qspi.rs +++ b/src/xspi/qspi.rs @@ -8,7 +8,7 @@ use crate::{ stm32, }; -use super::{common::BankSelect, Bank, Config, Qspi, SamplingEdge}; +use super::{common::BankSelect, Bank, Config, Qspi, QspiError, SamplingEdge}; /// Used to indicate that an IO pin is not used by the QSPI interface. pub struct NoIo {} @@ -229,12 +229,21 @@ pub trait QspiExt { } impl Qspi { - pub fn change_bank(&mut self, bank: BankSelect) { + pub fn change_bank_unchecked( + &mut self, + bank: BankSelect, + ) -> Result<(), QspiError> { + // Ensure that the peripheral is no longer busy before changing FSEL and DFM bits + if self.is_busy().is_err() { + return Err(QspiError::Busy); + }; + self.rb.cr.modify(|_, w| w.dfm().clear_bit()); match bank { BankSelect::One => self.rb.cr.modify(|_, w| w.fsel().clear_bit()), BankSelect::Two => self.rb.cr.modify(|_, w| w.fsel().set_bit()), } + Ok(()) } pub fn qspi_unchecked(