From ab97fefaf6d619240e6f89e7c1b95a88dca3c10b Mon Sep 17 00:00:00 2001 From: Ari Suutari Date: Fri, 22 Apr 2016 09:38:45 +0300 Subject: [PATCH] Use tickless idle to save power. --- config/lwipopts.h | 1 + config/pos_cmsis.h | 1 + config/poscfg.h | 7 ++++++- config/stm32f4xx_conf.h | 2 ++ main.c | 21 +++++++++++++++++++++ sta.c | 3 --- startup.c | 5 +++-- 7 files changed, 34 insertions(+), 6 deletions(-) diff --git a/config/lwipopts.h b/config/lwipopts.h index 6460b04..423c6c7 100644 --- a/config/lwipopts.h +++ b/config/lwipopts.h @@ -90,6 +90,7 @@ int sys_random(void); #define WDCFG_FIRMWARE "43362A2.bin" #define WDCFG_FIRMWARE_PATH "/firmware", "/flash" +//#define TIMERS_DEBUG LWIP_DBG_ON //#define TCPIP_DEBUG LWIP_DBG_ON //#define NETIF_DEBUG LWIP_DBG_ON //#define SOCKETS_DEBUG LWIP_DBG_OFF diff --git a/config/pos_cmsis.h b/config/pos_cmsis.h index 7572363..3b0a0ed 100644 --- a/config/pos_cmsis.h +++ b/config/pos_cmsis.h @@ -33,6 +33,7 @@ void USART2_IRQHandler(void); void SDIO_irq(void); void DMA2_Stream3_irq(void); +void RTC_WKUP_IRQHandler(void); /* * These are interrupt handlers inside Wiced usart code. diff --git a/config/poscfg.h b/config/poscfg.h index b2dd3fa..1f2a6d7 100644 --- a/config/poscfg.h +++ b/config/poscfg.h @@ -536,7 +536,6 @@ #define PORTCFG_IRQ_STACK_SIZE 2048 #define PORTCFG_VECTORS 1 -#define PORTCFG_TICK_SYSTICK 1 #define PORTCFG_CONOUT_ITM 0 #define PORTCFG_API_MAX_PRI 2 // same as used by Wiced /* @@ -544,5 +543,11 @@ */ #define PORTCFG_CON_USART 2 +#define PORTCFG_TICK_SYSTICK 0 +#define PORTCFG_TICK_RTC 1 +#define PORTCFG_POWER_TICKLESS_MIN MS(20) +#define POSCFG_FEATURE_POWER 1 +#define POSCFG_FEATURE_POWER_WAKEUP 1 +#define POSCFG_FEATURE_TICKLESS 1 #endif /* _POSCFG_H */ diff --git a/config/stm32f4xx_conf.h b/config/stm32f4xx_conf.h index eb0d5d1..5aabb6b 100644 --- a/config/stm32f4xx_conf.h +++ b/config/stm32f4xx_conf.h @@ -42,6 +42,8 @@ #include "stm32f4xx_spi.h" #include "stm32f4xx_wwdg.h" #include "stm32f4xx_rtc.h" +#include "stm32f4xx_exti.h" +#include "stm32f4xx_pwr.h" #include "stm32f4xx_flash.h" #include "misc.h" diff --git a/main.c b/main.c index 6226307..23d68fb 100644 --- a/main.c +++ b/main.c @@ -40,6 +40,7 @@ #include "lwip/mem.h" #include "lwip/memp.h" #include "lwip/sys.h" +#include "lwip/netifapi.h" #include "lwip/stats.h" #include "lwip/inet.h" @@ -154,7 +155,16 @@ static void mainTask(void* arg) eshStartTelnetd(); guiStart(); + +/* + * Enable sleep. It is initially enabled in pico]OS, but Wiced + * disables it during initialization. + */ + posPowerEnableSleep(); + +#if NOSCFG_FEATURE_CONIN eshConsole(); +#endif } @@ -185,6 +195,17 @@ int main(int argc, char **argv) #endif +#if !NOSCFG_FEATURE_CONIN + +/* + * STM32 cannot sleep deep if USART input is needed (because it needs clock). + */ + PWR->CR |= PWR_CR_LPDS; + PWR->CR &= (unsigned long) ( ~( PWR_CR_PDDS ) ); + + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; +#endif + nosInit(mainTask, NULL, 1, 5000, 512); return 0; } diff --git a/sta.c b/sta.c index ea5bd88..ceb0e5b 100644 --- a/sta.c +++ b/sta.c @@ -109,11 +109,8 @@ void ifStatusCallback(struct netif *netif) /* * Powersave experiments. Without these, about 73 mA is used. * With wifi powersave, 15-20 mA is used. - * Platform powersave cannot be used (yet), as it will stop - * systick. */ //wwd_wifi_enable_powersave(); - //platform_mcu_powersave_enable(); potatoStart(); } diff --git a/startup.c b/startup.c index 2536beb..bd4ec8c 100644 --- a/startup.c +++ b/startup.c @@ -47,10 +47,11 @@ void Default_Handler() extern unsigned int __stack[]; +PORT_WEAK_HANDLER(SysTick_Handler); PORT_WEAK_HANDLER(WWDG_irq); PORT_WEAK_HANDLER(PVD_irq); PORT_WEAK_HANDLER(TAMP_STAMP_irq); -PORT_WEAK_HANDLER(RTC_WKUP_irq); +PORT_WEAK_HANDLER(RTC_WKUP_IRQHandler); PORT_WEAK_HANDLER(FLASH_irq); PORT_WEAK_HANDLER(RCC_irq); PORT_WEAK_HANDLER(EXTI0_irq); @@ -151,7 +152,7 @@ PortExcHandlerFunc vectorTable[] __attribute__ ((section(".vectors"))) = WWDG_irq, // Window WatchDog PVD_irq, // PVD through EXTI Line detection TAMP_STAMP_irq, // Tamper and TimeStamps through the EXTI line - RTC_WKUP_irq, // RTC Wakeup through the EXTI line + RTC_WKUP_IRQHandler, // RTC Wakeup through the EXTI line FLASH_irq, // FLASH RCC_irq, // RCC EXTI0_irq, // EXTI Line0