@@ -265,11 +265,7 @@ impl<I: Instance> CanConfig<'_, I> {
265
265
/// Then copy the `CAN_BUS_TIME` register value from the table and pass it as the `btr`
266
266
/// parameter to this method.
267
267
pub fn set_bit_timing ( self , btr : u32 ) -> Self {
268
- let can = self . can . registers ( ) ;
269
- can. btr . modify ( |r, w| unsafe {
270
- let mode_bits = r. bits ( ) & 0xC000_0000 ;
271
- w. bits ( mode_bits | btr)
272
- } ) ;
268
+ self . can . set_bit_timing ( btr) ;
273
269
self
274
270
}
275
271
@@ -367,12 +363,8 @@ impl<I: Instance> CanBuilder<I> {
367
363
///
368
364
/// Then copy the `CAN_BUS_TIME` register value from the table and pass it as the `btr`
369
365
/// parameter to this method.
370
- pub fn set_bit_timing ( self , btr : u32 ) -> Self {
371
- let can = self . can . registers ( ) ;
372
- can. btr . modify ( |r, w| unsafe {
373
- let mode_bits = r. bits ( ) & 0xC000_0000 ;
374
- w. bits ( mode_bits | btr)
375
- } ) ;
366
+ pub fn set_bit_timing ( mut self , btr : u32 ) -> Self {
367
+ self . can . set_bit_timing ( btr) ;
376
368
self
377
369
}
378
370
@@ -479,6 +471,17 @@ where
479
471
unsafe { & * I :: REGISTERS }
480
472
}
481
473
474
+ fn set_bit_timing ( & mut self , btr : u32 ) {
475
+ // Mask of all non-reserved BTR bits, except the mode flags.
476
+ const MASK : u32 = 0x037F_03FF ;
477
+
478
+ let can = self . registers ( ) ;
479
+ can. btr . modify ( |r, w| unsafe {
480
+ let mode_bits = r. bits ( ) & 0xC000_0000 ;
481
+ w. bits ( mode_bits | ( btr & MASK ) )
482
+ } ) ;
483
+ }
484
+
482
485
/// Returns a reference to the peripheral instance.
483
486
///
484
487
/// This allows accessing HAL-specific data stored in the instance type.
0 commit comments