Skip to content

Commit aa20ceb

Browse files
committed
consolidate setup
1 parent 75df8b5 commit aa20ceb

File tree

1 file changed

+25
-53
lines changed

1 file changed

+25
-53
lines changed

src/xspi/mod.rs

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ mod common {
460460
w.dcyc().bits(dummy_cycles).instruction().bits(ir).fmode().bits(fmode)
461461
};
462462

463+
#[cfg(any(feature = "rm0455", feature = "rm0468"))]
464+
let w = w.isize().bits(instruction.size());
465+
463466
w.imode()
464467
.bits(imode)
465468
.admode()
@@ -479,6 +482,25 @@ mod common {
479482
self.rb.tcr.write(|w| unsafe { w.dcyc().bits(dummy_cycles) });
480483
self.rb.cr.modify(|_, w| unsafe { w.fmode().bits(fmode) });
481484
}
485+
486+
// Write alternate-bytes
487+
self.rb.abr.write(|w| unsafe {
488+
w.alternate().bits(alternate_bytes.bits())
489+
});
490+
491+
#[cfg(any(feature = "rm0455", feature = "rm0468"))]
492+
if instruction != XspiWord::None {
493+
self.rb.ir.write(|w| unsafe {
494+
w.instruction().bits(instruction.bits())
495+
});
496+
}
497+
498+
if address != XspiWord::None {
499+
// Write the address. The transaction starts on the next write
500+
// to DATA, unless there is no DATA phase configured, in which
501+
// case it starts here.
502+
self.rb.ar.write(|w| unsafe { w.address().bits(address.bits()) });
503+
}
482504
}
483505

484506
/// Begin a write over the XSPI interface. This is mostly useful for use with
@@ -596,33 +618,9 @@ mod common {
596618

597619
// Setup extended mode. Typically no dummy cycles in write mode
598620
self.setup_extended(instruction, address, alternate_bytes, 0, !data.is_empty(), false);
599-
// Write alternate-bytes
600-
self.rb.abr.write(|w| unsafe {
601-
w.alternate().bits(alternate_bytes.bits())
602-
});
603-
604-
if instruction != XspiWord::None {
605-
// Write instruction. If there is no address or data phase, the
606-
// transaction starts here.
607-
#[cfg(any(feature = "rm0433", feature = "rm0399"))]
608-
{
609-
let ir = instruction.bits_u8()?;
610-
self.rb.ccr.modify(|_, w| unsafe { w.instruction().bits(ir) });
611-
}
612-
#[cfg(any(feature = "rm0455", feature = "rm0468"))]
613-
self.rb.ir.write(|w| unsafe {
614-
w.instruction().bits(instruction.bits())
615-
});
616-
}
617-
618-
if address != XspiWord::None {
619-
// Write the address. The transaction starts on the next write
620-
// to DATA, unless there is no DATA phase configured, in which
621-
// case it starts here.
622-
self.rb.ar.write(|w| unsafe { w.address().bits(address.bits()) });
623-
}
624621

625622
// Write data to the FIFO in a byte-wise manner.
623+
// Transaction starts here
626624
unsafe {
627625
for byte in data {
628626
ptr::write_volatile(&self.rb.dr as *const _ as *mut u8, *byte);
@@ -765,37 +763,11 @@ mod common {
765763
.dlr
766764
.write(|w| unsafe { w.dl().bits(dest.len() as u32 - 1) });
767765

768-
// Setup extended mode. Read operations always have a data phase. if there is no
769-
// address, this will start the transaction
766+
// Setup extended mode. Read operations always have a data phase.
767+
// Transaction starts here
770768
self.setup_extended(instruction, address, alternate_bytes,
771769
dummy_cycles, true, true);
772770

773-
// Write alternate-bytes
774-
self.rb.abr.write(|w| unsafe {
775-
w.alternate().bits(alternate_bytes.bits())
776-
});
777-
778-
/*
779-
* p894
780-
*
781-
* If neither the address register (QUADSPI_AR) nor the data register (QUADSPI_DR)
782-
* need to be updated for a particular command, then the command sequence starts as
783-
* soon as QUADSPI_CCR is written. This is the case when both ADMODE and DMODE are
784-
* 00, or if just ADMODE = 00 when in indirect read mode (FMODE = 01).
785-
*
786-
* When an address is required (ADMODE is not 00) and the data register does not
787-
* need to be written (when FMODE = 01 or DMODE = 00), the command sequence starts
788-
* as soon as the address is updated with a write to QUADSPI_AR.
789-
*
790-
* In case of data transmission (FMODE = 00 and DMODE! = 00), the communication
791-
* start is triggered by a write in the FIFO through QUADSPI_DR.
792-
*/
793-
794-
// Write the address if there is one, transaction starts here
795-
if address != XspiWord::None {
796-
self.rb.ar.write(|w| unsafe { w.address().bits(address.bits()) });
797-
}
798-
799771
// Wait for the transaction to complete
800772
while self.rb.sr.read().tcf().bit_is_clear() {}
801773

0 commit comments

Comments
 (0)