For novel ideas about building embedded systems (both hardware and firmware), join the 28,000+ engineers who subscribe to The Embedded Muse, a free biweekly newsletter. The Muse has no hype and no vendor PR. Click here to subscribe.
ARM Assembly Language!, William Hohl and Christopher Hinds
click picture to order from Amazon.com
ARM Assembly Language (Fundamentals and Techniques), by William Hohl and Christopher Hinds, is a 400 page textbook on exactly what you'd expect. While virtually everyone in the embedded world is using C/C++ on ARM processors, a little assembly always seems to creep in. And, we really need to understand a processor's architecture to effectively manage interrupts and the like.
As mentioned, this is a textbook, and as such every chapter ends with sample problems.
The focus is on the ARM7TDMI and Cortex M4 architectures. This covers a very broad space as the M4 runs a superset of the instructions available on lower-end M-series devices. Thumb and Thumb 2 instructions get as much attention as does the ARM ISA. (For a book with more detail about the M0 and M0+ devices, see my review here ).
The book is practical, as it describes the use of the Code Composer and Keil tools. I wish it gave at least some attention to GCC as a lot of developers use those tools.
There's not a lot one can say about a book on assembly language. There is some bonus content. Three chapters delve deeply into floating point (only one of these covers ARM's floating-point instructions). This is important stuff, as the IEEE-795 format has all sorts of quirks that the authors explore at length.
The two chapters (one per ISA) on exception handling are very complete and do cover some of the hardware issues like the fast-interrupt (FIQ).
One chapter covers several actual processors and writing code to drive their peripherals. That's probably not useful for us pros, since it's unlikely we'd use the same MCUs, but is appropriate for a university setting where students probably have had little exposure to real hardware.
I was surprised, and disappointed, that there's no instruction set summary. Instead, instructions are introduced as needed, rather like one would expect in a college course. But a reference is important, because memories are fallible and combing through 400 pages of text to tease out which instruction you've forgotten is just not efficient. Not all instructions are covered; there's nothing on the SIMD variants.
This is a great book for students, and is good for someone just starting out with the ARM parts. But it's no reference, and needs to be supplemented with an ISA summary. It drives me crazy that books are so expensive, and at $86 this is no exception, but the authors have no control over these publishing decisions.
C For Everyone, Richard Man and CJ Willrich
C for Everyone, by Richard Man and CJ Willrich, is a new 400 page book covering the C language, with an emphasis on using it in embedded systems. I imagine a lot of embedded.com readers know Mr. Man, as he’s the principal behind compiler-vendor Imagecraft. The idea of a C book by a compiler writer appeals.
The book is well-written and almost chatty at times with a nice history of the language.
Section 1 is a short, high-level introduction to the C programming language, which is accessible to anyone wanting to learn about C. No real programming experience is required.
Section II is the real meat of the book. It provides a thorough description of C with pretty much all you need to know to build a system. There’s nothing about Windows APIs or the like; this is a book for an embedded wannabe.
It does a great job explaining types, and even has practical recommendations for deciding when to use a particular type. But, though the information is exactly correct, I disagree with the conclusion. MISRA and other standards mandate avoiding base types for all of the reasons we know, and I think the book would be better for providing that advice.
To be fair, there are lots of “Best Practices” suggestions, all of which are spot-on, and desired for C newbies. Indeed, the authors also offer valuable “Bug Trap” sidebars about oddities of the language many don’t know. For instance:
unsigned char uc =0xFE;
if(~uc == 0x1)…
… is bound to fail, for reasons they describe well.
Edsger Dijkstra would be horrified, but the authors describe when it makes sense to use the goto statement. They do warn that undisciplined use of the statement leads to spaghetti code. And I agree with them. While goto should be avoided, in certain (unusual) cases its use makes the code more comprehensible.
There’s practical advice, too. Two pages cover the rules for reading a complex declaration using the right-left-right rules. And there are some subjects you normally don’t see in a C book like variadic functions, recursion, and interrupt handling.
Newbies always get fouled up with pointers, but C for Everyone has a great chapter on the subject. I also recommend Understanding and Using C Pointers by Richard Reese
Oddly, with the exception of a few references, the book doesn’t cover Imagecraft’s fascinating library for Cortex-M parts. Their Jumpstart API is probably the second-fastest way to get started programming these parts. The fastest is mbed.org, which has a web-hosted tool chain so there’s no painful IDE installation required. But what makes mbed most interesting is that they have eliminated all of the peripheral programming we embedded people deal with. The Cortex-M parts have some quite complex I/O, and even the simple stuff often requires a lot of head scratching to set up. Mbed provides an API to tremendously simplify this. For instance, to configure a pin to be an input to an ADC and then read the analog, all you write is:
AnalogIn adc(p19); // Pin 19 is now an A/D inputThe problem with mbed is that it doesn’t really scale for professional work. Sans IDE there’s no debugger so one is left using printf statements. And one must have faith that mbed will be around tomorrow; if their site disappears, so does your project.
scale = adc.read(); // Read the A/D
Imagecraft sells a quite inexpensive ($99 for non-commercial work, $249 otherwise) traditional C environment with an API for Cortex-M parts that’s as easy to use as mbed’s. They support some ST parts today and plan to add many more. The book C for Everyone is part of the Jumpstart Microbox, a $99 kit including tools, the book (eBook), and an ST board with a debug link (this is for non-commercial work). Or, you can buy the eBook alone for $24.95. A printed version will be available through Amazon soon.
I do wish the book’s index were more complete (though the eBook version doesn’t really need one as it’s searchable; I was provided with an early printed book). And it’s not a beautiful work; the typography is rather pedestrian and there are few illustrations. But all-in-all this is an excellent work that will now be one of the standard suggestions I’ll give when people ask me that “how do I become an embedded programmer” question.
And they ask it a lot – 2021 times last month, which is about average.
Design Recipes for FPGAs, Peter Wilson
Peter Wilson's brand new book Design Recipes for FPGAs is an interesting addition to the writing about FPGAs. At 369 pages it might seem to be the One Real Reference, but in fact it's more a surf through design examples.
The examples are given in both VHDL and Verilog, the two most common Hardware Description Languages (HDLs) used in this industry. The book starts with a chapter about the basics of each; VHDL is treated in 16 pages; Verilog in 6. Those amount to about the fastest getting-started guides for any language I've seen. And the material is pretty good. It's far from complete, of course, but will give the novice a grounding in the basics.
But one warning: HDLs look a lot like a programming language. The last thing you want to think of when working with an HDL is programming. In C and other computer languages statements execute one after another. There's a flow. That's mostly absent with an HDL. It's hardware; everything is happening at the same time (with exceptions). In fact, in general (again, there are exceptions) it doesn't matter what order you write the HDL "instructions" in. At the latest ESC Charles Fulks gave some talks about FPGA work; we had a beer the night before and he said he prefers VHDL over Verilog because it looks less C-like than the latter, making it less likely the unwary will fall into the sequential-execution trap. Design Recipes for FPGAs doesn't talk about this, probably since it's aimed at people building hardware. Be warned; HDLs are very different from programming languages.
FPGA design has a number of steps -- the testbench, compilation, synthesis, routing, etc. and Mr. Wilson does take the reader through the design flow. But this is at a very high level. You'll need additional information to actually create a working FPGA. I recommend both Xilinix's and Altera's web sites as references. Xilinix's Vivado has a free version with limited, but enough for learning, functionality.
I thought the book would be a dreary litany of design examples that aren't useful or even interesting. But the second design presented is a complete CPU in both HDLs! The instruction set is tiny, but then so is the required HDL. It's pretty cool and partitioned nicely so as to be extremely understandable.
Later chapters give code for the DES encryption algorithm, filters, VGA controllers, etc. What's good about these is the clear HDL code that's well-described. Less than wonderful is that you'll get nothing from, say, the filter chapter unless you understand Z transforms. Mr. Wilson does give good references to use in boning up on that material.
There's an excellent chapter on mixed-signal (analog and digital together) with the AMS extensions, as well as good pointers on optimizing designs to use less FPGA fabric.
This is a great book for someone wanting to learn HDL design as the examples are crystal-clear, and it can be hard to find real-world HDL examples on the 'net. The chapter on a CPU design alone will teach one a lot about coding for FPGAs. You will want some additional material. I recommend The VHDL Language Guide (free here) and Verilog HDL (not free from here).
Definitive Guide to ARM Cortex-M0 and Cortex-M0+ Processors , Josepg Yiu
ARM has over 200 licensees for their Cortex-M parts, and there are thousands of variants on the market. While they introduced the M7 last year, which offers incredible performance for an MCU, the bottom end of the line has elicited an enormous amount of interest. The M0 core only needs about 12,000 gates so costs pretty much nothing. The M0+ has the same instruction set but better low-power performance for those battery-operated devices, plus more (optional) debug capabilities, and even an optional memory protection unit (a poor person's MMU).
Joseph Yiu has a new book about these two processors. The Definitive Guide to ARM Cortex-M0 and Cortex-M0+ Processors complements his earlier tome about the M3. At 746 pages I have to agree that it is indeed complete and is the "definitive" work about these parts. He works for ARM, and parts of the first two chapters do read like an ad for the company, though there's plenty of valuable information in them.
The book is very current, so current there's a great description of the EEMBC's work on ultra-low power benchmarks. For those of you working with battery-powered systems it's worthwhile to see what EEMBC is up to. A chapter covers low-power features, but you'll have to dig deeply into the data sheet of the part you're using, as the licensees add in a sometimes mind-boggling number of proprietary features to minimize the coulombs consumed.
The book's audience is, well, it's hard to say. I'd argue at practicing engineers as the details are all there. But there is an entire chapter devoted to explaining the fundamentals of embedded software development that readers of this site can skip. That section does have an introduction to the CMSIS library, an important resource for Cortex-M users, but we all know about reset, data types, and other fundamentals of this business.
As in his earlier book, Mr. Yiu does a good job explaining the MCUs' architecture and ISA. If you're using, or considering, these parts, this information is absolutely critical to have. ARM parts are complex, with multiple busses, pipelines of varying lengths, sometimes variable endianness, and other features that can be confusing.
The best parts are the four chapters about getting started with writing code. One each covers the Keil, IAR, GCC and mbed toolchains. Pick your tools, go to the appropriate chapter, and Mr. Yiu will guide you quickly through setting up an environment and writing your first Cortex-M0/M0+ code. He also targets some specific boards, such as Freescale's FRDM and ST's STM32 products. The chapter you use will pay for the book.
One section details porting code from various CPUs (e.g., the 8051) to the M0/M0+. That is sure to tick off vendors selling other sorts of parts! But mostly he details moving code from other, more capable, ARM devices to these entry-level devices, a process that has some landmines. The guidance given is Good Stuff.
The writing style is clear and the typography easy on the eyes. One quibble, which is perhaps more a complaint about the state of the publishing industry today: there was clearly no copy editor involved. Once upon a time these people, who were masters of the English language, would find obvious language errors and correct them. The Definitive Guide to ARM Cortex-M0 and Cortex-M0+ Processors has a lot of grammatical errors. An example: "Easy to learning programming of new devices." These are distracting but don't detract from the technical content.
It's $62 from Amazon, or $34 for a Kindle edition. 62 bucks for a book is ridiculous the state of things today. But if you're new to these components, swallow your outrage and buy the book. It will give you the insight embedded you need to be productive on real projects.
Embedded Systems Fundamentals with ARM Cortex-M based Microcontrollers, Alex Dean
In June I had business in Rayleigh, NC. Having just received a copy of Embedded Systems Fundamentals with ARM Cortex-M based Microcontrollers, and noting that the author teaches at NCSU, I decided to drop in and say hello. Alex Dean is a cool guy doing some fun things with his students. Back in the Paleozoic Era, when I was an EE student, we weren't even allowed to solder for fear someone might burn themselves (how else does one learn which end of a soldering iron to pick up?). Alex's students do a lot of hands-on embedded work.
Alex's book is a gem. It's in full color; nearly every page has color, including colored code as you'd see in an IDE. It advertises itself as a textbook, but this is not like any dreary old equation-laden textbook I know. It's an intro to the world of embedded systems, both hardware and software. Based around NXP's (née Freescale) FRDM-KL25Z development board ($15 from Digi-Key), this Cortex-M0+ board is a great starter kit. He uses the Keil uVision toolchain, which is free for programs that don't exceed 32 KB. One of the reasons I like this board is that the mbed group supports it, which means one can skip the whole IDE thing. But in the real world we use IDEs, so Alex made the right choice in using uVision.
The book starts with using switches to control LEDs, an old topic. But it shows how one calculates the LED resistor, explains what legal logic levels are and mean, and then covers the hassle of setting up the M0+'s GPIO registers.
I'm not too keen on his use of the word "task" in Chapter 3, as he defines that to be "a subroutine that performs a specific activity". To me, "task" has a very specific meaning in terms of multitasking, but this is a minor nit. He does refine tasking by taking these subroutines and then tying them together, first by a simple polling loop, then cooperative multitasking, and then using interrupts to invoke them. Finite state machines are well-covered; a nod to RTOSes completes this chapter.
The M0+'s architecture is well-described, with special emphasis on the interrupt system. Assembly language gets its due, and the book shows the sort of assembly generated by typical C statements. Some argue that assembly is so-five-minutes-ago. I disagree, and think that an understanding of what is going on at the low level is important in much embedded work.
Analog interfacing (including hardware details), PWM, WDTs and even DMA are covered. Several types of serial comm get detailed treatment.
One thing that makes this a strong work is that the practical details engineers deal with are treated in a way that is analogous to how we work. For instance, the I2C section shows packet formats and the open drain configuration used. The code needed to make I2C work is given and described. There are no proofs left to the student.
Seasoned developers know all this stuff, as the book is targeted to engineering students. However, if you're not familiar with the Cortex-M architecture, this is a good intro. Anyone wanting to learn about embedded development will be well-served by the book.
Real-Time Embedded Systems, Xiaocong Fan
Xiaocong Fan's new book, Real-Time Embedded Systems, is a weighty tome at 662 pages.
It's a textbook, not an O'Reilly or Microsoft Press-style quick read. Each chapter ends with problems. The introduction clearly lays out how it should be used in a classroom. Academia is often out of sync with the needs of practicing engineers, so I was surprised, and pleased, to find that this book uses C, not one of the languages-de-jour that no one really uses.
One of the early chapters is about cross-platform development, the environment we embedded people spend our lives in. It does an excellent job of covering the details no one talks about, like ELF/COFF files and link sections (e.g., .bss). Since this is a textbook, I sure hope instructors using it offer open-book exams. The level of detail about the file formats and the number of linker sections is far greater than any of us should memorize.
The "Microprocessor Primer" chapter gives pretty detailed information about four chips: the PIC18F8720, 8086, Pentium and ARM926, including timing diagrams that show how these devices access the bus. Good stuff, especially the choice of the PIC part. However, why the 8086 and Pentium in a book about embedded systems? I'm not sure if you can even buy an 8086 anymore; Digi-Key doesn't list the part. The ARM is a decent choice, but I would have added a Cortex-M device.
A chapter on interrupts delves deeply and quickly into the important nuances of the subject. Chaining and cascading are covered, as are the critical issues in sharing data with interrupt handlers.
170 pages are devoted to UML. Pretty much all of the books I have on UML are big, fat and boring. Mr. Fan can't bring any excitement to this dry subject, but this is a reasonably tight and thorough description of the subject.
Architectural design is covered well. One chapter deals with non-RTOS design; for example, using an interrupt-driven queue to sequence activities. The next 11 chapters deal with just about every aspect of using an RTOS. Some of the material has been well-covered in other books (like priority inversion). But there's much that's really interesting. We all think about avoiding deadlocks, for example. What about detecting them? Mr. Fan gives the theory and an algorithm for just that.
The book's take on task schedulability is more complete than any other reference I know. It's thick stuff; the math isn't hard, but the author prefers equations to prose at times. Developers of safety-critical systems may well benefit from this, and from the discussions about scheduling aperiodic and sporadic tasks.
POSIX in general and QNX in particular get a lot of attention. A chapter about QNX resource management will be useless to anyone not using that RTOS. But the vast majority of the material is OS agnostic.
Guess what's not in the book: any description about number systems and related subjects that, it seems, every computer book must exhaustively natter on about. Sometimes I think I could free up a few meters of shelf space by ripping out those chapters from all of the computer books stacked up here.
This book is not a beach read. It's heavy going at times. There's a lot of formal mathematical notation. But the subjects are covered well and there are plenty of very pertinent illustrations -- state charts, flow charts and more -- that clarify complex ideas. I recommend it for those willing to struggle a bit with the book; you'll get some really worthwhile ideas.
On to more book reviews.