Bare Metal C: Embedded Programming for the Real World
- Length: 304 pages
- Edition: 1
- Language: English
- Publisher: No Starch Press
- Publication Date: 2022-07-19
- ISBN-10: 1718501625
- ISBN-13: 9781718501621
- Sales Rank: #683593 (See Top 100 Books)
Bare Metal C teaches you to program embedded systems with the C programming language. You’ll learn how embedded programs interact with bare hardware directly, go behind the scenes with the compiler and linker, and learn C features that are important for programming regular computers.
Bare Metal C will teach you how to program embedded devices with the C programming language. For embedded system programmers who want precise and complete control over the system they are using, this book pulls back the curtain on what the compiler is doing for you so that you can see all the details of what’s happening with your program.
The first part of the book teaches C basics with the aid of a low-cost, widely available bare metal system (the Nucleo Arm evaluation system), which gives you all the tools needed to perform basic embedded programming. As you progress through the book you’ll learn how to integrate serial input/output (I/O) and interrupts into your programs. You’ll also learn what the C compiler and linker do behind the scenes, so that you’ll be better able to write more efficient programs that maximize limited memory. Finally, you’ll learn how to use more complex, memory hungry C features like dynamic memory, file I/O, and floating-point numbers.
Topic coverage includes:
- The basic program creation process
- Simple GPIO programming (blink an LED)
- Writing serial device drivers
- The C linker and preprocessor
- Decision and control statements
- Numbers, arrays, pointers, strings, and complex data types
- Local variables and procedures
- Dynamic memory
- File and raw I/O
- Floating-point numbers
- Modular programming
Title Page Copyright About the Author Introduction Part I: Embedded Programming Chapter 1: Hello World Installing GCC Downloading System Workbench for STM32 Our First Program Compiling the Program Making Mistakes Understanding the Program Adding Comments Improving the Program and Build Process The make Program Compiler Flags How the Compiler Works Behind the Scenes The Preprocessor The Compiler The Assembler The Linker Adding to Your Makefile Summary Questions Chapter 2: Introduction to the Integrated Development Environment Using System Workbench for STM32 Starting the IDE Creating Hello World Debugging the Program What the IDE Did for Us Importing the Book’s Programming Examples Summary Programming Problems Questions Chapter 3: Programming the Microcontroller The NUCLEO-F030R8 Development Board Programming and Debugging the Board Setting Up the Board Setting Up an Embedded Project Your First Embedded Program Initializing the Hardware Programming a GPIO Pin Toggling the LED Building the Completed Program Exploring the Build Process Exploring the Project Files Debugging the Application Stepping Through the Program Summary Programming Problems Questions Chapter 4: Numbers and Variables Working with Integers Declaring Variables to Hold Integers Assigning Values to Variables Initializing Variables Integer Sizes and Representations Number Representations Standard Integers Unsigned Integer Types Overflow Two’s Complement Representation in Signed Integer Types Shorthand Operators Controlling Memory-Mapped I/O Registers Using Bit Operations OR AND NOT Exclusive OR Shifting Defining the Meaning of Bits Setting the Values of Two Bits at Once Turning Off a Bit Checking the Values of Bits Summary Programming Problems Chapter 5: Decision and Control Statements The if Statement The if/else Statement Looping Statements The while Loop The for Loop Using the Button Initialization Choosing a Pulldown Circuit Getting the State of the Button Running the Program Loop Control The break Statement The continue Statement Anti-patterns The Empty while Loop Assignment in while Summary Programming Problems Chapter 6: Arrays, Pointers, and Strings Arrays Under the Hood: Pointers Array and Pointer Arithmetic Array Overflow Characters and Strings Summary Programming Problems Chapter 7: Local Variables and Procedures Local Variables Hidden Variables Procedures Stack Frames Recursion Programming Style Summary Programming Problems Chapter 8: Complex Data Types Enums Preprocessor Tricks and Enums Structures Structures in Memory Accessing Unaligned Data Structure Initialization Structure Assignment Structure Pointers Structure Naming Unions Creating a Custom Type Structures and Embedded Programming typedef Function Pointers and typedef typedef and struct Summary Programming Problems Chapter 9: Serial Output on the STM Writing a String One Character at a Time Defining Our Own putchar Serial Output A Brief History of Serial Communications Serial Hello World! UART Initialization Transmitting a Character Communicating with the Device Windows Linux and macOS Summary Programming Problems Chapter 10: Interrupts Polling vs. Interrupts Interrupts for Serial I/O Interrupt Routines Writing a String with Interrupts Program Details Interrupt Hell Using a Buffer to Increase Speed Sending Function Interrupt Routine Full Program The Problem Summary Programming Problems Chapter 11: The Linker The Linker’s Job Compilation and Linking Memory Models The Ideal C Model Nonstandard Sections The Linking Process Symbols Defined by the Linker Relocation and Linking Object Files The Linker Map Advanced Linker Usage Flash Memory for “Permanent” Storage Multiple Configuration Items Field Customization Example Firmware Upgrade Summary Programming Problems Chapter 12: The Preprocessor Simple Macros Parameterized Macros Code Macros Conditional Compilation Where Symbols Get Defined Command Line Symbols Predefined Symbols Include Files Other Preprocessor Directives Preprocessor Tricks Summary Programming Problems Part II: C for Big Machines Chapter 13: Dynamic Memory Basic Heap Allocation and Deallocation Linked Lists Adding a Node Printing the Linked List Deleting a Node Putting It All Together Dynamic Memory Problems Valgrind and the GCC Address Sanitizer Summary Programming Problems Chapter 14: Buffered File I/O The printf Function Writing the ASCII Table Writing to Predefined Files Reading Data The Evil gets Function Opening Files Binary I/O Copying a File Buffering and Flushing Closing Files Summary Programming Problems Chapter 15: Command Line Arguments and Raw I/O Command Line Arguments Raw I/O Using Raw I/O Using Binary Mode ioctl Summary Programming Problems Chapter 16: Floating-Point Numbers What Is a Floating-Point Number? Floating-Point Types Automatic Conversions Problems with Floating-Point Numbers Rounding Errors Digits of Precision Infinity, NaN, and Subnormal Numbers Implementation Alternatives Summary Programming Problems Chapter 17: Modular Programming Simple Modules Problems with the Simple Module Making the Module What Makes Good Modules Namespaces Libraries ranlib and Library Linking Deterministic vs. Nondeterministic Libraries Weak Symbols Summary Programming Problems Afterword Learn How to Write Learn How to Read Collaboration and Creative Theft Useful Open Source Tools Cppcheck Doxygen Valgrind SQLite Never Stop Learning Appendix: Project Creation Checklist Native C Project STM32 Workbench Embedded Project Index
Donate to keep this site alive
How to download source code?
1. Go to: https://nostarch.com/
2. Search the book title: Bare Metal C: Embedded Programming for the Real World
, sometime you may not get the results, please search the main title
3. Click the book title in the search results
3. Download the Source Code.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.