I welcome all lovers of programming, microcontrollers, and electronics in general to our website! In this article I’ll tell you a little about what we will be doing here, namely about the training course on ARM microcontrollers.

So, first, let’s figure out what you need to know and be able to do to start learning ARMs. But, in principle, nothing super complicated and enchanting 😉 Of course, people usually switch to ARM controllers after having already played enough with PICs and AVRs, that is, most of them are experienced developers. But I will try to describe in as much detail and clearly as possible everything that we will analyze, so that those who decided to try their hand at programming microcontrollers for the first time can easily understand the material. By the way, if you have any questions, or if something simply doesn’t work as intended, write in the comments, I’ll try to figure it out and help.

Now let's move on to technical issues) I have already mentioned the name “ARM Training Course” several times, but, by and large, this is not entirely true. There is no such thing as an ARM microcontroller. There is a controller with an ARM core(!), but this, you see, is still not the same thing. So, such devices are produced by a number of companies, among which STMicroelectronics and NXP Semiconductors stand out. Accordingly, they produce STM and LPC controllers. I opted for the STM32, I just liked them better =) It’s very captivating with STM that once you’ve dealt with any MK from the STM32F10x line, you won’t have any problems with any other. One line – one datasheet. By the way, there are a huge number of both expensive and not so expensive development boards with STM32 controllers, which is very pleasing, although at first we will debug our programs in a simulator to evaluate the capabilities of the controller before buying hardware. Here, just in case, is the official website of STMicroelectronics -.

Somehow we moved smoothly onto the topic of the compiler, so I’ll say a few words about it. Without thinking twice, I chose Keil, not least because of the powerful built-in simulator. You can look at the UART there, and at any register, and even a logic analyzer is available. In a word, Keil left me with mostly only pleasant impressions, although there are some disadvantages, of course, but not catastrophic. So you can safely download Keil uvision4 from off. site(). True, there is one BUT - the IDE is paid, but a demo mode is available with a code limit of 32 kB, which is more than enough for us for now. For whom this is not enough, there are a huge number of cracks for Keil 😉 Everything is installed without problems - we poke further a couple of times and everything installs perfectly and works without additional dances with a tambourine.

Actually, that’s all I wanted to tell you here, it’s time to move from words to action, but that’s in the next article. We will learn programming STM32 microcontrollers from scratch!

All pictures in this article are clickable.

Microcontrollers contain an ARM microprocessor core, more precisely ARM Cortex-M. This core is inherent not only in STM32 microcontrollers, it exists on its own, and many microcontrollers from different manufacturers are produced based on it.

Then we find this microcontroller in the list on the left and install the corresponding DFP package:

You may notice that among the installed packages there is CMSIS. CMSIS is a library for the Cortex-M core, common to all microcontrollers. The library is developed by ARM and is available for downloading from the official website after registration. It would be possible not to install this package, but to use the official release of the library, but these are additional complications.

Close the package manager and launch Keil uVision5 (pronounced mu-vision):

Keil uVision5 is part of MDK-ARM, a GUI environment that includes a code editor:

  1. UTF-8 encoding.
  2. The right code limit is 80 characters.
  3. Indent by 4 spaces.

These settings are quite controversial. Each developer has his own preferences.

Now let's create a project. To do this, select the menu “Project -> New uVision Project...”. In the window that opens, select the location and name of the project. It is better to create a separate folder for the project and save the project there.

After saving, a device selection window will appear. Select the desired microcontroller and click “OK”. If we had not installed the required package, the microcontroller would not be in the list:

In the next window you have to select the components that will be used in the project. You must select “CMSIS:CORE” and “Device:Startup”:

After clicking “OK” the project creation process will be completed.

In the future, you can always launch the component selection window to add or remove them. To do this, select the menu “Project -> Manage -> Run-Time Environment...”.

When you select components, you may find that a component depends on other components that you did not select. You will learn about this from the messages at the bottom of the window. You will need to select dependent components.

After creating a project in the described way, in the window on the right you will see the following project structure:

Here we see the project name “example”, the project goal “Target 1”, the empty file group “Source Group 1”, the CMSIS and Device components.

There can be any number of project goals. The goal includes the most important project settings including microcontroller selection. Goals are needed so that you can build a program in different ways for the same source code files. For example, you may need your project to span multiple microcontrollers.

File groups are needed to nicely group source code files. Groups help you easily navigate through files in a large project. For example, you might have a group of files responsible for LEDs, and a separate group with files for interacting with USB.

In the structure we see two files. One with an "s" extension. It contains source code in assembly language. Another with the extension "c". It contains source code in C language.

You can build the project and get the firmware file by pressing the F7 key. But in this form the project will not be built and you will receive an error because the “main()” function is missing.

The "main()" function is the entry point to your program, where the program begins. Its presence is mandatory if you write a program in C.

Let's create this function. Right-click on the “Source Group 1” group and select “Add New Item to ‘Source Group 1’...” (translation: add a new item to ‘Source Group 1’). Let's create a file "main.c":

Add the code to the created file:

Int main() ( return 0; )

You should add an empty line to the end of the file, otherwise during assembly you will receive a warning “warning: #1-D: last line of file ends without a newline”.

Now the project can be assembled using the F7 key. As a result, you will get the file “Objects\example.axf” (by default the file name is the same as the project name). The file is located in the project folder.

Typically the developer requires a firmware file in Intel HEX format. To get it, you need to configure the goal. To see the target settings, press Alt-F7, go to the "Output" tab and select "Create HEX File".

After the next build, you will receive the file “Objects\example.hex”.

Now the program does nothing, and there is no point in flashing it. Let's write a program that controls the state of the microcontroller pin.

Let's start selecting components using the menu “Project -> Manage -> Run-Time Environment...” and select the component “Device: STM32Cube Hal: GPIO”.

At the bottom of the window we will see the unsatisfied dependency “Device:STM32Cube Hal:Common”. Let's select this component and see an even larger list of dependencies. You must select all required dependencies:

  • Device:STM32Cube Hal:Common
  • Device:STM32Cube Hal:RCC
  • Device:STM32Cube Hal:PWR
  • Device:STM32Cube Hal:Cortex
  • Device:STM32Cube Framework:Classic

STM32Cube is a library provided by STMicroelectronics.

When choosing components, we choose which features of this library to use.

The microcontroller, in addition to the core, contains a large number of peripheral devices: ADC, DAC, timers, various interfaces and much more. Each peripheral device has its own name. For example, a device for working with microcontroller ports is called GPIO; you can learn about this from the documentation for the microcontroller.

The STM32Cube library is multi-level, that is, it includes many intermediate libraries. One of the intermediate libraries is called STM32Cube HAL, or simply HAL. It is divided into modules and each module corresponds to a peripheral device. The name of the module matches the name of the device, for example, there is a GPIO module.

There is a large amount of documentation for the STM32Cube. But the basic description of working with peripheral devices is contained in. This is the guide the developer uses most of the time. Let's turn to it to make the legs of the microcontroller move.

First, let’s connect the HAL in our program by adding a line before the definition of the “main()” function:

#include "stm32f4xx_hal.h"

At the very beginning of the “main()” function, we call the “HAL_Init()” function, which initializes the library.

This way we will get the following code in the "main.c" file:

#include "stm32f4xx_hal.h" int main() ( HAL_Init(); return 0; )

To be continued…

At this point I am forced to interrupt my article, since at the moment I have nothing to debug the program on, that is, I do not have a debug board at hand.

I wrote a program that is assembled and theoretically should work, but I do not want to mislead the reader. I consider the above material to be useful without any final result.

#include "stm32f4xx_hal.h" int main() ( HAL_Init(); // Enable clocking of port A. __HAL_RCC_GPIOA_CLK_ENABLE(); // Port settings. GPIO_InitTypeDef s; s.Pin = GPIO_PIN_0; // Output 0. s.Mode = GPIO_MODE_OUTPUT_PP; // Digital output. s.Pull = GPIO_NOPULL; // No pullup. s.Speed ​​= GPIO_SPEED_FREQ_VERY_HIGH; // Maximum speed. // Set up pin 0 port A. HAL_GPIO_Init(GPIOA, &s); // Infinitely toggle the port state with maximum speed. while(1) ( HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0); ) //return 0; ) void SysTick_Handler(void) ( HAL_IncTick(); )

Links

  1. Screencast " Eclipse and GNU Tools for development for ARM microcontrollers «.
  2. Microcontroller STM32F407VG.
  3. Development board STM32F4-Discovery.
  4. Library STM32CubeF4.

In recent years, 32-bit microcontrollers (MCUs) based on ARM processors have been rapidly conquering the world of electronics. This breakthrough is due to their high performance, advanced architecture, low energy consumption, low cost and advanced programming tools.

SHORT STORY
The name ARM is an acronym for Advanced RISC Machines, where RISC (Reduced Instruction Set Computer) stands for reduced instruction set processor architecture. The overwhelming number of popular microcontrollers, such as the PIC and AVR families, also have a RISC architecture, which has increased performance by simplifying the decoding of instructions and accelerating their execution. The emergence of advanced and productive 32-bit ARM microcontrollers allows us to move on to solving more complex problems that 8 and 16-bit MCUs can no longer cope with. The ARM microprocessor architecture with a 32-bit core and RISC instruction set was developed by the British company ARM Ltd, which exclusively develops kernels, compilers and debugging tools. The company does not produce MKs, but sells licenses for their production. MK ARM is one of the fastest growing segments of the MK market. These devices use energy-saving technologies, so they are widely used in embedded systems and dominate the market for mobile devices for which low power consumption is important. In addition, ARM microcontrollers are actively used in communications, portable and embedded devices where high performance is required. A feature of the ARM architecture is the computing core of the processor, which is not equipped with any additional elements. Each processor developer must independently equip this core with the necessary blocks for their specific tasks. This approach has worked well for large chip manufacturers, although it was initially focused on classic processor solutions. ARM processors have already gone through several stages of development and are well known for the ARM7, ARM9, ARM11 and Cortex families. The latter is divided into subfamilies of classic CortexA processors, CortexR real-time processors and CortexM microprocessor cores. It was the CortexM cores that became the basis for the development of a large class of 32-bit MCUs. They differ from other variants of the Cortex architecture primarily in the use of the 16-bit Thumb2 instruction set. This set combined the performance and compactness of “classic” ARM and Thumb instructions and was developed specifically for working with the C and C++ languages, which significantly improves code quality. The great advantage of microcontrollers built on the CortexM core is their software compatibility, which theoretically allows the use of high-level language program code in models from different manufacturers. In addition to indicating the area of ​​application of the core, MK developers indicate the performance of the CortexM core on a ten-point scale. Today, the most popular options are CortexM3 and CortexM4. MCUs with ARM architecture are produced by companies such as Analog Devices, Atmel, Xilinx, Altera, Cirrus Logic, Intel, Marvell, NXP, STMicroelectronics, Samsung, LG, MediaTek, MStar, Qualcomm, SonyEricsson, Texas Instruments, nVidia, Freescale, Milander, HiSilicon and others.
Thanks to the optimized architecture, the cost of MCUs based on the CortexM core is in some cases even lower than that of many 8-bit devices. “Younger” models can currently be purchased for 30 rubles. for the body, which creates competition for previous generations of MK. STM32 MICROCONTROLLERS Let's consider the most affordable and widespread MCU of the STM32F100 family from STMicroelectronics, which is one of the world's leading manufacturers of MCUs. The company recently announced the start of production of a 32-bit MK that takes advantage of industrial
STM32 cores in low-cost applications. MCUs of the STM32F100 Value line family are designed for devices where the performance of 16-bit MCUs is not enough, and the rich functionality of “regular” 32-bit devices is redundant. The STM32F100 line of MCUs is based on a modern ARM CortexM3 core with peripherals optimized for use in typical applications where 16-bit MCUs were used. The performance of the STM32F100 MCU at 24 MHz is superior to most 16-bit MCUs. This line includes devices with various parameters:
● from 16 to 128 kbytes of program flash memory;
● from 4 to 8 kbytes of RAM;
● up to 80 GPIO input/output ports;
● up to nine 16-bit timers with advanced functions;
● two watchdog timers;
● 16-channel high-speed 12-bit ADC;
● two 12-bit DACs with built-in signal generators;
● up to three UART interfaces supporting IrDA, LIN and ISO7816 modes;
● up to two SPI interfaces;
● up to two I2C interfaces supporting SMBus and PMBus modes;
● 7-channel direct memory access (DMA);
● CEC (Consumer Electronics Control) interface included in the HDMI standard;
● real time clock (RTC);
● NVIC nested interrupt controller.

The functional diagram of the STM32F100 is shown in Figure 1.

Rice. 1. Architecture of the MK line STM32F100

An additional convenience is the pin compatibility of the devices, which allows, if necessary, to use any MK of the family with greater functionality and memory without reworking the printed circuit board. The STM32F100 line of controllers is produced in three types of packages LQFP48, LQFP64 and LQFP100, having 48, 64 and 100 pins, respectively. The assignment of the pins is presented in Figures 2, 3 and 4. Such cases can be installed on printed circuit boards without the use of special equipment, which is a significant factor in small-scale production.


Rice. 2. STM32 MCU in LQFP48 package Fig. 3. STM32 MCU in LQFP64 package


Rice. 4. STM32 MCU in LQFP100 package

STM32F100 is an affordable and optimized device based on the CortexM3 core, supported by an advanced development environment for the STM32 family of microcontrollers, which contains
Free libraries for all peripherals, including motor control and touch keyboards.

CONNECTION DIAGRAM STM32F100C4
Let's consider the practical use of MK using the example of the simplest STM32F100C4 device, which, nevertheless, contains all the main blocks of the STM32F100 line. The electrical circuit diagram of the STM32F100C4 is shown in Figure 5.


Rice. 5. Connection diagram for MK STM32F100C4

Capacitor C1 ensures that the MK is reset when the power is turned on, and capacitors C2-C6 filter the supply voltage. Resistors R1 and R2 limit the signal current of the MK pins. The internal oscillator is used as the clock source, so there is no need to use an external crystal.


Inputs BOOT0 and BOOT1 allow you to select the method of loading the MK when turning on the power in accordance with the table. The BOOT0 input is connected to the zero potential bus through resistor R2, which protects the BOOT0 pin from a short circuit when used as an output port of PB2. Using connector J1 and one jumper, you can change the potential at the BOOT0 input, thereby determining how the MK is loaded - from flash memory or from the built-in bootloader. If you need to load the MK from RAM, a similar connector with a jumper can be connected to the BOOT1 input.
Programming of the MK is carried out via the UART1 serial port or through special programmers - JTAG or STLink debuggers. The latter is part of the popular debugging device STM32VLDISCOVERY, shown in Figure 6. On the STM32VLDIS COVERY board, the 4-pin connector of the programmer - STLink debugger - is designated SWD. The author of the article suggests programming the MK via the UART1 serial port, since it is much simpler, does not require special equipment and is not inferior in speed to JTAG or ST Link. Any personal computer (PC) that has a serial COM port or a USB port with a USBRS232 converter can be used as a control device capable of generating commands and displaying the results of the MK program, as well as as a programmer.

To interface the COM port of a PC with a MK, any converter of RS232 signals into logical signal levels from 0 to 3.3 V, for example, the ADM3232 microcircuit, is suitable. The TXD transmission line of the computer serial port, after the level converter, should be connected to the PA10 input of the microcontroller, and the RXD receiver line, through a similar converter, to the PA9 output.

If you need to use a non-volatile MK clock, you should connect a CR2032 battery with a voltage of 3 V and a quartz resonator with a frequency of 32768 Hz to it. For this purpose, the MK is equipped with Vbat/GND and OSC32_IN/OSC32_OUT pins. The Vbat pin must first be disconnected from the 3.3 V power bus.

The remaining free terminals of the MK can be used as needed. To do this, they should be connected to the connectors that are located around the perimeter of the printed circuit board for the MK, by analogy with the popular Arduino devices and the STM32VLDISCOVERY debug board.


Rice. 6. Debug device STM32VLDISCOVERY


Electrical circuit diagram STM32VLDISCOVERY.

Thus, depending on the purpose and method of using the MK, you can connect the necessary elements to it to use other functional blocks and ports, for example, ADC, DAC, SPI, I2C, etc. In the future, these devices will be considered in more detail.

PROGRAMMING
Today, many companies offer tools for creating and debugging programs for STM32 microcontrollers. These include Keil from ARM Ltd, IAR Embedded Workbench for ARM, Atol lic TrueStudio, CooCox IDE, GCC and Eclipse IDE. The developer can choose the software according to his preference. Below we will describe the Keil uVision 4 toolkit from the company Keil, which supports a huge number of types of microcontrollers, has a developed system of debugging tools and can be used for free with restrictions on the size of the generated code of 32 kbytes (which, in fact, is the maximum for the microcontrollers under consideration).

Easy and quick start with CooCox CoIDE.

So let's get started. Go to the official CooCox website and download the latest version of CooCox CoIDE. To download you need to register, registration is simple and free. Then install the downloaded file and run it.

CooCox CoIDE- a development environment based on Eclipse, which, in addition to STM32, supports a bunch of other families of microcontrollers: Freescale, Holtek, NXP, Nuvoton, TI, Atmel SAM, Energy Micro, etc. With each new version of CoIDE, the list of microcontrollers is constantly updated. After successfully installing CoIDE, run:

The Step 1 start window will appear, in which you need to select the manufacturer of our microcontroller. Press ST and go to Step 2 (selecting a microcontroller), in which you need to select a specific model. We have STM32F100RBT6B, so click on the corresponding model:

On the right, the Help window displays brief characteristics of each chip. After selecting the microcontroller we need, we proceed to the third step, Step 3 - to selecting the necessary libraries for work:

Let's create a simple project for blinking an LED, as is customary for learning microcontrollers.

To do this, we need the GPIO library, when enabled, CoIDE will ask you to create a new project. Click Yes on this proposal, indicate the folder where our project will be stored and its name. At the same time, CoIDE will connect to the project 3 others necessary for the library to work, and will also create all the necessary project structure:

Another good thing about CoIDE is that it has the ability to load examples directly into the development environment. In the Components tab you can see that there are examples for almost every library, click on GPIO (with 4 examples) and see them:

You can add your own examples there. As you can see in the screenshot above, the examples already contain code for blinking the GPIO_Blink LED. You can click the add button and it will be added to the project, but as an included file, so we will do it differently and simply copy the entire example code into the main.c file. The only thing is to replace the void GPIO_Blink(void) line with int main(void). So, press F7 (or select Project->Build from the menu) to compile the project and... no such luck!

The environment needs a GCC compiler, but we don't have one. Therefore, go to the GNU Tools for ARM Embedded Processors page, select your OS type on the right and download the latest version of the toolchain. Then we run the file and install gcc toolchain. Next, in the CoIDE settings we will indicate the correct path to the toolchain:

Press F7 again (Project->Build) and see that the compilation was successful:

All that remains is to flash the microcontroller. To do this, we connect our board to the computer using USB. Then, in the debugger settings you need to install ST-Link; to do this, select Project->Configuration in the menu and open the Debugger tab. Select ST-Link from the drop-down list and close the window:

Let's try to flash the MK. In the menu, select Flash->Program Download (or click on the corresponding icon on the toolbar) and see that the MK has been successfully flashed:

We see a blinking LED on the board, I think it makes no sense to provide a video or photo, because... everyone saw it.

Also, various debugging modes work in CoIDE; to do this, press CTRL+F5 (or in the Debug->Debug menu):

That's all. As you can see, setting up and working with CoIDE is very simple. I hope this article will encourage you to study very promising and inexpensive STM32 microcontrollers.

One of the reasons for the popularity of microcontrollers STM32 production STMicroelectronics– a variety of development and debugging tools. This applies to both hardware and software. It is possible to create and debug resident software for STM32 without material costs using a kit free programs. The article provides an overview of the most significant free software development tools: ST MCU Finder, STM32CubeMX, SW4STM32, STM32 Studio.

Company STMicroelectronics(ST) is the largest manufacturer of microcontrollers in the world, with the majority of them coming from the STM32 family. When developing new lines of controllers, STMicroelectronics pursues several strategic goals:

  • productivity increase;
  • increasing the level of integration: increasing memory capacity, expanding the list of peripherals;
  • reduction in consumption;
  • cost reduction.

It is obvious to any engineer that these goals are often mutually exclusive. For this reason, STMicroelectronics produces families and lines of microcontrollers with an emphasis on one or another of the above properties. Currently, the range includes ten families, each of which has its own advantages and occupies a certain niche in the market (Figure 1).

Let's give a brief description of the STM32 microcontroller families from ST.

Low-power microcontrollers of the STM32L families. This group unites families focused primarily on achieving a minimum level of consumption. For this, various methods are used: dynamic control of the supply voltage, a flexible clocking system, specialized peripherals (LP-Timer, LP-UART), a developed system of low-consumption modes, and so on.

Basic families STM32F0, STM32F1, STM32F3. This group includes families with balanced characteristics and a compromise in performance/consumption/price.

In turn, individual STMCube packages include:

  • hardware-independent HAL libraries for working with microcontroller hardware;
  • middle-level libraries. For example, as part of the most advanced software package STM32CubeF7 includes the following libraries and stacks: CMSIS-RTOS based on FreeRTOS, TCP/IP stack based on LwIP, FAT file system based on FatFs with NAND Flash support, StemWin - graphics stack based on SEGGER emWin, full USB stack (Host and Device). A Touch Library for touch applications is available for a number of families;
  • examples and project templates for various environments and debugging kits (Discovery, Nucleo, Evaluation Boards).

To understand how the components of the STM32Cube software platform interact, refer to the example presented in Figure 9. In this example, the user configures the microcontroller using STM32CubeMX. After completing the visual setup (pins, clocking, etc.), the STM32CubeMX generates C code, using libraries from the STM32CubeF4 software package. As a result, the user receives a complete C project generated for a specific integrated development environment: IAR™ EWARM, Keil™MDK-ARM, Atollic® TrueSTUDIO and AC6 System Workbench (SW4STM32). This project already includes all the necessary libraries and files.

The STM32CubeMX program greatly simplifies the work of programmers, but its possibilities are not unlimited. Before moving further, it is worth noting the existing limitations:

  • the generated C code covers only the configuration of the blocks and peripherals of the microcontroller. This means that the algorithmic part of the program cannot be generated automatically; it will need to be added manually;
  • STM32CubeMX will help you create only the starting configuration. Sometimes during operation the user needs to change the operating frequency of a peripheral unit or change the output configuration. You will have to prescribe all this yourself;
  • standard low-level libraries (HAL and LL) and intermediate level libraries, for example, StemWin or STM32_USB_Device_Library, are used to generate code;
  • During the generation process, the C file is built in such a way that special sections are allocated for the user in which he can place his code. If the user code is outside this framework, it will be overwritten in subsequent generations;
  • There are other block-specific limitations, which should be discussed in more detail in the STM32CubeMX manual.

Now that the composition, principle of operation and limitations of the STM32CubeMX are described, we can give an example of working with this program, create a “skeleton” of a simple project and demonstrate the operation of individual utilities.

Creating a simple program using STM32CubeMX

Let's take a closer look at creating a project skeleton in the STM32CubeMX environment. First you need to download the STM32CubeMX environment itself. This can be done absolutely free from the ST website. After installation, both the STM32CubeMX itself and folders with STM32Cube libraries will be located on the user’s disk.

The process of creating a project skeleton is carried out in steps.

Step one. Downloading current versions of libraries using a special utility. To do this, you first need to configure the network settings (Help → Updater Settings) and then run automatic updates (Help → Check for Updates). If the PC is not connected to the network, you will have to update the libraries manually.

Step two. After launching the STM32CubeMX on the start screen or in the “File” menu, you need to create a new project by clicking “New Project”. Next, STM32CubeMX will prompt you to select the target platform: a controller with the specified parameters or a debug board. Figure 10 shows, as an example, how the built-in search selected a list of controllers according to the following parameters: STM32F4 family, TQFP100 package, Flash volume of at least 592 KB, RAM more than 214 KB.

Step three. At the third stage, the developer will have to determine the purpose of the pins using the Pin Wizard (Figure 11). This utility helps you create the required configuration and check it for errors. It is worth noting the convenient lighting system, for example, the system pins are painted pale yellow.

Step four. The clock system is configured using the Clock Configuration tab (Clock Wizard utility). In this case, the user works with a visualized clock tree (Figure 12). With the help of Clock Wizard, you can select the source of the system clock signal, the values ​​of determinants and multipliers, as well as the clock sources of peripheral blocks in a few mouse clicks. If you wrote the code manually, this would require a lot of effort.

Step five. Creating C code begins with selecting the target framework in the project settings (Project → Settings). Currently available to the user: IAR™ EWARM, Keil™MDK-ARM, Atollic® TrueSTUDIO and AC6 System Workbench (SW4STM32) (Figure 13). Next, on the Code Generator tab, you should decide on the composition of the libraries copied to the project directory, settings for processing user code during regeneration (for example, save or delete), settings for using HAL (Figure 13).

For more detailed settings of the generator, go to the Advanced Settings tab (Figure 14). The main feature of the C-generator in the STM32CubeMX is the ability to use both HAL and LL drivers. This point should be discussed in more detail.

HAL is a set of abstract drivers that provide maximum cross-platform compatibility among STM32 controllers. At the same time, some drivers are absolutely universal (suitable for all STM32 controllers), while some are applicable only to individual lines with corresponding peripheral blocks (for example, encryption blocks). The main advantages of HAL are:

  • maximum cross-platform;
  • functional orientation. These drivers are not designed to work with individual controller blocks, but to perform specific tasks. This makes it possible to work not with registers, but with meaningful functions;
  • no deep knowledge of microcontroller architecture is required.

At the same time, HAL also has disadvantages: a significant amount of code, insufficient optimization of task execution, and relatively low performance. If these shortcomings are critical, then LL drivers should be used.

Low Layer APIs (LL) are hardware-dependent drivers that allow you to directly work with controller peripherals, including using inline functions and performing atomic access to registers. This approach does not require significant memory expenditure, the functions are as short and speed efficient as possible. The obvious disadvantages of LL drivers are reduced code compatibility when moving from one controller to another and the need for in-depth knowledge of the controller architecture.

Within the same project on STM32CubeMX, you can simultaneously use both HAL and LL, but for different peripheral units. For example, Figure 15 shows the settings of the C-generator, in which LL drivers are used for UART/TIM/RTC, and HAL is used for the remaining blocks.

Step six. After setting up the project, you should generate code by going to the Project → Generate Code menu. As a result, a project skeleton for the specified development environment will be generated in the specified project directory.

Sometimes there is a need to migrate a project from one platform to another. With the help of STM32CubeMX this can be done with minimal time.

Migration of projects using STM32CubeMX

To migrate a project from one platform to another, use the additional utility File → Import Project (Figure 15). It requires you to specify the type of new microcontroller and the migration mode. After this, the program automatically generates new code or, if there is incomplete compatibility of the kernels, indicates the difficulties that have arisen, prompting the user to eliminate them.

Incompatibilities found during migration may or may not be remediable. A fatal case occurs when the peripheral composition of the controllers differs significantly. For example, an Ethernet module was previously used, which is missing on the new MK (Figure 15). Obviously, in this case, migration is impossible.

But often the incompatibility is local in nature, when, for example, it is only necessary to reconfigure the clock tree parameters to match operating frequencies, or change the ADC or DMA channel number, and so on (Figure 16). In such cases, STM32CubeMX will offer to perform the migration manually, eliminating any difficulties that arise by editing the project in the utilities discussed above. In this case, the STM32CubeMX will signal the user about the presence of problems until they are resolved.

After receiving the final skeleton of the project, all that remains is to add the custom algorithmic part of the code, compile and debug. For this purpose, specialized environments are used. AC6's SW4STM32 environment for STM32 allows you to do this absolutely free.

AC6 System Workbench – free IDE for STM32

Special integrated IDEs are designed for editing, compiling and debugging programs. Most of them are commercial products (IAR™ EWARM, Keil™MDK-ARM, Atollic® TrueSTUDIO and others), but there are also free tools, such as AC6's System Workbench. Within the STMicroelectronics naming system, this IDE is called SW4STM32.

The SW4STM32 integrated environment is designed to work with STM32 microcontrollers. It is based on the Eclipse platform and is free and cross-platform. Its main advantages are:

  • support for working with STM32 microcontrollers, hardware debugging kits (STM32 Nucleo, Discovery and Evaluation boards), with software libraries (Standard Peripheral library and STM32Cube HAL);
  • no restrictions on the amount of program code;
  • free GCC C/C++ compiler;
  • free GDB debugger (GNU project);
  • open platform Eclipse IDE with support for group development of embedded software with SVN/GIT version control system;
  • compatibility with Eclipse plugins;
  • ST-LINK support;
  • multiplatform and compatible with Windows®, Linux and OS X®.

With SW4STM32 you can edit, compile and debug STM32 programs. To do this, it is convenient to use program skeletons created in STM32CubeMX. To import them, you need to perform the simplest operations: select the File -> Import menu, assign the import type “Existing Projects into Workspace”, specify the project directory, select the project itself and click Finish.

When working with projects created in STM32CubeMX, you should place custom code in special sections:

/*USER CODE BEGIN…*/

/*USER CODE END…*/

This must be done so that when re-generating code in the STM32CubeMX, the handwritten part of the program will not be overwritten. Regeneration is necessary in two cases:

  • when reconfiguring the used MK;
  • when migrating from one MK to another.

Thus, when working in conjunction with STM32CubeMX + SW4STM32, the user can reconfigure the controller at any time and migrate while preserving user code with minimal time.

When debugging programs in SW4STM32, the ability to widely monitor the state of memory, registers, and variables is available. The environment also has support for breakpoints (Figure 17). To start the debugging process, you need to click the “Debug” icon (in the form of a beetle), select the project type “Ac6 STM32 C/C++ Application”, define the debugger type and interface, and click the “OK” button.

SW4STM32 has support for SVN/GIT version control systems. This is important for large projects with multiple developers working on them. The version control system allows you to: register all changes made in the project; compare project versions; restore previous versions; resolve conflicts when several programmers work on one file; maintain several versions in parallel, and so on.

Within the framework of this article, it makes no sense to delve into the intricacies and differences between SVN and GIT. Let's just say that GIT, being a distributed system, allows programmers to work locally, having a complete project repository on the working machine. GIT also preserves change metadata, making it easier to merge versions and switch between versions. SVN requires a network connection between developers and saves entire files. SW4STM32 provides support for both SVN and GIT.

Let's look at the sequence of actions when connecting a project to SVN (Figure 18).

  • in an open project, right-click on its name in the directory panel and go to Team → Share Project(s) (Figure 18a);
  • select the SVN/GIT system type and click “Next” (Figure 18b);
  • select the directory for SVN and click “Next” (Figure 18c);
  • select the project storage directory in SVN and click “Finish” (Figure 18d);
  • on the “General” tab (Figure 18e) select the SVN URL, repository label, username, password, click “Next”;
  • enter a comment for the project, select the file to be placed under SVN control, click “OK” (Figure 18e).

In the future, to synchronize a file or the entire project, you need to right-click on its name in the directory panel and select Team → Commit. In the window that opens, write an explanation of the changes and click “OK”.

To disable SVN you should use the Team → Disconnect command.

To import a project from SVN, use the menu command Import → SVN → Project from SVN. Next, you need to make a number of import settings in the pop-up dialog boxes.

SW4STM32 has very broad capabilities, but the environment also has disadvantages that are quite typical for free environments:

  • lack of a built-in simulator;
  • the GCC compiler is inferior to its commercial counterparts in terms of code size and performance;
  • developer support for SW4STM32 will not be as prompt as in the case of paid environments.

However, it is worth noting that these shortcomings may not be so critical, especially for simple projects.

Code debugging can be done not only in SW4STM32, but using additional tools. Let's look at some of them.

STMStudio - an easy way to debug applications on STM32

STM Studio– a proprietary utility produced by STMicroelectronics, which helps debugging a program and allows you to track the values ​​of user variables when executing code in real time. This program runs under Windows OS and uses the ST-LINK debugger to communicate with the microcontroller.

STM Studio has the following features:

  • reading variables from RAM “on the fly”, without affecting the operation of the user program;
  • using executable files .elf, .out, .axf to import variables;
  • displaying variable values ​​in tabular and graphical form;
  • graphical output in the form of graphs or charts;
  • the ability to display dependencies of variables when one of the variables is plotted along the X-axis, and the second – along the Y-axis;
  • Logging data to a file for later viewing.

The STM Studio window consists of several panels (Figure 19).

Working with STM Studio begins with importing variables. To do this, you need to load the same executive file into the program that is located in the microcontroller itself. The following formats, which are generated during compilation, are suitable for this: .elf, .out, .axf. Next you need to run the command File → Import variables. In the dialog box, when selecting the “Expand table elements” item, the user will be able to manually select any global variables from the proposed table. To start debugging, you must execute the “Run” command.

As mentioned above, STM Studio allows you to display variables in three forms: text, chart and graph (Figure 20). The display type setting can be changed at any time. In addition, all data is additionally recorded in a log file for further analysis. An interesting feature of STM Studio is the ability to display the dependencies of some variables on others, as well as construct expressions from variables.

A popular means of passing debugging information is to use the console and the printf() output function.

Implementing printf() terminal output via USART

Using the standard printf() function is one of the most popular methods for outputting debugging information. Using this output function, the user can transfer any data to the development environment console or terminal. Most integrated environments support this feature. When using STM32, there are two ways to implement this method: traditional, using UART, and additional, through the SWO interface using the ST-LINK debugger. The implementation of each of them is simplified as much as possible when using STM32CubeMX and SW4STM32.

Let's first consider the first implementation option - via UART. To do this you will have to perform the following sequence of actions:

  • provide a hardware connection to a PC;
  • configure the UART in the STM32CubeMX environment;
  • implement the printf() function itself in the SW4STM32 environment.

Connection to a PC can be done in three ways: through a COM port and an RS-232 transceiver chip; via a USB port and a UART-USB converter chip (for example, FT232); using the ST-LINK USB debugger interface. Regardless of which method is selected, the hardware UART must then be configured.

Using STM32CubeMX, UART configuration is performed in a few clicks (Figure 21). First, on the Pin Wizard tab, the corresponding controller pins are switched to UART operating mode. Next, in the “Configuration” tab, UART parameters are configured: exchange type, speed, presence of stop bits, and so on. After this, a C code is generated.

In the SW4STM32 environment, you need to include the standard library and define the _io_putchar() and _write() functions, for example, like this:

/*USER CODE BEGIN Includes*/

#include

/*USER CODE END Includes*/

/*USER CODE BEGIN 1*/

int __io_putchar(int ch)

c = ch & 0x00FF;

HAL_UART_Transmit(&huart2,&*c,1,10);

int _write(int file, char *ptr, int len)

for (DataIdx = 0; DataIdx< len; DataIdx++)

The advantages of this approach to transmitting debugging information can be considered:

  • use of the UART interface, which is present in all STM32 microcontrollers without exception;
  • ease of setup and familiarity for programmers. You can use old developments from projects with other controllers;
  • lack of complex hardware (except for the UART-USB bridge or RS-232 transceiver);
  • lack of complex software. Works with all IDE or terminal programs.

However, this method also has disadvantages. Firstly, you will have to sacrifice the UART channel for debugging. And secondly, such an implementation affects the operation of the controller, since it takes up the core to process the printf() function code. In the case of STM32, there is a more specialized, and most importantly, simpler method that does not take up microcontroller resources - using a combination of SWO and ST-LINK.

Implementing printf() terminal output via SWO

When using a combination of SWO and ST-LINK, creating terminal I/O is even simpler than in the method discussed above with hardware UART. In this case, communication with the PC is carried out through the SWO interface and the USB interface used in ST-LINK. The sequence of actions remains approximately the same as in the previous case.

First, using the STM32CubeMX, the SWO interface pins are configured in the “Pin Wizard” and “Configuration” tabs (Figure 22). After this, the code for the development environment is regenerated.

The next step is to write code for the __io_putchar(int ch) handler, like this:

/*USER CODE BEGIN 1*/

int __io_putchar(int ch)

ITM_SendChar(ch);

/*USER CODE END 1*/

For debugging it is convenient to use the STLink Utility utility (Figure 23).

Advantages of the method:

  • does not require additional resources and does not occupy communication interfaces;
  • works in parallel with the main program and does not affect the speed of its execution, since it does not use the kernel for calculations;
  • an ideal choice for debugging kits with ST-LINK on board, as it represents a ready-made solution.

Among the disadvantages of this implementation method, one can note the hardware dependence, since ST-LINK is required.

Conclusion

STMicroelectronics produces more than seven hundred models of STM32 microcontrollers, which differ in performance/consumption/price/level of integration. Each user will be able to choose the optimal model taking into account the requirements of a specific application.

An important advantage of the STM32 is the presence of a developed system of debugging tools. More than one hundred debugging boards (Nucleo, Discovery, Evaluation Boards) are offered to developers. An even greater help for programmers will be the availability of a complete set of free application software for creating, compiling and debugging program code:

ST MCU Finder is an application for smartphones that helps you choose the most optimal MCU for a specific application;

STM32CubeMX is a cross-platform graphical editor for configuring STM32 microcontrollers and automatically generating code. STM32CubeMX is also able to provide assistance in choosing the optimal microcontroller, estimating power consumption and simplifying project migration between different MCUs.

SW4STM32 is a cross-platform integrated software development environment for STM32 microcontrollers.

STM32 Studio is a utility for tracking and graphically visualizing variable values ​​while executing code in real time.

ST-LINK Utility allows you, together with the ST-Link programmer, to enter and output debugging information through the SWO interface.

This set of software allows you to complete the full development cycle of resident software without spending a single ruble.

Literature

  1. Data brief. NUCLEO-XXXXKX. STM32 Nucleo-32 board. Rev 3. ST Microelectronics, 2016.
  2. Data brief. NUCLEO-XXXXRX. STM32 Nucleo-64 board. Rev 8. ST Microelectronics, 2016.
  3. Data brief. NUCLEO-XXXXZX. STM32 Nucleo-144 board. Rev 5. ST Microelectronics, 2017.
  4. UM1718. User manual. STM32CubeMX for STM32 configuration and initialization C code generation. Rev 18. ST Microelectronics, 2017.
  5. UM1884. User manual. Description of STM32L4 HAL and Low-layer drivers. Rev 5. ST Microelectronics, 2016.
  6. UM1025. User manual. Getting started with STM-STUDIO. Rev6. ST Microelectronics, 2013.
  7. UM0892.User manual STM32 ST-LINK utility software description. Rev 22. ST Microelectronics, 2016.

One of the reasons for the popularity of microcontrollers STM32 production STMicroelectronics– a variety of development and debugging tools. This applies to both hardware and software. It is possible to create and debug resident software for STM32 without material costs using a kit free programs. The article provides an overview of the most significant free software development tools: ST MCU Finder, STM32CubeMX, SW4STM32, STM32 Studio.

Company STMicroelectronics(ST) is the largest manufacturer of microcontrollers in the world, with the majority of them coming from the STM32 family. When developing new lines of controllers, STMicroelectronics pursues several strategic goals:

  • productivity increase;
  • increasing the level of integration: increasing memory capacity, expanding the list of peripherals;
  • reduction in consumption;
  • cost reduction.

It is obvious to any engineer that these goals are often mutually exclusive. For this reason, STMicroelectronics produces families and lines of microcontrollers with an emphasis on one or another of the above properties. Currently, the range includes ten families, each of which has its own advantages and occupies a certain niche in the market (Figure 1).

Let's give a brief description of the STM32 microcontroller families from ST.

Low-power microcontrollers of the STM32L families. This group unites families focused primarily on achieving a minimum level of consumption. For this, various methods are used: dynamic control of the supply voltage, a flexible clocking system, specialized peripherals (LP-Timer, LP-UART), a developed system of low-consumption modes, and so on.

Basic families STM32F0, STM32F1, STM32F3. This group includes families with balanced characteristics and a compromise in performance/consumption/price.

In turn, individual STMCube packages include:

  • hardware-independent HAL libraries for working with microcontroller hardware;
  • middle-level libraries. For example, as part of the most advanced software package STM32CubeF7 includes the following libraries and stacks: CMSIS-RTOS based on FreeRTOS, TCP/IP stack based on LwIP, FAT file system based on FatFs with NAND Flash support, StemWin - graphics stack based on SEGGER emWin, full USB stack (Host and Device). A Touch Library for touch applications is available for a number of families;
  • examples and project templates for various environments and debugging kits (Discovery, Nucleo, Evaluation Boards).

To understand how the components of the STM32Cube software platform interact, refer to the example presented in Figure 9. In this example, the user configures the microcontroller using STM32CubeMX. After completing the visual setup (pins, clocking, etc.), the STM32CubeMX generates C code, using libraries from the STM32CubeF4 software package. As a result, the user receives a complete C project generated for a specific integrated development environment: IAR™ EWARM, Keil™MDK-ARM, Atollic® TrueSTUDIO and AC6 System Workbench (SW4STM32). This project already includes all the necessary libraries and files.

The STM32CubeMX program greatly simplifies the work of programmers, but its possibilities are not unlimited. Before moving further, it is worth noting the existing limitations:

  • the generated C code covers only the configuration of the blocks and peripherals of the microcontroller. This means that the algorithmic part of the program cannot be generated automatically; it will need to be added manually;
  • STM32CubeMX will help you create only the starting configuration. Sometimes during operation the user needs to change the operating frequency of a peripheral unit or change the output configuration. You will have to prescribe all this yourself;
  • standard low-level libraries (HAL and LL) and intermediate level libraries, for example, StemWin or STM32_USB_Device_Library, are used to generate code;
  • During the generation process, the C file is built in such a way that special sections are allocated for the user in which he can place his code. If the user code is outside this framework, it will be overwritten in subsequent generations;
  • There are other block-specific limitations, which should be discussed in more detail in the STM32CubeMX manual.

Now that the composition, principle of operation and limitations of the STM32CubeMX are described, we can give an example of working with this program, create a “skeleton” of a simple project and demonstrate the operation of individual utilities.

Creating a simple program using STM32CubeMX

Let's take a closer look at creating a project skeleton in the STM32CubeMX environment. First you need to download the STM32CubeMX environment itself. This can be done absolutely free from the ST website. After installation, both the STM32CubeMX itself and folders with STM32Cube libraries will be located on the user’s disk.

The process of creating a project skeleton is carried out in steps.

Step one. Downloading current versions of libraries using a special utility. To do this, you first need to configure the network settings (Help → Updater Settings) and then run automatic updates (Help → Check for Updates). If the PC is not connected to the network, you will have to update the libraries manually.

Step two. After launching the STM32CubeMX on the start screen or in the “File” menu, you need to create a new project by clicking “New Project”. Next, STM32CubeMX will prompt you to select the target platform: a controller with the specified parameters or a debug board. Figure 10 shows, as an example, how the built-in search selected a list of controllers according to the following parameters: STM32F4 family, TQFP100 package, Flash volume of at least 592 KB, RAM more than 214 KB.

Step three. At the third stage, the developer will have to determine the purpose of the pins using the Pin Wizard (Figure 11). This utility helps you create the required configuration and check it for errors. It is worth noting the convenient lighting system, for example, the system pins are painted pale yellow.

Step four. The clock system is configured using the Clock Configuration tab (Clock Wizard utility). In this case, the user works with a visualized clock tree (Figure 12). With the help of Clock Wizard, you can select the source of the system clock signal, the values ​​of determinants and multipliers, as well as the clock sources of peripheral blocks in a few mouse clicks. If you wrote the code manually, this would require a lot of effort.

Step five. Creating C code begins with selecting the target framework in the project settings (Project → Settings). Currently available to the user: IAR™ EWARM, Keil™MDK-ARM, Atollic® TrueSTUDIO and AC6 System Workbench (SW4STM32) (Figure 13). Next, on the Code Generator tab, you should decide on the composition of the libraries copied to the project directory, settings for processing user code during regeneration (for example, save or delete), settings for using HAL (Figure 13).

For more detailed settings of the generator, go to the Advanced Settings tab (Figure 14). The main feature of the C-generator in the STM32CubeMX is the ability to use both HAL and LL drivers. This point should be discussed in more detail.

HAL is a set of abstract drivers that provide maximum cross-platform compatibility among STM32 controllers. At the same time, some drivers are absolutely universal (suitable for all STM32 controllers), while some are applicable only to individual lines with corresponding peripheral blocks (for example, encryption blocks). The main advantages of HAL are:

  • maximum cross-platform;
  • functional orientation. These drivers are not designed to work with individual controller blocks, but to perform specific tasks. This makes it possible to work not with registers, but with meaningful functions;
  • no deep knowledge of microcontroller architecture is required.

At the same time, HAL also has disadvantages: a significant amount of code, insufficient optimization of task execution, and relatively low performance. If these shortcomings are critical, then LL drivers should be used.

Low Layer APIs (LL) are hardware-dependent drivers that allow you to directly work with controller peripherals, including using inline functions and performing atomic access to registers. This approach does not require significant memory expenditure, the functions are as short and speed efficient as possible. The obvious disadvantages of LL drivers are reduced code compatibility when moving from one controller to another and the need for in-depth knowledge of the controller architecture.

Within the same project on STM32CubeMX, you can simultaneously use both HAL and LL, but for different peripheral units. For example, Figure 15 shows the settings of the C-generator, in which LL drivers are used for UART/TIM/RTC, and HAL is used for the remaining blocks.

Step six. After setting up the project, you should generate code by going to the Project → Generate Code menu. As a result, a project skeleton for the specified development environment will be generated in the specified project directory.

Sometimes there is a need to migrate a project from one platform to another. With the help of STM32CubeMX this can be done with minimal time.

Migration of projects using STM32CubeMX

To migrate a project from one platform to another, use the additional utility File → Import Project (Figure 15). It requires you to specify the type of new microcontroller and the migration mode. After this, the program automatically generates new code or, if there is incomplete compatibility of the kernels, indicates the difficulties that have arisen, prompting the user to eliminate them.

Incompatibilities found during migration may or may not be remediable. A fatal case occurs when the peripheral composition of the controllers differs significantly. For example, an Ethernet module was previously used, which is missing on the new MK (Figure 15). Obviously, in this case, migration is impossible.

But often the incompatibility is local in nature, when, for example, it is only necessary to reconfigure the clock tree parameters to match operating frequencies, or change the ADC or DMA channel number, and so on (Figure 16). In such cases, STM32CubeMX will offer to perform the migration manually, eliminating any difficulties that arise by editing the project in the utilities discussed above. In this case, the STM32CubeMX will signal the user about the presence of problems until they are resolved.

After receiving the final skeleton of the project, all that remains is to add the custom algorithmic part of the code, compile and debug. For this purpose, specialized environments are used. AC6's SW4STM32 environment for STM32 allows you to do this absolutely free.

AC6 System Workbench – free IDE for STM32

Special integrated IDEs are designed for editing, compiling and debugging programs. Most of them are commercial products (IAR™ EWARM, Keil™MDK-ARM, Atollic® TrueSTUDIO and others), but there are also free tools, such as AC6's System Workbench. Within the STMicroelectronics naming system, this IDE is called SW4STM32.

The SW4STM32 integrated environment is designed to work with STM32 microcontrollers. It is based on the Eclipse platform and is free and cross-platform. Its main advantages are:

  • support for working with STM32 microcontrollers, hardware debugging kits (STM32 Nucleo, Discovery and Evaluation boards), with software libraries (Standard Peripheral library and STM32Cube HAL);
  • no restrictions on the amount of program code;
  • free GCC C/C++ compiler;
  • free GDB debugger (GNU project);
  • open platform Eclipse IDE with support for group development of embedded software with SVN/GIT version control system;
  • compatibility with Eclipse plugins;
  • ST-LINK support;
  • multiplatform and compatible with Windows®, Linux and OS X®.

With SW4STM32 you can edit, compile and debug STM32 programs. To do this, it is convenient to use program skeletons created in STM32CubeMX. To import them, you need to perform the simplest operations: select the File -> Import menu, assign the import type “Existing Projects into Workspace”, specify the project directory, select the project itself and click Finish.

When working with projects created in STM32CubeMX, you should place custom code in special sections:

/*USER CODE BEGIN…*/

/*USER CODE END…*/

This must be done so that when re-generating code in the STM32CubeMX, the handwritten part of the program will not be overwritten. Regeneration is necessary in two cases:

  • when reconfiguring the used MK;
  • when migrating from one MK to another.

Thus, when working in conjunction with STM32CubeMX + SW4STM32, the user can reconfigure the controller at any time and migrate while preserving user code with minimal time.

When debugging programs in SW4STM32, the ability to widely monitor the state of memory, registers, and variables is available. The environment also has support for breakpoints (Figure 17). To start the debugging process, you need to click the “Debug” icon (in the form of a beetle), select the project type “Ac6 STM32 C/C++ Application”, define the debugger type and interface, and click the “OK” button.

SW4STM32 has support for SVN/GIT version control systems. This is important for large projects with multiple developers working on them. The version control system allows you to: register all changes made in the project; compare project versions; restore previous versions; resolve conflicts when several programmers work on one file; maintain several versions in parallel, and so on.

Within the framework of this article, it makes no sense to delve into the intricacies and differences between SVN and GIT. Let's just say that GIT, being a distributed system, allows programmers to work locally, having a complete project repository on the working machine. GIT also preserves change metadata, making it easier to merge versions and switch between versions. SVN requires a network connection between developers and saves entire files. SW4STM32 provides support for both SVN and GIT.

Let's look at the sequence of actions when connecting a project to SVN (Figure 18).

  • in an open project, right-click on its name in the directory panel and go to Team → Share Project(s) (Figure 18a);
  • select the SVN/GIT system type and click “Next” (Figure 18b);
  • select the directory for SVN and click “Next” (Figure 18c);
  • select the project storage directory in SVN and click “Finish” (Figure 18d);
  • on the “General” tab (Figure 18e) select the SVN URL, repository label, username, password, click “Next”;
  • enter a comment for the project, select the file to be placed under SVN control, click “OK” (Figure 18e).

In the future, to synchronize a file or the entire project, you need to right-click on its name in the directory panel and select Team → Commit. In the window that opens, write an explanation of the changes and click “OK”.

To disable SVN you should use the Team → Disconnect command.

To import a project from SVN, use the menu command Import → SVN → Project from SVN. Next, you need to make a number of import settings in the pop-up dialog boxes.

SW4STM32 has very broad capabilities, but the environment also has disadvantages that are quite typical for free environments:

  • lack of a built-in simulator;
  • the GCC compiler is inferior to its commercial counterparts in terms of code size and performance;
  • developer support for SW4STM32 will not be as prompt as in the case of paid environments.

However, it is worth noting that these shortcomings may not be so critical, especially for simple projects.

Code debugging can be done not only in SW4STM32, but using additional tools. Let's look at some of them.

STMStudio - an easy way to debug applications on STM32

STM Studio– a proprietary utility produced by STMicroelectronics, which helps debugging a program and allows you to track the values ​​of user variables when executing code in real time. This program runs under Windows OS and uses the ST-LINK debugger to communicate with the microcontroller.

STM Studio has the following features:

  • reading variables from RAM “on the fly”, without affecting the operation of the user program;
  • using executable files .elf, .out, .axf to import variables;
  • displaying variable values ​​in tabular and graphical form;
  • graphical output in the form of graphs or charts;
  • the ability to display dependencies of variables when one of the variables is plotted along the X-axis, and the second – along the Y-axis;
  • Logging data to a file for later viewing.

The STM Studio window consists of several panels (Figure 19).

Working with STM Studio begins with importing variables. To do this, you need to load the same executive file into the program that is located in the microcontroller itself. The following formats, which are generated during compilation, are suitable for this: .elf, .out, .axf. Next you need to run the command File → Import variables. In the dialog box, when selecting the “Expand table elements” item, the user will be able to manually select any global variables from the proposed table. To start debugging, you must execute the “Run” command.

As mentioned above, STM Studio allows you to display variables in three forms: text, chart and graph (Figure 20). The display type setting can be changed at any time. In addition, all data is additionally recorded in a log file for further analysis. An interesting feature of STM Studio is the ability to display the dependencies of some variables on others, as well as construct expressions from variables.

A popular means of passing debugging information is to use the console and the printf() output function.

Implementing printf() terminal output via USART

Using the standard printf() function is one of the most popular methods for outputting debugging information. Using this output function, the user can transfer any data to the development environment console or terminal. Most integrated environments support this feature. When using STM32, there are two ways to implement this method: traditional, using UART, and additional, through the SWO interface using the ST-LINK debugger. The implementation of each of them is simplified as much as possible when using STM32CubeMX and SW4STM32.

Let's first consider the first implementation option - via UART. To do this you will have to perform the following sequence of actions:

  • provide a hardware connection to a PC;
  • configure the UART in the STM32CubeMX environment;
  • implement the printf() function itself in the SW4STM32 environment.

Connection to a PC can be done in three ways: through a COM port and an RS-232 transceiver chip; via a USB port and a UART-USB converter chip (for example, FT232); using the ST-LINK USB debugger interface. Regardless of which method is selected, the hardware UART must then be configured.

Using STM32CubeMX, UART configuration is performed in a few clicks (Figure 21). First, on the Pin Wizard tab, the corresponding controller pins are switched to UART operating mode. Next, in the “Configuration” tab, UART parameters are configured: exchange type, speed, presence of stop bits, and so on. After this, a C code is generated.

In the SW4STM32 environment, you need to include the standard library and define the _io_putchar() and _write() functions, for example, like this:

/*USER CODE BEGIN Includes*/

#include

/*USER CODE END Includes*/

/*USER CODE BEGIN 1*/

int __io_putchar(int ch)

c = ch & 0x00FF;

HAL_UART_Transmit(&huart2,&*c,1,10);

int _write(int file, char *ptr, int len)

for (DataIdx = 0; DataIdx< len; DataIdx++)

The advantages of this approach to transmitting debugging information can be considered:

  • use of the UART interface, which is present in all STM32 microcontrollers without exception;
  • ease of setup and familiarity for programmers. You can use old developments from projects with other controllers;
  • lack of complex hardware (except for the UART-USB bridge or RS-232 transceiver);
  • lack of complex software. Works with all IDE or terminal programs.

However, this method also has disadvantages. Firstly, you will have to sacrifice the UART channel for debugging. And secondly, such an implementation affects the operation of the controller, since it takes up the core to process the printf() function code. In the case of STM32, there is a more specialized, and most importantly, simpler method that does not take up microcontroller resources - using a combination of SWO and ST-LINK.

Implementing printf() terminal output via SWO

When using a combination of SWO and ST-LINK, creating terminal I/O is even simpler than in the method discussed above with hardware UART. In this case, communication with the PC is carried out through the SWO interface and the USB interface used in ST-LINK. The sequence of actions remains approximately the same as in the previous case.

First, using the STM32CubeMX, the SWO interface pins are configured in the “Pin Wizard” and “Configuration” tabs (Figure 22). After this, the code for the development environment is regenerated.

The next step is to write code for the __io_putchar(int ch) handler, like this:

/*USER CODE BEGIN 1*/

int __io_putchar(int ch)

ITM_SendChar(ch);

/*USER CODE END 1*/

For debugging it is convenient to use the STLink Utility utility (Figure 23).

Advantages of the method:

  • does not require additional resources and does not occupy communication interfaces;
  • works in parallel with the main program and does not affect the speed of its execution, since it does not use the kernel for calculations;
  • an ideal choice for debugging kits with ST-LINK on board, as it represents a ready-made solution.

Among the disadvantages of this implementation method, one can note the hardware dependence, since ST-LINK is required.

Conclusion

STMicroelectronics produces more than seven hundred models of STM32 microcontrollers, which differ in performance/consumption/price/level of integration. Each user will be able to choose the optimal model taking into account the requirements of a specific application.

An important advantage of the STM32 is the presence of a developed system of debugging tools. More than one hundred debugging boards (Nucleo, Discovery, Evaluation Boards) are offered to developers. An even greater help for programmers will be the availability of a complete set of free application software for creating, compiling and debugging program code:

ST MCU Finder is an application for smartphones that helps you choose the most optimal MCU for a specific application;

STM32CubeMX is a cross-platform graphical editor for configuring STM32 microcontrollers and automatically generating code. STM32CubeMX is also able to provide assistance in choosing the optimal microcontroller, estimating power consumption and simplifying project migration between different MCUs.

SW4STM32 is a cross-platform integrated software development environment for STM32 microcontrollers.

STM32 Studio is a utility for tracking and graphically visualizing variable values ​​while executing code in real time.

ST-LINK Utility allows you, together with the ST-Link programmer, to enter and output debugging information through the SWO interface.

This set of software allows you to complete the full development cycle of resident software without spending a single ruble.

Literature

  1. Data brief. NUCLEO-XXXXKX. STM32 Nucleo-32 board. Rev 3. ST Microelectronics, 2016.
  2. Data brief. NUCLEO-XXXXRX. STM32 Nucleo-64 board. Rev 8. ST Microelectronics, 2016.
  3. Data brief. NUCLEO-XXXXZX. STM32 Nucleo-144 board. Rev 5. ST Microelectronics, 2017.
  4. UM1718. User manual. STM32CubeMX for STM32 configuration and initialization C code generation. Rev 18. ST Microelectronics, 2017.
  5. UM1884. User manual. Description of STM32L4 HAL and Low-layer drivers. Rev 5. ST Microelectronics, 2016.
  6. UM1025. User manual. Getting started with STM-STUDIO. Rev6. ST Microelectronics, 2013.
  7. UM0892.User manual STM32 ST-LINK utility software description. Rev 22. ST Microelectronics, 2016.