File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -64,8 +64,8 @@ impl DelayMs<u8> for Delay {
64
64
65
65
impl DelayUs < u32 > for Delay {
66
66
fn delay_us ( & mut self , us : u32 ) {
67
- // The RVR register is 24 bits wide, as SysTick is based on a 24 bit counter
68
- const MAX_RVR : u32 = 1 << 24 ;
67
+ // The SysTick Reload Value register supports values between 1 and 0x00FFFFFF.
68
+ const MAX_RVR : u32 = 0x00FF_FFFF ;
69
69
70
70
// Depending on hclk (core clock), this 32 bit value allows
71
71
// delays between 1 min to 9 min.
@@ -79,17 +79,19 @@ impl DelayUs<u32> for Delay {
79
79
// Like dividing total_rvr / MAX_RVR
80
80
// and delaying by MAX_RVR * (fraction).
81
81
while total_rvr != 0 {
82
- let current_rvr = if total_rvr < MAX_RVR {
82
+ let current_rvr = if total_rvr <= MAX_RVR {
83
83
total_rvr
84
84
} else {
85
85
MAX_RVR
86
86
} ;
87
- total_rvr -= current_rvr;
88
87
89
88
self . syst . set_reload ( current_rvr) ;
90
89
self . syst . clear_current ( ) ;
91
90
self . syst . enable_counter ( ) ;
92
91
92
+ // Update the tracking variable while we are waiting...
93
+ total_rvr -= current_rvr;
94
+
93
95
while !self . syst . has_wrapped ( ) { }
94
96
95
97
self . syst . disable_counter ( ) ;
You can’t perform that action at this time.
0 commit comments