81
External Use TM Hands-On Workshop : Create Low-Power Applications with MQX™ and MQX™ Lite RTOS FTF-SDS-F0040 APR.2014 Maclain Lobdell | Freescale Software Product Manager Vincent Leynaert | Freescale FAE

Hands-On Workshop: Create Low-Power Applications with … · Hands-On Workshop: Create Low-Power Applications with MQX™ and MQX™ Lite RTOS FTF-SDS-F0040 . 4 Hour Class. Learn

Embed Size (px)

Citation preview

External Use

TM

Hands-On Workshop: Create Low-Power Applications with MQX™ and MQX™ Lite RTOS FTF-SDS-F0040

A P R . 2 0 1 4

Maclain Lobdell | Freescale Software Product ManagerVincent Leynaert | Freescale FAE

TM

External Use 1

Hands-On Workshop: Create Low-Power Applications with MQX™ and MQX™ Lite RTOS

FTF-SDS-F0040 4 Hour Class

Learn how to take advantage of the power management capabilities of MQX and MQX Lite RTOS. See how to create feature-rich applications without killing battery life. Attendees will get hands-on experience with system power mode transitions, driver state transitions and slowing or stopping the system tick timer for power savings.

TM

External Use 2

Session Introduction

• Power efficiency is an increasingly important part of embedded product design. Power consumption budgets are tightening even though performance expectations are ever increasing.

• You can create power efficient applications while using an RTOS for sophisticated designs.

TM

External Use 3

Session Objectives

• After completing this session you will be able to: − Understand how power management capabilities can be used in RTOS-

based applications− Understand how to perform system power mode transitions, frequency

scaling, driver state transitions, and slow or stop the RTOS system tick timer for power savings

TM

External Use 4

Agenda• Quick Review of MQX Software Solutions • Tools for Analyzing MCU Power• Kinetis MCU Low Power Features• MQX RTOS Power Management Features− Hands On

• Optimizing Applications for Low Power− Optimizing/Disabling the System Tick Timer− Architecting State Transitions− Hands On

• MQX Lite RTOS Power Management Features− Hands On

TM

External Use 5

Implementing the techniques discussed in this class, we were able to reduce energy consumption by 98%

98%Reduction in Energy Consumption (In our example applications in a 5-min window)

Units in joules (watt*second)

No Optimization Sleep while Idle Stop ModeTick Disabled

18

14

6

10

20.3

TM

External Use 6

Freescale MQX™ Software Solutions

Product Features• MQX™ Real Time Operating System

Kernel− Deterministic multi-tasking preemptive

scheduler − Extensive inter-task synchronization,

message passing, and much more• MQX™ Real Time Communication Suite

Now with optional IPv6 add-on package− Broad networking protocol support

(TCP,UDP, ICMP, HTTP, DHCP, FTP, Telnet, …)

− Fully re-entrant, responsive, designed for embedded systems

• MQX™ File System− Embedded FAT file system compatible

with FAT-12, FAT-16, or FAT-32 file systems

• MQX™ USB Host/Device Stack− USB 1.0/2.0; low-/full-/high-speed

• Board Support Packages− Pre-configured MQX Kernel, stacks, and

peripheral drivers for Freescale HW

Enabling the development of connected and intelligent applications of the future

Commercial-grade MCU software platform at no cost with optional support packages

Download at: www.freescale.com/mqx

Softw

are

and

Har

dwar

e Ev

alua

tion

& D

ev T

ools

Stac

ks(T

CP

/IP, U

SB

)

Mid

dlew

are

Operating System

Bootloader

App

licat

ion

Spec

ific

BSP, Drivers & HAL

Libraries(DSP, Math, Encryption)

MCU Hardware

Customer Application

TM

External Use 7

Why use an RTOS?

• Create Deterministic and Connected Designs− Lower latency versus super loop software architecture− Multiple communications interfaces are much easier to manage with an RTOS− Integrated middleware and upper layer protocols such as TCP/IP, USB, Flash

Systems, Web Servers, Wi-Fi support, CAN protocols, SSL, SNMP

• Ease of Development− Board Support Packages (BSPs) available with peripheral drivers− Spend time developing application code, not maintaining a scheduling system

• Portability and Scalability− Standard APIs for high portability of application code to other MCUs− Configurable features to scale across products− Enable only features needed for low overhead

• Maintainability and Stability− Add new features without affecting system timing and higher priority functions

TM

External Use 8

Features, Performance, Sophistication

Bare Metal (No OS)

Basic FeaturedThread-Based RTOS

Full Featured Thread-Based RTOS

Process-BasedRTOS/OS

Pote

ntia

l Siz

e(M

emor

y Fo

otpr

int)

Each “process” has own memory space. More Multi-media and sophisticated applications.

More features. More integrated protocol stacks and middleware. Low to high footprint.Basic features. Some

protocol stacks and middleware. Low to medium footprint.

High-Level RTOS Landscape

MQX SMX

Nucleus RTX

Integrity RTXC

ThreadX CMX

eCOSFreeRTOS uCOS-II

MQX Lite

CMX-Tiny

Linux

QNX

VxWorks

WinCE

TM

External Use 9

20131989 Time 2000 Time 2004 Time 2008 2009 2010 2011 2012

Precise Founded• MQX Began

20062005

Embedded Access Inc. (EAI) • Licensed Provider of MQX• Roots from Precise & ARC• Strategic Freescale Partner

ARC acquired Precise with MQX Introducing Freescale MQX• Acquired MQX license across

Freescale’s portfolio from ARC.

Proven: 20+ years in the marketplace

• Used in millions and millions of products in medical, industrial, and defense markets from Fortune 500 companies.

• Freescale holds a broad license to MQX across its portfolio.

TM

External Use 10

Freescale MQX Growing in Popularity!

Freescale MQX 3rd Most Popular MCU RTOS in 2013 UBM Survey

#1

#2#3

Freescale MQX 65K+ Downloads19K+ Unique Users

TM

External Use 11

What's New in MQX RTOS 4.1

New Board Support Package − TWR-K21F120M (Kinetis K21 Tower System Module)

New Features and Updates− Enhanced tools support for CodeWarrior, IAR, Keil, ARM® DS-5™, and

GNU tools for ARM®

− Vybrid BSP Updates Drivers added or extended: eDMA. DSP codec, FTM Quadrature decoder, DCU, NAND flash file system driver, SAI, eSAI, ASRC, UART w/ eDMA, and FlashX w/ QuadSPI.

− Extended DMA support in Kinetis and Vybrid BSPs SPI, SAI, & eSAI drivers w/ eDMA; eSDHC w/ ADMA

− Other EnhancementsUpdated LWADC, RTC, Hardware Timer w/ Low Power Timer (LPT), Kinetis Flash Swap, NAND Flash File System (FFS) added.

− Software compatibility improvementMQX custom types replaced w/ standard C99 types

ARM DS-5

TM

External Use 12

MQX 4.1 Board Support Packages

• 24 Complimentary BSPs covering all Kinetis K, Vybrid, and select ColdFire and Power Families

• Numerous additional BSPs for legacy devices available free of charge in earlier MQX versions

• Other BSPs available for purchase for other architectures

• MQX Lite also available for all Kinetis K, L, & some E Series in Processor Expert

VBYRIDTWR‐VF65GS10  (M4&A5) √AUTOEVB (M4&A5) √KINETISTWR‐K20D50M √TWR‐K20D72M √TWR‐K21D50M √TWR‐K21F120M √TWR‐K40X256 √TWR‐K40D100M √TWR‐K53N512 √TWR‐K60D100M √TWR‐K60F120M √TWR‐K60N512 √TWR‐K64F120M *KWIKSTICK (K40) √TWR‐K70120M √COLDFIRE V1‐V4TWR‐MCF51JF √TWR‐MCF52259 √TWR‐MCF54418 √POWER ARCHITECTURETWR‐PXD10 √TWR‐PXS20 √TWR‐PXS30 √TWR‐PXN20 √

PLATFORM MQX 4.1

* MQX 4.1-based standalone release (separate installer than main release)

TM

External Use 13

Freescale MQX Lite RTOS Launched in 2012

MQX RTOS MQX Lite RTOS

Delivery Mechanism Traditional installer with full source for Kernel, services and BSPs

Processor Expert (PEx) Kernel and services component, configurable software generated by PEx

I/O Drivers MQX POSIX compatible drivers with option for using PEx drivers

PEx drivers only

Configurability User selects needed services from full or lightweight versions

Reduced services available; lightweight options only

Example Footprint (3 tasks, sem, event)

<10 Kbytes FLASH <8 Kbytes FLASH

Kinetis K Series, ColdFireProcessors, Vybrid ARM® Controller Solutions, Power Architecture solutions, Digital Signal Controllers

Kinetis L and K Series

TM

External Use 14

Freescale MQX Level 2 SupportAccelerating MQX RTOS-based development projects

What are the benefits of MQX Level 2 Support?• Direct senior level support access• Specified response times• Support for software customizations• Troubleshooting support on custom hardware • Early access to software releases and bug fixes• Private support portal, telephone, & web conferencing supportWhen to consider upgrading to MQX Level 2 Support?• Before next MQX RTOS-based development project starts• Tight resources or schedule, or just to insure project efficiencyHow to get MQX Level 2 Support?• Packages available for purchase at www.freescale.com/mqx/support• See website for complete details

TM

External Use 15

Freescale MQX Support and Engineering ServicesLevel 1 Support Level 2 Support Engineering Services

Plan Overview Basic Standard Premium

Software development services.  On‐site 

support/training.  Cost based on project 

definition.  

Releases AvailableApprox. once a 

QuarterApprox. once a 

Quarter Early1Access to MQX Online Community / Online Training Yes Yes YesService Requests (SW running on FSL Eval HW only) Yes Yes YesReport bugs for fix in quarterly releases Yes Yes YesBSP customization support ‐ Yes YesPrivate Support Portal ‐ Yes YesAccess to Early Beta Releases 1 ‐ ‐ YesHot Fixes 2 ‐ Yes YesInitial Response Time 3 ‐ 2 business days 1 business dayMax Hours of Support Engineer's Time 4 ‐ 20 hours 100 hoursWeb Conferencing to debug issue 5 ‐ 4 hours 10 hoursPhone Support 5 ‐ Yes YesHands‐on Support of Customer‐Provided Hardware (shipped to Freescale Support) ‐ ‐ YesSupport Plan Term ‐ 6 Months 12 MonthsPrice Free $3,000  $12,000 Part Number ‐ DL‐MQXLVL2‐S DL‐MQXLVL2‐P

1 Early access to beta releases weeks/months before quarterly releases are typically available2 Access to bug fixes on issues you report immediately when available3 Amount of time to receive acknowledge of support request4 Any time support engineer spends including time preparing bug fixes. 5 Hours counted in Support Engineers Time

TM

External Use 16

Agenda• Quick Review of MQX Software Solutions • Tools for Analyzing MCU Power• Kinetis MCU Low Power Features• MQX RTOS Power Management Features− Hands On

• Optimizing Applications for Low Power− Optimizing/Disabling the System Tick Timer− Architecting State Transitions− Hands On

• MQX Lite RTOS Power Management Features− Hands On

TM

External Use 17

Debugging through Low Power States• Some low power modes keep debug engine Fully Functional,

static or shut off.

• Kinetis debug interface had been designed to support graceful reconnect of the debug connection when low power state is exited (using handshake bits in MDM_AP debug register)

• The IDE and debug probe tool may or may not support graceful reconnect . You should check with supplier of the tool if the supports of low power mode of Kinetis is effective or not

TM

External Use 18

Example : CodeWarrior Support for debugging through Low Power Modes• Using OpenSDA/USB multilink (P&E

micro) in LLS and VLLSx, debugger loses connection with target and a reconnect action is needed to continue with debug session once the target has recovered from these states

• Control for reconnect behavior can be defined either on the first pop-up windows when a connection is lost either in:− Remote System View Properties of the

connection used Advanced

• NOTE: behavior is saved per connection, but you can re-use connections in multiple projects

TM

External Use 19

(active mode) Energy profiling - Tool off the shelf

Example : IAR I-scope• 12-bit A/D converter for current • Current Measurements− Uses a sensitive differential amplifier− Measures differential across a shunt

resistor − max voltage = 100mV

• Example: for ~40mA max use a 2.4 ohm shunt(this gives plenty of headroom)

TM

External Use 20

(active/passive mode) Energy profiling

The range of current between the very low power states and RUN mode is large

There is a factor x1000 between a standby mode = from hundreds of nA or a couple uAcompare to Active mode = in the range of few mA

Using a shunt resistor also may not be convenient since there might no be ideal value for shunt

It might be then of better option to use a current probe or dedicated hardware

(Note : a tool like IAR scope have a resolution of 200uA)

TM

External Use 21

(active/passive) Energy profiling with dedicated hardware• Low current and Dynamic Measure• Auto-scale adjustment• Large Scale : 100 nA – 100mA• Precision 10nA• No-hardware calibration

Designed and published with courtesy of

Multiple shunts(3 shunts used)

DUT

TM

External Use 22

Energy profiling using tool off the shelf & dedicated hardware

3 shunts used

Lauterbach allow multiple voltage/current probing while debuggingV[3..0] voltage inputs (0..5 V, 1 MOhm) I[2..0] current inputs (requires shunt resistance)12 bit resolution (625 KHz sampling rate for one channel)

TM

External Use 23

Agenda• Quick Review of MQX Software Solutions • Tools for Analyzing MCU Power• Kinetis MCU Low Power Features• MQX RTOS Power Management Features− Hands On

• Optimizing Applications for Low Power− Optimizing/Disabling the System Tick Timer− Architecting State Transitions− Hands On

• MQX Lite RTOS Power Management Features− Hands On

TM

External Use 24

Low Power Capabilities and application concern

What would be my concern as application designer :• What is still active while going into standby mode ?• What could be my wake event source ?• Are wake up to be regular scheduled or asynchronous ?• Do I spend more time in sleep than in active mode ?• How often do I wake-up ?• Does the RAM is preserved or not ?• How fast do I need to wake-up ?

Kinetis has flexible power modes− Kinetis has 10+ Run, Wait & Stop modes − This allow to select and customize power usage at best with application

requirements

TM

External Use 25

Kinetis Extended Power Modes

Run

VLPR

Wait

VLPW

Stop

VLPS

LLS

VLLS3

VLLS2

VLLS1

RecoveryTime

“Typical” Idd Range

-

-

-

278uA/MHz

5.2us

5.2us

6us

7035us

70us

130us+EE restore

2.1uA

1.5uA

1.4uA

678nA

867uA @ 4MHz

509uA @ 4MHz

310uA

3.5uA

VLLS0 367nA/176nA

-

7.5mA @ 50MHz

Kinetis Power Modes

Act

ive

Stan

dby

mod

e

Peripherals activity Wake-up event

RAMRegisters

32 b

ytes

Mode

pres

erve

d 4K

Allows peripherals to function, while CPU goes to sleep reducing power consumption

CPU /peripheral clock maximum freq restricted

LLWU controls wakeup sources including LPT, RTC, LCD, HSCMP, DAC and select pin interrupts.

ADC, LPT, RTC, LCD, HSCMP, DACand pin interrupts functional(Smart Peripherals for Kinetis L)

TM

External Use 26

Agenda• Quick Review of MQX Software Solutions • Tools for Analyzing MCU Power• Kinetis MCU Low Power Features• MQX RTOS Power Management Features− Hands On

• Optimizing Applications for Low Power− Optimizing/Disabling the System Tick Timer− Architecting State Transitions− Hands On

• MQX Lite RTOS Power Management Features− Hands On

TM

External Use 27

MQX Low Power Manager

Starting with version 3.8, MQX integrates a Low Power Management (LPM) driver to take advantage of MCU low power capabilities.

TM

External Use 28

MQX Low Power Manager

• The LPM driver included with Kinetis MQX BSPs has the following capabilities− Transitioning MCU power mode− Preparing other peripheral drivers for changing power modes− Changing clock configuration (Frequency Scaling)

• LPM functionality is currently available for Kinetis platforms only • It must be enabled in user_config.h using the

MQX_ENABLE_LOW_POWER configuration option.

TM

External Use 29

MQX Low Power Manager CapabilitiesTransitioning MCU power modes• The LPM typically utilizes 4 operation modes, which are mapped to power

modes of the MCU. This is defined at compile time.• In the K21 BSP, the LPM operation modes are mapped like this by default

• The operation mode mapping can be modified in init_lpm.c

TM

External Use 30

MQX Low Power Manager CapabilitiesPreparing other peripheral drivers for changing power modes

• The LPM provides a mechanism for other drivers in the BSP to register with the LPM to get notifications when the LPM changes the clock settings or power mode.

• Add your application specific steps such as disabling/enabling peripherals, shutting down peripheral clocks, changing baud rates, reconfiguring pin functionality, etc, to callback functions registered with the LPM.

TM

External Use 31

MQX Low Power Manager CapabilitiesChanging clock configuration (Frequency Scaling)

• LPM serves as a wrapper around another MQX component, the Clock Manager.

• The Clock Manager can be configured manually or by Processor Expert to set up clock configurations used by the application.

48 MHzPEE

12 MHzPEE

2 MHzBLPI

clockconfig 0

clockconfig 1

clockconfig 2

TM

External Use 32

MQX Low Power Manager CapabilitiesAdditional Features

• Enabling/Disabling Idle Sleep Feature − Automatic transition into low power mode in idle task

• Waking up the Core from Low Power Mode after an Interrupt− Kinetis MCUs feature the capability to automatically go back into certain low

power modes when exiting an ISR that woke up the CPU. − The LPM can signal the CPU not to return to low power mode again after the ISR

finishes. This is done by calling the function _lpm_wakeup_core() from the ISR that you want to use as the wakeup source.

TM

External Use 33

MQX Low Power Manager Driver Details

• Applications call _lpm_set_operation_mode() or _lpm_set_clock_configuration() to change the LPM state.

• Most of the source code for the LPM can be found in <MQX Installation Directory>\mqx\source\io\lpm

• Example application using the LPM can be found in<MQX Installation Directory>\ mqx\examples\lowpower

• For more information see Chapter 21 Low Power Manager in the Freescale MQX™ I/O Drivers – User Guide

TM

External Use 34

MQX Low Power ManagerNew in MQX 4.1: VLLSx Support

• VLLSx modes offer maximum power savings, but requires the system to go through a reset when exiting VLLSx modes and going back to a run mode.

• The LPM is capable of putting the system into VLLSx mode and handling wake ups from the Low Leakage Wake-up Unit.

• The LPM reports the wakeup source

TM

External Use 35

Hands-on

• Running low power demo• Enabling the low power demo for UART wake-up• Enabling the low power demo for SW3 wake-up

TM

External Use 36

Agenda• Quick Review of MQX Software Solutions • Tools for Analyzing MCU Power• Kinetis MCU Low Power Features• MQX RTOS Power Management Features− Hands On

• Optimizing Applications for Low Power− Optimizing/Disabling the System Tick Timer− Architecting State Transitions− Hands On

• MQX Lite RTOS Power Management Features− Hands On

TM

External Use 37

What is the RTOS tick?

• Periodic timer interrupt used to keep track of time• Typically, it is 5ms, 10ms, 100ms periods• The priority of the interrupt is higher than tasks. Preempt tasks• Operating system time unit• Reflects the minimal time resolution

5ms

TM

External Use 38

What is the RTOS tick?

• To allow for delays, timeouts, and measurements (MQX measures time in ticks, instead of in seconds and milliseconds)

• MQX keeps the time internally as a 64-bit count of the number of tick interrupts

• Features depending on the tick− Time delay− Timeout while waiting for events, semaphores, and so on− Software timers− Time-slice scheduling

TM

External Use 39

The Tick can be disabled

• Context switches (jumping between tasks) can occur at any time. No need to wait for system tick.− Example: event gets set which immediately triggers the scheduler

to switch to a task waiting on that event

• Scheduling occurs if any one of the following occurs:− the active task yields control− the active task calls a blocking MQX function− an interrupt occurs− a timeslice expires− a higher priority task becomes ready

Only one that requires the tick

TM

External Use 40

RTOS System Tick

What impact does the tick have on power consumption?• Run Modes: Minimal• Low Power Modes: Could wake up the system which has benefits

and drawbacksWhat impact does the tick have on system efficiency?• Minimal, but it does preempt tasks and uses CPU cycles to update

the time

TM

External Use 41

• ARMv7-M SysTick Timer – default MQX RTOS tick

• SysTick provides a simple, 24-bit clear-on-write, decrementing, wrap-on-zero counter.

• Used for RTOS tick timer which fires at a programmable rate and invokes a SysTickroutine.

• On Kinetis, it is clocked by the Cortex M4 FCLK (also clocks NVIC). Same frequency as system clock.

• Limited adjustability – cannot slow it down very much.

Modes SysTickRunning?

RUN, VLPR YesWAIT, VLPW YesSTOP, VLPS No *LLS NoVLLSx No* Unless debugger attached. If debugger

attached it will continue to run.

SysTick Timer – Default MQX Tick

TM

External Use 42

SysTick Timer – Default MQX Tick

Can the tick be shut off manually? Yes− SYST_CSR &= ~SysTick_CSR_TICKINT_MASK; /*disable systick */

− If there is no tick, then you can’t use the time delay, timeouts, and software timers. You have to use hardware timer interrupts or other interrupts to synchronize tasks.

Where is the tick service routine?− Init_bsp.c− void _bsp_systimer_callback(pointer dummy)

Note: #define MQX_USE_TICK 0 /*this will not disable the tick, it will remove the time API functions.*/

TM

External Use 43

Low Power Timer – Can also be used for Tick

• Low Power Timer (LPT), available in all low power modes

• Freescale Kinetis MCUs include a Low Power Timer.

• 16-bit time counter or pulse counter with compare

• Optional interrupt can generate asynchronous wake-up from any low-power mode

• Configurable clock source and 4-bit prescaler – can clock slower than SysTick

• Can use as system tick or a wake-up timer

Modes LPT Running?

RUN, VLPR YesWAIT, VLPW YesSTOP, VLPS YesLLS YesVLLSx Yes

TM

External Use 44

Systick as the RTOS Tick

Advantages• Systick is automatically disabled in several low power modes• Using the Systick as RTOS Tick, frees up the LPT for other useDisadvantages• Less flexibility in tick period, than LPT• If entering low power mode with the tick disabled, you cannot rely on

time calculated by the system tick, until the time is re-synced on wakeup

• The Systick is useful as the RTOS tick if: − The application can go to sleep with no ticks running

TM

External Use 45

Low Power Timer (LPT) as the RTOS Tick

Advantages• LPT tick can wake you up from all low power modes • You can set the period longer than SysTickDisadvantages• LPT tick can wake you up from all low power modes

• The LPT is useful as the RTOS tick if: − The application has periodic tasks depending on the tick. Using the LPT as

the system tick, lets the application keep the tick running in all low power modes.

− The application can elongate the tick period for more time in low power mode.

TM

External Use 46

Waking up for an Interrupt, going right back to sleep

• Kinetis MCUs return to low power mode after servicing an interrupt if the sleep on exit bit is set. (Wait or Stop modes)

Interrupt

MCU Power ModeRun

Low Power

TM

External Use 47

Staying awake after an interrupt

• Even if the sleep-on-exit features is enabled, the MQX low power manager function call used within an ISR to keep the system from returning to sleep on exit from an interrupt.

• Useful if an interrupt is used to wake up from low power mode.

/* Do not return to sleep after isr again */_lpm_wakeup_core ();

• This clears the sleep on exit bitSCB_SCR &= (~ (SCB_SCR_SLEEPONEXIT_MASK));

TM

External Use 48

5ms

Tried to go into low power mode for 100 ms, but had to wake up every 5 ms to service the tick

Tick Interrupt

Run

Low Power

The Tick Wakeup Problem

TM

External Use 49

Tick Wake-up Problem Solutions

• Easiest solution − Use a mode/timer combo that disables the tick automatically.

Unlimited Tick-less periodRequires waking up from an interrupt / wake-up sourceTime gets out of sync / Can’t rely on ticks for task timing during tick off-time.

• Other solution− Slow the tick down (extend tick period)

Longer tick-less period when you are in low power modeCan still use ticks for scheduling tasks while in low power modesTime granularity reduced for tick-dependent features (Note: not interrupt servicing or context switch time)

TM

External Use 50

Affect of Slower Ticks – Reduced Granularity

• Example – Task A tries to wait for 10ms._time_delay(10ms) /* block task for 10 ms */

Case 1 – 5ms tick

Case 2 – 15 ms tick

0 5 10 15 20 25 30 35 40

0 15 30

A

B

A

B

Blocked for ~10ms!

Blocked for ~15ms…

Note: Tick accuracy is 0-1 tick

TM

External Use 51

Typical Kinetis MQX Stop Mode Tick-lessSysTick as tick timer

5ms

Tried to go into low power mode for 25 ms

Stayed asleep until it was time to get up!

With SysTick timer on Kinetis, ticks are automatically shut off in stop mode.

Wake up from an interrupt or wake-up source.

TM

External Use 52

Re-syncing MQX time with RTC

• When the tick is disabled, the time gets out of sync.

• Easily re-synced using the real time clock (RTC) or another clock source (network time, etc.)

TM

External Use 53

Agenda• Quick Review of MQX Software Solutions • Tools for Analyzing MCU Power• Kinetis MCU Low Power Features• MQX RTOS Power Management Features− Hands On

• Optimizing Applications for Low Power− Optimizing/Disabling the System Tick Timer− Architecting State Transitions− Hands On

• MQX Lite RTOS Power Management Features− Hands On

TM

External Use 54

Choices to make when architecting your application• When do you want to go to into low power modes?− When in the idle task? (Automatic)− From an application task? (Manual)

• How fast do you need to wake up?• What do you want the wake up trigger(s) to be?• Do you have periodic tasks that need to always run?• How precise does your tick timing need to be?

Example Application Profiles• Always active• Frequently active with short idle periods• Bursts of activity with long idle periods• What is yours?

TM

External Use 55

Example Application 1Frequently active with short idle periods

• Low Power Features Used− Sleep while idle

Sleep while idle• When no task needs to run,

the idle task will put the MCU in low power mode. Typically Wait mode.

Normal Operation

Sleep while idle

Ticks continue to run.Puts MCU into low power between ticks.

Task ATask B

Idle Task

Task ATask B

Run Mode

Wait Mode

Run Mode

Run Mode

Wait Mode

Automatic –handled in the idle task

TM

External Use 56

Example Application 2Bursts of activity with long idle periods

• Low Power Features Used− Sleep while idle− Low power mode entry

from application task

Low power mode entry• When nothing to do for an

extended time, go to sleep with no ticks running

Wakeup Event• Timer, RTC, or GPIO

Normal Operation

Standby

VLPS or LLS

Run

Fast Wake-up

Sleep while idle

Example ApplicationsHandheld device – If no user input or data received after ~10 secondsController - sleep for long periods of time between tasks

Wait

RTOS System Tick Turned off

TM

External Use 57

Example Application 3Bursts of activity with long idle periods

• Low Power Features Used− Sleep while idle− Low power mode entry from

application task− Low power mode entry into

VLLSx (very low leakage stop) –now supported in MQX 4.1

Low power mode entry• When nothing to do for an

extended time, go to sleep with no ticks running.

• After more time with nothing going on, go to the lowest power mode.

Wakeup Event• Timer, RTC, or GPIO • Wakeup slower due to system

reset when exiting VLLSx

Normal Operation

Standby

Shelf

VLLSx

LLS

Run Mode

Fast Wake-up

Slower Wake-up

Sleep while idle

Wait

Note: wake-up times from low power modes can be optimized by using the FLL as the system clock source

RTOS System Tick Turned off

TM

External Use 58

Example Application 4

CALC

POLL

STBY

SHELF

LLS

VLPR (4 MHz)

Fast Wake-up

Slower Wake-up

RUN (50 MHz)

POLL

CALC

POLL POLL POLL

CALC

STBYSHELF

VLLS1

RTOS System Tick Turned off

TM

External Use 59

Hands-on

• Running a few of the application examples created for this class• Demonstrates the following features− Sleep while idle− Entering low power mode when no user input – with fast wakeup − Entering very low power mode with slower wakeup− Re-syncing MQX time after tick shut off

TM

External Use 60

Agenda• Quick Review of MQX Software Solutions • Tools for Analyzing MCU Power• Kinetis MCU Low Power Features• MQX RTOS Power Management Features− Hands On

• Optimizing Applications for Low Power− Optimizing/Disabling the System Tick Timer (Cont’d)− Architecting State Transitions− Hands On

• MQX Lite RTOS Power Management Features− Hands On

TM

External Use 61

Changing the TICK Time in MQX

• There are two ways to change the TICK timer.1. Changing the SysTick within the BSP2. Use the LPTMR as the TICK

TM

External Use 62

Changing the SysTick within the BSP

Remember: we cannot guarantee the correct behavior if you modify original settings. Only change this value if you know what you are doing.

• BSP timer is clocked by system tick.• It is possible to edit BSP_ALARM_FREQUENCY in order to have

smaller ticks.

TM

External Use 63

Changing the SysTick within the BSP

• By default, it is defined to get 200 ticks per second. In order to change this value it is necessary to go to the BSP project and change the value of the next macro:

#ifndef BSP_ALARM_FREQUENCY#define BSP_ALARM_FREQUENCY (200)

#endif

• This macro sets the number of ticks per second.• This macro can be found in <Board_Name>.h file.<MQX Installation Directory>\ mqx\source\bsp\<board_name>

TM

External Use 64

Changing the SysTick within the BSP

• Delays are calculated in the following way:

N_TICKS = Number of ticks REQ_ms = Number of milliseconds requested

ticks_per_s = Number of ticks per second

mssperticksmsREQTICKSN

1000____ ×

=

TM

External Use 65

Changing the SysTick within the BSP

• Example:If BSP_ALARM_FREQUENCY is set as default (100) and you request a 55ms delay you will have:

This value will be truncated to 5 ticks. If it is requested any delay from 0 to 9 ms then it is necessary to have 0 ticks. But you will have some latency delay.

ticksms

ticksmsTICKSN 5.51000

10055_ =×

=

TM

External Use 66

Using the LPTMR as the TICK in two steps

STEP 1:At the beginning of the task used for initialization call this function:_lpt_install_kernel();

• With these parameters:• Timer to initialize • Period in microseconds • Input clock sources mask• Interrupt priority • Unmask the timer after installation • Example:

_lpt_install_kernel(0,5000,LPT_FLAG_CLOCK_SOURCE_LPO,2,TRUE);

TM

External Use 67

Using the LPTMR as the TICK in three steps

STEP 2: After disabling the SysTick from the core:SYST_CSR &= ~SysTick_CSR_TICKINT_MASK;

TM

External Use 68

Hands-on

• Enabling the Low Power Timer as RTOS TICK

TM

External Use 69

Agenda• Quick Review of MQX Software Solutions • Tools for Analyzing MCU Power• Kinetis MCU Low Power Features• MQX RTOS Power Management Features− Hands On

• Optimizing Applications for Low Power− Optimizing/Disabling the System Tick Timer− Architecting State Transitions− Hands On

• MQX Lite RTOS Power Management Features− Hands On

TM

External Use 70

MQX Lite Low Power Features

• MQX Lite in CW 10.5− Supports clock mode changes and sleeping while idle

Processor Expert Low Power Features• Logical device drivers in conjunction with processor component

implement low power features of a target microcontroller.

• Each LDD component defines two methods related to the low power capability − SetOperationMode() − GetDriverState().

TM

External Use 71

Processor ExpertCpu_SetOperationMode

TM

External Use 72

Usage of Low Power API in Logical Device Drivers

TM

External Use 73

Changing the System Tick in MQX Lite

Go to ProcessorExpert components -> MQXLite -> SystemTimer1 -> Properties and change 1. Counter from SYST_CVR to LPTMR0_CNR 2. Counter direction from Down to Up 3. Regenerate code recompile 4. That’s all.

TM

External Use 74

Hands-on Demo

• MQX Lite Example – Entering/Exiting Low Power

TM

External Use 75

Key Take-Aways and References

75

TM

External Use 76

Session Summary

• You can create low power applications while using an RTOS.• MQX RTOS for Kinetis MCUs has tick-less modes.• MQX & MQX Lite RTOS Power Management capabilities allow you

to take control of your applications to save energy and prolong battery life.

TM

External Use 78

Become an MQX RTOS Pro!

• Download the Latest Releases• Check out the Learn to use MQX page• Watch the Online Training Videos• See the 80+ Examples & Demos• Read the 12+ Application Notes• View the Getting Started Guides• Attend more in-person Training Events• Collaborate in the MQX Community• Start creating applications! Start with an example. Best way

to learn

TM

External Use 79

Freescale MQX™ Software Solutionswww.freescale.com/mqx

TM

© 2014 Freescale Semiconductor, Inc. | External Use

www.Freescale.com