Application Note. Using embos tickless support with STM32

Similar documents
embos Real-Time Operating System CPU & Compiler specifics for embos Visual Studio Simulation

embos Real-Time Operating System embos plug-in for IAR C-Spy Debugger Document: UM01025 Software Version: 3.0 Revision: 0 Date: September 18, 2017

Application Note. embos/ip Migration Guide

embos Real-Time Operating System embos plug-in for IAR C-Spy Debugger Document: UM01025 Software Version: 3.1 Revision: 0 Date: May 3, 2018

embos/ip Switch Board

embos Real Time Operating System CPU & Compiler specifics for PIC18 core using C18 compiler and MPLAB

embos Real-Time Operating System CPU & Compiler specifics for Texas Instruments using TI Code Composer for MSP430

Application Note. Analyzing HardFaults on Cortex-M CPU

Flasher ATE. Production Programmer. Getting Started. Document: AN08007 Manual Version: 1.0 Revision: 2 Date: January 9, 2018

embos Real Time Operating System CPU & Compiler specifics for RENESAS M16C CPUs and HEW workbench Document Rev. 1

embos Real Time Operating System CPU & Compiler specifics for RENESAS M16C CPUs and IAR compiler Document Rev. 5

embos Real Time Operating System CPU & Compiler specifics for Texas Instruments MSP430 CPUs and Rowley compiler for MSP430 Document Rev.

SEGGER J-Scope. User Guide. Document: UM08028 Software Version: 5.10 Revision: 0 Date: November 26, 2015

empower Evaluation and prototyping platform for SEGGER software User Guide & Reference Manual

embos Real Time Operating System CPU & Compiler specifics for ARM core with ARM RealView Developer Suite 3.0 Document Rev. 1

embos Real Time Operating System CPU & Compiler specifics for RENESAS SH2A CPUs and KPIT GNU compiler Document Rev. 1

AN3996 Application Note

embos Real-Time Operating System CPU & Compiler specifics for Renesas RX using Renesas CCRX compiler and e2studio

embos Real Time Operating System CPU & Compiler specifics for RENESAS SH2 CPUs and RENESAS HEW4 Document Rev. 1

embos Real-Time Operating System CPU & Compiler specifics for SH2A core using IAR Embedded Workbench

IAR PowerPac RTOS for Texas Instruments MSP430 Microcontroller Family

May 15, 2015 EE 354 Fall 2015 Lecture 6 Timers and timer interrupts

embos Real-Time Operating System CPU & Compiler specifics for Renesas RX using KPIT GNU tools

embos Real-Time Operating System CPU & Compiler specifics for RH850 using IAR

emfile NAND Image Creator User & Reference Guide Document: UM02003 Software version: 1.03 Revision: 0 Date: November 16, 2016

embos Real-Time Operating System CPU & Compiler specifics for Renesas RX using IAR compiler for RX

AN3279 Application Note

embos Real-Time Operating System CPU & Compiler specifics for Cortex- M using Rowley CrossStudio for ARM

EE 354 Fall 2018 Timers and timer interrupts

AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Features. Introduction. AVR 8-bit Microcontrollers APPLICATION NOTE

embos Real-Time Operating System CPU & Compiler specifics for ARM core using Keil MDK

AN2592 Application note

Laboratory Exercise 7

APPLICATION NOTE. Atmel AT03261: SAM D20 System Interrupt Driver (SYSTEM INTERRUPT) SAM D20 System Interrupt Driver (SYSTEM INTERRUPT)

AN Sleep programming for NXP bridge ICs. Document information

LPC4088 Timer Interrupts CM0506 Small Embedded Systems

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 F²MC-FR FAMILY 32-BIT MICROCONTROLLER MB91460 RELOAD TIMER APPLICATION NOTE

AN3268 Application note

ARM Cortex-M and RTOSs Are Meant for Each Other

APPLICATION NOTE. Atmel AT03782: Using Low Power Modes in SAM4N Microcontroller. Atmel 32-bit Microcontroller. Features.

AN2202 Application note

APPLICATION NOTE. Atmel AVR1638: XMEGA RTC Calibration. 8-bit Atmel Microcontrollers. Features. Introduction

Realtek Ameba-1 Power Modes

AVR42772: Data Logger Demo Application on XMEGA A1U Xplained Pro. Introduction. Features. AVR XMEGA Microcontrollers APPLICATION NOTE

embos Real-Time Operating System CPU & Compiler specifics for RZ core using KPIT GNU and ARM DS-5

embos Real-Time Operating System CPU & Compiler specifics for Document: UM01039 Software Version: 5.02 Revision: 0 Date: June 26, 2018

uip, TCP/IP Stack, LPC1700

AN4749 Application note

APPLICATION NOTE. AT05567: TC Capture on External Interrupt with the Event System on SAM D20. Preface ASF PROJECT DOCUMENTATION

EFM32LG890 Errata, Chip Rev. E

AN4696 Application note

ECE 271 Microcomputer Architecture and Applications University of Maine

ECO and Workarounds for Bugs in ESP32

Towards More Power Friendly Xen

embos Real-Time Operating System CPU & Compiler specifics for Renesas RH850 and IAR

ARM Cortex core microcontrollers

ELEC 3040/3050 Lab 6. Time-based interrupts (Digital stopwatch design)

F²MC-16FX FAMILY ALL SERIES STANDBY MODES & POWER MANAGEMENT 16-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

AN4820 Application note

ECO and Workarounds for Bugs in ESP32

STM32F4 Labs. T.O.M.A.S Technically Oriented Microcontroller Application Services V1.07

Lab 3a: Scheduling Tasks with uvision and RTX

AN2781 Application note

AN5123 Application note

ARM Cortex core microcontrollers 12 th Energy efficient operation

The EFM32 I2C module allows simple, robust and cost effective communication between integrated circuits using only one data and one clock line.

AN3265 Application note

AT11512: SAM L Brown Out Detector (BOD) Driver. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

AVR Timers TIMER0. Based on:

AVR1518: XMEGA-A1 Xplained Training - XMEGA Clock System. 8-bit Atmel Microcontrollers. Application Note. Prerequisites.

TN0132 Technical note

AN3281 Application note

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 FR FAMILY 32-BIT MICROCONTROLLER MB91460 REAL TIME CLOCK APPLICATION NOTE

embos Real-Time Operating System CPU & Compiler specifics for Cortex M using Atmel Studio

Emulating Dual SPI Using FlexIO

embos Real-Time Operating System CPU & Compiler specifics for ARM core using Atollic TrueStudio

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Description of STM8 LIN software package (STSW-STM8A-LIN) release 4.1. Table 1. Release information. STM8 LIN package

AT03664: Getting Started with FreeRTOS on SAM D20/D21/R21/L21/L22. Introduction. Features. SMART ARM-based Microcontrollers APPLICATION NOTE

AMBA Remap and Pause. Technical Reference Manual. Revision: r0p0. Copyright 1997 ARM Limited. All rights reserved. ARM DDI 0048AC

IAR PowerPac RTOS for ARM Cores

APPLICATION NOTE. Atmel AT03304: SAM D20 I 2 C Slave Bootloader SAM D20. Description. Features

Engineer-to-Engineer Note

Embedded assembly is more useful. Embedded assembly places an assembly function inside a C program and can be used with the ARM Cortex M0 processor.

LPC-H1343 development board Users Manual

AT09381: SAM D - Debugging Watchdog Timer Reset. Introduction. SMART ARM-based Microcontrollers APPLICATION NOTE

AN2548 Application note

AN2676 Application note

APPLICATION NOTE. How to Securely Switch Atmel s LIN Transceiver ATA6662/ATA6662C to Sleep Mode ATA6662/ATA6662C. Concerning Atmel ATA6662

UNIBOX. An Intelligent Network Controller. Knowledge Base: Billing Module

AN4045 Application note

STM8 I 2 C optimized examples

EFM32TG222 Errata History

EFR32 Mighty Gecko Family EFR32MG1 with Integrated Serial Flash Errata History

AT03975: Getting Started with SAM L21. Descripton. Features. SMART ARM-Based Microcontroller APPLICATION NOTE

AN4666 Application note

AN5181. Building a thermometer using the STM8 Nucleo-64 boards. Application note. Introduction

Interrupt/Timer/DMA 1

AN3140 Application note

Transcription:

Application Note Using embos tickless support with STM32 Document: AN01002 Revision: 0 Date: June 26, 2014 A product of SEGGER Microcontroller GmbH & Co. KG www.segger.com

2 Disclaimer Specifications written in this document are believed to be accurate, but are not guaranteed to be entirely free of error. The information in this manual is subject to change for functional or performance improvements without notice. Please make sure your manual is the latest edition. While the information herein is assumed to be accurate, SEGGER Microcontroller GmbH & Co. KG (SEGGER) assumes no responsibility for any errors or omissions. SEGGER makes and you receive no warranties or conditions, express, implied, statutory or in any communication with you. SEGGER specifically disclaims any implied warranty of merchantability or fitness for a particular purpose. Copyright notice You may not extract portions of this manual or modify the PDF file in any way without the prior written permission of SEGGER. The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license., Hilden / Germany Trademarks Names mentioned in this manual may be trademarks of their respective companies. Brand and product names are trademarks or registered trademarks of their respective holders. Manual versions This manual describes the current software version. If any error occurs, inform us and we will try to assist you as soon as possible. Contact us for further information on topics or routines not yet specified. Print date: June 26, 2014 Revision Date By Description 0 140626 TS First version.

3 Abstract This application note describes the usage of the embos tickless support with a STM32F103 CPU. Introduction Stopping the system tick interrupt allows the microcontroller to remain in a deep power saving state until an interrupt occurs. This helps to save power for e.g. battery powered devices. The embos tickless support stops the periodic system tick interrupt during idle periods. Idle periods are periods of time when there are no tasks or software timer ready for execution. Implementation of OS_Idle() We use instead of the generic Cortex-M systick timer the hardware timer TIM2. We use the timer in up-counting mode. In order to use the tickless support the OS_Idle() function has to be modified. The default OS_Idle() function is just an endless loop which starts the low power mode: void OS_Idle(void) { while (1) { asm(" wfi"); The tickless OS_Idle() function calculates the amount of time which should be spent in low power mode and reprograms the timer accordingly: void OS_Idle(void) { OS_TIME IdleTicks; OS_DI(); IdleTicks = OS_GetNumIdleTicks(); if (IdleTicks > 1) { if ((OS_U32)IdleTicks > TIM2_MAX_TICKS) { IdleTicks = TIM2_MAX_TICKS; OS_StartTicklessMode(IdleTicks, &_EndTicklessMode); TIM2_ARR = (OS_TIMER_RELOAD * IdleTicks) - TIM2_CNT; // Set compare reg. OS_EI(); while (1) { asm(" wfi"); The following description analyzes the OS_Idle() function step by step: void OS_Idle(void) { OS_TIME IdleTicks; OS_DI(); Interrupts are disabled to avoid a timer interrupt. IdleTicks = OS_GetNumIdleTicks(); if (IdleTicks > 1) { The OS_Idle() function reads the idle ticks with OS_GetNumIdleTicks(). The tickless mode is only enabled when there is more than one idle tick. If there are zero or one idle ticks the scheduler is executed at the next system tick hence it makes no sense to enable the tickless mode.

4 CHAPTER if ((OS_U32)IdleTicks > TIM2_MAX_TICKS) { IdleTicks = TIM2_MAX_TICKS; The STM32F103 hardware timer TIM2 is a 16bit timer. We set the clock prescaler register TIM2_PSC to 63 which devides the peripheral clock by 64. The CPU runs at OS_FSYS = 72 MHz. Hence the maximum count time is: T = (0xFFFF x (TIM2_PSC + 1)) / OS_FSYS = 0.058253 sec ~ 58 msec This setup uses 1 msec per system tick. Thus we can stay at most for 58 system ticks in low power mode. If idle ticks are greater than this maximum value we just set idle ticks to 58. For example OS_GetNumIdleTicks() returns 200. The tickless mode will be enabled for 58 system ticks. The next time OS_Idle() is executed OS_GetNumIdleTicks() returns 142. The tickless mode will again be enabled for 58 system ticks for another two times. The last time OS_GetNumIdleTicks() returns 26. OS_Delay(200) System tick interrupts OS_Global.Time 0 1 2 60 118 176 202 203 Instead of having 200 interrupts (each one for each system tick) we need only 4 timer interrupts. The system can stay in low power mode for a much longer time which saves power. if (IdleTicks > 1) {... OS_StartTicklessMode(IdleTicks, &_EndTicklessMode); TIM2_ARR = (OS_TIMER_RELOAD * IdleTicks) - TIM2_CNT; // Set compare register OS_StartTicklessMode() sets the idle ticks and the callback function. The idle ticks information is later used in the callback function. The callback function is described below. We adjust the timer compare register to the new calculated value. Since the timer is already running we have to subtract the current timer value. _OS_EI(); while (1) { asm(" wfi"); Interrupts are reenabled and the CPU enters in the endless while loop the low power mode.

5 Implementation of the callback function() The callback function calculates how long we actually stayed in low power mode and corrects the system time accordingly. The hardware timer will be reset to the default system tick time of 1 msec. static void _EndTicklessMode(void) { OS_U16 NumTicks; OS_U16 Cnt; OS_U16 IReq; if (OS_Global.TicklessExpired) { // The timer interrupt was executed => we completed the sleep time else { Cnt = TIM2_CNT; IReq = TIM2_SR & (1uL << 0u); if (IReq) { else { // // We assume OS_TIMER_RELOAD Counts per tick and hardware timer // which counts up. // NumTicks = Cnt / OS_TIMER_RELOAD; Cnt TIM2_CNT = Cnt; OS_AdjustTime(NumTicks); -= (NumTicks * OS_TIMER_RELOAD); TIM2_ARR = OS_TIMER_RELOAD; // Set default value for 1 tick The following description analyzes the callback function step by step: static void _EndTicklessMode(void) {... if (OS_Global.TicklessExpired) { If the hardware timer has expired and the system tick interrupt was executed the flag OS_Global.TicklessExpired is set to 1. This can be used to determine if the system stayed in low power mode for the complete idle time. If this flag is set we can use the value in OS_Global.TicklessFactor to adjust the system time. else { Cnt = TIM2_CNT; IReq = TIM2_SR & (1uL << 0u); if (IReq) { The same is true when the system tick interrupt was not executed but the interrupt pending flag in the timer status register is set. We adjust the system time with OS_Global.TicklessFactor. else { NumTicks = Cnt / OS_TIMER_RELOAD; Cnt -= (NumTicks * OS_TIMER_RELOAD); TIM2_CNT = Cnt; OS_AdjustTime(NumTicks); This last else branch is executed when the scheduler was triggered by another interrupt than the timer interrupt. In this case we calculate how many system ticks did the system actually spent in low power mode. We adjust the timer count register and the system time accordingly. TIM2_ARR = OS_TIMER_RELOAD; // Set default value for 1 tick The timer compare register is reset to default value for one system tick which is equal to 1 msec.

6 CHAPTER