diff options
author | 2021-02-09 17:44:18 +0000 | |
---|---|---|
committer | 2021-02-09 17:44:18 +0000 | |
commit | 2281fd667a05f6fc6e9a12d8045cff49687a13ad (patch) | |
tree | 7628b69a29f6a41d07338a2b8694106524de8f53 /asm/inline.rs | |
parent | c714cdf20e012280a5c722d190a121a6bce10ddc (diff) | |
parent | fdc3ab0b4817faa9f99f507afc6a4a992134fb48 (diff) | |
download | cortex-m-2281fd667a05f6fc6e9a12d8045cff49687a13ad.tar.gz cortex-m-2281fd667a05f6fc6e9a12d8045cff49687a13ad.tar.zst cortex-m-2281fd667a05f6fc6e9a12d8045cff49687a13ad.zip |
Merge #328
328: Prevent underflow when calling delay(n) with n<2 r=jonas-schievink a=ovidiusabou
Calling delay(1) causes a very long wait (freeze) otherwise.
86cd463788b97ca3894936101c6cf4f3512f0fbc introduced this behaviour by
changing the cycle count from n / 4 + 1 to n / 2 which forces an
underflow when n<2.
Co-authored-by: Ovidiu Sabou <ovidiu@sabou.org>
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Diffstat (limited to 'asm/inline.rs')
-rw-r--r-- | asm/inline.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/asm/inline.rs b/asm/inline.rs index ef203cd..5887baf 100644 --- a/asm/inline.rs +++ b/asm/inline.rs @@ -55,7 +55,8 @@ pub unsafe fn __delay(cyc: u32) { // The loop will normally take 3 to 4 CPU cycles per iteration, but superscalar cores // (eg. Cortex-M7) can potentially do it in 2, so we use that as the lower bound, since delaying // for more cycles is okay. - let real_cyc = cyc / 2; + // Add 1 to prevent an integer underflow which would cause a long freeze + let real_cyc = 1 + cyc / 2; asm!( // Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m. "1:", |