@@ -442,17 +442,23 @@ mod common {
442
442
/// and the data phase.
443
443
/// * `data` - true is there is a data phase, false for no data phase.
444
444
fn setup_extended( & mut self , instruction: XspiWord , address: XspiWord ,
445
- alternate_bytes: XspiWord , dummy_cycles: u8 , data: bool ) {
445
+ alternate_bytes: XspiWord , dummy_cycles: u8 , data: bool , read : bool ) {
446
446
447
+ let fmode = if read { 0b01 } else { 0b00 } ;
447
448
let mode = self . mode. reg_value( ) ;
448
449
let imode = if instruction != XspiWord :: None { mode } else { 0 } ;
449
450
let admode = if address != XspiWord :: None { mode } else { 0 } ;
450
451
let abmode = if alternate_bytes != XspiWord :: None { mode } else { 0 } ;
451
452
let dmode = if data { mode } else { 0 } ;
452
453
454
+ //writing to ccr will trigger the start of a transaction if there is no address or
455
+ //data rm0433 pg 894, so we do it all in one go
453
456
self . rb. ccr. modify( |_, w| unsafe {
454
457
#[ cfg( any( feature = "rm0433" , feature = "rm0399" ) ) ]
455
- let w = w. dcyc( ) . bits( dummy_cycles) ;
458
+ let w = {
459
+ let ir = instruction. bits_u8( ) . unwrap( ) ;
460
+ w. dcyc( ) . bits( dummy_cycles) . instruction( ) . bits( ir) . fmode( ) . bits( fmode)
461
+ } ;
456
462
457
463
#[ cfg( any( feature = "rm0455" , feature = "rm0468" ) ) ]
458
464
let w = w. isize ( ) . bits( instruction. size( ) ) ;
@@ -472,7 +478,29 @@ mod common {
472
478
} ) ;
473
479
474
480
#[ cfg( any( feature = "rm0455" , feature = "rm0468" ) ) ]
475
- self . rb. tcr. write( |w| unsafe { w. dcyc( ) . bits( dummy_cycles) } ) ;
481
+ {
482
+ self . rb. tcr. write( |w| unsafe { w. dcyc( ) . bits( dummy_cycles) } ) ;
483
+ self . rb. cr. modify( |_, w| unsafe { w. fmode( ) . bits( fmode) } ) ;
484
+ }
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
+ }
476
504
}
477
505
478
506
/// Begin a write over the XSPI interface. This is mostly useful for use with
@@ -578,9 +606,6 @@ mod common {
578
606
579
607
self . is_busy( ) ?;
580
608
581
- // Setup extended mode. Typically no dummy cycles in write mode
582
- self . setup_extended( instruction, address, alternate_bytes, 0 , !data. is_empty( ) ) ;
583
-
584
609
// Clear the transfer complete flag.
585
610
self . rb. fcr. write( |w| w. ctcf( ) . set_bit( ) ) ;
586
611
@@ -591,32 +616,11 @@ mod common {
591
616
. write( |w| unsafe { w. dl( ) . bits( data. len( ) as u32 - 1 ) } ) ;
592
617
}
593
618
594
- // Configure the mode to indirect write.
595
- fmode_reg!( self ) . modify( |_, w| unsafe { w. fmode( ) . bits( 0b00 ) } ) ;
596
-
597
- // Write alternate-bytes
598
- self . rb. abr. write( |w| unsafe {
599
- w. alternate( ) . bits( alternate_bytes. bits( ) )
600
- } ) ;
601
-
602
- // Write instruction. If there is no address or data phase, the
603
- // transaction starts here.
604
- #[ cfg( any( feature = "rm0433" , feature = "rm0399" ) ) ]
605
- {
606
- let ir = instruction. bits_u8( ) ?;
607
- self . rb. ccr. modify( |_, w| unsafe { w. instruction( ) . bits( ir) } ) ;
608
- }
609
- #[ cfg( any( feature = "rm0455" , feature = "rm0468" ) ) ]
610
- self . rb. ir. write( |w| unsafe {
611
- w. instruction( ) . bits( instruction. bits( ) )
612
- } ) ;
613
-
614
- // Write the address. The transaction starts on the next write
615
- // to DATA, unless there is no DATA phase configured, in which
616
- // case it starts here.
617
- self . rb. ar. write( |w| unsafe { w. address( ) . bits( address. bits( ) ) } ) ;
619
+ // Setup extended mode. Typically no dummy cycles in write mode
620
+ self . setup_extended( instruction, address, alternate_bytes, 0 , !data. is_empty( ) , false ) ;
618
621
619
622
// Write data to the FIFO in a byte-wise manner.
623
+ // Transaction starts here
620
624
unsafe {
621
625
for byte in data {
622
626
ptr:: write_volatile( & self . rb. dr as * const _ as * mut u8 , * byte) ;
@@ -751,10 +755,6 @@ mod common {
751
755
752
756
self . is_busy( ) ?;
753
757
754
- // Setup extended mode. Read operations always have a data phase.
755
- self . setup_extended( instruction, address, alternate_bytes,
756
- dummy_cycles, true ) ;
757
-
758
758
// Clear the transfer complete flag.
759
759
self . rb. fcr. write( |w| w. ctcf( ) . set_bit( ) ) ;
760
760
@@ -763,28 +763,10 @@ mod common {
763
763
. dlr
764
764
. write( |w| unsafe { w. dl( ) . bits( dest. len( ) as u32 - 1 ) } ) ;
765
765
766
- // Configure the mode to indirect read.
767
- fmode_reg!( self ) . modify( |_, w| unsafe { w. fmode( ) . bits( 0b01 ) } ) ;
768
-
769
- // Write alternate-bytes
770
- self . rb. abr. write( |w| unsafe {
771
- w. alternate( ) . bits( alternate_bytes. bits( ) )
772
- } ) ;
773
-
774
- // Write instruction. If there is no address phase, the
775
- // transaction starts here.
776
- #[ cfg( any( feature = "rm0433" , feature = "rm0399" ) ) ]
777
- {
778
- let ir = instruction. bits_u8( ) ?;
779
- self . rb. ccr. modify( |_, w| unsafe { w. instruction( ) . bits( ir) } ) ;
780
- }
781
- #[ cfg( any( feature = "rm0455" , feature = "rm0468" ) ) ]
782
- self . rb. ir. write( |w| unsafe {
783
- w. instruction( ) . bits( instruction. bits( ) )
784
- } ) ;
785
-
786
- // Write the address. Transaction starts here.
787
- self . rb. ar. write( |w| unsafe { w. address( ) . bits( address. bits( ) ) } ) ;
766
+ // Setup extended mode. Read operations always have a data phase.
767
+ // Transaction starts here
768
+ self . setup_extended( instruction, address, alternate_bytes,
769
+ dummy_cycles, true , true ) ;
788
770
789
771
// Wait for the transaction to complete
790
772
while self . rb. sr. read( ) . tcf( ) . bit_is_clear( ) { }
0 commit comments