|Bare Metal C|
Author: Steve Oualline
C is a wonderful language if you really want to find out how computers work and the idea of using a small single board computer as a teaching aid is a good one. In this case "bare metal" means getting up close and personal with a .NUCLEO-G070RB. I'm not really very sure why this board is used - it isn't cheap, it isn't popular is and it isn't well supported compared to an Arduino or a Raspberry Pi. The software that you have to use is also specific to the device and is an Eclipse-based wrapper for GCC. If you are using Windows you are also going to also need to install MinGW as GCC is essentially a Linux program. Having to install something like MinGW is necessary for most C development under Windows, but other systems supply installers that do the job automatically. Put simply, the hardware and the software used in this book don't have a huge user base and as such the specific knowledge you gain might not be as useful as it could be.
There is also the issue of what "bare metal" means. Some might be expecting to interact directly with the hardware without system software. In fact, what this book describes is the use of a software library to access the GPIO lines etc. I don't think that this is unreasonable but you might not agree. If you really are looking for a book on bare metal programming in the strictest sense this isn't it.
If you are happy with the choice of hardware and development software then this book might well teach you useful things about C and computing. Part I is called "Embedded Programming". It starts off using C to create a simple Hello World program and then it's hardware equivalent, i.e. Blinky which flashes an LED. On the way there's details of how a compiler and linker do their job of taking your source code to loadable machine code. At first the command line is used along with make and then we transition to the IDE and ignore the low-level stuff.
After this brief meeting with the specific hardware the subject turns to more general programming issues. First we deal with data types and, as it's C, this inevitably leads on to binary, hex and two's complement. Then, as it's about hardware as well, we have a long section on logical operations and setting and resetting bits. It doesn't go far enough with bit manipulation for most applications of C on bare metal. It also hints at the big problem of undefined behavior, but doesn't actually explain it.
Finally we reach the flow of control - if, while, for, break and continue. The example of using if is to test the state of a button. There's not much on C's complex for loop, which is probably a good thing, and nothing at all on the switch statement, which is perhaps a shortcoming.
Next we look at arrays and strings. This is very standard but lacks enough attention to the problems of null-terminated strings. The chapter is mostly about the way arrays are pointers to an area of memory and the next chapter expands on some of these ideas with a look at local variables and the stack. From here we move on consider the struct, including unions and typedef. What is missing is a consideration of casting and its role in low-level programming as a way of transforming data from one thing to another.
This part of the book ends with some general considerations - serial output, interrupts and using the linker and preprocessor.
The second part of the book is on "C for Big Machines" and it focuses on aspects of C that are generally encountered. It makes you wonder why we have focused on the single board computer in the previous section. The first topic is dynamic memory - malloc and all that. The example is a linked list and we have a section on Valgrind to check your program. I'd have preferred some more basic examples on allocating arrays and structs on the heap.
Next we focus on file I/O and this, of course, brings us to operating system dependent features. Some single board devices don't have an operating system and don't support file based I/O. The final two chapters are on floating point arithmetic, and again some single board computers don't support floating point and modular programming. The whole of the second half of the book really isn't about bare metal C, no matter how you define it.
This book covers a lot of ground in a very short space. Often important topics are thrown in as a single sentence or suggestion rather than discussed as a principle. For example, undefined behavior is touched on as:
don't write things like answer=++i - i++.
There is so much more to say.
There are also big omissions such as virtually nothing on the problems of string handling. I'm also not sure why we have to go to the trouble of setting up the NUCLEO-G070RB and its custom software when the second half of the book doesn't make use of it. If you want to learn C at this deeper level you don't really need a special piece of hardware and if you do there are easier ways of doing the job.
At the end of the day the value of the book depends very much on whether you are going to see the NUCLEO-G070RB as a development board as an investment in the future - i.e. are you planning to use it for some other project. If not then this book isn't going to be an attractive option.
|Last Updated ( Wednesday, 09 August 2023 )|