diff options
author | Damien George <damien.p.george@gmail.com> | 2014-08-25 18:12:44 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-08-25 18:12:44 +0100 |
commit | 34e43c7ee9700249dc6e5b333b7c264d45d6b530 (patch) | |
tree | ae9f69ed4447c994c16ee166af76d66f4a8dee1b /stmhal/systick.c | |
parent | 3475b041018afe006fc792b504acef20c60426bc (diff) | |
download | micropython-34e43c7ee9700249dc6e5b333b7c264d45d6b530.tar.gz micropython-34e43c7ee9700249dc6e5b333b7c264d45d6b530.zip |
stmhal: Improve efficiency of SysTick IRQ and HAL_Delay.
SysTick IRQ now increases millisecond counter directly (ie without
calling HAL_IncTick). Provide our own version of HAL_Delay that does a
wfi while waiting. This more than halves power consumption when running
a loop containing a pyb.delay call. It used to be like this, but new
version of HAL library regressed this feature.
Diffstat (limited to 'stmhal/systick.c')
-rw-r--r-- | stmhal/systick.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/stmhal/systick.c b/stmhal/systick.c index b2381d08eb..b4dd68ffec 100644 --- a/stmhal/systick.c +++ b/stmhal/systick.c @@ -33,6 +33,18 @@ #include "irq.h" #include "systick.h" +// We provide our own version of HAL_Delay that calls __WFI while waiting, in +// order to reduce power consumption. +void HAL_Delay(uint32_t Delay) { + extern __IO uint32_t uwTick; + uint32_t start = uwTick; + // Wraparound of tick is taken care of by 2's complement arithmetic. + while (uwTick - start < Delay) { + // Enter sleep mode, waiting for (at least) the SysTick interrupt. + __WFI(); + } +} + bool sys_tick_has_passed(uint32_t start_tick, uint32_t delay_ms) { return HAL_GetTick() - start_tick >= delay_ms; } |