Implement Delay from embedded-hal 1.0#193
Open
holly-hacker wants to merge 4 commits intostm32-rs:masterfrom
Open
Implement Delay from embedded-hal 1.0#193holly-hacker wants to merge 4 commits intostm32-rs:masterfrom
holly-hacker wants to merge 4 commits intostm32-rs:masterfrom
Conversation
This now uses the occasional 64bit arithmetic, but this should be fine given that this is a busy-loop delay function.
ccc0e49 to
6aa637c
Compare
Contributor
Author
|
Force-pushed to solve changelog merge conflict |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #192
This PR implements
Delayfromembedded-halv1.0 forstm32f0xx_hal::delay::Delayand uses a u64 tick counter instead of a u32 tick counter to increase the range of time the user can sleep.Since
stm32F0xx-hal's prelude imports the entirety ofembedded-halv0.2.7's prelude, importingembedded-halv1.0'sDelayNstrait may cause some ugly resolution conflicts on thedelay_usanddelay_msfunctions but this is not something users should be doing often and the timer isn't accurate enough fordelay_nsto be useful anyway.u64 tick counter overhead
From my testing, using a 64-bit counter did not increase the overhead of the timer for low values (delaying 1ns still takes ~700ns) even though the Cortex-M0 does not have 64bit arithmetic. I assume this is due to compiler optimization and inlining. If I force this optimization to not happen by passing the input through
core::hint::black_box, I get the following cycle counts (all onopt-level='s',lto="fat", STM32F070RB @ 48MHz, measured usingSYST::get_current()at call site):u32(optimized)u64(optimized)u32(black_box)u64(black_box)I briefly experimented with having
delay_ticks_u32anddelay_ticks_u64based on the requested tick count (by comparingusornsto0xFFFF_FFFF/48), but I don't think the code duplication was worth the trade-off since people that need sub-1us timing will likely implement their own delay loops.