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

Running an example program


Manufacturers usually make a small number of example programs available that provide a tutorial introduction and demonstrate the potential of their evaluation boards. A simple program that flashes (that is, blinks) a Light-emitting diode (LED) on the board is usually provided. ANSI C is by far the most popular language amongst embedded system programmers, but other high level languages such as C++ and C# may also be supported. A brief introduction to the C programming language is provided in Chapter 2, C Language Programming.

The Examples tab in the pack installer for the STM32F4 series MCUs provides a link to a C program called CMSIS-RTOS Blinky (MCBSTM32F400) that flashes an LED connected to a GPIO port. The program is integrated within an MDK-ARM Project. Integrated development environments such as MDK-ARM usually manage software development tasks as projects, as in addition to the program source code itself, there are other target-specific details that are needed when the code is compiled. A project provides a good container for such things. We review the steps required to create a project from scratch in the next section.

How to do it…

  1. Invoke uVision5. Open the Pack Installer, and copy the example program to a new folder (name the folder CMSIS-RTOS_Blinky).

  2. Connect the evaluation board as described in the previous section. In addition to the ULINK cable, remember to connect a USB cable to supply power to your evaluation board.

  3. Invoke uVision5 from the taskbar, select ProjectOpen Project; navigate to the folder named CMSIS-RTOS_Blinky, and open the file named blinky.uvprojx.

  4. Build the project by selecting ProjectRebuild all target files, and then download the executable code to the board using FlashDownload. Take a moment to locate the Build, Rebuild, and Download shortcut icons on the toolbar as these save time.

  5. Finally, press the RESET button on the evaluation board, and confirm that Blinky is running. You may notice that the Blinky example program does a little more than just flash one LED.

  6. Once you have confirmed that your evaluation board is working, close the project (ProjectClose Project), and quit uVision5.

How it works…

The program uses some advanced concepts such as CMSIS-RTOS (discussed in Chapter 8, Real-Time Embedded Systems.) to produce a visually interesting flashing LED pattern. We will not attempt to explain the code here, but the next section will develop a much simpler Blinky project called hello_blinky.uvprojx.