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 {
6464
6565impl DelayUs < u32 > for Delay {
6666 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 ;
6969
7070 // Depending on hclk (core clock), this 32 bit value allows
7171 // delays between 1 min to 9 min.
@@ -79,17 +79,19 @@ impl DelayUs<u32> for Delay {
7979 // Like dividing total_rvr / MAX_RVR
8080 // and delaying by MAX_RVR * (fraction).
8181 while total_rvr != 0 {
82- let current_rvr = if total_rvr < MAX_RVR {
82+ let current_rvr = if total_rvr <= MAX_RVR {
8383 total_rvr
8484 } else {
8585 MAX_RVR
8686 } ;
87- total_rvr -= current_rvr;
8887
8988 self . syst . set_reload ( current_rvr) ;
9089 self . syst . clear_current ( ) ;
9190 self . syst . enable_counter ( ) ;
9291
92+ // Update the tracking variable while we are waiting...
93+ total_rvr -= current_rvr;
94+
9395 while !self . syst . has_wrapped ( ) { }
9496
9597 self . syst . disable_counter ( ) ;
You can’t perform that action at this time.
0 commit comments