You are on page 1of 51

The Designer's Guide to the Cortex-M

Processor Family Trevor Martin


Visit to download the full and correct content document:
https://ebookmass.com/product/the-designers-guide-to-the-cortex-m-processor-family
-trevor-martin/
The Designer’s Guide to the
Cortex-M Processor Family
This page intentionally left blank
The Designer’s Guide to the
Cortex-M Processor Family
Third Edition

Trevor Martin
Hitex (UK) Ltd., Coventry, England, United Kingdom
Newnes is an imprint of Elsevier
The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, United Kingdom
50 Hampshire Street, 5th Floor, Cambridge, MA 02139, United States
Copyright © 2023 Elsevier Ltd. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical,
including photocopying, recording, or any information storage and retrieval system, without permission in writing from the
publisher. Details on how to seek permission, further information about the Publisher’s permissions policies and our
arrangements with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency, can be found
at our website: www.elsevier.com/permissions.
This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may
be noted herein).

Notices
Knowledge and best practice in this field are constantly changing. As new research and experience broaden our
understanding, changes in research methods, professional practices, or medical treatment may become necessary.
Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any
information, methods, compounds, or experiments described herein. In using such information or methods they should be
mindful of their own safety and the safety of others, including parties for whom they have a professional responsibility.
To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any
injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or
operation of any methods, products, instructions, or ideas contained in the material herein.

ISBN: 978-0-323-85494-8

For Information on all Newnes publications


visit our website at https://www.elsevier.com/books-and-journals

Publisher: Mara E. Conner


Acquisitions Editor: Tim Pitts
Editorial Project Manager: Zsereena Rose Mampusti
Production Project Manager: Erragounta Saibabu Rao
Cover Designer: Christian J. Bilbow
Typeset by MPS Limited, Chennai, India
Contents

About the author .................................................................................................xvii


Foreword..............................................................................................................xix
Preface.................................................................................................................xxi
Acknowledgments ...............................................................................................xxiii

Chapter 1: Introduction to the Cortex-M Processor Family ....................................... 1


Introduction.................................................................................................................... 1
Book Structure ............................................................................................................... 1
External URL .......................................................................................................1
Cortex-M Processor Family ........................................................................................... 2
Cortex Profiles .....................................................................................................2
Cortex-M Hardware Architectures .......................................................................3
Armv7-M ....................................................................................................................... 5
Cortex-M3............................................................................................................5
Cortex-M4............................................................................................................9
Cortex-M7..........................................................................................................12
Armv6-M ..................................................................................................................... 14
Cortex-M0..........................................................................................................14
Cortex-M0 1 .....................................................................................................17
Armv8-M ..................................................................................................................... 20
Cortex-M33/M23 ...............................................................................................20
Armv8.1-M .................................................................................................................. 22
Cortex-M55........................................................................................................22
Cortex-M85........................................................................................................23
Conclusion ................................................................................................................... 24

Chapter 2: Developing Software for the Cortex-M Family ...................................... 25


Introduction.................................................................................................................. 25

v
vi Contents

Keil Microcontroller Development Kit ......................................................................... 25


Community Edition ............................................................................................26
Software Packs ...................................................................................................26
The Tutorial Exercises ................................................................................................. 27
Installation ................................................................................................................... 27
Exercise 2.1: Building a First Program ........................................................................ 30
The Blinky Project .............................................................................................30
Configuring a Project from Scratch ....................................................................32
Configuring the Run Time Environment ............................................................33
Project Configuration .........................................................................................57
Exercise 2.2: Hardware Debug ..................................................................................... 69
How to Get Out of Jail Free ...............................................................................75
Startup Barrier ...................................................................................................75
Third-Party Configuration Tools .................................................................................. 75
Conclusion ................................................................................................................... 76

Chapter 3: Cortex-M Architecture ........................................................................ 77


Introduction.................................................................................................................. 77
Cortex-M Instruction Set .............................................................................................. 77
Programmer’s Model and CPU Registers ..................................................................... 78
Program Status Register .....................................................................................80
Q Bit and Saturated Math’s Instructions ............................................................81
Interrupts and Multicycle Instructions ................................................................82
Conditional Execution—If Then blocks .............................................................82
Exercise 3.1: Saturated Maths and Conditional Execution .................................85
Cortex-M Memory Map and Busses............................................................................. 91
Write Buffer .......................................................................................................93
Memory Barrier Instructions ..............................................................................93
System Control Block ........................................................................................94
Memory Access .................................................................................................94
Bit Manipulation .......................................................................................................... 95
Exercise 3.2: Bit Banding ..................................................................................98
Dedicated Bit Manipulation Instructions ............................................................99
SysTick Timer ............................................................................................................. 99
Nested Vector Interrupt Controller ............................................................................. 100
Operating Modes ..............................................................................................101
Interrupt Handling—Entry ...............................................................................101
Interrupt Handling—Exit .................................................................................103
Exiting Interrupt Routines Important! ..............................................................104
Contents vii

Exercise 3.3: SysTick Interrupt ........................................................................104


Cortex-M Processor Exceptions .......................................................................109
Usage Fault ......................................................................................................110
Bus Fault..........................................................................................................111
Memory Manager Fault....................................................................................111
Hard Fault ........................................................................................................112
Enabling Fault Exceptions ...............................................................................112
Priority and Preemption ...................................................................................112
Groups and Subgroup .......................................................................................113
Processor Exceptions .......................................................................................114
Run Time Priority Control ...............................................................................115
Exception Model ..............................................................................................115
NVIC Tail Chaining .........................................................................................116
NVIC Late Arriving .........................................................................................116
NVIC POP Preemption ....................................................................................117
Exercise 3.4: Working with Multiple Interrupts ...............................................118
Bootloader Support ..........................................................................................124
Exercise 3.5: Bootloader ..................................................................................125
Power Management.................................................................................................... 130
Entering Low-Power Modes.............................................................................132
Configuring the Low-Power Modes .................................................................132
Exercise 3.6: Low-Power Modes......................................................................134
Moving From the Cortex-M3 ..................................................................................... 135
Cortex-M4........................................................................................................136
Cortex-M0........................................................................................................136
Cortex-M0 1 ...................................................................................................138
Conclusion ................................................................................................................. 139

Chapter 4: Common Microcontroller Software Interface Standard .........................141


Introduction................................................................................................................ 141
CMSIS Specifications ................................................................................................ 143
CMSIS-Core ....................................................................................................145
CMSIS-RTOS ..................................................................................................145
CMSIS-DSP .....................................................................................................145
CMSIS-Driver ..................................................................................................145
CMSIS-SVD and DAP .....................................................................................146
CMSIS-Pack ....................................................................................................147
CMSIS-NN ......................................................................................................147
CMSIS-ZONE ..................................................................................................148
viii Contents

CMSIS-Build ...................................................................................................148
Overview of CMSIS-Core .......................................................................................... 148
Coding Rules ...................................................................................................148
CMSIS-Core Structure .....................................................................................152
Interrupts and Exceptions .................................................................................157
Exercise 4.1: CMSIS and User Code Comparison ............................................160
CMSIS-Core Register Access ..........................................................................161
CMSIS-Core CPU Intrinsic Instructions ...........................................................163
Exercise 4.2: Intrinsic Bit Manipulation ...........................................................164
CMSIS SIMD Intrinsics ...................................................................................164
CMSIS-Core Debug Functions .........................................................................165
CMSIS Core Functions for Corex-M7 ..............................................................165
Armv8-M Support ............................................................................................166
Conclusion ................................................................................................................. 166

Chapter 5: Advanced Architecture Features .........................................................167


Introduction................................................................................................................ 167
Cortex Processor Operating Modes ............................................................................ 167
Exercise 5.1: Stack Configuration ....................................................................170
Supervisor Call ................................................................................................173
Exercise 5.2: SVC ............................................................................................175
PEND_SV Exception .......................................................................................178
Exercise 5.3: Pend_SV .....................................................................................178
Interprocessor Events ................................................................................................. 181
Exclusive Access Instructions ..........................................................................181
Exercise 5.4: Exclusive Access ........................................................................184
Memory Protection Unit ............................................................................................ 185
Configuring the MPU.......................................................................................187
CMSIS Core MPU Support ..............................................................................190
Exercise 5.5: MPU Configuration ....................................................................192
Memory Protection Unit Subregions ................................................................198
Memory Protection Unit Limitations ................................................................199
AHB Lite Bus Interface ...................................................................................199
Conclusion ................................................................................................................. 201

Chapter 6: Cortex-M7 Processor .........................................................................203


Introduction................................................................................................................ 203
Superscaler Architecture ............................................................................................ 205
Branch Prediction....................................................................................................... 205
Contents ix

Exercise 6.1: Simple Loop ...............................................................................206


Bus Structure ............................................................................................................. 208
Memory Hierarchy ..................................................................................................... 210
Exercise 6.2: Locating Code and Data into the TCM .......................................211
Open Main.c .............................................................................................................. 213
Cache Units .....................................................................................................213
Cache Operation ..............................................................................................214
Instruction Cache .............................................................................................217
Exercise 6.3: Instruction Cache ........................................................................218
Data Cache................................................................................................................. 218
Memory Barriers ..............................................................................................220
Example 6.4: Data Cache .................................................................................220
MPU and Cache Configuration ........................................................................221
Cache Policy ....................................................................................................221
Double Precision Floating Point Unit ......................................................................... 228
Functional Safety ....................................................................................................... 228
Cortex-M7 Safety Features ..............................................................................229
Safety Documentation ......................................................................................229
Conclusion ................................................................................................................. 230

Chapter 7: Armv8-M Architecture and Processors ................................................231


Introduction................................................................................................................ 231
Armv8-M ................................................................................................................... 231
Common Architectural Enhancements .............................................................232
Armv8 Baseline Enhancements ........................................................................233
Armv8-M Mainline Enhancements...................................................................234
Coprocessor Interface .......................................................................................234
Trust Zone .......................................................................................................235
Exercise 7.1: TrustZone Configuration.............................................................242
Armv8.1-M ................................................................................................................ 246
Helium Vector Extension .................................................................................247
CPU Extension .................................................................................................251
Exercise 7.2: Armv8.1 Performance .................................................................252
Coresight Debug Enhancements .......................................................................254
Memory Error Correction Codes ......................................................................254
Performance Monitoring ..................................................................................256
Security ............................................................................................................257
CPU Comparison ....................................................................................................... 261
Conclusion ................................................................................................................. 261
x Contents

Chapter 8: Debugging With CoreSight .................................................................263


Introduction................................................................................................................ 263
CoreSight Hardware ................................................................................................... 265
Debugger Hardware ................................................................................................... 267
CoreSight Debug Architecture ................................................................................... 267
Debug Adapters ...............................................................................................268
Exercise 8.1: CoreSight Debug ........................................................................268
Debug Limitations ...........................................................................................278
Customizing the Debugger ......................................................................................... 278
Instrumentation Trace ......................................................................................278
Exercise 8.2: Setting up the ITM .....................................................................279
Event Recorder ................................................................................................282
Exercise 8.3: Basic Event Recorder .................................................................282
Event Recorder Annotations.............................................................................285
Exercise 8.4: Event Viewer Annotations ..........................................................286
Exercise 8.5: Customizing the Debugger I .......................................................289
Component Viewer ..........................................................................................291
Exercise 8.6: Customizing the Debugger II ......................................................291
System Control Block Debug Support........................................................................ 293
Tracking Faults ................................................................................................294
Exercise 8.7: Processor Fault Exceptions .........................................................295
Power Analysis .......................................................................................................... 299
Instruction Trace With the Embedded Trace Macro Cell ........................................... 301
Exercise 8.8: Using the ETM Trace .................................................................303
CMSIS-DAP .............................................................................................................. 306
Cortex-M0 1 Micro Trace Buffer.............................................................................. 308
Exercise 8.9: Micro Trace Buffer .....................................................................308
System Viewer ........................................................................................................... 311
Conclusion ................................................................................................................. 312

Chapter 9: Practical DSP for Cortex-M Microcontrollers ......................................313


Introduction................................................................................................................ 313
Hardware Floating Point Unit .................................................................................... 313
FPU Integration................................................................................................314
FPU Registers ..................................................................................................315
Cortex-M7 FPU ...............................................................................................316
Enabling the FPU .............................................................................................316
Exceptions and the FPU ...................................................................................316
Using the FPU .................................................................................................317
Contents xi

Exercise 9.1: Floating Point Unit .....................................................................317


Cortex-M4/M7 DSP and SIMD Instructions............................................................... 323
Exercise 9.2: SIMD Instructions ......................................................................327
Exercise 9.3: Optimizing DSP Algorithms .......................................................330
The CMSIS-DSP Library ........................................................................................... 337
CMSIS-DSP Library Functions ........................................................................338
Exercise 9.4: Using the CMSIS-DSP Library ...................................................339
DSP Data Processing Techniques ............................................................................... 343
Exercise 9.5: FIR Filter with Block Processing ................................................344
Fixed Point DSP with Q Numbers ...................................................................347
Exercise 9.6: Fixed Point FFT Transform ........................................................349
Machine Learning ...................................................................................................... 350
Classical Machine Learning .............................................................................350
CMSIS-Neural Net ...........................................................................................352
Micro Neural processing Unit ..........................................................................353
Conclusion ................................................................................................................. 353

Chapter 10: Using a Real-Time Operating System ...............................................355


Introduction................................................................................................................ 355
First Steps With CMSIS-RTOS2 ......................................................................356
Accessing the CMSIS-RTOS2 API ............................................................................ 356
Threads ...................................................................................................................... 357
Understanding the Scheduler ............................................................................357
Starting the RTOS ............................................................................................359
Advanced Debug Features................................................................................367
Creating Threads ..............................................................................................369
Thread Management and Priority .....................................................................374
Memory Management ......................................................................................377
Joinable Threads ..............................................................................................382
Multiple Instances ............................................................................................384
Understanding RTOS API Calls ................................................................................. 386
Time Management ..................................................................................................... 386
Time Delay ......................................................................................................386
Absolute Time Delay .......................................................................................387
Virtual Timers ..................................................................................................388
Idle Thread.......................................................................................................391
Performance Analysis During Hardware Debugging ........................................394
Inter-Thread Communication ..................................................................................... 394
Thread Flags ....................................................................................................395
xii Contents

Event Flags ......................................................................................................397


Semaphores ......................................................................................................399
Mutex...............................................................................................................408
Data Exchange ........................................................................................................... 411
Message Queue ................................................................................................413
Extended Message Queue ................................................................................414
Message Queue API .........................................................................................415
Memory Pool ...................................................................................................415
Configuration ............................................................................................................. 418
System Configuration.......................................................................................419
Thread Configuration .......................................................................................420
System Timer Configuration ............................................................................422
RTX5 License ............................................................................................................ 423
Conclusion ................................................................................................................. 423

Chapter 11: RTOS Techniques ...........................................................................425


Introduction................................................................................................................ 425
RTOS and Interrupts .................................................................................................. 425
RTOS Interrupt Handling ........................................................................................... 427
Exercise 11.1: RTOS Interrupt Handling..........................................................428
User Supervisor Functions ......................................................................................... 430
Exercise 11.2: RTOS and User SVC Exceptions ........................................................ 430
Power Management.................................................................................................... 432
Power Management First Steps ........................................................................433
Power Management Strategy ............................................................................435
Watchdog Management.............................................................................................. 437
Integrating Interrupt Service Routines ..............................................................438
Exercise 11.3: Power and Watchdog Management ...........................................439
Startup Barrier .................................................................................................444
Designing for Real Time ............................................................................................ 445
Buffering Techniques  The Double or Circular Buffer ..................................445
Buffering Techniques FIFO Memory Pool .......................................................446
Exercise 11.4: RTX Real Time ........................................................................449
Functional Safety ....................................................................................................... 453
Arm Functional Safety Run-Time System .................................................................. 454
Software Test Library ......................................................................................456
RTX Safety Features ........................................................................................456
FuSa RTX Kernel ............................................................................................456
MPU Protection Zones .....................................................................................457
Contents xiii

Safety Class .....................................................................................................464


Temporal Isolation ...........................................................................................465
Fault Handling .................................................................................................466
Additional Safety Features ...............................................................................467
Conclusion ................................................................................................................. 467

Chapter 12: CMSIS-Driver ................................................................................469


Introduction................................................................................................................ 469
CMSIS-Driver API..................................................................................................... 471
Exercise 12.1: CMSIS-Driver...........................................................................472
Driver Validation ....................................................................................................... 477
Exercise 12.2: Driver Validation ......................................................................477
CMSIS Virtual IO ...................................................................................................... 481
CMSIS VIO API Functions ..............................................................................482
Implementing the VIO Driver ..........................................................................486
Extending the CMSIS-Driver Specification ................................................................ 489
Custom CMSIS-Driver .....................................................................................489
Custom Driver Validation ................................................................................494
Exercise 12.5: Custom Driver Validation .........................................................494
Conclusion ................................................................................................................. 498

Chapter 13: Test-Driven Development ................................................................499


Introduction................................................................................................................ 499
The TDD Development Cycle .................................................................................... 500
Test Framework ...............................................................................................501
Test Framework Integration .............................................................................501
Test Framework Automation ............................................................................502
Designing for Testability ............................................................................................ 502
Software Testing with Sub-Projects .................................................................503
Exercise 13.1: Test-Driven Development ................................................................... 503
Adding the Unity Test Framework ...................................................................504
Adding the Test Cases .....................................................................................506
Automating the TDD Cycle .............................................................................509
Testing RTOS Treads................................................................................................. 512
Exercise 13.2: Testing RTOS Threads ....................................................................... 514
Decoupling Low-Level Functions ....................................................................515
Testing Interrupts ....................................................................................................... 516
Exercise 13.3: Testing with Interrupts ........................................................................ 517
Conclusion ................................................................................................................. 519
xiv Contents

Chapter 14: Software Components .....................................................................521


Introduction................................................................................................................ 521
Designing a Software Component .............................................................................. 521
Component API ...............................................................................................523
Module Structure .............................................................................................523
Development Workflow ...................................................................................524
Exercise 14.1 Component GPS Interface..........................................................525
Adding Custom IDE Support ..................................................................................... 528
Configuration Wizard.......................................................................................529
Component Viewer ..........................................................................................529
Event Recorder ................................................................................................529
Component Characterization ............................................................................531
Exercise 14.2 GPS Component ........................................................................531
Designing a Configuration Wizard ...................................................................533
Exercise Configuration Wizard ........................................................................533
Software Component Reuse with CMSIS Pack .......................................................... 536
CMSIS Pack Structure .....................................................................................537
CMSIS Pack Utilities .......................................................................................537
Updating and Testing the Software Component ...............................................545
Generating the Component Pack ......................................................................546
Autogenerated Header Files .............................................................................550
Adding Example Projects .................................................................................551
Deploying Software Components .....................................................................553
Conclusion ................................................................................................................. 553

Chapter 15: MCU Software Architecture ............................................................555


Introduction................................................................................................................ 555
Software Architecture for Microcontrollers ................................................................ 556
Superloop .........................................................................................................556
Time-Triggered Architecture ............................................................................556
Event-Triggered Architecture ...........................................................................556
RTOS ...............................................................................................................557
Objectives of our Architecture .........................................................................557
RTOS-Layered Architecture.............................................................................558
Design Synthesis ..............................................................................................562
Implementation ................................................................................................563
Additional Tools ..............................................................................................572
Exercise 15.1: Case Study ................................................................................573
Continuous Integration ............................................................................................... 574
Contents xv

Exercise 15.2: Cloud-Based Continuous Integration.........................................574


CMSIS-Toolbox ......................................................................................................... 575
CMSIS-Toolbox Project Format .......................................................................576
Layers ..............................................................................................................577
Exercise 15.3: Configuring CMSIS-Toolbox ....................................................577

Chapter 16: The Road Ahead .............................................................................583


Keil Studio ................................................................................................................. 583
Arm Virtual Hardware .....................................................................................583
IoT and Machine Learning ......................................................................................... 585
Project Centauri for the IoT .............................................................................585
CMSIS v6 ........................................................................................................586
Machine Learning ...................................................................................................... 588
Confidential AI ................................................................................................588
Conclusion ................................................................................................................. 589

Appendix A .......................................................................................................591
Index ..................................................................................................................601
This page intentionally left blank
About the author
Trevor Martin is a senior technical specialist in Hitex UK, where he has worked over 25
years. Trevor has worked with a wide range of microcontrollers and associated development
tools. Since the launch of the Cortex-M3 processor in 2004, Trevor has contributed
numerous articles and application notes for many of the leading Cortex-M-based
microcontrollers. Having an extensive knowledge of the Cortex-M processor family, Trevor
is also familiar with many of the development techniques, application software, and
communication protocols required for today’s embedded applications.

xvii
This page intentionally left blank
Foreword
This is the third edition of a book that has become a dear friend to many software
developers using Arm Cortex-M-based microcontrollers. When it was first published in
2013, the dominance of the Arm architecture in all things embedded was not in sight and
the term “IoT” was not an everyday term.
Since the beginnings in the mid-2000s, Arm Cortex-M-based microcontrollers have evolved
from low-power 16-bit replacements to high-performance processors running up to 1 GHz.
The list of supported devices on Arm’s device database is close to 10,000 entries—all
applications can be covered with a specific MCU from one of Arm’s silicon partners. But
not only the computing performance was increased, also many interfaces, especially for
Internet connectivity, have been added even to the tiniest device. Adding safety and
security features while maintaining the low-power heritage and low-cost advantage is a big
challenge for software developers.
Arm’s “Common Microcontroller Software Interface Standard” or in short CMSIS helps to
simplify software reuse, reduce the learning curve for microcontroller developers, speed up
project build and debug, and thus reduce the time to market for new applications. It plays
an important role in every Cortex-M software developer’s day-to-day work. From its
humble beginnings in 2009 up to now, it grew from a vendor-independent hardware
abstraction layer to a set of tools, APIs, frameworks, and flows.
CMSIS is supported throughout Arm’s wide ecosystem. It is an integral part of many SDKs
and IDEs that are available to developers. Lots of third-party software vendors (including
the major cloud service providers) deliver their software stacks as Open-CMSIS-Packs.
New development flows built on these packs help developers to maintain their software and
enable CI/CD DevOps flows. Using Arm Virtual Hardware, this enables automated build
and test in the cloud. These new flows ensure high software quality throughout the whole
development process.
While it has become an impressive toolbox software developers can choose from, it is not
always easy to understand which CMSIS component is used and when. This book’s tutorial-
based approach helps developers to understand the various components and how to use
them effectively.

xix
xx Foreword

Trevor is an experienced professional and has held hundreds of workshops on embedded


development. His book is a condensed version of his expertise and takes you through all
steps that are required to create embedded applications successfully. Being very hands-on,
both new and experienced developers can learn new approaches to embedded software
development. I hope you enjoy reading it as much as I did.

Christopher Seidl
Preface
ARM first introduced the Cortex-M processor family in 2004. Since then, the Cortex-M
processor family has gained wide acceptance as general-purpose processors for small
microcontrollers. At the time of writing, there are several thousands of standard
microcontrollers that feature the Cortex-M processor and the pace of development shows no
sign of slowing down. The Cortex-M processor is now well established as an industry
standard architecture for embedded systems. As such, the knowledge of how to use it is
becoming a requisite skill for professional developers. This book is intended as both an
introduction to the Cortex-M processor family and a guide to the techniques used to
develop an application software to run on them. The book is written as a tutorial, and the
chapters are intended to be worked through in order. Each chapter contains a set of
examples that present the key principles outlined in this book using a minimal amount of
code. Each example is designed to be built with the community edition of the Keil MDK.
These examples run in a simulator so that you can use this book without any additional
hardware. That said the examples can also be run on low-cost hardware modules that are
widely available through the Internet.
This book can be divided into two sections. In this first section, we will examine the
Cortex-M processors, and the software support and tools used to develop the application
code.
Chapter 1 provides an introduction and feature overview of each processor in the Cortex-M
family.
Chapter 2 introduces the basics of building a C project for a Cortex-M processor.
Chapter 3 provides an architectural description of the Cortex-M3 and its differences from
the other Cortex-M processors.
Chapter 4 introduces the CMSIS programming standard for Cortex-M processors.
Chapter 5 extends Chapter 3 by introducing the more advanced features of the Cortex-M
architecture.
Chapter 6 covers the Cortex-M7 and introduces its new architectural features and extended
memory model.

xxi
xxii Preface

Chapter 7 discusses on the next generation of Cortex-M processors introduced by the


Armv8-M architecture and the new extensions to the existing programmer’s model.
Chapter 8 provides a description of the CoreSight debug system and its real-time features.
Chapter 9 discusses the math and DSP support available on the Cortex-M4 and how to
design real-time DSP applications.
In the second half of this book, we will look more closely at how to construct a software
program for a Cortex-M processor. This section emphasizes the use of an RTOS-based
layered software architecture that promotes software testing and code reuse.
Chapter 10 introduces the use of an RTOS on a Cortex-M processor. This is a key
framework that helps to design and manage more complex codebases.
Chapter 11 examines some real-world techniques that can be used when developing an
RTOS-based project.
Chapter 12 discusses on the CMSIS Driver specification. It starts with installing, followed
by validating and using a standard driver. We will next look at how a CMSIS driver is
constructed and how to extend the range of drivers with a custom driver profile.
Chapter 13 provides an introduction to software testing on a Cortex-M microcontroller and
introduces an important design technique called Test-Driven Development (TDD).
Chapter 14 looks at designing reusable software components within a TDD framework. The
CMSIS Pack specification is used to create a device-independent component that can be
installed into the toolchain.
Chapter 15 defines a layered software architecture based on the techniques learned in the
preceding chapters.
With Chapter 16 (the final chapter), we will look just over the horizon at near-future
developments in silicon and software.
This book is useful for students, beginners, and advanced and experienced developers alike.
However, it is assumed that you have a basic knowledge of how to use microcontrollers and
that you are familiar with the the ‘C‘ programming language. In addition, it is helpful to
have basic knowledge of how to use the μVision debugger and IDE.

Trevor Martin
Acknowledgments
I would like to thank Tim Pitts, Zsereena Rose Mampusti, and Saibabu Rao Erragounta of
Elsevier and Joseph Yui of ARM along with Christopher Seidl and all the team at Keil.

xxiii
This page intentionally left blank
CHAPTER 1

Introduction to the Cortex-M Processor


Family

Introduction
The objective of this book is to provide you with a fundamental understanding of the Cortex-
M processor family and an overview of the essential software libraries, standards,
development techniques, and tools required to design effective and efficient application code.

Book Structure
This book is arranged as a tutorial and it is best to work through it chapter by chapter. Each
chapter contains a number of hands-on examples that use the community edition of the Keil
MDK toolchain. The Keil MDK is the industry-leading reference toolchain for Cortex-M
microcontrollers and the community edition license allows unrestricted use for noncommercial
projects. The MDK debugger also provides a sophisticated simulator that allows you to run most
of the examples in this book without the need for additional hardware. In the initial chapters, we
will look at the general Cortex-M programmer’s model and the features of each Cortex-M
processor. Alongside the exploration of the processor hardware, we will see how to access these
features from our development software. We will also review a set of specifications called the
“Common Microcontroller Software Interface Standard”, which provides software and tools that
enable software development over the whole range of Cortex-M processors. In the second half of
the book, we will look at more sophisticated software development techniques and then in the last
few chapters bring these together to create a modular component-based general-purpose software
architecture that can be used to develop a wide range of applications. So let’s make a start with
an overview of the current range of Cortex-M processors.

External URL

Throughout the book, there are a lot of external links and references. For the paper copy of
this book, there is a pdf that contains a set of clickable links for each chapter. This pdf can
be downloaded from the GitHub repository which contains the book example set (see
Chapter 2: Developing Software for the Cortex-M Family). If any of the URL links stop
working, I will update the pdf with an alternative.

The Designer’s Guide to the Cortex-M Processor Family.


DOI: https://doi.org/10.1016/B978-0-323-85494-8.00016-4 1
© 2023 Elsevier Ltd. All rights reserved.
2 Chapter 1

Cortex-M Processor Family


In the late 1990s and early noughties, several Silicon vendors adopted the now “classic” ARM7
and ARM9 processors as the CPU for a new generation of high-performance microcontrollers.
While this represented a huge step forward in performance, both the ARM7 and ARM9 were only
CPUs each silicon vendor had to provide their own bus structure, interrupt handling, and power
management. So while the CPU was the same across different families, every implementation was
different and the overall market remained very fragmented. With the introduction of the next-
generation Cortex processor, this all changed. In addition to all its technical benefits, the Cortex-M
processor provides a standard core that is the same to use across all the different manufacturer’s
devices. This creates a range of benefits which are summarized below.
• Learn to use the Cortex-M processors once then reuse that knowledge many times.
• Create industry-wide standards to accelerate code development.
• A standard core means that silicon vendors must innovate in order to differentiate their
devices from competitors.
• A standard processor creates a wide and deep ecosystem for supporting software, tools,
and hardware.

Cortex Profiles

In 2004 Arm introduced its new Cortex family of processors. The Cortex processor family
is subdivided into three different profiles (Fig. 1.1). Each profile is optimized for different
segments of embedded systems applications.

Figure 1.1
The Cortex processor family has three profiles: Application, Real Time, and Microcontroller.
Introduction to the Cortex-M Processor Family 3

The Cortex-A profile has been designed as a high-end application processor. Cortex-A
processors are capable of running feature-rich operating systems (OSs) such as embedded
versions of Windows and Linux. The key applications for Cortex-A are consumer
electronics such as smartphones, tablet computers, and set-top boxes. The second Cortex
profile is Cortex-R. This is the real-time profile that delivers a high-performance processor
which is the heart of an application-specific device. Very often, a Cortex-R processor forms
part of a “system-on-chip” design that is focused on a specific task such as hard disk drive
control, automotive engine management, and medical devices. The final profile is Cortex-M
or the microcontroller profile. Unlike earlier Arm CPUs, the Cortex-M processor family has
been designed specifically for use within a small microcontroller to provide high-
performance processing and real-time deterministic interrupt handling coupled with low-
power consumption.

Cortex-M Hardware Architectures

The Cortex-M processor family is spread across four architectural revisions that
provide a range of features and extensions to the core processor. The four revisions
are Armv6-M, Armv7-M, Armv8-M, and Armv8.1-M. Each of these architectures has
the same core programmer’s model and is upward compatible with the next
architectural revision. Fig. 1.2 shows the key processor features available to each
architectural revision.

Figure 1.2
The Cortex-M profile has five different variants with a common programmer’s model.
4 Chapter 1

The full range of Cortex-M processors is shown in Fig. 1.3. Starting with the simplest
devices the Armv6-M architecture contains three processors: Cortex-M0, Cortex-M1, and
Cortex-M0 1 . The Cortex-M0 and Cortex-M0 1 are the smallest processors in the family.
They allow silicon manufacturers to design low-cost, low-power devices that can replace
existing 8-bit microcontrollers while still offering 32-bit performance. The Cortex-M1 has
much of the same features as the Cortex-M0 but has been designed as a “soft core” to run
inside a Field Programmable Gate Array device.
The next group of Cortex-M processors exists within the Armv7-M architecture. These are
the Cortex-M3, Cortex-M4, and Cortex-M7. The Cortex-M3 is the mainstay of the Cortex-
M family and was the first Cortex-M variant to be launched. It has enabled a new
generation of high-performance 32-bit microcontrollers that can be manufactured at a very
low cost. Today, there are many Cortex-M3-based microcontrollers available from a wide
variety of silicon manufacturers. This represents a seismic shift where Cortex-M-based
microcontrollers have essentially replaced traditional 8/16-bit microcontrollers and even
other 32-bit microcontrollers. The next highest performing member of the Cortex-M family
is the Cortex-M4. This has all the features of the Cortex-M3 and adds support for digital
signal processing (DSP). The Cortex-M4 also includes hardware floating-point support for
single-precision calculations. The Corex-M7 is the Armv7-M architecture processor with
the highest level of performance while still maintaining the Cortex-M programmer’s model.
The Cortex-M7 has also been designed for use in high reliability and safety-critical
systems.

Figure 1.3
The Cortex-M profile has nine different variants with a common programmer’s model.
Another random document with
no related content on Scribd:
— Sitä kenraali Löfbergkin sanoo. Mutta kaikki eivät ole yhtä
voimakkaat luonteeltaan ja rohkeat kuin neiti Fährling.

— Ei siihen tarvita kuin hiukan hyvää tahtoa ja rakkautta. Mutta


sitä ei jokaisella ole.

Hertta vaipui mietteihinsä. Olihan hänkin tuollaista työalaa


haaveillut, eikä mikään olisi häntä lähtemästäkään estänyt. Ei
kukaan häntä täällä tarvinnut eikä kaivannut. Ja kuitenkin hän
epäröi, eikä voinut lopullista päätöstä tehdä. Puuttuiko häneltä ehkä
rohkeutta, vai eikö hänen harrastuksensa asiaan olisi ollut
todellinen?

— Te näytätte niin väsyneeltä, neiti Ek. Te olette liian ahkera ja


innokas työssänne.

— En minä ole väsynyt. Harvoin olen tuntenut sellaista työintoa


kuin nyt. Mutta tämä työ ei yksin tyydytä minua, vaikka nuo tunnit
kenraali Löfbergin luona ovatkin minulle oikeita juhlahetkiä. Minä
tahtoisin vieläkin tuntuvammin tarttua työhön.

— Mutta onhan teillä kotinnekin. Tarvitaanhan sielläkin teidän


voimianne.

— Oi, älkää puhuko minulle kodistani. Minä olen siellä enemmän


yksin kuin ulkona maailmassa, jossa ainakin joskus voi tavata
ymmärtävän sielun.

— Ajatelkaa kotia, sanoi Hertta hetken kuluttua, — ilman mitään


lämmittävää tunnetta, ilman äidin ohjaavaa kättä. Kun minä katselen
noita nuoria tyttöjä, niin minun käy heitä niin äärettömän kateeksi.
Heille elämä aina hymyilee, jota vastoin minulle — mitä iloa minulla
voisi olla — —

— Te olette katkera, neiti Ek. Ettekö usko että moni on saanut


viettää vieläkin valottomampaa nuoruutta kuin te? On saanut taistella
toimeentulonsa puolesta, ja saanut kärsiä hairahdusten vuoksi, joihin
itse on ollut aivan syytön.

— Uskon sen kyllä. Mutta sen sijaan voi lohdutus olla kahta
kalliimpi, kun sen vihdoin on saanut. Onhan esimerkiksi teilläkin Elli,
joka pienellä kädellään poistaa kaikki teidän huolenne.

— Te olette niin ivallinen. Jos te tietäisitte mikä rakkaus on, niin te


myös puhuisitte toisin.

— Rakkausko? Se on utukuva, jota kaikki ihmiset ajavat takaa,


mutta saavutettuaan sen, se haihtuu heiltä käsiin.

— Te herätätte ihmetystäni, neiti Ek.

— Ihmetyttääkö se teitä, että nuorelta naiselta elämä jo on ehtinyt


riistää kaikki unelmat? Uneksinhan minäkin kerran, mutta siitä on jo
niin pitkä aika. Sanokaa itse, tohtori Hammar, mitä jää jäljelle, jos
ihminen kadottaa kaiken sen, mikä hänelle on ollut kallista ja pyhää?
Ja juuri sen tähden, etten usko persoonalliseen onneen, tahtoisin
saada jotain muuta, joka täyttäisi tyhjyyden omassa itsessäni,
tahtoisin antaa ja uhrata jotain kansalleni.

— Mutta ilman rakkautta te ette voi mitään saada aikaan.

Soitto salissa oli la'annut. Useita nuoria tyttöjä astui huoneesen.


Heidän poskensa hohtivat ja viuhkoillaan he löyhyttelivät itseään. He
kerääntyivät Elsan ympärille ja hyväilivät häntä.
— Voi Elsa kulta, kuinka hieno hän on, ja kuinka hyvin hän tanssii.
Luulisi ilmassa lentävänsä.

Elsa naurahti.

— Serkkuniko? No, tanssiihan hän.

— Ja sen sinä sanot noin välinpitämättömästi, vaikka hän on niin


fiksu.

Elsa nojautui vallattomasti nojatuolin selkämystä vasten ja


heilutteli kenkänsä kärkeä.

— Kuinka kaunis sinä olet, Elsa. Etkö todellakaan ole kähertänyt


hiuksiasi? Sinullahan on oikea glooria otsasi ympärillä.

Elsa kohautti vain olkapäitään.

— Tiedättehän tytöt, etten käherrä, ääni oli hiukan kopea. — Ei,


mennään takaisin saliin; nyt aloitamme masurkan.

Elsa kiiruhti masurkka-askelin toisten edellä saliin.

— Ettekö tahdo tulla tanssimaan, kysyi Antti Hertalta, joka oli


jäänyt paikoilleen istumaan.

— Kiitos, ei minua haluta.

Antti läksi tyttöjen jäljessä salin ovelle ja jäi katsomaan toisten


tanssia.

Elli tanssi luutnantti Tauben kanssa. Hän tanssi hyvin, se oli Antin
myönnettävä ja jonkunlaisella mielihyvällä hän seurasi Ellin sulavia
liikkeitä. Taube ei vaan ollut hänelle mieleen. Hänen katseensa oli
liian lämmin ja lähentelevä ja Ellikin silmäsi häneen niin kirkkaasti.
Mutta Antti poisti nuo ajatukset heti paikalla, olihan Elli niin
ystävällinen ja herttainen kaikille.

Niin, hän rakasti Elliä, tuota hentoa, suloista lasta, joka oli
päivänpaistetta varten syntynyt. Hän tasoittaisi hänen tiensä, niin
ettei hänen koskaan tarvitsisi mitään kärsiä, eikä tulla katkeraksi,
niinkuin Hertta. Hertta parka! Hänen silmänsä olivat syvät ja
surulliset, niiden katsetta ei helposti unohtanut. Mutta miksi hän oli
katkera ja tyly ja miksi hän puhui niin ivallisesti Antin suhteesta
Elliin? Olisiko hän huomannut sen, mitä Antti ei itsekkään käsittänyt,
ei ajatellut, ainoastaan joskus hämärästi tunsi… Ei, hän oli vain niin
hermostunut ja väsynyt tänä iltana. — — —

Luutnantti Taube vei Ellin sivuhuoneesen istumaan. Matala sohva


oli suurien kasvien peitossa ja himmeä kattolamppu antoi huoneelle
salaperäisen leiman. Luutnantti Taube kohotti viinilasia.

— Maljanne, neiti Elli, meidän uudistetun tuttavuutemme malja!


Tiedättekö kuinka hyvin nuo kiharat teitä pukevat, teidän ei pidä
koskaan niistä luopua.

Elli leikitteli viuhkallansa.

— Sanokaa, ettei se ole totta, mitä teistä kerrotaan, eihän se voi


olla mahdollista, että te olisitte kihloissa! Ja kenenkä kanssa sitten?
Vakavan kirjatoukan. Ei hän teille sovi.

Elli säpsähti. Hän oli kokonaan unohtanut Antin, hän ei ollut


kertaakaan muistanut häntä koko iltana. Hän oli antanut itseään
sokaista, tanssi oli noussut hänelle päähän ja viini kiihoitti hänen
vertansa.
— Antakaa minun mennä. Elli nousi istualtaan. — Mitä muut
sanoisivat jos he tietäisivät että olen kahden teidän kanssanne,
erillään kaikista toisista.

— Eivät he sano mitään, pikku Elli, tehän olette kihloissa.

Elli riuhtaisi kätensä irti, jota luutnantti Taube koetti pidättää. — —


Budoarista kuului vilkasta keskustelua. Rouva Löfberg istui


mukavassa korituolissa ja sohvassa, talon emännän rinnalla, rouva
Illman. Senaattori Taube ja kenraali Löfberg juttelivat ikkunan
ääressä.

— Tiesinhän minä sen edeltäpäin, sanoi rouva Illman kiihkeästi, —


heidän kanssaan ei koskaan tule toimeen. He tekeytyvät
puolueettomiksi, mutta ovat itse asiassa punaisempia kuin koskaan
ennen.

Rouva Illmanin kiihkeä ääni veti herrojen huomion puoleensa. He


vetivät tuolinsa lähemmäksi rouvia ja kenraali Löfberg sanoi
naureskellen:

— Luulenpa että rouvat ovat törmänneet yhteen. Onko sula


sovinto rikottu?

— Minä en ainakaan enää tahdo olla heidän kanssansa


tekemisissä, sanoi rouva Illman yhä kiihtyvällä äänellä.

Rouva Löfberg oli iltamatoimikuntaan pyytänyt muutamia


ruotsinmielisiä naisia, hän oli toivonut voivansa panna toimeen
iltaman, johon molemmat puolueet ottaisivat osaa. Mutta aie oli
mennyt myttyyn. Jo ensi kokouksessa oli erimielisyyttä syntynyt ja
molemmat puolueet olivat pitäneet puoliansa. Olihan niitäkin, jotka
olivat koettaneet sovittaa, mutta se ei onnistunut, kun riita lopulta
muuttui persoonalliseksi. Rouva Tauben ehdoituksesta oli päätetty
pitää kaksi iltamaa, kumpikin puolue eriksensä.

— Onhan se vain eduksi, puolusteli rouva Taube. — Tungos on


siten vähempi ja tunnelma kodikkaampi. Se, joka haluaa, voi sitä
paitsi ottaa osaa molempiin.

— Ihmeellistä se vaan on, ettemme voi sovinnossa elää, sanoi


rouva Löfberg. — Eikö ole yhdentekevää, mitä esitetään milläkin
kielellä, kun vaan molemmat pääsevät oikeuksiinsa.

— Onko se yhdentekevää, intoili rouva Illman, — jos koko ohjelma


on ruotsinkielinen, paitsi mahdollisesti jotakuta suomalaista
lausuntokappaletta. Niin, niin, minä tunnen nuo rouvat, suoraan
sanoen, he halveksivat meitä ja meidän kieltämme.

Keskustelu kävi ruotsiksi niinkuin tavallisestikin suomenmielisten


rouvain keskuudessa.

— Arvoisat rouvat ovat osittain itse syypäät tuohon


halveksumiseen, sanoi kenraali Löfberg. — Jos te itse käyttäisitte
kansan kieltä, niin voisitte myöskin vaatia, että muutkin pitäisivät sitä
arvossa.

— Kun lapsuudestaan asti on tottunut käyttämään ruotsia, niin on


niin vaikea luopua siitä tavasta, sanoi rouva Löfberg.

— Ei siihen tarvita kuin lujaa tahtoa ja rakkautta. Mutta oma


mukavuus on aina jokaista lähinnä.

Rouvat näyttivät hiukan noloilta. Ei kukaan sanonut mitään.


Rouva Taube huomasi Hertan, joka oli pysähtynyt oven suuhun.
Hän viittasi hänet luoksensa ja puheli puoliääneen hänen
kanssansa.

— Se on siis sovittu, hän sanoi, — sinä tulet minun kanssani tuon


miehen luo. Hän näytti niin rehelliseltä. Tahtoisin mielelläni häntä
auttaa.

Rouva Taube nousi ylös ja pyysi vieraitaan siirtymään ruokasaliin.


Senaattori Taube tarjosi käsivartensa rouva Löfbergille. Soitto salissa
oli tauonnut. Leveät ovet, jotka yhdistivät salin ja ruokasalin yhdeksi
huoneeksi, olivat avautuneet ja pöydältä loistivat sähkön kirkkaassa
valossa korkeat kristallimaljakot ja kiiltävät hopeat.
V.

Puoliyö oli jo kulunut, kun Hertta astui kotiinsa. Kotiportilla hän näki
tulta isänsä ikkunasta. Isä oli siis vielä ylhäällä, ja jos hän ei
erehtynyt, niin istui Väisänen hänen toverinansa pöydän toisessa
päässä.

Hän koetti hiipiä huoneesensa niin hiljaa kuin mahdollista, mutta


Väisänen kuuli eteisen oven avautuvan.

— Hertta neiti tulee kotiin, hän sanoi astuen eteiseen ja tarjosi


kätensä tutunomaisesti. — Oliko hauska tanssiaisissa?

— Hertta, kuului kapteenin ääni.

Hertta astui sisään. Tupakan savusta huone oli aivan harmaana ja


ilma tuntui painostavalta.

— Istuhan tänne, tyttöseni, me juuri puhelimme sinusta. Saitko


paljon tanssia?

— En tanssinut yhtään.

— Merkillinen tyttö, kapteeni kääntyi Väisäsen puoleen, — ei


häntä huvita mikään, mikä muita nuoria. Mitä jos lähettäisimme
hänet ulos maailmaan huvittelemaan?

Hertta, joka oli kuunnellut vain puolella korvalla, säpsähti äkkiä.


Mistä tuo huolenpito nyt johtui, eihän isä ennen ollut kysellyt hänen
huvejansa. Hän aikoi lähteä huoneesensa, mutta kapteeni pidätti
häntä.

— Älä lähde, meillä on sinun kanssasi hiukan puhuttavaa. Olen


ajatellut että saat uudella vuodella lähteä ulkomaille, herra Väisänen
on ystävällisesti lupautunut matkatoveriksi. Voit lähteä Sveitsiin tai
Pariisiin, minne mielemmin vain haluat.

Hertta katsoi yhä enenevällä hämmästyksellä isäänsä.

— En minä halua minnekään, en ainakaan ulkomaille. Ja herra


Väisäsenkö seurassa?

— No, hyvä lapsi, mitä kummaa siinä on. Hän on minun läheinen
ystäväni, ja hän lähtee sinne joka tapauksessa.

Väisänen oli koko ajan ollut ääneti, mutta terävillä silmillään hän
seurasi pienintäkin ilmeen vivahdusta Hertan kasvoissa. Hän näytti
niin itsetietoiselta ja varmalta omasta asiastansa.

Hertta ei tiennyt mitä sanoa.

— Isä, on jo niin myöhäistä, ja minua väsyttää. Voimmehan


keskustella siitä toiste. Hyvää yötä.

Hän ojensi kätensä Väisäselle, joka tarttui kiihkeästi siihen ja


suuteli sitä. Puna kohosi Hertan poskille, suun ympärille ilmaantui
jäykkä piirre ja nyökäyttäen päätä isälleen hän poistui huoneesta.
— Sinä pysyt siis sanassasi, Väisänen, kysyi kapteeni Hertan
mentyä.

— Pysyn tietenkin, sillä ehdolla kuin jo mainitsin. Koetan järjestää


asiani toisella tavalla.

— Mutta jos Hertta ei suostu. Hän on niin omapäinen ja pakoittaa


en voi.

— Siitä sinun on huoli pidettävä. Kyllä hän suostuu, jos oikein


asian selität. Eihän hän voi tahtoa sinun perikatoasi.

Huonot ajat olivat vaikuttaneet kapteeninkin raha-asioihin. Hän oli


kerännyt itselleen vähäisen omaisuuden ja asettuessaan kaupunkiin,
hän oli ostanut itselleen talon. Väisäsen kehoituksesta hän oli
hankkinut osakkeita "Vesa" yhtiössä, joka hyvänä raha-aikana oli
perustettu halkojen vientiä varten Pietariin. Yritys oli ollut erittäin
lupaava ja kapteeni oli ottanut suuremman lainankin, voidakseen
lunastaa kaikki hänelle tarjona olleet osakkaat. Mutta huono aika oli
tullut juuri silloin kun yhtiöstä toivottiin suuria osinkoja. Kapteeni oli
pulassaan kääntynyt Väisäsen puoleen ja Väisänen oli hänelle
lainannut rahoja, joskin korkealla korolla.

Väisänen oli jo edeltäpäin nähnyt mikä vaara kapteenia uhkasi.


Mutta tuo rahapula oli hänelle vain mieleen. Hän toivoi itse siitä
hyötyvänsä, hän halusi saada omaksensa kapteenin talon, joka
asemansa puolesta oli aivan erinomainen. Mielikuvituksessaan hän
oli jo nähnyt viisikerroksisen kivitalon kohoavan entisen sijalle ja
kuvitellut itseään sen omistajana.

Hän oli tarjoutunut ostamaan taloa, kun kapteeni oli kireitä aikoja
valitellut. Mutta kauppahinnasta he eivät voineet sopia. Silloin oli
Väisäsen mieleen juolahtanut toinen tuuma. Hän päätti naida Hertan,
olihan hän sievä tyttö, joskin hiukan kopea, ja talon hän saisi aivan
kaupantekijäisiksi. Samalla Hertta aukaisisi hänelle tien korkeampiin
piireihin, ainoa mikä häneltä nykyisessä asemassaan vielä puuttui.
Ja saadakseen aikeensa onnistumaan, hän oli mielestään keksinyt
erinomaisen keinon. Hän pyysi kapteenilta Herttaa vaimoksensa.
Hän sanoi rakastavansa häntä ja katselleensa häntä jo kauan.

Mutta kapteeni oli nauranut hänen aikeillensa, eikä ottanut niitä


todeksi. Silloin Väisäsen kelloon tuli toinen ääni. Hän sanoi
välttämättä tarvitsevansa rahoja ja pyysi kapteenin määrä-ajan
kuluttua maksamaan hänelle velkansa takaisin.

Kapteenin epätoivo ja tuska ei liikuttanut Väisästä vähintäkään.


Hän oli sen jo edeltäpäin arvannut, mutta hänellä oli valtit
käsissänsä. Ja yhä julkeammaksi hän kävi vaatimuksessansa.

Kapteeni oli vihdoin luvannut puhua Hertan kanssa ja koettaa


välittää asiaa. Tosin hän olisi toivonut Hertalle toisellaisen miehen,
olihan Hertta saanut hyvän kasvatuksen, hän olisi kelvannut vaikka
kuinka hienosukuiselle herralle. Mutta olihan Väisänenkin kelpo
mies, kyllä hän vaimonsa jaksaisi elättää. Ja mitä kauemmin hän
asiata tuumi, sitä edullisemmaksi se hänestä muuttui. Ja vihdoin hän
tuli niin sokaistuksi, että hän mielestään ajatteli vain tyttärensä
onnea päättäessään kehoittaa häntä suostumaan.
VI.

Oli kirkas ja kaunis aamupäivä. Rouva Taube istui reessä muhkeaan


turkkiinsa kääriytyneenä. Hertta Ek oli hänen rinnallaan. Kulkuset
kilisivät ja kepeästi reki kiiti katua pitkin.

He eivät vaihtaneet montakaan sanaa, he nauttivat vain raittiista


ilmasta, joka tulvimalla tulvi heidän keuhkoihinsa.

Reen nopea kulku hiljeni heidän tullessaan pitkälle sillalle. Sillan


molemmin puolin avautui sileä jääkenttä, toisella puolella pojat
luistelivat, toisella jää oli vielä heikkoa ja sillan alla kulki virta
mustana ja kahlehtimatta. Kaupungin vanhalta tullilta he kääntyivät
oikeanpuoliselle viertotielle, jonka sivukäytävällä liikkui taaja
kansanjoukko. Ne olivat tehtaan työntekijöitä kaikki, jotka läksivät
ruokatunnillensa kotiin.

— Miten kalpeat ja laihat nuo ihmisraukat ovat, sanoi Hertta


katsellen heitä myötätuntoisuudella. — Kyllä heissä tuntuvat raskaan
työn jäljet.

— Katsohan tuota naistakin, sanoi rouva Taube, osoittaen nuorta


vaimoa vanhan miehen rinnalla, — kuinka välinpitämättömältä ja
väsähtäneeltä hän näyttää. Ja tuo nuori mies, joka on ennenaikojaan
tullut köyryselkäiseksi. Kyllä ruumiillinen, raskas työ tekee ihmiset
vanhoiksi.

Hertta ei voinut kääntää katsettaan tuosta pitkästä jonosta. Hän


näki joukossa lapsia, jotka näyttivät pysähtyneen kesken
kasvamistaan. Kädet ja jalat olivat suhteettoman suuret ja kasvot
olivat vanhenneet ennenkuin nuoruuden tuoreus oli niihin ehtinyt.

Tosin heiltä ei leipä puuttunut. Olihan heillä kullakin työnsä ja


ansionsa. Mutta puuttuihan heiltä sittenkin kaikki muu. Kaikki se mitä
hän ja niin monet muut hänen kanssansa olivat tottuneet pitämään
elämän välttämättömyytenä. Kaikki se, mikä kevensi väsynyttä
mieltä ja sulostutti elämän.

Tie kääntyi nyt vasemmalle leveältä viertotieltä. Talot kapean ja


epätasaisen tien molemmin puolin olivat matalat ja ränstyneet.
Ikkunoissa ei ollut kaihtimia ja pihoilla vallitsi epäjärjestys ja
siivottomuus. Se oli köyhimmän työväestön asuinpaikka.

Rouva Taube ja Hertta astuivat ulos reestä ja käskivät ajurin


odottaa.
Repaleisia lapsia kokoontui portille ja katsoa tuijottivat tulijoihin.

Rouva Taube puhutteli erästä poikaa ja kysyi työmies Puolakkaa.


Poika ei vastannut mitään.

He astuivat portista sisään. Pihanpuolella oli kaksi ovea, portaat


olivat jäiset ja liukkaat. He kolkuttivat ensimäistä ovea. Kun ei
vastausta kuulunut, avasivat he oven. Takan ääressä seisoi keski-
ikäinen nainen hämmentämässä pataa. Rouva Taube uudisti
kysymyksensä.
Nainen katsahti tulijoihin. Hänen katseensa siveli rouva Tauben
lämmintä, komeaa turkkia ja pysähtyi uutuuttaan kiiltäviin
päällyskenkiin. Vaimo pudisti päätänsä.

— Puolakka? Olisiko se perheellinen mies?

Ja nopeasti hän alkoi kertoa kuka missäkin huoneessa asui.

— Tässä vastapäätä, porstuan toisella puolella asuu vanha


pariskunta. Vaimo on sokea ja mies käy kaupitsemassa harjoja.
Heitäkö rouva hakee? Huonosti he elävät, kyllä olisivat avun
tarpeessa. Heidän vieressään asuu nuori pariskunta; mies on
muurari; viikolla hän putosi alas telineiltä, ehkä rouva on kuullut,
seisoihan se lehdissä. He veivät hänet klinikkaan. Vaimo parka on
viimeisillään, tietäähän sen millainen elämä silloin on. Ja tuolla
toisella puolella — — —

Vaimo puhui lakkaamatta, antamatta itseään häiritä. Hän tunsi


kaikki koko talossa ja monet naapuritalotkin, itse hän oli leski ja piti
nuoria miehiä ruuassa ja kortteerissa. Ajat olivat kalliit ja rahat
tiukalla, mutta elihän sitä sentään päivästä toiseen.

Vaimon katse ei miellyttänyt Herttaa. Se ei ollut suora ja


avonainen.
Ja suun ympärillä oli omituinen piirre; puoleksi hymyä, puoleksi
tuskaa.

— Rouva on hyvä vaan ja menee tuohon toiseen rappuun, kyllä


siellä pitäisi olla mies, joka vast'ikään tuli maalta työn hakuun. Mutta
turha hänen oli tulla, ei täällä työtä kaikille riitä.
He läksivät pois hyvillänsä kun pääsivät erilleen tuosta suulaasta
eukosta. Toisista portaista he löysivätkin miehen, joka oli juuri
ulosmenossa, mutta tavatessaan naiset, hän pyysi heitä astumaan
sisään.

Huone oli melkein tyhjä. Ikkunan luona pieni pöytä ja sen edessä
horjuva tuoli. Nurkassa vuode, jossa joku lepäsi rääsyjen alla.

— Tulin puhumaan teidän kanssanne, rouva Taube pysähtyi


keskelle lattiaa. — Te voitte saada halonhakkuuta meillä toistaiseksi,
kunnes saatte sopivampaa työtä. Koetan hankkia teille
halonhakkuuta muualtakin. Ja tässä olisi teille takki, ettehän te
noissa ryysyissä voi olla. Mutta oletteko te raitis mies? Rouva
Tauben katse kiintyi viinapulloon, joka seisoi ikkunalla.

— En minä, hyvä rouva, juo, mistä sitä viinaan rahaa saisi, kun ei
ole leipäänkään. Jos minä edes olisin yksin kärsimässä, mutta vaimo
ja lapset, joilla ei ole mitään. Se on isännän, tuo pullo tuossa.

— Ei sekään juo, kuului naisen valittava ääni vuoteesta. — Mutta


kun minä en kykene ruokaa keittämään, niin pitäähän hänen saada
jotakin lämmittävää kuivan kannikan lisäksi.

— Mikä teitä vaivaa? Rouva Taube astui lähemmäksi.

— Siitä saakka kun sain tämän pienen, vaimo näytti likaista


kääröä vieressänsä, — olen ollut kovin heikko. En kykene
mihinkään. Ja lapsikin on kipeä, se huutaa yöt päivät.

Rouva Taube katseli pientä kääröä. Se oli parin kuukauden vanha


poikalapsi, mutta niin laiha ja heikko, että olisi voinut luulla sitä parin
viikon vanhaksi. Pää ja kasvot olivat ruvessa, ilkeän ihotaudin
vallassa.

— Teidän pitäisi saada lapsenne sairashuoneesen, sanoi rouva


Taube.

— Kukapa sen sinne toimittaa. Kuka köyhän lasta säälii? Ei


kukaan muu kuin Jumala. Hän sen aikanaan korjaa.

— Koetan tehdä minkä voin, sanoi rouva Taube.

— Ja te, Puolakka, te tulette huomenna työhön. Tuumimme sitten


jotain lastennekin puolesta.

Rouva Taube ja Hertta läksivät pois. Ummehtunut ilma huoneessa


kävi aivan sietämättömäksi. He ajoivat samaa tietä takaisin, kuin
olivat tulleetkin.

— Eikö tohtori Hammar voisi toimittaa tuota lapsiraukkaa


sairaalaan, sanoi Hertta. — Hän on parasta aikaa lasten-osastolla.

— Aioin juuri neuvotella hänen kanssansa. Jotain apua on heille


hankittava.

Heidän tullessaan keskikaupungille, oli kaupungin hienosto juuri


kävelyllään. Naiset käyskentelivät katukäytävällä turkkireunuksisissa
sirkkeleissään. Hattuhöyhenet huojuivat tuulenhengessä ja suut
hymyilivät. Kenoselkäiset upseerit kilisyttivät kannuksiansa, ja
nuorten virkamiesten kepit heiluivat huolettomasti ilmassa. Olihan
vihdoinkin kirkas talvipäivä, puut helmeilivät härmässä ja
turkinkaulukset suojelivat arkoja korvalehtiä pakkaselta.
VII.

— Saammeko tänään päivällistä, Eva? kysyi kenraali Löfberg


astuessaan ruokasaliin ja katsoessaan kelloa.

Rouva Löfberg näytti tuskaantuneelta. Hänellä oli juuri ollut


ompeluseura koolla ja hän kääri kokoon töitä, jotka olivat levällään
pöydällä.

— Aivan heti, sanoi hän kärsimättömästi. — Mutta voinko minä


sille mitään, jos päivällinen viivähtääkin. Itsehän sinä olet pannut
nämät hommat niskoilleni.

— Enhän minä sinua moiti, Eva. Kenraali hyväili rouvaansa. —


Neiti Ek tulee vain heti paikalla ja minulla on työtä hänen kanssansa.

— Nuo iankaikkiset hätäaputoimet! Ne ovat mullistaneet koko


kotimme, ei täällä enää muusta puhuta, eikä muuta ajatella. Joka
askeleeni kolahtaa hätäaputoimiin. Minä olen niin väsynyt ja
kyllästynyt.

— Mutta etkö myönnä, että olemme saaneet paljon aikaan?


Ensiksikin vilja- ja vaatelähetykset moneen eri kuntaan. Ja sitten
työkoulut, turvakodit ja keittiöt. Ja yhä useampia aiomme perustaa.
Olen varma siitä, etteivät nuo toimenpiteet ole turhat. Tänäänkin sain
kirjeen Vaaralammelta. He kiittävät siitä avusta, jonka kunta on
saanut ja varsinkin sisar Cecilian työ on ollut siellä siunausta
tuottava. Ja mitä sanot neiti Fährlingistä, joka omilla varoillaan on
perustanut turvakodin 20 lapselle? Keskuskomitea on pyytänyt häntä
laajentamaan kotia niin suureksi, että siinä olisi tilaa 40 lapselle.
Uudet turvatit tietysti keskuskomitea kustantaa.

— Neiti Fährling on aina ollut hiukan omituinen.

— Onko se omituista, jos hän tekee suurempia uhrauksia, kuin


mihin meidän sivistyneet naiset tavallisesti ovat tottuneet?

— En todellakaan ymmärrä mitä sinä meiltä vielä vaatisit.


Viikkokausiin emme ole tehneet muuta kuin juosseet talosta taloon
rahoja keräämässä ja ommelleet vaatteita kerjäläiskakaroille. Olisi
meillä parempaakin tekemistä ollut.

— Tosiaankin, mitä tekemistä teillä on! Käytte huveissa ja


tanssiaisissa ja vaivaatte päätänne viimeisillä muodeilla! Rahoja te
osaatte tuhlata, mutta mitään hyödyllistä te ette tee. Mutta minä
sanon, siitä on loppu tehtävä. Sinulla ei ole oikeutta käydä silkissä ja
sametissa, kun kansalta puuttuu leipäkin. Sinun täytyy oppia
säästämään ja ajattelemaan muitakin kuin vaan omaa itseäsi.

Kenraali oli kiihkoissaan. Rouva Löfberg ei ollut tottunut näkemään


miestään sellaisessa mielentilassa ja hän seisoi siinä aivan
hämmästyneenä, tietämättä mitä sanoa. Hänen tavalliset aseensa,
pilkallinen hymy ja ivalliset sanat, olivat kadottaneet voimansa. Hän
tunsi jotain nyyhkytyksen tapaista kurkussansa, hän, tuo kopea
rouva, joka oli melkein kyyneleet unohtanut, turvautui nenäliinaansa
ja painoi sen kosteita silmiään vasten.
Kenraali astui hänen luoksensa huomatessaan hänen
liikutuksensa.

— Eva, suo anteeksi kiivauteni. Äänen sävy oli lempeä.

Rouva Löfberg tunsi jälleen seisovansa lujalla pohjalla.

— Mitäpä sinä välittäisit meidän tarpeistamme, kun vain saat


rakkaille talonpojillesi hyvät päivät.

Hänen säännöllisistä nuorekkaista kasvoistaan oli pieninkin


liikutuksen jälki kadonnut.

Kenraali Löfberg kohotti olkapäitään ja hänen kasvonsa


synkistyivät uudelleen.

— Siinä sitä taas ollaan. Sinä et ole koskaan voinut ymmärtää


minua ja minun harrastuksiani. Etkä sinä ole koskaan tahtonutkaan
minua ymmärtää.

Kenraali Löfberg läksi huoneesta ja sulki oven jäljessään. — —

Hertta istui kenraali Löfbergin työhuoneessa työnsä ääressä. Hän


kirjoitti muistiin mille paikkakunnalle edellisellä viikolla oli viljaa
lähetetty. Kuntia oli toistakymmentä ja hehtomäärä nousi varsin
korkealle.

Antti Hammar oli astunut sisään ja kumartui Hertan olkapään yli


silmäillen kirjaan.

— Mikä siunattu asia että rautatierahti on maksuton, hän sanoi. —


Kuinka suuret summat muuten kuljetukseen menisi.

— Maksaa se sittenkin, kun ei rautateitse pääse perille saakka.


Antti tunsi Hertan hengityksen sivelevän poskeansa. Hän käänsi
katseensa Herttaan, mutta tämä ei sitä huomannut. Hän katsoi vain
suoraan alas työhönsä.

Antti kävi istumaan pöydän ääreen.

— Minulla on teille hyviä uutisia, neiti Ek. Pieni turvattinne on nyt


lastensairaalassa.

Hertta katsoi ylös työstään.

— Entäs äiti?

— Kyllä hän pian parantuu, ei hänellä mitään varsinaista vikaa ole.


Mutta mies kuuluu juopottelevan.

Hertta ojensi Antille paperin.

— Tuossa on kirje neiti Fährlingiltä.

— Onko hän käynyt Soimäellä perustamassa turvakotia?

— Ei, ei vielä. Jos saamme täältä sopivan johtajan, niin hänen ei


tarvitsekkaan lähteä.

Soimäeltä oli tullut pyyntö toimikunnalle turvakodin ja


kansankeittiön perustamisesta ja toimikunta oli päättänyt täyttää
heidän toivomuksensa. Sopivaa henkilöä ei kuitenkaan vielä ollut
ilmaantunut sinne lähtemään.

— Tiedättekö mitä, sanoi Antti äkkiä, — nyt minä tiedän kuka


sinne lähtee. Te sinne lähdette.

You might also like