Book Image

ARM?? Cortex?? M4 Cookbook

By : Dr. Mark Fisher
Book Image

ARM?? Cortex?? M4 Cookbook

By: Dr. Mark Fisher

Overview of this book

Embedded microcontrollers are at the core of many everyday electronic devices. Electronic automotive systems rely on these devices for engine management, anti-lock brakes, in car entertainment, automatic transmission, active suspension, satellite navigation, etc. The so-called internet of things drives the market for such technology, so much so that embedded cores now represent 90% of all processor’s sold. The ARM Cortex-M4 is one of the most powerful microcontrollers on the market and includes a floating point unit (FPU) which enables it to address applications. The ARM Cortex-M4 Microcontroller Cookbook provides a practical introduction to programming an embedded microcontroller architecture. This book attempts to address this through a series of recipes that develop embedded applications targeting the ARM-Cortex M4 device family. The recipes in this book have all been tested using the Keil MCBSTM32F400 board. This board includes a small graphic LCD touchscreen (320x240 pixels) that can be used to create a variety of 2D gaming applications. These motivate a younger audience and are used throughout the book to illustrate particular hardware peripherals and software concepts. C language is used predominantly throughout but one chapter is devoted to recipes involving assembly language. Programs are mostly written using ARM’s free microcontroller development kit (MDK) but for those looking for open source development environments the book also shows how to configure the ARM-GNU toolchain. Some of the recipes described in the book are the basis for laboratories and assignments undertaken by undergraduates.
Table of Contents (16 chapters)
ARM Cortex M4 Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

This book begins with an introduction to the ARM Cortex family and covers its basic concepts. We cover the installation of the ARM uVision Integrated Development Environment and topics, such as target devices, evaluation boards, code configuration, and GPIO. You will learn about the core programming topics that deal with structures, functions, pointers, and debugging in this book. You will also learn about various advanced aspects, such as data conversion, multimedia support, real-time signal processing, and real-time embedded systems. You will also get accustomed with creating game applications, programming I/O, and configuring GPIO and UART ports. By the end of this book, you will be able to successfully create robust and scalable ARM Cortex-based applications.

What this book covers

Chapter 1, A Practical Introduction to ARM® Cortex®, shows you how to compile, download, and run simple programs on an evaluation board.

Chapter 2, C Language Programming, introduces you to writing programs in C, a high-level language that was developed in the 1970s and is popular among embedded-system developers.

Chapter 3, Programming I/O, investigates some of the functions that configure I/O devices, and you will gain an understanding of what is involved in writing I/O interfaces for other targets.

Chapter 4, Assembly Language Programming, explains how to write functions in assembly language. Assembly language is a low-level programming language that is specific to particular computer architecture. Therefore, unlike programs written high-level languages, programs written in assembly language cannot be easily ported to other hardware architectures.

Chapter 5, Data Conversion, introduces approaches to data conversion, namely analog to digital conversion and vice versa. This chapter also covers the principal features used by microcontrollers for data conversion.

Chapter 6, Multimedia Support, discusses support for various multimedia peripherals, which are discrete components connected to the microcontroller by a bus. Support for an LCD touchscreen, audio codec, and camera peripherals is a very attractive feature of the STM32F4xxx microcontroller, and selecting an evaluation board that includes these peripherals, although more expensive, will be covered in this chapter.

Chapter 7, Real-Time Signal Processing, introduces you to Digital Signal Processing (DSP) and reviews the ARM Cortex M4 instruction set support for DSP applications. This chapter will walk through a DMA application using the codec, followed by designing a low-pass filter.

Chapter 8, Real-Time Embedded Systems, shows you how to write a multithreaded program using flags for communication and ensuring mutual exclusion when accessing shared resources.

Chapter 9, Embedded Toolchain, teaches you how to install the GNU ARM Eclipse toolchain for the Windows Operating System and to build and run a simple Blinky program on the MCBSTM32F400 evaluation board. This chapter will also show you how to use the STM32CubeMX Framework (API) and how to port projects to GNU ARM Eclipse.

What you need for this book

You require the Keil Development Board MCBSTM32F400 (v1.1) and ARM ULINK-ME for this book.

Who this book is for

This book is aimed at those with an interest in designing and programming embedded systems. These could include electrical engineers or computer programmers who want to get started with microcontroller applications using the ARM Cortex M4 architecture in a short time frame. This book's recipes can also be used to support students learning embedded programming for the first time. Basic knowledge of programming using a high-level language is essential but those familiar with other high-level languages such as Python or Java should not have too much difficulty picking up the basics of embedded C programming.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it…, How it works…, There's more…, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Copy the function named SystemClock_Config() from the example."

A block of code is set as follows:

#ifdef __RTX
extern uint32_t os_time;

uint32_t HAL_GetTick(void) {
  return os_time; 
}
#endif

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Run the program by pressing RESET on the evaluation board."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/ARMCortexM4Cookbook_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.