From 34e43c7ee9700249dc6e5b333b7c264d45d6b530 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 25 Aug 2014 18:12:44 +0100 Subject: 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. --- stmhal/stm32f4xx_it.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'stmhal/stm32f4xx_it.c') diff --git a/stmhal/stm32f4xx_it.c b/stmhal/stm32f4xx_it.c index 4bd13c05c..74fdf53d1 100644 --- a/stmhal/stm32f4xx_it.c +++ b/stmhal/stm32f4xx_it.c @@ -173,7 +173,11 @@ void PendSV_Handler(void) { * @retval None */ void SysTick_Handler(void) { - HAL_IncTick(); + // Instead of calling HAL_IncTick we do the increment here of the counter. + // This is purely for efficiency, since SysTick is called 1000 times per + // second at the highest interrupt priority. + extern __IO uint32_t uwTick; + uwTick += 1; // Read the systick control regster. This has the side effect of clearing // the COUNTFLAG bit, which makes the logic in sys_tick_get_microseconds -- cgit v1.2.3