Programming Embedded Systems



Similar documents
ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

CS5460: Operating Systems

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

Embedded Software development Process and Tools: Lesson-3 Host and Target Machines

Embedded Software development Process and Tools:

Migrating Application Code from ARM Cortex-M4 to Cortex-M7 Processors

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Keil C51 Cross Compiler

STM32JAVA. Embedded Java Solutions for STM32

Real Time Programming: Concepts

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc()

Chapter 12. Development Tools for Microcontroller Applications

picojava TM : A Hardware Implementation of the Java Virtual Machine

Chapter 13. PIC Family Microcontroller

Microcontrollers Deserve Protection Too

APPLICATION NOTE. AT04056: Getting Started with FreeRTOS on Atmel SAM Flash MCUs. Atmel SMART. Introduction

Validating Java for Safety-Critical Applications

A N. O N Output/Input-output connection

Lecture 22: C Programming 4 Embedded Systems

CSCI E 98: Managed Environments for the Execution of Programs

CHAPTER 7: The CPU and Memory

Software based Finite State Machine (FSM) with general purpose processors

Linux flash file systems JFFS2 vs UBIFS

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

ECE 3803: Microprocessor System Design D Term 2011 Course Syllabus Department of Electrical and Computer Engineering Worcester Polytechnic Institute

Hello and welcome to this presentation of the STM32L4 Firewall. It covers the main features of this system IP used to secure sensitive code and data.

Data Management for Portable Media Players

2 Introduction to Java. Introduction to Programming 1 1

Overview of the Cortex-M3

ARM Microprocessor and ARM-Based Microcontrollers

The Design and Performance of Real-Time Java Middleware

Parameter passing in LISP

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-3: Windows and Memory Management

Chapter 7 Memory Management

Software Development Environment

RAM & ROM Based Digital Design. ECE 152A Winter 2012

Using the CoreSight ITM for debug and testing in RTX applications

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

EEM870 Embedded System and Experiment Lecture 1: SoC Design Overview

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-12: ARM

Operating Systems and Networks

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Memories of an Arduino

Object Oriented Software Design II

Introduction to Embedded Systems. Software Update Problem

Performance Improvement In Java Application

The new 32-bit MSP432 MCU platform from Texas

This tutorial will take you through step by step approach while learning Operating System concepts.

Chapter 5 Names, Bindings, Type Checking, and Scopes

Price/performance Modern Memory Hierarchy

Building Embedded Systems

HVM TP : A Time Predictable and Portable Java Virtual Machine for Hard Real-Time Embedded Systems JTRES 2014

AN4296 Application note

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

A deeper look at Inline functions

Recent Advances in Financial Planning and Product Development

Tutorial: Getting Started

Microprocessor or Microcontroller?

Enterprise Manager Performance Tips

With respect to the way of data access we can classify memories as:

Operating System Overview. Otto J. Anshus

On Demand Loading of Code in MMUless Embedded System

Simple C Programs. Goals for this Lecture. Help you learn about:

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

An Oracle White Paper September Advanced Java Diagnostics and Monitoring Without Performance Overhead

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

General Introduction

Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers. 8-bit Atmel Microcontrollers. Application Note.

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Zing Vision. Answering your toughest production Java performance questions

STM32 F-2 series High-performance Cortex-M3 MCUs

Garbage Collection in the Java HotSpot Virtual Machine

Memory Basics. SRAM/DRAM Basics

Memory. The memory types currently in common usage are:

AN3307 Application note

AN4664 Application note

Java Garbage Collection Best Practices for Sizing and Tuning the Java Heap

Understanding Java Garbage Collection

Building Blocks for PRU Development

Lecture 25 Symbian OS

Module 2. Embedded Processors and Memory. Version 2 EE IIT, Kharagpur 1

Real Time Cloud Computing

Developing Embedded Software in Java Part 1: Technology and Architecture

CS 153 Design of Operating Systems Spring 2015

ELEC 377. Operating Systems. Week 1 Class 3

1 The Java Virtual Machine

Fachbereich Informatik und Elektrotechnik SunSPOT. Ubiquitous Computing. Ubiquitous Computing, Helmut Dispert

MQX Lite Real-Time Operating System User Guide

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

CIS570 Modern Programming Language Implementation. Office hours: TDB 605 Levine

Chapter 13 Embedded Operating Systems

7a. System-on-chip design and prototyping platforms

Embedded Software development Process and Tools: Lesson-4 Linking and Locating Software

Transcription:

Programming Embedded Systems Lecture 13 Overview of memory management Monday Feb 27, 2012 Philipp Rümmer Uppsala University Philipp.Ruemmer@it.uu.se 1/32

Lecture outline Memory architecture of microcontrollers, in particular ARM CORTEX M3 Memory management in embedded software Scoped memory in RTSJ 2/32

Memory architecture of micro-controllers (in particular considering ARM CORTEX M3) 3/32

Architecture MCUs often use a Harvard approach Separate memory + buses for code (ROM) and data (RAM) Code is executed in place (not copied to RAM before execution) Some amount of RAM/ROM is integrated in MCU Typically: much ROM, little RAM Can be extended using external memory if needed 4/32

Read-only memory (ROM) Used to store code + static data (e.g., lookup tables) Unrestricted reading, separate procedure for writing Most common (today): flash memory Other kinds: PROM, UV-EPROM, EEPROM STM32F10x has 16KiB 1MiB of ROM 5/32

Random-access memory (RAM) Used for data (stack, heap) In principle also for code, but uncommon Two main kinds: SRAM, DRAM Both very common Often accessed through a hierarchy of caches Not so common for internal RAM in MCUs; difficult WCET analysis STM32F10x has 4KiB 96KiB of internal SRAM, no cache (but low latency) 6/32

CORTEX M3 memory map RAM + ROM + special-purpose regions are uniformly mapped into a 32bit address space Details depend of CORTEX M3 version 7/32

E.g., interface for debugging On-chip peripherals STM32F10x External memory map Internal 8/32

Bit band interface Motivation: accessing individual bits in memory is cumbersome Multiple instructions to set/reset bit, not atomic But very often necessary: access control bits, locks, etc. 9/32

Bit band interface (2) Bit band alias: 32MiB region B that allows to access individual bits of a 1MiB region A Every bit in A corresponds to a word (4 byte) in B 0 0x00000000 1 0xFFFFFFFF 10/32

Managing memory 11/32

Ways to manage memory At compile-time At startup-time Dynamically during runtime 12/32

Management at compile time Compiler/linker creates segments for different kinds of code/data code (read-only,.text) read-only data read-write data zero-initialised read-write data put into ROM Further segments possible, as needed Code/data is directly flashed to MCU; RAM is initialised during start-up 13/32

Management at compile time Mapping of data to segments can be automatic or explicit (compiler-specific) #pragma to specify segment Layout of segments in memory can be chosen 14/32

In MDK-ARM Zero-initialised read-write data (.bss, RAM): char rwdata[1024]; Read-write data (.data, RAM): char rwdata[3] = {1, 2, 3}; Default segment used Read-only data (.constdata, ROM): const char rodata[3] = {1, 2, 3}; 15/32

In MDK-ARM (example) int x1 = 5; // in.data (default) int y1[100]; // in.bss (default) int const z1[3] = {1,2,3}; // in.constdata (default) #pragma arm section rwdata = "foo", rodata = "bar" int x2 = 5; // in foo (data part of region) int y2[100]; // in.bss int const z2[3] = {1,2,3}; // in bar char *s2 = "abc"; // s2 in foo, "abc" in.conststring 16/32

In embedded systems Most common way of memory management: Allocate all required memory at compile-time (in read-write or read-only segments, as needed) Little risk of runtime errors due to memory management (e.g., it is checked at compile-time whether enough memory is present) 17/32

Dynamic memory management Manual management: malloc, free More flexible, might be necessary in some cases E.g., to implement OS functions: allocate stack for tasks, task control blocks, queues, semaphores, etc. 18/32

Dynamic memory management (2) Can cause various problems in embedded systems Possibly insufficient memory at runtime Fragmentation Implementation of malloc, free can be of substantial size malloc, free thread-safe? Compromise: no free, malloc is only used during startup 19/32

Dynamic memory management (3) FreeRTOS comes with 3 allocators (programmer can choose) Heap_1: only malloc is implemented, memory is never freed Heap_2: also provides free Heap_3: in addition, thread-safe implementation Size of managed heap is specified in FreeRTOSConfig.h: #define configtotal_heap_size ( ( size_t ) ( 17 * 1024 ) ) 20/32

More high-level memory management? Memory in Real-time Java 21/32

Real-time garbage collectors GCs for real-time systems are hard to get right Interruptions by GC have to be scheduled correctly GC must keep up with application Overhead in memory consumption due to delayed deallocation Too large, complicated, not trustworthy Mostly for soft real-time systems 22/32

Kinds of memory in RTSJ Heap memory Real-time garbage-collected, otherwise same as in normal Java Immortal memory Memory that is never reclaimed Scoped memory Region-based memory management Allocation using new, deallocation by deleting regions (reference-counting) Physical memory 23/32

Basic idea of scoped memory Organise memory in different regions e.g., one region for long-living objects of a thread, one region for temporary objects of a method,... Allocate memory as usual, but within regions (using malloc, new, etc.) Free memory by explicitly deleting whole regions 24/32

Memory Areas Areas are in RTSJ represented using class MemoryArea NB: each MemoryArea object is related to two memory regions: The region in which the MemoryArea object itself is allocated The region represented by the MemoryArea object Important MemoryArea methods: enter, newinstance, newarray 25/32

Scoped memory Every RealTimeThread runs in a memory allocation context Refers to some MemoryArea Chosen explicitly by programmer Nested contexts possible stack While in allocation context A, objects created with new are stored in A 26/32

Scoped memory (2) Contents of a scoped MemoryArea are cleared when the last thread exits the context ( reference counting ) MemoryArea can then be reused 27/32

Examples Simple use of memory scopes Nesting 28/32

Observations Scope nesting has to be acyclic References between scopes are restricted 29/32

Allowed references (Taken from The Real-Time Specification for Java, Version 1.0.2) 30/32

Typical use of scopes Identify self-contained computations (or parts) Estimate memory consumption of each computation Allocate sufficient amount of memory, using LT/VTMemory Execute computation within enter-block NB: memory areas can be reused! 31/32

Further reading Peter C. Dibble, Real-Time Java Platform Programming 32/32