Essential Tools for Learning STM32: A Comprehensive Guide

This Article Includes:

1. STM32Cube Ecosystem

2. CubeMX

3. CubeIDE

4. CubeProg

5. Developing with CubeIDE

5.1 STM32CubeIDE Home

5.2 Project Creation

5.3 Program Download

6. Conclusion

1. STM32Cube Ecosystem

I remember trying CubeMX when ST first launched it. Back then, the automatically generated peripheral initialization code had some small errors. Now, with the iterative upgrades of this system, the Cube ecosystem has become more complete and easier to use.

The STM32Cube Ecosystem provided by ST offers a complete set of free development software tools and embedded software packages, which include functions from peripheral configuration to program development, program downloading, and system monitoring. As shown in the figure below:

Essential Tools for Learning STM32: A Comprehensive Guide
▲STM32Cube Ecosystem
  • STM32 CubeMX can initialize configuration code for almost all STM32 devices. This is a graphical configuration software developed based on Java, which can automatically generate the necessary C code for Cortex-M and can also generate device trees for Cortex-A cores that support Linux systems.

  • STM32 CubeIDE is a free integrated development environment launched by ST, based on Eclipse and GNU C/C++ open-source toolchain, which can compile and debug code. The official also integrated STM32 CubeMX into IDE, making the entire software configuration and development seamless and very convenient.
  • STM32CubeProgrammer is a software programming tool that supports reading and writing devices and external memory via (JTAG, SWD, UART, USB DFU, I2C, SPI, CAN) and more.
  • STM32CubeMonitor series tools. This powerful monitoring tool can help developers fine-tune the behavior and performance of their applications in real time. I haven’t tried this yet, but I’ll trust the official claims for now.

Therefore, using the above ST Cube family for STM32 software development, there are still many pitfalls to climb through in practice. The overall process is basically as follows:

Essential Tools for Learning STM32: A Comprehensive Guide
▲Development Process
  • Step 1: Use CubeMX to initialize the corresponding chip peripheral functions, etc.

  • Step 2: Use CubeIDE for code editing and debugging. Of course, if you prefer, you can also use IAR, Keil, or VSCode. This is completely based on personal preference and habits. However, it is said that CubeIDE integrates CubeMX, which is quite appealing. Plus, if you want to use the gcc compiler, it saves a lot of configuration hassle.
  • Step 3: Use CubeProgrammer for program burning, which mainly supports many protocols, and it feels like they are boasting quite a bit.
  • Step 4: More functional plugins may come out in the future, but currently, they don’t seem very necessary.

2. CubeMX

The installation of STM32 CubeMX is very simple, but you need to submit an email to download, and you can complete it according to the system prompts. Additionally, the code automatically generated by STM32 CubeMX currently supports the official HAL library and LL library, while the standard peripheral library that the author often used before has been abandoned by ST, and the latest STM32F7 does not support the standard peripheral library anymore.

At the same time, CubeMX initializes and generates C code projects, and the final project can be compatible with IAR, Keil MDK, and GCC. Therefore, this is quite convenient, as you don’t have to deal with registers according to the manual, nor do you need to port the official standard peripheral library demo. It is truly where you don’t understand, you just point and click.

  • The encapsulation of HAL library is relatively good, but the code is a bit verbose. It has good universality and portability, in line with software engineering design principles, but will sacrifice some efficiency.
  • The LL library is lower level. The choice between these two still depends on personal preference and team needs.

3. CubeIDE

Download and install CubeIDE from the official website. Assuming you have successfully installed and opened the software, you will see:

Essential Tools for Learning STM32: A Comprehensive Guide

CubeIDE has integrated CubeMX, and you can quickly start a new STM32 project step by step.

4. CubeProg

Looking at the introduction of STM32 CubeProg, it is actually quite good. First, this software supports multiple platforms such as: Windows, Linux, macOS, etc. It is developed in Java, and this series is mostly developed in Java. Additionally, it may have better support for st-link. If you use jlink, using openocd is also fine, but after all, it is a suite. Below are some simple points:

  • Supports erasing, reading, and writing Flash and other operations;
  • Supports Motorola S19, HEX, ELF, and binary formats;
  • Firmware upgrades for ST-LINK;
  • Multi-platform: Windows, Linux, macOS, this is really a strong point.

5. Developing with CubeIDE

Quickly create STM32 HAL library projects using STM32CubeIDE.

(1) STM32CubeIDE Home

Go to the official download page, select the corresponding operating system and version, and download and install. The download page is as follows:

Essential Tools for Learning STM32: A Comprehensive Guide
▲Download Page

Address: https://www.st.com/en/development-tools/stm32cubeide.html

After installation, opening STM32CubeIDE will directly take you to the homepage, where you can start creating STM32 projects or importing projects, as shown in the figure below:

Essential Tools for Learning STM32: A Comprehensive Guide

Read STM32CubeIDE Documentation has a wealth of official documents; you can quickly get started, including:

  • Installation tutorials;
  • User manuals;

(2) Project Creation

Essential Tools for Learning STM32: A Comprehensive Guide

After setting the project name and path, you have basically completed the project creation, as shown in the figure below:

Essential Tools for Learning STM32: A Comprehensive Guide
▲Project Creation

During this period, it may connect to download library files and corresponding MCU peripheral files, so keep the network smooth and be patient.

After successfully creating the project, as shown in the figure below:

Essential Tools for Learning STM32: A Comprehensive Guide

You can see that the left side is the HAL library, and the right side is the CubeMAX configuration interface. Thus, the project generation is complete, and the next step is to compile and download.

Additionally, in the file list, you can see the TEST.ioc file, which is the configuration file for CubeMAX, equivalent to an ini file for some software. CubeMAX mainly saves and loads device configurations by reading and writing this file, and you can see specific information by opening it with a text editor, as shown below:

#MicroXplorer Configuration settings - do not modify
FREERTOS.IPParameters=Tasks01
FREERTOS.Tasks01=defaultTask,0,128,StartDefaultTask,Default,NULL
File.Version=6
KeepUserPlacement=false
Mcu.Family=STM32F1
Mcu.IP0=FREERTOS
Mcu.IP1=NVIC
Mcu.IP2=RCC
Mcu.IP3=SYS
Mcu.IPNb=4
Mcu.Name=STM32F103Z(C-D-E)Tx
Mcu.Package=LQFP144
Mcu.Pin0=VP_FREERTOS_VS_CMSIS_V1
Mcu.Pin1=VP_SYS_VS_ND
Mcu.Pin2=VP_SYS_VS_Systick
Mcu.PinsNb=3
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F103ZETx
MxCube.Version=5.3.0
MxDb.Version=DB.5.0.30
NVIC.BusFault_IRQn=true:0:0:false:false:true:false:false:false
NVIC.DebugMonitor_IRQn=true:0:0:false:false:true:false:false:false
NVIC.HardFault_IRQn=true:0:0:false:false:true:false:false:false
NVIC.MemoryManagement_IRQn=true:0:0:false:false:true:false:false:false
NVIC.NonMaskableInt_IRQn=true:0:0:false:false:true:false:false:false
NVIC.PendSV_IRQn=true:15:0:false:false:false:true:false:false
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.SVCall_IRQn=true:0:0:false:false:false:false:false:false
NVIC.SysTick_IRQn=true:15:0:false:false:true:true:false:true
NVIC.UsageFault_IRQn=true:0:0:false:false:true:false:false:false
PCC.Checker=false
PCC.Line=STM32F103
PCC.MCU=STM32F103Z(C-D-E)Tx
PCC.PartNumber=STM32F103ZETx
PCC.Seq0=0
PCC.Series=STM32F1
PCC.Temperature=25
PCC.Vdd=3.3
PinOutPanel.RotationAngle=0
ProjectManager.AskForMigrate=true
ProjectManager.BackupPrevious=false
ProjectManager.CompilerOptimize=6
ProjectManager.ComputerToolchain=false
ProjectManager.CoupleFile=false
ProjectManager.CustomerFirmwarePackage=
ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=true
ProjectManager.DeviceId=STM32F103ZETx
ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.0
ProjectManager.FreePins=false
ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true
ProjectManager.LibraryCopy=1
ProjectManager.MainLocation=Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=
ProjectManager.ProjectBuild=false
ProjectManager.ProjectFileName=TEST.ioc
ProjectManager.ProjectName=TEST
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false
RCC.APB1Freq_Value=8000000
RCC.APB2Freq_Value=8000000
RCC.FamilyName=M
RCC.IPParameters=APB1Freq_Value,APB2Freq_Value,FamilyName,PLLCLKFreq_Value,PLLMCOFreq_Value,TimSysFreq_Value
RCC.PLLCLKFreq_Value=8000000
RCC.PLLMCOFreq_Value=4000000
RCC.TimSysFreq_Value=8000000
VP_FREERTOS_VS_CMSIS_V1.Mode=CMSIS_V1
VP_FREERTOS_VS_CMSIS_V1.Signal=FREERTOS_VS_CMSIS_V1
VP_SYS_VS_ND.Mode=No_Debug
VP_SYS_VS_ND.Signal=SYS_VS_ND
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
board=custom
isbadioc=false

You don’t need to worry too much about this, as you can configure it through a graphical interface, and the software will automatically modify this configuration file.

(3) Program Download

You can directly click the hammer icon in the toolbar:

Essential Tools for Learning STM32: A Comprehensive Guide
▲Build

Quickly build, and it will automatically generate the elf file, which is the file that the emulator can burn; then you can directly view the Build information in the window, including errors, etc., as shown below:

12:52:59 **** Incremental Build of configuration Debug for project TEST ****
make -j4 all 
arm-none-eabi-gcc "../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DSTM32F103xE -DUSE_HAL_DRIVER -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.d" -MT"Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.o"
...
Finished building target: TEST.elf
 
arm-none-eabi-objdump -h -S  TEST.elf  > "TEST.list"
arm-none-eabi-size   TEST.elf 
   text    data     bss     dec     hex filename
   3860      20    8228   12108    2f4c TEST.elf
Finished building: default.size.stdout

Click the bug icon in the toolbar:

Essential Tools for Learning STM32: A Comprehensive Guide
▲Debug

To debug:

Essential Tools for Learning STM32: A Comprehensive Guide
▲Toolbar

In the menu bar, find Run options and locate Debug Configurations, as shown in the figure below, configure the emulator and interface method for debugging, and finally click Debug to download TEST.elf to the target.

Essential Tools for Learning STM32: A Comprehensive Guide
▲Debugger Configuration

After successfully starting the debug, as shown in the figure below:

Essential Tools for Learning STM32: A Comprehensive Guide
▲Start Debugging

6. Conclusion

I have briefly learned and introduced Cube. There are still many pitfalls to climb, and I recommend looking at the encapsulation of HAL, and if necessary, you can also check LL. Overall, it still conforms to the CMSIS standards.
Additionally, regarding the development environment, if you need to use CubeIDE for development, it has already integrated CubeMAX, so you don’t need to download it separately; you can complete everything in one stop. However, if you only need to generate initialization code, it is still necessary to install CubeMAX separately.
Essential Tools for Learning STM32: A Comprehensive Guide

END

Source: Xiaomai Dashu
Copyright belongs to the original author. If there is any infringement, please contact for deletion.
Recommended Reading
Secretly revealing the year-end bonus situation of various companies (latest version)
After reading these C language examples, you will definitely say five “wow”!
What is the principle of the recently popular electronic blood oxygen meter? Is it accurate?

→ Follow for more updates ←

Leave a Comment

×