Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Bare-Metal Embedded C Programming
Bare-Metal Embedded C Programming

Bare-Metal Embedded C Programming: Develop high-performance embedded systems with C for Arm microcontrollers

Arrow left icon
Profile Icon Israel Gbati
Arrow right icon
$22.99 $33.99
eBook Sep 2024 438 pages 1st Edition
eBook
$22.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Israel Gbati
Arrow right icon
$22.99 $33.99
eBook Sep 2024 438 pages 1st Edition
eBook
$22.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$22.99 $33.99
Paperback
$41.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Bare-Metal Embedded C Programming

Constructing Peripheral Registers from Memory Addresses

Bare-metal programming is all about working directly with the registers in the microcontroller without going through a library, allowing us to gain a deeper understanding of the microcontroller’s capabilities and limitations. This approach enables us to optimize our firmware for speed and efficiency, which are two very important parameters in embedded systems where resources are often limited.

In this chapter, our journey begins with an exploration of various firmware development methodologies, highlighting the different levels of abstraction each offers. We then proceed to learn how to identify the ports and pins associated with key components on our development board. This step is crucial for establishing a proper interface with the microcontroller’s peripherals.

Next, we delve into defining the addresses of some peripherals using the microcontroller’s official documentation. This will allow us to...

Technical requirements

All the code examples for this chapter can be found on GitHub at https://github.com/PacktPublishing/Bare-Metal-Embedded-C-Programming.

The different types of firmware development

There are several ways to develop the firmware for a particular microcontroller depending on the resources provided by the microcontroller’s manufacturer. When it comes to developing firmware for STM32 microcontrollers from STMicroelectronics, we can use the following:

  • Hardware Abstraction Layer (HAL): This is a library provided by STMicroelectronics. It simplifies the process by offering high-level APIs for configuring every aspect of the microcontroller. What is great about HAL is its portability. We can write code for one STM32 microcontroller, and easily adapt it for another, thanks to the uniformity of their APIs.
  • Low Layer (LL): Also from STMicroelectronics, the LL library is a leaner alternative to HAL, offering a faster, more expert-oriented approach that’s closer to the hardware.
  • Bare-Metal C programming: With this approach, we dive right into the hardware, accessing the microcontroller’s registers...

Locating and understanding the development board’s components

In this section, our focus is to pinpoint the specific ports and pins on the microcontroller to which the user LED, user push button, berg pins, and Arduino-compatible headers are connected on the development board. Understanding these connections is crucial for our programming tasks. To accurately identify these connections, we will consult the NUCLEO-F411 User Manual.

Figure 2.2: Development board showing components of interest

Figure 2.2: Development board showing components of interest

Now, let’s locate the microcontroller pin connected to the User LED on the development board.

Locating the LED connection

Our first step is to navigate through the table of contents to find the section dedicated to LEDs. This can be done quickly by locating Figure 2.3 in the manual, which shows the page number for the LEDs section and allows us to jump directly to it.

Click on the page number to jump to the LEDs section.

Figure 2.3: This is the part of the NUCLEO-F411 User Manual’s table of contents showing the page number of the LEDs section
...

Defining and creating registers through documentation insights

In the previous section, we established that the User LED is connected to pin PA5. This means that it is linked to pin number 5 on GPIO PORTA. In other words, to get to the LED, we have to go through PORTA and then locate pin number 5 of that port.

As illustrated in Figure 2.10, the microcontroller has exposed pins on all four sides. These pins are organized into distinct groups known as ports. For instance, pins in PORTA are denoted with the PA prefix, while those in PORTB start with PB, and so forth. This systematic arrangement allows us to easily identify and access specific pins for programming and hardware interfacing tasks.

Figure 2.10: STM32F411 pinout

Figure 2.10: STM32F411 pinout

In the next section, we will go through the steps to locate the precise address of GPIO PORTA.

Locating GPIO PORTA

To effectively interact with any part of our microcontroller, it’s essential to know the memory address...

Register manipulation – from configuration to running your first firmware

In this section, we will apply the knowledge acquired throughout this chapter to develop our first bare-metal firmware.

We begin by creating a new project, a process we covered in Chapter 1. Here is a summary of the steps:

  1. Start a new project: Go to File | New | STM32 Project in your IDE.
  2. Select the target microcontroller: A Target Selection window will appear, prompting you to choose the microcontroller or development board for your project.
  3. Use the board selector: Click on the Board Selector tab.
  4. Search for our board: Input NUCLEO-F411 in the Commercial Part Number field.
  5. Select our board: From the list of boards that appear, choose NUCLEO-F411RE and then click Next.
  6. Name our project: Assign a name to your project, for instance, RegisterManipulation.
  7. Project configuration: In the project options, select an Empty project setup.
  8. Final step: Click Finish to create...

Summary

In this chapter, we delved into the core of bare-metal programming, emphasizing the direct interaction with microcontroller registers. This gave us insight into some of the key registers of our microcontroller and the structure of those registers.

We began by exploring various firmware development approaches, each offering a distinct level of abstraction. These approaches included the HAL, LL, Bare-Metal C programming, and the assembly language. This exploration helped us understand the trade-offs and applications of each approach in firmware development.

We spent a significant part of the chapter defining addresses of some peripherals using the official documentation. This step was important in creating addresses for various registers within those peripherals. It involved gathering specific memory addresses, typecasting them for register access, and creating aliases for bits in the registers.

The chapter culminated in a practical application where we configured PA5...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn to develop bare-metal firmware for Arm microcontrollers from scratch
  • Understand hardware intricacies to minimize your dependency on third-party libraries
  • Navigate microcontroller manuals with ease and learn to write optimized code
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Bare-Metal Embedded C Programming takes you on an unparalleled journey to equip you with the skills and knowledge to excel in the world of embedded systems. The author, with over a decade of hands-on experience in engineering, takes a unique, practical approach to teach you how to decode microcontroller datasheets so that you’re able to extract vital information for precise firmware development. Register manipulation will become second nature to you as you learn to craft optimized code from scratch. The book provides in-depth insights into the hardware intricacies of microcontrollers. You'll navigate user manuals and documentation with ease, ensuring a profound understanding of the underlying technology. The true uniqueness of this book lies in its commitment to fostering independent expertise. Instead of simply copy pasting, you'll develop the capability to create firmware with confidence, paving the way for professional-grade mastery. By the end of this book, you'll have honed your skills in reading datasheets, performing register manipulations, and crafting optimized code, as well as gained the confidence needed to navigate hardware intricacies and write optimized firmware independently, making you a proficient and self-reliant embedded systems developer.

Who is this book for?

Whether you're an experienced engineer seeking in-depth expertise in decoding datasheets, precise register manipulations, and creating firmware from scratch, or a software developer transitioning to the embedded systems domain, this book is your comprehensive guide. It equips you with the practical skills needed for confident, independent firmware development, making it an essential resource for professionals and enthusiasts in the field.

What you will learn

  • Decode microcontroller datasheets, enabling precise firmware development
  • Master register manipulations for optimized Arm-based microcontroller firmware creation
  • Discover how to navigate hardware intricacies confidently
  • Find out how to write optimized firmware without any assistance
  • Work on exercises to create bare-metal drivers for GPIO, timers, ADC, UART, SPI, I2C, DMA, and more
  • Design energy-efficient embedded systems with power management techniques

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 30, 2024
Length: 438 pages
Edition : 1st
Language : English
ISBN-13 : 9781835463567
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 30, 2024
Length: 438 pages
Edition : 1st
Language : English
ISBN-13 : 9781835463567
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 125.97
RAG-Driven Generative AI
$43.99
Bare-Metal Embedded C Programming
$41.99
Offensive Security Using Python
$39.99
Total $ 125.97 Stars icon

Table of Contents

20 Chapters
Chapter 1: Setting Up the Tools of the Trade Chevron down icon Chevron up icon
Chapter 2: Constructing Peripheral Registers from Memory Addresses Chevron down icon Chevron up icon
Chapter 3: Understanding the Build Process and Exploring the GNU Toolchain Chevron down icon Chevron up icon
Chapter 4: Developing the Linker Script and Startup File Chevron down icon Chevron up icon
Chapter 5: The “Make” Build System Chevron down icon Chevron up icon
Chapter 6: The Common Microcontroller Software Interface Standard (CMSIS) Chevron down icon Chevron up icon
Chapter 7: The General-Purpose Input/Output (GPIO) Peripheral Chevron down icon Chevron up icon
Chapter 8: System Tick (SysTick) Timer Chevron down icon Chevron up icon
Chapter 9: General-Purpose Timers (TIM) Chevron down icon Chevron up icon
Chapter 10: The Universal Asynchronous Receiver/Transmitter Protocol Chevron down icon Chevron up icon
Chapter 11: Analog-to-Digital Converter (ADC) Chevron down icon Chevron up icon
Chapter 12: Serial Peripheral Interface (SPI) Chevron down icon Chevron up icon
Chapter 13: Inter-Integrated Circuit (I2C) Chevron down icon Chevron up icon
Chapter 14: External Interrupts and Events (EXTI) Chevron down icon Chevron up icon
Chapter 15: The Real-Time Clock (RTC) Chevron down icon Chevron up icon
Chapter 16: Independent Watchdog (IWDG) Chevron down icon Chevron up icon
Chapter 17: Direct Memory Access (DMA) Chevron down icon Chevron up icon
Chapter 18: Power Management and Energy Efficiency in Embedded Systems Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.