Setup
table of contents
Traditions…
Writing a "Hello, World!"
program is a time-honored tradition that continues to be relevant today. This simple program serves as a sanity check before diving into more complex tasks. It allows you to test your coding environment and ensure everything is functioning correctly. Interestingly, some folks also consider this program to be a harbinger of good luck.
Oh! Where are my manners? Here is a very quick setup tour to begin with. Moreover, Don’t forget to check out Mastering STM32. This books is a good resource to familiarize with the STM32 environment and would be considered as one of the most comprehensive introductory book in the STM32 domain.
Quick Setup Tour
-
Compiler
andMSYS2
: Since we’re using C as our primary language, you’ll need a compiler, specifically GCC. However, don’t just download GCC by itself; opt for MSYS2 for a more complete environment. Even if you’re not using Visual Studio, they offer a helpful guide for this setup. -
Download and setup
CubeIDE
,CubeMX
, andCubeProgrammer
:- CubeIDE: Our base IDE for generating HAL codes.
- CubeMX: Our configuration tool that will be our trusty companion throughout the project.
- CubeProgrammer: While CubeIDE is a valuable tool, it’s based on the older Eclipse platform that has since gone open source. You might want to complement it with your favorite text editor or integrated development environment (IDE) for more modern development experiences.
- Text Editor or IDE: While CubeIDE is a valuable tool, it’s based on the older Eclipse platform that has since gone open source. You might want to complement it with your favorite text editor or integrated development environment (IDE) for more modern development experiences.
NOTE
During my experimentation with various development tools, I would like to recommend you to stick with your favorite IDE. My favorite one is Clion as it integrates well with CMake, in which I will use a template to automate CMake file during the projects. However, for your convenience, you’ll still need STM’s software. For example, I generate codes using CubeIDE and then switch back to CLion. If configurations need adjustments, I can rely on CubeMX to assist me in the process.
Creating the First Program
- Launch
CubeIDE
- Go to
File > New > STM32 Project
. - In the target selection part, navigate to
Board Selector
. - Enter your Commercial Part Number (for example, mine was
STM32F407G-DISC1
). - Select your board from the list.
- Click
Next
. - Provide a
Project Name
and ClickNext
- In the
Code Generator Options
, choose the option that saysCopy only the necessary library files
. - Click
Finish
. - Ensure that the option to Initialize all peripherals with their
Default Mode
is set to Yes.
Now, you should see your Pinout Configuration tab in CubeIDE.
- In CubeIDE, open the
Pinout Configuration
tab, which is opened by default. This tab displays your microprocessor’s default pin configuration, with some peripherals already configured and named for your convenience. - Check the
Clock Configuration
tab, where you’ll find clock settings already configured. - Next, navigate to
Project Manager
, and on the left-hand side, selectCode Generator
. - In the On
Generated File
section, opt forGenerate peripheral initialization as a pair of '.c/.h' files per peripheral
.
With these essentials in place and the recommended reading, you’re well-equipped to embark on your embedded systems journey. Keep in mind that the following sections won’t delve into every detail, but they’ll provide you with a solid foundation.