-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Bare-Metal Embedded C Programming
By :
In this section, we will explore the essential tools that form the backbone of our development process. Understanding these tools is important, as they will be our companions in transforming ideas into functioning firmware.
When selecting tools for firmware development, we have two primary options.
These IDEs boast a GUI-centric design, enabling users to conveniently create new files, build, compile, and step through code lines interactively. For the demonstrations and exercises in this book, we’ll use the STM32CubeIDE. It has all the requisite features and is generously available for free, without any code size constraints.
assemble, compile, and link are often used. In this book, we’ll use the open source GNU Arm Embedded Toolchain. Based on the renowned open source GNU Compiler Collection (GCC), this integrates a GCC compiler tailored for ARM, the GNU Debugger (GDB) debugger, and several other invaluable utilities.In the following section, we will carefully go through the process of setting up our preferred IDE, the STM32CubeIDE.
Throughout this book, we’ll use both the STM32CubeIDE and the GNU Arm Embedded Toolchain to develop our firmware. Leveraging an IDE such as STM32CubeIDE enables us to easily analyze and compare the linker script and startup files, autogenerated by the IDE, against those we’ll construct from the ground up.
Let’s start by downloading and installing STM32CubeIDE:
Figure 1.1: The home page of st.com
Figure 1.2: The All software versions section of the stm32cubeide page
.zip file will be downloaded into your Downloads folder.Let’s install the STM32CubeIDE:
st-stm32cubeide file to initiate the installer.
Figure 1.3: The installer showing the Choose Components page
Having successfully installed STM32CubeIDE on our computer, we will now proceed to configure our alternate development tool, the GNU Arm Embedded Toolchain.
In this section, we will go through the process of setting up the GNU Arm Embedded Toolchain – an important tool for developing firmware for ARM-based microcontrollers:
.exe version. For Linux or macOS users, choose the corresponding .tar file for your operating system.
Figure 1.4: The GNU Arm Embedded Toolchain installer
Figure 1.5: The installer showing the Add path to environment variable option
For firmware development with the GNU Arm Toolchain, OpenOCD plays an integral role, facilitating both the downloading of firmware into our microcontroller and the debugging of code in real time.
Let’s set up OpenOCD:
Figure 1.6: The Unofficial binary packages section
Figure 1.7: The OpenOCD packages
win32-x64.zip version. For Linux or macOS users, download the corresponding .tar file for your operating system.bin subfolder. Here, you’ll find the openocd.exe application. This is the application we shall call in the command prompt together with the specific script of our chosen microcontroller, in order to debug or download code onto the microcontroller.Within the xpack-openocd-0.12.0-2 | openocd | scripts directory structure, you’ll find scripts tailored for various microcontrollers and development boards.
Next, we need to add OpenOCD to our environment variables:
openocd folder to your Program Files directory.
Figure 1.8: OpenOCD moved to Program Files, showing the path to the bin folder
openocd bin folder.
Figure 1.9: The This PC properties page
Figure 1.10: The System Properties pop-up window
Figure 1.11: The Environment Variables popup
Figure 1.12: The Edit environment variable popup
Finally, we have successfully completed the setup process. We have configured two essential, standalone tools to develop firmware for STM32 microcontrollers – the STM32CubeIDE for an IDE, and the GNU Arm Embedded Toolchain, complemented by OpenOCD, to develop and debug our firmware without an IDE.
Next, we will turn our attention to our development board.