@@ -14,24 +14,9 @@ use stable_deref_trait::StableDeref;
14
14
15
15
use crate :: hal:: serial:: { self , Write } ;
16
16
17
- use crate :: stm32:: { USART1 , USART2 } ;
18
-
19
- #[ cfg( any(
20
- feature = "stm32l4x2" ,
21
- feature = "stm32l4x3" ,
22
- feature = "stm32l4x5" ,
23
- feature = "stm32l4x6" ,
24
- ) ) ]
25
- use crate :: stm32:: USART3 ;
26
-
27
- #[ cfg( any( feature = "stm32l4x5" , feature = "stm32l4x6" , ) ) ]
28
- use crate :: stm32:: UART4 ;
29
-
30
- #[ cfg( any( feature = "stm32l4x5" , feature = "stm32l4x6" , ) ) ]
31
- use crate :: stm32:: UART5 ;
32
-
33
17
use crate :: dma:: { dma1, CircBuffer , DMAFrame , FrameReader , FrameSender } ;
34
18
use crate :: gpio:: { self , Alternate , Floating , Input } ;
19
+ use crate :: pac;
35
20
use crate :: rcc:: { Clocks , APB1R1 , APB2 } ;
36
21
use crate :: time:: { Bps , U32Ext } ;
37
22
@@ -203,7 +188,7 @@ macro_rules! hal {
203
188
) ,
204
189
) +) => {
205
190
$(
206
- impl <PINS > Serial <$USARTX, PINS > {
191
+ impl <PINS > Serial <pac :: $USARTX, PINS > {
207
192
/// Configures the serial interface and creates the interface
208
193
/// struct.
209
194
///
@@ -220,14 +205,14 @@ macro_rules! hal {
220
205
/// configuration. (`MAPR` is used to map the USART to the
221
206
/// corresponding pins. `APBX` is used to reset the USART.)
222
207
pub fn $usartX(
223
- usart: $USARTX,
208
+ usart: pac :: $USARTX,
224
209
pins: PINS ,
225
210
config: Config ,
226
211
clocks: Clocks ,
227
212
apb: & mut $APB,
228
213
) -> Self
229
214
where
230
- PINS : Pins <$USARTX>,
215
+ PINS : Pins <pac :: $USARTX>,
231
216
{
232
217
// enable or reset $USARTX
233
218
apb. enr( ) . modify( |_, w| w. $usartXen( ) . set_bit( ) ) ;
@@ -374,7 +359,7 @@ macro_rules! hal {
374
359
}
375
360
376
361
/// Splits the `Serial` abstraction into a transmitter and a receiver half
377
- pub fn split( self ) -> ( Tx <$USARTX>, Rx <$USARTX>) {
362
+ pub fn split( self ) -> ( Tx <pac :: $USARTX>, Rx <pac :: $USARTX>) {
378
363
(
379
364
Tx {
380
365
_usart: PhantomData ,
@@ -386,31 +371,31 @@ macro_rules! hal {
386
371
}
387
372
388
373
/// Frees the USART peripheral
389
- pub fn release( self ) -> ( $USARTX, PINS ) {
374
+ pub fn release( self ) -> ( pac :: $USARTX, PINS ) {
390
375
( self . usart, self . pins)
391
376
}
392
377
}
393
378
394
- impl <PINS > serial:: Read <u8 > for Serial <$USARTX, PINS > {
379
+ impl <PINS > serial:: Read <u8 > for Serial <pac :: $USARTX, PINS > {
395
380
type Error = Error ;
396
381
397
382
fn read( & mut self ) -> nb:: Result <u8 , Error > {
398
- let mut rx: Rx <$USARTX> = Rx {
383
+ let mut rx: Rx <pac :: $USARTX> = Rx {
399
384
_usart: PhantomData ,
400
385
} ;
401
386
rx. read( )
402
387
}
403
388
}
404
389
405
- impl serial:: Read <u8 > for Rx <$USARTX> {
390
+ impl serial:: Read <u8 > for Rx <pac :: $USARTX> {
406
391
type Error = Error ;
407
392
408
393
fn read( & mut self ) -> nb:: Result <u8 , Error > {
409
394
// NOTE(unsafe) atomic read with no side effects
410
- let isr = unsafe { ( * $USARTX:: ptr( ) ) . isr. read( ) } ;
395
+ let isr = unsafe { ( * pac :: $USARTX:: ptr( ) ) . isr. read( ) } ;
411
396
412
397
// NOTE(unsafe): Only used for atomic writes, to clear error flags.
413
- let icr = unsafe { & ( * $USARTX:: ptr( ) ) . icr } ;
398
+ let icr = unsafe { & ( * pac :: $USARTX:: ptr( ) ) . icr } ;
414
399
415
400
Err ( if isr. pe( ) . bit_is_set( ) {
416
401
icr. write( |w| w. pecf( ) . clear( ) ) ;
@@ -427,33 +412,33 @@ macro_rules! hal {
427
412
} else if isr. rxne( ) . bit_is_set( ) {
428
413
// NOTE(read_volatile) see `write_volatile` below
429
414
return Ok ( unsafe {
430
- ptr:: read_volatile( & ( * $USARTX:: ptr( ) ) . rdr as * const _ as * const _)
415
+ ptr:: read_volatile( & ( * pac :: $USARTX:: ptr( ) ) . rdr as * const _ as * const _)
431
416
} ) ;
432
417
} else {
433
418
nb:: Error :: WouldBlock
434
419
} )
435
420
}
436
421
}
437
422
438
- impl <PINS > serial:: Write <u8 > for Serial <$USARTX, PINS > {
423
+ impl <PINS > serial:: Write <u8 > for Serial <pac :: $USARTX, PINS > {
439
424
type Error = Error ;
440
425
441
426
fn flush( & mut self ) -> nb:: Result <( ) , Error > {
442
- let mut tx: Tx <$USARTX> = Tx {
427
+ let mut tx: Tx <pac :: $USARTX> = Tx {
443
428
_usart: PhantomData ,
444
429
} ;
445
430
tx. flush( )
446
431
}
447
432
448
433
fn write( & mut self , byte: u8 ) -> nb:: Result <( ) , Error > {
449
- let mut tx: Tx <$USARTX> = Tx {
434
+ let mut tx: Tx <pac :: $USARTX> = Tx {
450
435
_usart: PhantomData ,
451
436
} ;
452
437
tx. write( byte)
453
438
}
454
439
}
455
440
456
- impl serial:: Write <u8 > for Tx <$USARTX> {
441
+ impl serial:: Write <u8 > for Tx <pac :: $USARTX> {
457
442
// NOTE(Void) See section "29.7 USART interrupts"; the only possible errors during
458
443
// transmission are: clear to send (which is disabled in this case) errors and
459
444
// framing errors (which only occur in SmartCard mode); neither of these apply to
@@ -462,7 +447,7 @@ macro_rules! hal {
462
447
463
448
fn flush( & mut self ) -> nb:: Result <( ) , Error > {
464
449
// NOTE(unsafe) atomic read with no side effects
465
- let isr = unsafe { ( * $USARTX:: ptr( ) ) . isr. read( ) } ;
450
+ let isr = unsafe { ( * pac :: $USARTX:: ptr( ) ) . isr. read( ) } ;
466
451
467
452
if isr. tc( ) . bit_is_set( ) {
468
453
Ok ( ( ) )
@@ -473,13 +458,13 @@ macro_rules! hal {
473
458
474
459
fn write( & mut self , byte: u8 ) -> nb:: Result <( ) , Error > {
475
460
// NOTE(unsafe) atomic read with no side effects
476
- let isr = unsafe { ( * $USARTX:: ptr( ) ) . isr. read( ) } ;
461
+ let isr = unsafe { ( * pac :: $USARTX:: ptr( ) ) . isr. read( ) } ;
477
462
478
463
if isr. txe( ) . bit_is_set( ) {
479
464
// NOTE(unsafe) atomic write to stateless register
480
465
// NOTE(write_volatile) 8-bit write that's not possible through the svd2rust API
481
466
unsafe {
482
- ptr:: write_volatile( & ( * $USARTX:: ptr( ) ) . tdr as * const _ as * mut _, byte)
467
+ ptr:: write_volatile( & ( * pac :: $USARTX:: ptr( ) ) . tdr as * const _ as * mut _, byte)
483
468
}
484
469
Ok ( ( ) )
485
470
} else {
@@ -488,7 +473,7 @@ macro_rules! hal {
488
473
}
489
474
}
490
475
491
- impl Rx <$USARTX> {
476
+ impl Rx <pac :: $USARTX> {
492
477
pub fn circ_read<B , H >(
493
478
& self ,
494
479
mut chan: $rx_chan,
@@ -499,7 +484,7 @@ macro_rules! hal {
499
484
H : AsMutSlice <Element = u8 >
500
485
{
501
486
let buf = buffer[ 0 ] . as_mut_slice( ) ;
502
- chan. set_peripheral_address( unsafe { & ( * $USARTX:: ptr( ) ) . rdr as * const _ as u32 } , false ) ;
487
+ chan. set_peripheral_address( unsafe { & ( * pac :: $USARTX:: ptr( ) ) . rdr as * const _ as u32 } , false ) ;
503
488
chan. set_memory_address( buf. as_ptr( ) as u32 , true ) ;
504
489
chan. set_transfer_length( ( buf. len( ) * 2 ) as u16 ) ;
505
490
@@ -546,7 +531,7 @@ macro_rules! hal {
546
531
BUFFER : Sized + StableDeref <Target = DMAFrame <N >> + DerefMut + ' static ,
547
532
N : ArrayLength <MaybeUninit <u8 >>,
548
533
{
549
- let usart = unsafe { & ( * $USARTX:: ptr( ) ) } ;
534
+ let usart = unsafe { & ( * pac :: $USARTX:: ptr( ) ) } ;
550
535
551
536
// Setup DMA transfer
552
537
let buf = & * buffer;
@@ -588,8 +573,8 @@ macro_rules! hal {
588
573
/// Checks to see if the USART peripheral has detected an idle line and clears
589
574
/// the flag
590
575
pub fn is_idle( & mut self , clear: bool ) -> bool {
591
- let isr = unsafe { & ( * $USARTX:: ptr( ) ) . isr. read( ) } ;
592
- let icr = unsafe { & ( * $USARTX:: ptr( ) ) . icr } ;
576
+ let isr = unsafe { & ( * pac :: $USARTX:: ptr( ) ) . isr. read( ) } ;
577
+ let icr = unsafe { & ( * pac :: $USARTX:: ptr( ) ) . icr } ;
593
578
594
579
if isr. idle( ) . bit_is_set( ) {
595
580
if clear {
@@ -604,8 +589,8 @@ macro_rules! hal {
604
589
/// Checks to see if the USART peripheral has detected an character match and
605
590
/// clears the flag
606
591
pub fn is_character_match( & mut self , clear: bool ) -> bool {
607
- let isr = unsafe { & ( * $USARTX:: ptr( ) ) . isr. read( ) } ;
608
- let icr = unsafe { & ( * $USARTX:: ptr( ) ) . icr } ;
592
+ let isr = unsafe { & ( * pac :: $USARTX:: ptr( ) ) . isr. read( ) } ;
593
+ let icr = unsafe { & ( * pac :: $USARTX:: ptr( ) ) . icr } ;
609
594
610
595
if isr. cmf( ) . bit_is_set( ) {
611
596
if clear {
@@ -620,8 +605,8 @@ macro_rules! hal {
620
605
/// Checks to see if the USART peripheral has detected an receiver timeout and
621
606
/// clears the flag
622
607
pub fn is_receiver_timeout( & mut self , clear: bool ) -> bool {
623
- let isr = unsafe { & ( * $USARTX:: ptr( ) ) . isr. read( ) } ;
624
- let icr = unsafe { & ( * $USARTX:: ptr( ) ) . icr } ;
608
+ let isr = unsafe { & ( * pac :: $USARTX:: ptr( ) ) . isr. read( ) } ;
609
+ let icr = unsafe { & ( * pac :: $USARTX:: ptr( ) ) . icr } ;
625
610
626
611
if isr. rtof( ) . bit_is_set( ) {
627
612
if clear {
@@ -634,7 +619,7 @@ macro_rules! hal {
634
619
}
635
620
}
636
621
637
- impl Tx <$USARTX> {
622
+ impl Tx <pac :: $USARTX> {
638
623
/// Creates a new DMA frame sender
639
624
pub fn frame_sender<BUFFER , N >(
640
625
& self ,
@@ -644,7 +629,7 @@ macro_rules! hal {
644
629
BUFFER : Sized + StableDeref <Target = DMAFrame <N >> + DerefMut + ' static ,
645
630
N : ArrayLength <MaybeUninit <u8 >>,
646
631
{
647
- let usart = unsafe { & ( * $USARTX:: ptr( ) ) } ;
632
+ let usart = unsafe { & ( * pac :: $USARTX:: ptr( ) ) } ;
648
633
649
634
// Setup DMA
650
635
channel. set_peripheral_address( & usart. tdr as * const _ as u32 , false ) ;
@@ -763,28 +748,28 @@ macro_rules! impl_pin_traits {
763
748
$(
764
749
impl private:: SealedTx for
765
750
gpio:: $tx<Alternate <gpio:: $af, Input <Floating >>> { }
766
- impl TxPin <$instance> for
751
+ impl TxPin <pac :: $instance> for
767
752
gpio:: $tx<Alternate <gpio:: $af, Input <Floating >>> { }
768
753
) *
769
754
770
755
$(
771
756
impl private:: SealedRx for
772
757
gpio:: $rx<Alternate <gpio:: $af, Input <Floating >>> { }
773
- impl RxPin <$instance> for
758
+ impl RxPin <pac :: $instance> for
774
759
gpio:: $rx<Alternate <gpio:: $af, Input <Floating >>> { }
775
760
) *
776
761
777
762
$(
778
763
impl private:: SealedRtsDe for
779
764
gpio:: $rts_de<Alternate <gpio:: $af, Input <Floating >>> { }
780
- impl RtsDePin <$instance> for
765
+ impl RtsDePin <pac :: $instance> for
781
766
gpio:: $rts_de<Alternate <gpio:: $af, Input <Floating >>> { }
782
767
) *
783
768
784
769
$(
785
770
impl private:: SealedCts for
786
771
gpio:: $cts<Alternate <gpio:: $af, Input <Floating >>> { }
787
- impl CtsPin <$instance> for
772
+ impl CtsPin <pac :: $instance> for
788
773
gpio:: $cts<Alternate <gpio:: $af, Input <Floating >>> { }
789
774
) *
790
775
) *
0 commit comments