@@ -16,13 +16,18 @@ pub fn bkpt() {
16
16
17
17
/// Blocks the program for *at least* `cycles` CPU cycles.
18
18
///
19
- /// This is implemented in assembly so its execution time is independent of the optimization
20
- /// level, however it is dependent on the specific architecture and core configuration .
19
+ /// This is implemented in assembly as a fixed number of iterations of a loop, so that execution
20
+ /// time is independent of the optimization level .
21
21
///
22
- /// NOTE that the delay can take much longer if interrupts are serviced during its execution
23
- /// and the execution time may vary with other factors. This delay is mainly useful for simple
24
- /// timer-less initialization of peripherals if and only if accurate timing is not essential. In
25
- /// any other case please use a more accurate method to produce a delay.
22
+ /// The loop code is the same for all architectures, however the number of CPU cycles required for
23
+ /// one iteration varies substantially between architectures. This means that with a 48MHz CPU
24
+ /// clock, a call to `delay(48_000_000)` is guaranteed to take at least 1 second, but for example
25
+ /// could take 2 seconds.
26
+ ///
27
+ /// NOTE that the delay can take much longer if interrupts are serviced during its execution and the
28
+ /// execution time may vary with other factors. This delay is mainly useful for simple timer-less
29
+ /// initialization of peripherals if and only if accurate timing is not essential. In any other case
30
+ /// please use a more accurate method to produce a delay.
26
31
#[ cfg( cortex_m) ]
27
32
#[ inline]
28
33
pub fn delay ( cycles : u32 ) {
@@ -33,9 +38,9 @@ pub fn delay(cycles: u32) {
33
38
let real_cycles = 1 + cycles / 2 ;
34
39
unsafe {
35
40
asm ! (
36
- // The `bne` on some cores (eg Cortex-M4) will take a different number of instructions
41
+ // The `bne` on some cores (eg Cortex-M4) will take a different number of cycles
37
42
// depending on the alignment of the branch target. Set the alignment of the top of the
38
- // loop to prevent surprising timing changes when the alignment of the delay() changes.
43
+ // loop to prevent surprising timing changes when the alignment of `fn delay()` changes.
39
44
".p2align 3" ,
40
45
// Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m.
41
46
"1:" ,
0 commit comments