Embedded System Design Techniques™: Mastering the ARM© Cortex-M© Processor Class 5: Low Power Design Techniques May 22, 2015 Jacob Beningo, CSDP
Course Overview Overview of STM32 ARM Cortex-M0+ Project Setup and Compilation ARM Cortex-M Architecture Writing Embedded Software with CMSIS Low Power Design Techniques
Session Overview Energy Profiling Wait for Interrupt Sleep-on-exit Low Power Modes Low Power Example
Introduction So what is the problem? Consumer Level Demand for longer battery lives Devices are used more often for longer periods of time Engineering Level Short design cycles Management Decisions Lack of low power experience Use of Proper tools
Energy Profiling 3.7 V Energy Profile Key Points Power profile can be calculated from A x V Energy Profile can be approximated by current only! Integrating the energy profile will provide mAh used Can be used to identify heavy energy usage periods Can be used to estimate battery discharge time
Energy Profile – STM32CubeMx
Low Power Modes – STM32Lx
Low Power Mode Summary
Power Mode Registers
WFI vs WFE if(WakeupType == POWER_WAKE_WFI) { /* Wait For Interrupt */ __WFI(); } else /* Wait For Event */ __SEV(); __WFE();
Sleep on Exit
Wakeup Considerations
STM32 Sleep Mode Example DEBUGGER WARNING! void Power_ModeStop(PowerWake_t WakeupType) { uint32_t temp = 0; temp = PWR->CR; temp &= (uint32_t)~(PWR_CR_PDDS | PWR_CR_LPSDSR); PWR->CR = temp; SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; if(WakeupType == POWER_WAKE_WFI) __WFI(); } WARNING! DEBUGGER Sleep
STM32 Sleep Mode Example // Enable the SYSCFG block RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // Setup Interrupts on GPIO C13 SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PC; // set pin to use // Configure GPIO C13 as an external interrupt for falling edge EXTI->IMR |= EXTI_IMR_IM13; // unmask interrupt EXTI->EMR |= EXTI_EMR_EM13; // unmask event EXTI->RTSR &= ~EXTI_RTSR_TR13; // set rising edge EXTI->FTSR |= EXTI_FTSR_TR13; // set falling edge // Interrupt to enable for button NVIC_EnableIRQ(EXTI4_15_IRQn);
STM32 Sleep Mode Example void EXTI4_15_IRQHandler(void) { if (EXTI->PR & (1<<13)) // clear pending interrupt EXTI->PR |= (1<<13); } void Tsk_1000ms(void) Power_ModeStop(POWER_WAKE_WFI);
Tips for Energy Conservation Tip #1 – Turn Off Unused Module and Clocks If it is not being used then don’t let it consume energy! Clock gating stops the peripheral from causing logic to switch which uses energy P = C * F * Vcc2 + IL * Vcc
Tips for Energy Conservation Tip #2 – Use a LPT or RTC Lower Energy Usage due to slower OSC Used to interrupt system and wake up from extremely low power state
Tips for Energy Conservation Tip #3 – Beware Communication Channels Can be power hungry peripherals May require periodic waking Use DMA to lighten the Load Can keep the CPU asleep Transfer data from peripheral to memory Uart Serial Wake-Up Peripheral Sleeps until data is received Wakes up and then performs functions
Tips for Energy Conservation Tip #4 – Use Energy Profiling Tools
Tips for Energy Conservation Tip #5 - Think Outside the Box USB Device USB Host D+ D- USB Device USB Host Tx Rx
Additional Resources Download Course Material for Updated C Doxygen Templates (May 2015) Example source code Templates Microcontroller API Standard EDN Embedded Basics Articles Embedded Bytes Newsletter From www.beningo.com under - Blog and Articles > Software Techniques > CEC Mastering ARM Cortex-M
Jacob Beningo Newsletters P.O. Box 400 Embedded Bytes Linden, Michigan 48451 www.beningo.com Newsletters Embedded Bytes http://bit.ly/1BAHYXm Training MicroPython Bootloaders Low Power Design Real-time Software C/C++ Embedded : jacob@beningo.com : 810-844-1522 : Jacob_Beningo : Beningo Engineering : JacobBeningo : Embedded Basics Jacob Beningo Principal Consultant 22