Professional Documents
Culture Documents
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
v
vi 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
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
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
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
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.
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.
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.
— 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.
Elsa naurahti.
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. — — —
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ä.
— En tanssinut yhtään.
— 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.
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.
Huone oli melkein tyhjä. Ikkunan luona pieni pöytä ja sen edessä
horjuva tuoli. Nurkassa vuode, jossa joku lepäsi rääsyjen alla.
— 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.
— Entäs äiti?