Skip to content

Commit 7fdafd5

Browse files
ianrreesadamgreig
authored andcommitted
Document asm::delay() behaviour more thoroughly (#597)
1 parent 24a29b1 commit 7fdafd5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cortex-m/src/asm.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ pub fn bkpt() {
1717

1818
/// Blocks the program for *at least* `cycles` CPU cycles.
1919
///
20-
/// This is implemented in assembly so its execution time is independent of the optimization
21-
/// level, however it is dependent on the specific architecture and core configuration.
22-
///
23-
/// NOTE that the delay can take much longer if interrupts are serviced during its execution
24-
/// and the execution time may vary with other factors. This delay is mainly useful for simple
25-
/// timer-less initialization of peripherals if and only if accurate timing is not essential. In
26-
/// any other case please use a more accurate method to produce a delay.
20+
/// This is implemented in assembly as a fixed number of iterations of a loop, so that execution
21+
/// time is independent of the optimization level.
22+
///
23+
/// The loop code is the same for all architectures, however the number of CPU cycles required for
24+
/// one iteration varies substantially between architectures. This means that with a 48MHz CPU
25+
/// clock, a call to `delay(48_000_000)` is guaranteed to take at least 1 second, but for example
26+
/// could take 2 seconds.
27+
///
28+
/// NOTE that the delay can take much longer if interrupts are serviced during its execution and the
29+
/// execution time may vary with other factors. This delay is mainly useful for simple timer-less
30+
/// initialization of peripherals if and only if accurate timing is not essential. In any other case
31+
/// please use a more accurate method to produce a delay.
2732
#[inline]
2833
pub fn delay(cycles: u32) {
2934
call_asm!(__delay(cycles: u32));

0 commit comments

Comments
 (0)